Ejemplo n.º 1
0
    public void Update()
    {
        if (State != RoutineState.Processing)
        {
            return;
        }

        if (www != null && www.isDone)
        {
            State = RoutineState.Suspended;
            if (www.error != null)
            {
                OnHttpError(www.error);
            }
            else
            {
                OnHttpResponse();
            }
        }
        else
        {
            processingTime += Time.deltaTime;
            if (processingTime > NetworkConfiger.mTimeLimit)
            {
                OnTimeOut();
            }
        }
    }
 public void Pause()
 {
     if (m_State == RoutineState.Running)
     {
         m_State = RoutineState.Paused;
     }
 }
Ejemplo n.º 3
0
    private void AdvanceRoutine()
    {
        switch (_state)
        {
        case RoutineState.OuterRadius:
            _state = RoutineState.InnerRadius;
            _advanceRoutineTime = Time.time + _timeAtInnerRadius;
            break;

        case RoutineState.InnerRadius:
            _state = RoutineState.WaitingAtLine;
            _advanceRoutineTime = Time.time + _timeWaitingAtLine;
            break;

        case RoutineState.WaitingAtLine:
            _state = RoutineState.AdvancingLine;
            _advanceRoutineTime = Time.time + _timeAdvancingLine;
            break;

        case RoutineState.AdvancingLine:
            _state = RoutineState.OuterRadius;
            _advanceRoutineTime = Time.time + _timeAtOuterRadius;
            break;
        }
    }
Ejemplo n.º 4
0
 public void Pause()
 {
     if (State != RoutineState.Running)
     {
         return;
     }
     State = RoutineState.Paused;
 }
Ejemplo n.º 5
0
 public void Resume()
 {
     if (State != RoutineState.Paused)
     {
         return;
     }
     State = RoutineState.Running;
 }
Ejemplo n.º 6
0
 public void AddStateToManager()
 {
     RoutineState routine = new RoutineState();
     NPCStateManager stateManager = new NPCStateManager();
     stateManager.AddState(routine);
     bool success = stateManager.CheckForState(routine);
     Assert.IsTrue(success);
 }
Ejemplo n.º 7
0
 public void Stop()
 {
     if (State != RoutineState.Running || State != RoutineState.Paused)
     {
         return;
     }
     State = RoutineState.Finished;
 }
Ejemplo n.º 8
0
    public void GetRequest()
    {
        DisposeWWW();
        State = RoutineState.Processing;
        string url = commandInfo.url;

        www    = new WWW(url);
        m_time = Time.time;
    }
Ejemplo n.º 9
0
 public void Stop()
 {
     if (!(State == RoutineState.Running || State == RoutineState.Paused))
     {
         return;
     }
     EditorApplication.update -= Update;
     State = RoutineState.Finished;
 }
    // LOGIC

    public void Start()
    {
        if (m_State != RoutineState.None)
        {
            return;
        }

        m_State = RoutineState.Running;
    }
Ejemplo n.º 11
0
 public void Start(IEnumerator routine)
 {
     if (State != RoutineState.Ready)
     {
         return;
     }
     State        = RoutineState.Running;
     this.routine = routine;
 }
Ejemplo n.º 12
0
 public void AddExistingStateToManager()
 {
     RoutineState routine = new RoutineState();
     NPCStateManager stateManager = new NPCStateManager();
     stateManager.AddState(routine);
     stateManager.AddState(routine);
     int success = 1;
     int check = stateManager.CurrentManagerStates().Count;
     Assert.AreEqual(success, check);
 }
Ejemplo n.º 13
0
            public void Start(IEnumerator routine)
            {
                if (State != RoutineState.Ready)
                {
                    return;
                }
                this.runner = Run(routine);
                State       = RoutineState.Running;

                EditorApplication.update += Update;
            }
Ejemplo n.º 14
0
        private void SetTaskState(RoutineState activeState)
        {
            state      = activeState;
            isComplete = false;

            switch (state)
            {
            case RoutineState.Complete:
                isComplete = true;
                break;
            }
        }
Ejemplo n.º 15
0
 public void OnTimeOut()
 {
     if (commandInfo.isBackGround)
     {
         State = RoutineState.Idle;
     }
     else
     {
         State = RoutineState.Suspended;
         var msg = new NetMsg <string>();
         msg.code = -1;
         msg.err  = "time out";
         msg.ret  = "TIME_OUT";
         OnException(msg);
     }
 }
 public IEnumerator Step()
 {
     if (m_State == RoutineState.Running)
     {
         if (m_Enumerator != null)
         {
             if (!m_Enumerator.MoveNext())
             {
                 m_State = RoutineState.Finished;
             }
             else
             {
                 yield return(m_Enumerator.Current);
             }
         }
     }
 }
