72 lines
1.7 KiB
C#
72 lines
1.7 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 TransTest());
|
|
}
|
|
|
|
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 TransTest : IMonoKit
|
|
{
|
|
public void OnUpdate()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.K))
|
|
{
|
|
MonoCenter.Mono.StartCoroutine(FixSystemCenter.StateMachine.SwitchState(FixState.BodyModule, "Head"));
|
|
}
|
|
|
|
if (Input.GetKeyDown(KeyCode.Q))
|
|
{
|
|
var bodyModuleSystem = FixSystemCenter.SystemDic.Get<BodyModuleSystem>();
|
|
var module = bodyModuleSystem.FindBodyModuleByName("Memory");
|
|
Debug.Log(module.name);
|
|
module.EnableCut();
|
|
}
|
|
}
|
|
}
|
|
|
|
public interface IMonoKit
|
|
{
|
|
void OnUpdate();
|
|
}
|
|
} |