框架上传
This commit is contained in:
51
Assets/00.StaryEvo/Samples/Runtime/IOC/Script/IOCExample.cs
Normal file
51
Assets/00.StaryEvo/Samples/Runtime/IOC/Script/IOCExample.cs
Normal 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("蓝牙连接成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user