Ejemplo n.º 17
0
    void OnException(NetMsg <string> msg)
    {
        bool?suspend = null;

        if (exceptionCallback != null)
        {
            suspend = exceptionCallback.Invoke(msg);
        }
        if (suspend == true)
        {
            this.State = RoutineState.Suspended;
        }
        else
        {
            this.State = RoutineState.Idle;
        }
    }
Ejemplo n.º 18
0
            public IEnumerator Run()
            {
                while (routine.MoveNext())
                {
                    yield return(routine.Current);

                    while (State == RoutineState.Paused)
                    {
                        yield return(null);
                    }

                    if (State == RoutineState.Finished)
                    {
                        yield break;
                    }
                }

                State = RoutineState.Finished;
            }
Ejemplo n.º 19
0
    public void OnHttpError(string errorMsg)
    {
        Debug.LogError("HTTP ERROR:" + errorMsg);
        if (commandInfo.isBackGround)
        {
            State = RoutineState.Idle;
        }
        else
        {
            State = RoutineState.Suspended;

            //                #if !RELEASE
            //
            //                CommandLineControl.Instance.WriteLine(LogLevel.Error, "network fatal: " + errorMsg);
            //
            //                #endif
            var msg = new NetMsg <string>();
            msg.code = -1;
            msg.err  = errorMsg;
            msg.ret  = "HTTP_ERROR";
            OnException(msg);
        }
    }
Ejemplo n.º 20
0
 public void Start()
 {
     state = RoutineState.Running;
 }
    // CTOR

    public Routine(IEnumerator i_Enumerator)
    {
        m_Enumerator = i_Enumerator;
        m_State      = RoutineState.None;
    }
Ejemplo n.º 22
0
    private void OnHttpResponse()
    {
        string result = "";

#if ((UNITY_ANDROID || UNITY_STANDALONE_WIN) && !UNITY_EDITOR) || UNITY_EDITOR_WIN
        if (www.responseHeaders.ContainsKey("CONTENT-ENCODING") && www.responseHeaders["CONTENT-ENCODING"].Equals("deflate"))
        {
            result = NetworkUtil.UnzipString(www.bytes);
        }
        else
        {
            result = www.text;
        }
#else
        result = www.text;
#endif
        NetworkManager.delay = Time.time - m_time;

        switch (Application.platform)
        {
        case RuntimePlatform.WindowsEditor:
        case RuntimePlatform.OSXEditor:
            if (result.Length > 16000)
            {
                Debug.Log("[BACK]:  " + www.url + " " + (Time.time - m_time).ToString("0.0") + "s :" + result.Substring(0, 16000));
                Debug.Log("+  " + www.url + " " + (Time.time - m_time).ToString("0.0") + "s :" + result.Substring(16000));
            }
            else
            {
                Debug.Log("[BACK]:  " + www.url + " " + (Time.time - m_time).ToString("0.0") + "s :" + result);
            }
            break;

        case RuntimePlatform.Android:
        case RuntimePlatform.IPhonePlayer:


                #if !RELEASE
            if (result.Length > 1000)
            {
                Debug.Log("[BACK]:  " + www.url + " " + (Time.time - m_time).ToString("0.0") + "s :" + result.Substring(0, 1000));
            }
            else
            {
                Debug.Log("[BACK]:  " + www.url + " " + (Time.time - m_time).ToString("0.0") + "s :" + result);
            }

            // // 输入到内嵌命令行
            // if (result.Length > 1050)
            // {
            //  ConsoleMgr.Instance.WriteLine(LogLevel.Debug, ("[BACK]:  " + www.url + " " + (Time.time - m_time).ToString("0.0") + "s :" + result.Substring(1050)));
            // }
            // else
            // {
            //  ConsoleMgr.Instance.WriteLine(LogLevel.Debug, ("[BACK]:  " + www.url + " " + (Time.time - m_time).ToString("0.0") + "s :" + result));
            // }
                #else
            if (GameCore.Conf.Instance.ModeDebug)
            {
                if (result.Length > 1000)
                {
                    Debug.Log("[BACK]:  " + mWWW.url + " " + (Time.time - m_time).ToString("0.0") + "s :" + result.Substring(0, 1000));
                }
                else
                {
                    Debug.Log("[BACK]:  " + mWWW.url + " " + (Time.time - m_time).ToString("0.0") + "s :" + result);
                }
            }
                #endif
            break;
        }


        if (string.IsNullOrEmpty(result))
        {
            State = RoutineState.Suspended;
            var msg = new NetMsg <string>();
            msg.code = -1;
            msg.err  = "no result";
            OnException(msg);
            return;
        }

        if (!result.StartsWith("{"))
        {
            byte[] bytesData = System.Convert.FromBase64String(result);
            result = EncryptionMgr.Instance.DecryptStringFromBytes(bytesData);
                        #if UNITY_EDITOR
            if (result.Length > 1000)
            {
                Debug.Log("[BACK]:  " + www.url + " " + (Time.time - m_time).ToString("0.0") + "s :" + result.Substring(0, 1000));
            }
            else
            {
                Debug.Log("[BACK]:  " + www.url + " " + (Time.time - m_time).ToString("0.0") + "s :" + result);
            }
                        #endif
        }

        string code = result.Substring(8, 3);
        if (code.Equals("200"))
        {
            // 200 success
            Type classType = null;
            classType = commandInfo.runtimeClass;
            NetBaseMsg msg = JsonMapperExtend.ToObject(classType, result) as NetBaseMsg;
            if (NetworkManager.requestSuccessPredealHandler != null)
            {
                NetworkManager.requestSuccessPredealHandler.Invoke(msg);
            }
            if (successCallback != null)
            {
                successCallback.Invoke(msg);
            }
        }
        else if (code.Equals("203"))
        {
            // 203 server application not luanched
            var msg = NetworkUtil.MainJasonMapper().ToObject <NetMsg <string> >(result);
            OnException(msg);
        }
        else if (code.Equals("204"))
        {
            // 207 data locked
            var msg = NetworkUtil.MainJasonMapper().ToObject <NetMsg <string> >(result);
            OnException(msg);
            return;
        }
        else if (code.Equals("206"))
        {
            // 206 Repeated
            var msg = NetworkUtil.MainJasonMapper().ToObject <NetMsg <string> >(result);
            OnException(msg);
        }
        else if (code.Equals("207"))
        {
            // 207 Id Frozen
            var msg = NetworkUtil.MainJasonMapper().ToObject <NetMsg <string> >(result);
            OnException(msg);
        }
        else if (code.Equals("208"))
        {
            // 208 Specal: Do nothing
        }
        else
        {
            // Fail
            NetMsg <string> msg = NetworkUtil.MainJasonMapper().ToObject <NetMsg <string> >(result);
            if (failCallback != null)
            {
                failCallback.Invoke(msg);
            }
        }
        State = RoutineState.Idle;
    }
