Closed transong6778 closed 2 years ago
public class TestScript : MonoBehaviour { public class TestEventMsg : IEventMessage, IReference { public string Value;
// 在回收的时候该方法会被执行 public void OnRelease() { Value = null; } } // Start is called before the first frame update void Start() { // 创建模块 MotionEngine.CreateModule<EventManager>(); EventManager.Instance.AddListener<TestEventMsg>(OnMsg2); EventManager.Instance.AddListener<TestEventMsg>(OnMsg1); TestEventMsg msg = ReferencePool.Spawn<TestEventMsg>(); msg.Value = "hello world"; EventManager.Instance.SendMessage(msg); } void OnMsg1(IEventMessage msg) { if(msg is TestEventMsg temp) { Debug.Log("msg1 " + temp.Value); EventManager.Instance.RemoveListener<TestEventMsg>(OnMsg2); } } void OnMsg2(IEventMessage msg) { if(msg is TestEventMsg temp) { Debug.Log("msg2 " + temp.Value); } }
}
现象为触发了两次 msg1
印象里GF有处理这个
public class TestScript : MonoBehaviour { public class TestEventMsg : IEventMessage, IReference { public string Value;
}
现象为触发了两次 msg1