68 lines
1.6 KiB
C#
68 lines
1.6 KiB
C#
using System;
|
|
using AibisDream.FixSystem;
|
|
using UnityEngine;
|
|
|
|
namespace AibisDream.Framework
|
|
{
|
|
public class MonoCenter : MonoBehaviour
|
|
{
|
|
public static event Action OnUpdate;
|
|
|
|
public static MonoCenter Mono;
|
|
private static IOCContainer _iocContainer;
|
|
|
|
private void Awake()
|
|
{
|
|
if (Mono)
|
|
Destroy(Mono.gameObject);
|
|
else Mono = this;
|
|
|
|
InitKits();
|
|
}
|
|
|
|
private void InitKits()
|
|
{
|
|
_iocContainer ??= new IOCContainer();
|
|
// 在这里添加相应的工具
|
|
Register(new MoveableSystem());
|
|
Register(new WaveTest());
|
|
}
|
|
|
|
private void Register<T>(T kit) where T : IMonoKit
|
|
{
|
|
_iocContainer.Register(kit);
|
|
OnUpdate += kit.OnUpdate;
|
|
}
|
|
|
|
private void Unregister<T>() where T : class, IMonoKit
|
|
{
|
|
var kit = _iocContainer.Unregister<T>();
|
|
OnUpdate -= kit.OnUpdate;
|
|
}
|
|
|
|
private void Update() => OnUpdate?.Invoke();
|
|
}
|
|
|
|
public class WaveTest : IMonoKit
|
|
{
|
|
public void OnUpdate()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.Space))
|
|
{
|
|
FixSystemCenter.SystemDic.Get<OscilloscopeSystem>().PlayWave(FixSystem.WaveformType.Sine, true);
|
|
}
|
|
|
|
if (Input.GetKeyDown(KeyCode.A))
|
|
{
|
|
FixSystemCenter.SystemDic.Get<OscilloscopeSystem>().StartScan();
|
|
}
|
|
}
|
|
}
|
|
|
|
public interface IMonoKit
|
|
{
|
|
void OnUpdate();
|
|
}
|
|
}
|
|
|