Ejemplo n.º 23
0
    private void MakeStateManager()
    {
        RoutineState routine = new RoutineState(player, gameObject);
        routine.AddTransition(Transition.PlayerLearning, StateID.InteractiveStateID);

        InteractiveState interactive = new InteractiveState(player, gameObject);
        interactive.AddTransition(Transition.SetPlayerTask, StateID.WaitingStateID);

        WaitingState waiting = new WaitingState(player, gameObject);
        waiting.AddTransition(Transition.PlayerTaskComplete, StateID.EndStateID);

        EndState end = new EndState(player, gameObject);
        end.AddTransition(Transition.AllDone, StateID.RoutineStateID);

        manager = new NPCStateManager();
        manager.AddState(routine);
        manager.AddState(interactive);
        manager.AddState(waiting);
        manager.AddState(end);
    }
Ejemplo n.º 24
0
    public void PostRequest()
    {
        DisposeWWW();

        if (commandInfo.isBlock)
        {
            if (NetworkManager.blockInputHandler != null)
            {
                NetworkManager.blockInputHandler.Invoke(true);
            }
        }
        State = RoutineState.Processing;
        string url = commandInfo.url;

        WWWForm form = null;

        foreach (KeyValuePair <string, string> kv in NetworkArgument.baseParam)
        {
            arg.AddParam(kv.Key, kv.Value);
        }

        if (NetworkManager.addExtraParamHandler != null)
        {
            NetworkManager.addExtraParamHandler.Invoke(arg);
        }

        form = arg.ToWWWForm();
        Dictionary <string, string> headers = form.headers;

        headers["netid"] = net_id.ToString();
        www = new WWW(url, form.data, headers);

        #if !RELEASE
        int  length  = 1000;
        bool sendCml = false;
        switch (Application.platform)
        {
        case RuntimePlatform.WindowsEditor:
        case RuntimePlatform.OSXEditor:
            length  = 90000;
            sendCml = false;
            break;

        default:
            length  = 1000;
            sendCml = true;
            break;
        }
        if (arg.ToString().Length > length)
        {
            Debug.Log("[SEND]:" + url + "      args:" + arg.ToString().Substring(0, length));
        }
        else
        {
            Debug.Log("[SEND]:" + url + "      " + arg.ToString());
        }
        #else
        if (Config.ModeDebug || GameInfo.Instance.showLog)
        {
            if (mArg.ToString().Length > 1000)
            {
                Debug.Log("[SEND]:" + url + "      " + mArg.ToString().Substring(0, 1000));
            }
            else
            {
                Debug.Log("[SEND]:" + url + "      " + mArg.ToString());
            }
        }
        #endif

        m_time = Time.time;
    }