Skip to content

Commit

Permalink
Merge pull request #17 from VirtueSky/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
VirtueSky authored Sep 16, 2024
2 parents 0650592 + 19d4b1c commit b06f5b8
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion VirtueSky/ControlPanel/ConstantPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Binary file modified VirtueSky/Utils/Editor/UnityPackage/max-sdk.unitypackage
Binary file not shown.
48 changes: 39 additions & 9 deletions VirtueSky/Variables/Runtime/Base_Variable/BaseVariable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.Serialization;
using VirtueSky.DataStorage;
using VirtueSky.Events;
using VirtueSky.Inspector;
Expand All @@ -9,13 +10,21 @@ namespace VirtueSky.Variables
{
public class BaseVariable<TType> : BaseEvent<TType>, IVariable<TType>, 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;

Expand All @@ -24,7 +33,7 @@ public class BaseVariable<TType> : BaseEvent<TType>, IVariable<TType>, 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;
Expand All @@ -36,10 +45,22 @@ public class BaseVariable<TType> : BaseEvent<TType>, IVariable<TType>, 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
Expand All @@ -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();
Expand Down Expand Up @@ -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
}
}
4 changes: 2 additions & 2 deletions VirtueSky/Variables/Runtime/Float_Variable/FloatVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b06f5b8

Please sign in to comment.