using AX.MessageSystem; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; [RequireComponent(typeof(CloneBase))] public abstract class ReplayBase : MonoBehaviour { protected CloneBase cloneBase; // Use this for initialization public virtual void Start() { cloneBase = GetComponent(); MessageDispatcher.AddListener("ClearObject", Clear); MessageDispatcher.AddListener("ReplayFrame", ReplayFrameClone); MessageDispatcher.AddListener("ReplayEvent", ReplayEventClone); } public virtual void OnDestroy() { MessageDispatcher.RemoveListener("ClearObject", Clear); MessageDispatcher.RemoveListener("ReplayFrame", ReplayFrameClone); MessageDispatcher.RemoveListener("ReplayEvent", ReplayEventClone); } // Update is called once per frame void Update() { } public void ReplayFrameClone(IMessage obj) { var item = (ObjectData)obj.Data; if (item.cloneObjType == cloneBase.cloneObjType) { if (cloneBase.clonePrefab != null) { CloneObject(item.json); } } } public abstract void CloneObject(string json); private void ReplayEventClone(IMessage obj) { var item = (EventData)obj.Data; if (item.cloneObjType == cloneBase.cloneObjType && item.eventType == RecordEventType.Clone) { CloneObject(item.json); } } /// /// 清空父对象下所有物体 /// /// public virtual void Clear(IMessage obj) { foreach (Transform child in transform) { EntitiesManager.Instance.DeleteObj(child.gameObject); } } }