diff --git a/README.md b/README.md index 3069aee8..251a7b61 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,9 @@ ### 1: Download the repo and drop it into folder `Assets` ### 2: Add the line below to `Packages/manifest.json` -for version `3.0.1` +for version `3.0.2` ```csharp -"com.virtuesky.sunflower":"https://github.com/VirtueSky/sunflower.git#3.0.1", +"com.virtuesky.sunflower":"https://github.com/VirtueSky/sunflower.git#3.0.2", ``` ## Includes modules diff --git a/VirtueSky/ControlPanel/ConstantPackage.cs b/VirtueSky/ControlPanel/ConstantPackage.cs index eff4620c..218f1a38 100644 --- a/VirtueSky/ControlPanel/ConstantPackage.cs +++ b/VirtueSky/ControlPanel/ConstantPackage.cs @@ -2,7 +2,7 @@ { public class ConstantPackage { - public const string VersionSunflower = "3.0.1"; + public const string VersionSunflower = "3.0.2"; public const string PackageNameInAppPurchase = "com.unity.purchasing"; public const string MaxVersionInAppPurchase = "4.12.2"; public const string PackageNameNewtonsoftJson = "com.unity.nuget.newtonsoft-json"; diff --git a/VirtueSky/Utils/Editor/UnityPackage/max-sdk.unitypackage b/VirtueSky/Utils/Editor/UnityPackage/max-sdk.unitypackage index d20217c0..ed88dcc4 100644 Binary files a/VirtueSky/Utils/Editor/UnityPackage/max-sdk.unitypackage and b/VirtueSky/Utils/Editor/UnityPackage/max-sdk.unitypackage differ diff --git a/VirtueSky/Variables/Runtime/Base_Variable/BaseVariable.cs b/VirtueSky/Variables/Runtime/Base_Variable/BaseVariable.cs index 13001365..34961d82 100644 --- a/VirtueSky/Variables/Runtime/Base_Variable/BaseVariable.cs +++ b/VirtueSky/Variables/Runtime/Base_Variable/BaseVariable.cs @@ -1,6 +1,7 @@ using System; using UnityEditor; using UnityEngine; +using UnityEngine.Serialization; using VirtueSky.DataStorage; using VirtueSky.Events; using VirtueSky.Inspector; @@ -9,13 +10,21 @@ namespace VirtueSky.Variables { public class BaseVariable : BaseEvent, IVariable, ISerializationCallbackReceiver, IGuidVariable { - [ShowIf(nameof(isSetData)), ReadOnly, SerializeField] - protected string id; + [TitleColor("Id", CustomColor.Gold, CustomColor.Aqua), ShowIf(nameof(isSetData)), SerializeField] + private TypeId typeId; - [Tooltip("Set initial value for scriptable variable"), SerializeField] + [ShowIf(nameof(IsShowGuid)), ReadOnly, SerializeField] + protected string guid; + + [ShowIf(nameof(IsShowCustomId)), SerializeField] + private string customId; + + + [TitleColor("Init value", CustomColor.Chartreuse, CustomColor.OrangeVariant), Tooltip("Set initial value for scriptable variable"), SerializeField] protected TType initializeValue; - [Tooltip("Set data into dictionary, if not set data then scriptable variable will action as runtime variable"), + [TitleColor("Save Data", CustomColor.Tomato, CustomColor.MediumSpringGreen), + Tooltip("Set data into dictionary, if not set data then scriptable variable will action as runtime variable"), SerializeField] protected bool isSetData; @@ -24,7 +33,7 @@ public class BaseVariable : BaseEvent, IVariable, ISerializ ShowIf(nameof(isSetData)), SerializeField] protected bool isSaveData; - [Tooltip("Raise event when value is changed"), SerializeField] + [TitleColor("Raise event", CustomColor.DeepSkyBlue, CustomColor.Magenta), Tooltip("Raise event when value is changed"), SerializeField] protected bool isRaiseEvent; [NonSerialized] protected TType runtimeValue; @@ -36,10 +45,22 @@ public class BaseVariable : BaseEvent, IVariable, ISerializ public string Guid { - get => id; - set => id = value; + get => guid; + set => guid = value; + } + + public string CustomId + { + get => customId; + set => customId = value; } + public string Id => typeId switch + { + TypeId.Guid => guid, + _ => customId, + }; + private void OnEnable() { #if UNITY_EDITOR @@ -49,12 +70,12 @@ private void OnEnable() public virtual TType Value { - get => isSetData ? GameData.Get(id, initializeValue) : runtimeValue; + get => isSetData ? GameData.Get(Id, initializeValue) : runtimeValue; set { if (isSetData) { - GameData.Set(id, value); + GameData.Set(Id, value); if (isSaveData) { GameData.Save(); @@ -92,5 +113,14 @@ public override string ToString() { return Value.ToString(); } + + private bool IsShowGuid => isSetData && typeId == TypeId.Guid; + private bool IsShowCustomId => isSetData && typeId == TypeId.CustomId; + } + + public enum TypeId + { + Guid, + CustomId } } \ No newline at end of file diff --git a/VirtueSky/Variables/Runtime/Float_Variable/FloatVariable.cs b/VirtueSky/Variables/Runtime/Float_Variable/FloatVariable.cs index 0c3aabe5..8c31a364 100644 --- a/VirtueSky/Variables/Runtime/Float_Variable/FloatVariable.cs +++ b/VirtueSky/Variables/Runtime/Float_Variable/FloatVariable.cs @@ -42,13 +42,13 @@ public void Add(float value) public override float Value { - get => isSetData ? GameData.Get(id, initializeValue) : runtimeValue; + get => isSetData ? GameData.Get(Id, initializeValue) : runtimeValue; set { var clampedValue = IsClamped ? Mathf.Clamp(value, minMax.x, minMax.y) : value; if (isSetData) { - GameData.Set(id, clampedValue); + GameData.Set(Id, clampedValue); if (isSaveData) { GameData.Save(); diff --git a/VirtueSky/Variables/Runtime/Integer_Variable/IntegerVariable.cs b/VirtueSky/Variables/Runtime/Integer_Variable/IntegerVariable.cs index cff6f18d..932c33f6 100644 --- a/VirtueSky/Variables/Runtime/Integer_Variable/IntegerVariable.cs +++ b/VirtueSky/Variables/Runtime/Integer_Variable/IntegerVariable.cs @@ -41,13 +41,13 @@ public void Add(int value) public override int Value { - get => isSetData ? GameData.Get(id, initializeValue) : runtimeValue; + get => isSetData ? GameData.Get(Id, initializeValue) : runtimeValue; set { var clampedValue = IsClamped ? Mathf.Clamp(value, minMax.x, minMax.y) : value; if (isSetData) { - GameData.Set(id, clampedValue); + GameData.Set(Id, clampedValue); if (isSaveData) { GameData.Save(); diff --git a/package.json b/package.json index 64cbbc3c..e8c2ffe2 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "com.virtuesky.sunflower", "displayName": "Sunflower", "description": "Core ScriptableObject Architecture for building Unity games", - "version": "3.0.1", + "version": "3.0.2", "unity": "2022.3", "category": "virtuesky", "license": "MIT",