修该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,59 @@
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
namespace Stary.Evo.Example.ClickClick
{
public class DIPExample : MonoBehaviour
{
// 1. 设计模块接口
public interface IStorage
{
void SaveString(string key, string value);
string LoadString(string key, string defaultValue = "");
}
// 2. 实现接口
// 运行时存储
public class PlayerPrefsStorage : IStorage
{
public void SaveString(string key, string value)
{
PlayerPrefs.SetString(key, value);
}
public string LoadString(string key, string defaultValue = "")
{
return PlayerPrefs.GetString(key, defaultValue);
}
}
// 4. 使用
private void Start()
{
// 创建一个 IOC 容器
var container = new IOCContainer();
// 注册运行时模块
container.Register<IStorage>(new PlayerPrefsStorage());
var storage = container.Get<IStorage>();
storage.SaveString("name", "运行时存储");
Debug.Log(storage.LoadString("name"));
// 切换实现
//container.Register<IStorage>(new EditorPrefsStorage());
storage = container.Get<IStorage>();
Debug.Log(storage.LoadString("name"));
}
}
}

View File

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

View File

@@ -0,0 +1,51 @@
using Stary.Evo;
using UnityEngine;
public class IOCExample : MonoBehaviour
{
void Start()
{
// 创建一个 IOC 容器
var container = new IOCContainer();
// 注册一个蓝牙管理器的实例
container.Register<IBluetoothManager>(new BluetoothManager());
// 根据类型获取蓝牙管理器的实例
var bluetoothManager = container.Get<IBluetoothManager>();
//连接蓝牙
bluetoothManager.Connect();
container.Register<IBluetoothManager>(new BluetoothManager1());
// 根据类型获取蓝牙管理器的实例
var bluetoothManager1 = container.Get<IBluetoothManager>();
//连接蓝牙
bluetoothManager1.Connect();
}
public interface IBluetoothManager
{
void Connect();
}
public class BluetoothManager:IBluetoothManager
{
public void Connect()
{
Debug.Log("蓝牙连接成功");
}
}
public class BluetoothManager1:IBluetoothManager
{
public void Connect()
{
Debug.Log("蓝牙连接成功");
}
}
}

View File

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