public override void PoolRecycle() { Clean(); if (MechaEditArea != null) { DestroyImmediate(MechaEditArea); MechaEditArea = null; } base.PoolRecycle(); }
public void Initialize(MechaInfo mechaInfo) { Clean(); MechaInfo = mechaInfo; if (!IsPlayer) { MechaBaseAIAgent = new MechaBaseAIAgent(this); } // AI if (mechaInfo.MechaConfig != null) { string aiConfigKey = mechaInfo.MechaConfig.MechaAIConfigKey; if (!string.IsNullOrEmpty(aiConfigKey)) { BehaviourTree bt = ConfigManager.Instance.GetEnemyAIConfig(aiConfigKey); BehaviourTreeOwner.behaviour = bt; BehaviourTreeOwner.updateMode = Graph.UpdateMode.NormalUpdate; BehaviourTreeOwner.StartBehaviour(); AIManager.Instance.AddBehaviourTreeOwner(BehaviourTreeOwner); } } MechaInfo.OnAddMechaComponentInfoSuc = (mci, gp_matrix) => AddMechaComponent(mci); MechaInfo.OnRemoveMechaInfoSuc += (mi) => { OnRemoveMechaSuc?.Invoke(this); PoolRecycle(); }; MechaInfo.OnDropMechaComponent = (mci) => { MechaComponentDropSprite mcds = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.MechaComponentDropSprite] .AllocateGameObject <MechaComponentDropSprite>(ClientBattleManager.Instance.MechaComponentDropSpriteContainerRoot); mcds.Initialize(mci, MechaComponentDict[mci.GUID].transform.position); }; MechaInfo.MechaEditorInventory = new MechaEditorInventory( DragAreaDefines.MechaEditorArea.ToString(), DragAreaDefines.MechaEditorArea, ConfigManager.GridSize, ConfigManager.EDIT_AREA_FULL_SIZE, ConfigManager.EDIT_AREA_FULL_SIZE, false, false, false, 0, () => ControlManager.Instance.Building_RotateItem.Down); MechaInfo.MechaEditorInventory.OnRemoveItemSucAction = (item) => { ((MechaComponentInfo)item.ItemContentInfo).RemoveMechaComponentInfo(); }; MechaInfo.MechaEditorInventory.RefreshInventoryGrids(); MechaInfo.OnInstantiated?.Invoke(); // 将已经积攒的未实例化的组件实例化 MechaInfo.OnInstantiated = null; MechaInfo.MechaEditorInventory.RefreshConflictAndIsolation(); // MechaEditorArea if (mechaInfo.MechaCamp == MechaCamp.Player) { GameObject mea = PrefabManager.Instance.GetPrefab(nameof(MechaEditArea)); GameObject meaGO = Instantiate(mea); meaGO.transform.parent = transform; meaGO.transform.localPosition = new Vector3(0, -0.5f, 0); MechaEditArea = meaGO.GetComponent <MechaEditArea>(); MechaEditArea.Init(mechaInfo); } foreach (KeyValuePair <uint, MechaComponentInfo> kv in mechaInfo.MechaComponentInfoDict) // 将其它的组件实例化 { if (MechaComponentDict.ContainsKey(kv.Key)) { continue; } AddMechaComponent(kv.Value); } GridShown = false; SlotLightsShown = false; Initialize_Fighting(mechaInfo); }