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