Ejemplo n.º 1
0
    // private IEnumerator Wait(float time, OnCallBack calback){
    //  yield return new WaitForSeconds(time);
    //  calback( this);
    //  yield break;
    // }

    private GameObject GetNPCTarget(ScriptGui.NPCAction npc)
    {
        GameObject npcOBJ = npc.UsingNPCTarget ? OBJTarget : (mIsMain ? AutoTileMap_Editor.Instance.GetNPC(npc.IdNpc) : null);

        // GameObject npcOBJ = null;
        // if(npc.UsingNPCTarget){
        //  var tTarget =  AutoTileMap_Editor.Instance.GetNPC(Detail);
        //  if(tTarget){
        //      npcOBJ = tTarget.gameObject;
        //  }
        // }
        // if(!npcOBJ){
        //  npcOBJ = AutoTileMap_Editor.Instance.GetNPC(npc.IdNpc);
        // }
        if (npcOBJ == null)
        {
            if (npc.UsingNPCTarget)
            {
                InputFieldHelper.Instance.ShowNoti(string.Format("Error at Script ({0}): : Not found NPC on target", IdxScript));
            }
            else
            {
                InputFieldHelper.Instance.ShowNoti(string.Format("Error at Script ({0}): : Not found NPC ({1})", IdxScript, npc.IdNpc));
            }
        }
        return(npcOBJ);
    }
Ejemplo n.º 2
0
 public void EndAction()
 {
     Debug.Log("ScriptGame End " + Key);
     mActionWait = null;
     mIsRun      = false;
     if (mOnEndAction != null)
     {
         var callBack = mOnEndAction;
         mOnEndAction = null;
         callBack(this);
     }
 }
Ejemplo n.º 3
0
    private void doNpcFaceTo(ScriptGui.NPCAction npc, Vector3 to)
    {
        GameObject npcOBJ = GetNPCTarget(npc);

        if (npcOBJ != null && npcOBJ.activeSelf)
        {
            mActionWait = npc;
            NpcLookatDCallback.InstanceOf(npcOBJ).LookTo(to, (NpcLookatDCallback n) => {
                mActionWait = null;
                this.NextActionTo(npc.Next, 0);
            });
        }
    }
Ejemplo n.º 4
0
 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);
     }
 }
Ejemplo n.º 5
0
 public void StartNormal(int idxMap, int idxScript, ScriptGui.ScriptYaml script, GameObject npcTarget, OnEndAction onEndAction = null)
 {
     // if(mIsRun){
     //  Debug.Log("Can't start action when running");
     //  return;
     // }
     Debug.Log("Start Normal Action " + Key + " ,idxScript: " + idxScript);
     IdxMap       = idxMap;
     IdxScript    = idxScript;
     Script       = script;
     OBJTarget    = npcTarget;
     mIsMain      = false;
     mOnEndAction = onEndAction;
     mActionWait  = null;
     ResetValueFlag();
     StartScope();
 }
Ejemplo n.º 6
0
    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);
        }
    }