修该json

This commit is contained in:
2025-03-31 11:19:27 +08:00
parent ffcdddbd2a
commit 613e0f7f61
37 changed files with 10 additions and 6 deletions

View File

@@ -0,0 +1,41 @@
using UnityEngine;
namespace Stary.Evo.Example.Counter
{
public interface IAchievementSystem : ISystem
{
}
public class AchievementSystem : AbstractSystem, IAchievementSystem
{
public IArchitecture Architecture { get; set; }
public override void Dispose()
{
}
protected override void OnInit()
{
var counterData = this.GetData<ICounterData>();
var previousCount = counterData.Count.Value;
counterData.Count.Register(newCount =>
{
if (newCount >= 10 && previousCount < 10)
{
Debug.Log("解锁 10 次点击成就");
}
else if (newCount >= 20 && previousCount < 20)
{
Debug.Log("解锁 20 次点击成就");
}
previousCount = newCount;
});
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f241abf86b6647ea93571ad2f92c913a
timeCreated: 1624955512

View File

@@ -0,0 +1,13 @@
namespace Stary.Evo.Example.Counter
{
public class CommandAnd : AbstractCommand
{
protected override void OnExecute()
{
this.GetData<ICounterData>().Count.Value++;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ca5d6aa1e6bbab64dbbdeace6b015b23
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,12 @@
namespace Stary.Evo.Example.Counter
{
public class CommandSub : AbstractCommand
{
protected override void OnExecute()
{
CounterApp.Interface.GetData<ICounterData>().Count.Value--;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b07fd1086f5d247448c730438ab61e75
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
namespace Stary.Evo.Example.Counter
{
public class CounterApp : Architecture<CounterApp>
{
protected override void Init()
{
RegisterSystem<IAchievementSystem>(new AchievementSystem());
RegisterData<ICounterData>(new CounterData());
RegisterUtility<IStorage>(new PlayerPrefsStorage());
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4b9e1b9962882b647b727dc4749d40dd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,32 @@
namespace Stary.Evo.Example.Counter
{
public interface ICounterData : IData
{
BindableProperty<int> Count { get; }
}
public class CounterData : AbstractData, ICounterData
{
public override void Dispose()
{
}
protected override void OnInit()
{
var storage = this.GetUtility<IStorage>();
Count.Value = storage.LoadInt("COUNTER_COUNT", 0);
Count.Register( count => { storage.SaveInt("COUNTER_COUNT", count); });
}
public BindableProperty<int> Count { get; } = new BindableProperty<int>()
{
Value = 0
};
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 10c86a7a3c934d4796a6ec85a27f5a81
timeCreated: 1624948547

View File

@@ -0,0 +1,53 @@
using UnityEngine;
using UnityEngine.UI;
namespace Stary.Evo.Example.Counter
{
public class CounterViewController : MonoBehaviour, IController
{
private Text _countText;
private ICounterData mCounterData;
void Start()
{
// 获取
mCounterData = this.GetData<ICounterData>();
mCounterData.Count.Register(UpdateView);
_countText = transform.Find("CountText").GetComponent<Text>();
_countText.text = mCounterData.Count.Value.ToString();
transform.Find("ButtonAdd").GetComponent<Button>()
.onClick.AddListener(() =>
{
// 交互逻辑
this.SendCommand<CommandAnd>();
});
transform.Find("ButtonSub").GetComponent<Button>()
.onClick.AddListener(() =>
{
// 交互逻辑
this.SendCommand<CommandSub>();
});
}
//表现逻辑
void UpdateView(int countValue)
{
_countText.text = countValue.ToString();
}
private void OnDestroy()
{
mCounterData.Count.Register(UpdateView);
mCounterData = null;
}
IArchitecture IBelongToArchitecture.GetArchitecture()
{
return CounterApp.Interface;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 856a6da247744b64e940e39f89e90657
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,47 @@
using UnityEditor;
using UnityEngine;
namespace Stary.Evo.Example.Counter
{
public interface IStorage:IUtility
{
void SaveInt(string key, int value);
int LoadInt(string key, int defaultValue = 0);
}
public class PlayerPrefsStorage : IStorage
{
public void SaveInt(string key, int value)
{
Debug.Log("PlayerPrefsStorage执行");
PlayerPrefs.SetInt(key, value);
}
public int LoadInt(string key, int defaultValue = 0)
{
return PlayerPrefs.GetInt(key, defaultValue);
}
}
public class EditorPrefsStorage : IStorage
{
public void SaveInt(string key, int value)
{
#if UNITY_EDITOR
Debug.Log("EditorPrefsStorage执行");
EditorPrefs.SetInt(key, value);
#endif
}
public int LoadInt(string key, int defaultValue = 0)
{
#if UNITY_EDITOR
return EditorPrefs.GetInt(key, defaultValue);
#else
return 0;
#endif
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 888277c00f124f46b4aede962dea86c2
timeCreated: 1624936004