public void ResumeAction() { if (mIsRun) { return; } mIsRun = true; Debug.Log("ScriptGame Resume " + Key); if (mActionWait != null) { ScriptGuiBase.NPCAction action = mActionWait; mActionWait = null; DoActionNPC(mScopeIndext, 0, action); } }
private void DoActionNPC(int scopeIndext, int countStack, ScriptGuiBase.NPCAction npc) { if (mActionWait != null) { Debug.LogError("Have mActionWait"); return; } mActionWait = null; if (npc.Action == ScriptGui.NPCAction.EAction.Show) { if (npc.UsingNPCTarget) { if (!OBJTarget) { EndAction(); InputFieldHelper.Instance.ShowNoti(string.Format("Error at Script ({0}): : Not found NPC on target", IdxScript)); return; } OBJTarget.gameObject.SetActive(true); AutoTileMap_Editor.Instance.WarpTo(OBJTarget.transform, npc.x, npc.y); } else { TriggerDetail detail = new TriggerDetail() { refMap = IdxMap, typeObj = eSlotAonTypeObj.Person, refId = npc.IdNpc, isCreateFromMap = false, x = npc.x, y = npc.y }; if (AutoTileMap_Editor.Instance.ShowNPC(detail) == null) { EndAction(); return; } } var t = npc.Next; NextActionTo(t, countStack + 1); return; } GameObject npcOBJ = GetNPCTarget(npc); if (npcOBJ == null) { if (mIsMain) { var t = npc.Next; NextActionTo(t, countStack + 1); } else { EndAction(); } return; } if (!npcOBJ.activeSelf) { var t = npc.Next; NextActionTo(t, countStack + 1); return; } if (npcOBJ == OBJTarget) { CLEAR_ALL_ACTION_NPC(npcOBJ); } else { if (mIsMain) { //Pause other NPC ScriptGame s_from_npc = TriggerGame.Instance.GetScriptGameCache_NPC_Begin(npcOBJ, false); TriggerGame.Instance.AddScriptNeedResume(s_from_npc); } } switch (npc.Action) { case ScriptGui.NPCAction.EAction.Show: { // No Check break; } case ScriptGui.NPCAction.EAction.Hide: { if (npc.UsingNPCTarget == false) { AutoTileMap_Editor.Instance.RemoveNPC(npc.IdNpc); } else { if (OBJTarget != null) { OBJTarget.SetActive(false); } } break; } case ScriptGui.NPCAction.EAction.Move: { // AutoTileMap_Editor.Instance.AddNPC( npc.IdNpc, npc.x, npc.y, true); // GameObject npcOBJ = GetNPCTarget(npc); if (npcOBJ != null && npcOBJ.activeSelf) { mActionWait = npc; var high = AutoTileMap_Editor.Instance.MapSelect.GetHighRef(npc.x, npc.y) * 0.5f; var to = new Vector3((0.5f + npc.x) * AutoTileMap_Editor.Instance.CellSize.x, high + 1, -(0.5f + npc.y) * AutoTileMap_Editor.Instance.CellSize.y); var c = npcOBJ.GetComponent <NavMeshAgentCallback>(); if (c == null) { c = npcOBJ.AddComponent <NavMeshAgentCallback>(); } c.WalkTo(1, to, ( NavMeshAgent nav ) => { mActionWait = null; var t = npc.Next; this.NextActionTo(t, 0); }); } break; } case ScriptGui.NPCAction.EAction.LookAtCharacter: { // GameObject npcOBJ = GetNPCTarget(npc); if (npcOBJ != null && npcOBJ.activeSelf) { bool requestLockBack = mIsMain; if (NpcLookatMainCallback.InstanceOf(npcOBJ).LookTo(AutoTileMap_Editor.Instance.Agent, requestLockBack, (NpcLookatMainCallback n) => { mActionWait = null; var t = npc.Next; this.NextActionTo(t, 0); })) { mActionWait = npc; } else { var t = npc.Next; this.NextActionTo(t, 0); } } break; } case ScriptGui.NPCAction.EAction.Animation_Talk: { // GameObject npcOBJ = GetNPCTarget(npc); if (npcOBJ != null && npcOBJ.activeSelf) { var b = npcOBJ.GetComponent <BasicMecanimControl>(); if (b != null) { mActionWait = npc; b.TalkWithAni((BasicMecanimControl bb) => { mActionWait = null; var t = npc.Next; this.NextActionTo(t, 0); }); } } break; } case ScriptGui.NPCAction.EAction.Animation_Face_Down: { doNpcFaceTo(npc, new Vector3(0, 0, -1)); return; } case ScriptGui.NPCAction.EAction.Animation_Face_Up: { doNpcFaceTo(npc, new Vector3(0, 0, 1)); return; } case ScriptGui.NPCAction.EAction.Animation_Face_Left: { doNpcFaceTo(npc, new Vector3(-1, 0, 0)); return; } case ScriptGui.NPCAction.EAction.Animation_Face_Right: { doNpcFaceTo(npc, new Vector3(1, 0, 0)); return; } default: { EndAction(); return; } } if (mActionWait == null) { var t = npc.Next; NextActionTo(t, countStack + 1); } }