Exemplo n.º 1
0
 private void TestTweenWapper()
 {
     if ((GUILayout.Button("Create TweenWarpper")))
     {
         TweenWarpper = new TweenWarpper();
     }
     if ((GUILayout.Button("Play Tween")))
     {
         TestFloat = 0;
         TweenWarpper.Set(DOTween
                          .To(() => { return(TestFloat); }, (f) => { TestFloat = f; }, 100, 5)
                          .OnComplete(() => { VeerDebug.Log("tween complete ..."); })
                          .OnKill(() => { VeerDebug.Log("tween kill ..."); }));
     }
     if ((GUILayout.Button("Just Kill")))
     {
         TweenWarpper.Abort(AbortMethod.JustKill);
     }
     if ((GUILayout.Button("Force With OnKill")))
     {
         TweenWarpper.Abort(AbortMethod.ForceCompleteWithKillCallback);
     }
     if ((GUILayout.Button("Force With OnComplete")))
     {
         TweenWarpper.Abort(AbortMethod.ForceCompleteWithOnCompleteCallback);
     }
     if ((GUILayout.Button("Force With OnKill and OnComplete")))
     {
         TweenWarpper.Abort(AbortMethod.ForceCompleteWithOnCompleteAndOnKill);
     }
 }
Exemplo n.º 2
0
    // 测试开启 多线程 Abort
    public void Test_TaskAbort()
    {
        List <Task> taskList = new List <Task>();

        TaskListChecker  = new List <string>();
        TaskCountChecker = 500;
        for (int i = 1; i < 501; i++)
        {
            string index = i.ToString();
            TaskListChecker.Add(index);
            taskList.Add(Task <string> .Run(() =>
            {
                SomeCalculateSimple();
                return(index);
            }).ContinueInMainThreadWith((obj) =>
            {
                TaskCountChecker--;

                if (obj == null)
                {
                    VeerDebug.Log(" time out : " + index);
                    return;
                }

                VeerDebug.Log(" thread over : " + obj.Result);
                TaskListChecker.Remove(obj.Result);
            }, 10f));
        }

        foreach (var task in taskList)
        {
            task.CheckAbort();
        }
    }
        void Start()
        {
            ClassA     classA = new ClassA();
            JSONObject json   = classA.ToJsonObject();

            VeerDebug.Log(json.ToString());
        }
Exemplo n.º 4
0
    /// <summary>
    /// 解析形如 "0.000601,7.072153,0,YXZ" 的旋转信息
    /// </summary>
    public static Quaternion ParseWebOrientationString(string veerWebOrientationString, bool bIgnoreX = false, bool bIgnoreY = false, bool bIgnoreZ = false)
    {
        Quaternion result = Quaternion.identity;

        if (string.IsNullOrEmpty(veerWebOrientationString))
        {
            return(result);
        }

        try
        {
            string[] str = veerWebOrientationString.Split(new char[] { ',' });
            if (str.Length == 4)
            {
                string     k = str[3].ToLower();
                Quaternion q = Quaternion.identity;
                Quaternion x = Quaternion.identity;
                Quaternion y = Quaternion.identity;
                Quaternion z = Quaternion.identity;

                x = Quaternion.AngleAxis(-float.Parse(str[0]) * Mathf.Rad2Deg, Vector3.right);
                y = Quaternion.AngleAxis(-float.Parse(str[1]) * Mathf.Rad2Deg, Vector3.up);
                z = Quaternion.AngleAxis(float.Parse(str[2]) * Mathf.Rad2Deg, Vector3.forward);

                for (int i = 0; i < 3; i++)
                {
                    if (k[i] == 'x' && !bIgnoreX)
                    {
                        q *= x;
                    }
                    else if (k[i] == 'y' && !bIgnoreY)
                    {
                        q *= y;
                    }
                    else if (k[i] == 'z' && !bIgnoreZ)
                    {
                        q *= z;
                    }
                }

                // songlingyi
                // Web 端设置 Setting 初始角度 时 使用的是 Camera 方向
                // 而 VR 端使用球的旋转来设
                // 因此此处要对 Quaternion 取反
                result = Quaternion.Inverse(q);
            }
        }
        catch (System.Exception e)
        {
            VeerDebug.Log(e.Message);
            VeerDebug.Log(e.StackTrace);
            return(Quaternion.identity);
        }

        return(result);
    }
Exemplo n.º 5
0
 // 测试 Task.RunInMainThread 没什么用,正常阻塞
 public void Test_RunInMainThread()
 {
     // executed in the main thread
     VeerDebug.Log(" Test_RunInMainThread Start ...");
     Task.RunInMainThread(() =>
     {
         VeerDebug.Log(" Test_RunInMainThread ...");
         GameObject g = new GameObject("_auto_Test_RunInMainThread");
         int rst      = SomeCalculate();
     });
     VeerDebug.Log(" Test_RunInMainThread End ...");
 }
Exemplo n.º 6
0
 public void Test_Debug()
 {
     VeerDebug.Log(GetRandomString());
     VeerDebug.Log(GetRandomString());
     VeerDebug.Log("TagA", GetRandomString());
     VeerDebug.Log("TagA", GetRandomString());
     VeerDebug.Log("TagB", GetRandomString());
     VeerDebug.Log("TagB", GetRandomString());
     VeerDebug.Log("TagC", GetRandomString());
     VeerDebug.Log("TagC", GetRandomString());
     VeerDebug.Log("TagD", GetRandomString());
     VeerDebug.Log("TagD", GetRandomString());
 }
Exemplo n.º 7
0
 // 测试 Task.Run
 public void Test_Run()
 {
     // executed in the new thread
     // log 的 次序是不确定的,注意 异步编程 / 多线程编程 的常见问题
     VeerDebug.Log(" Test_Run Start ...");
     Task.Run(() =>
     {
         VeerDebug.Log(" Test_Run ...");
         // 在 Run 中操作 UnityEngine.Object 子类会引发 Crash
         //GameObject g = new GameObject("_auto_Test_Run");
     });
     VeerDebug.Log(" Test_Run End ...");
 }
Exemplo n.º 8
0
 // 测试 Task.Run 返回后执行 Main Thread 回调方法
 public void Test_RunIntFunc()
 {
     Task <int> .Run(() =>
     {
         int rst = SomeCalculate();
         VeerDebug.Log(" in another thread rst : " + rst);
         return(rst);
     }).ContinueInMainThreadWith((obj) =>
     {
         VeerDebug.Log(" in main thread rst : " + obj.Result);
         GameObject g = new GameObject("_auto_Test_RunIntFunc");
     });
 }
Exemplo n.º 9
0
    private void Test_8_FastJsonMyText()
    {
        string jsonString = "{\"StringField\":\"ha\\\"ha\\\"ha\"}";

        VeerDebug.Log("json string : " + jsonString);

        TestJsonConvert test = FastJson.Deserialize <TestJsonConvert>(jsonString);

        VeerDebug.Log("fast json string field : " + test.StringField);

        string serialize = FastJson.Serialize(test);

        VeerDebug.Log("fast json serialize : " + serialize);
    }
Exemplo n.º 10
0
    private void Test_7_JsonObjectCreate()
    {
        JSONObject json = JSONObject.obj;

        json.AddField("StringField", TestInnerJsonText);

        string jsonString = json.ToString();

        VeerDebug.Log("json to string : " + jsonString);

        JSONObject jsonParse = JSONObject.Create(jsonString);

        VeerDebug.Log("json parsed : " + jsonParse.ToString());
    }
Exemplo n.º 11
0
        public void Test_DefReset()
        {
            VeerDebug.Log(StaticDefaultReset.StaticStringField);
            ObjectDefaultReset.DefaultReset(typeof(StaticDefaultReset));
            VeerDebug.Log(StaticDefaultReset.StaticStringField);

            NoStaticDefaultReset inst = new NoStaticDefaultReset();

            VeerDebug.Log(NoStaticDefaultReset.StaticStringField);
            VeerDebug.Log(inst.StringField);
            VeerDebug.Log(inst.IntField);
            inst.DefaultReset();
            VeerDebug.Log(NoStaticDefaultReset.StaticStringField);
            VeerDebug.Log(inst.StringField);
            VeerDebug.Log(inst.IntField);
        }
Exemplo n.º 12
0
    private void Test_5_OriginalEqualUnescape()
    {
        string ori = TestInnerJsonText;
        string une = TestEscapeUnescapeJsonText;

        VeerDebug.Log("Original Unescape Length : " + TestInnerJsonText.Length + "  " + TestEscapeUnescapeJsonText.Length);

        for (int i = 0; i < ori.Length; i++)
        {
            if (ori[i] != une[i])
            {
                VeerDebug.Log(i.ToString() + " : " + ori[i] + " " + une[i]);
            }
        }

        VeerDebug.Log("OriginalEqualUnescape : " + (TestInnerJsonText == TestEscapeUnescapeJsonText).ToString());
    }
Exemplo n.º 13
0
    private void Test_9_FastJsonSerialize()
    {
        JSONObject json = JSONObject.obj;

        json.AddField("StringField", TestInnerJsonText);

        string jsonString = json.ToString();

        VeerDebug.Log("json to string : " + jsonString);

        TestJsonConvert test = FastJson.Deserialize <TestJsonConvert>(jsonString);

        VeerDebug.Log("fast json string field : " + test.StringField);

        string serialize = FastJson.Serialize(test);

        VeerDebug.Log("fast json serialize : " + serialize);
    }
Exemplo n.º 14
0
 private void TestOriginTween()
 {
     if ((GUILayout.Button("Check Tween")))
     {
         if (Tween1 == null)
         {
             VeerDebug.Log("tween is null ...");
         }
         else
         {
             VeerDebug.Log("tween is exist ...");
         }
     }
     if ((GUILayout.Button("Create Tween 1")))
     {
         TestFloat = 0;
         Tween1    = DOTween.To(() => { return(TestFloat); }, (f) => { TestFloat = f; }, 100, 5)
                     .OnComplete(() => { VeerDebug.Log("tween complete ..."); })
                     .Pause();
     }
     if ((GUILayout.Button("Create Tween 2")))
     {
         TestFloat = 0;
         Tween2    = DOTween.To(() => { return(TestFloat); }, (f) => { TestFloat = f; }, 100, 5)
                     .OnComplete(() => { VeerDebug.Log("tween complete ..."); })
                     .Pause();
     }
     if ((GUILayout.Button("Play Tween 1")))
     {
         Tween1.Play();
     }
     if ((GUILayout.Button("Play Tween 2")))
     {
         Tween2.Play();
     }
     if ((GUILayout.Button("Complete Tween 1")))
     {
         Tween1.Complete();
     }
     if ((GUILayout.Button("Kill Tween 1")))
     {
         Tween1.Kill();
     }
 }
Exemplo n.º 15
0
    private static void AsyncDeserializeJsonCallback <T>(Action <bool, T> callback, Task <T> obj)
    {
        if (obj == null)
        {
#if UNITY_EDITOR
            VeerDebug.Log(" AsyncDeserializeJson failed by timeout ...");
#endif
            callback(false, default(T));
            return;
        }
        else if (obj.IsFaulted || obj.IsAborted || !obj.IsCompleted)
        {
            callback(false, default(T));
            return;
        }
        else
        {
            callback(true, obj.Result);
            return;
        }
    }
Exemplo n.º 16
0
 private void OnGUI()
 {
     if (GUILayout.Button("Check"))
     {
         if (req == null)
         {
             VeerDebug.Log("is null");
         }
         else
         {
             VeerDebug.Log("is exist");
         }
     }
     if (GUILayout.Button("Create"))
     {
         req = new SimpleHttpReq(new System.Uri("https://qvcdn.veervr.tv/ie/scene2.jpg?sign=efb3c091d9ed64c5d4c5219ede1934e3&t=5dfc0f00"), (result, res, reqId) =>
         {
             if (result == SimpleHttpResult.Abort)
             {
                 VeerDebug.Log("callback abort");
             }
             else if (result == SimpleHttpResult.FailedForNetwork)
             {
                 VeerDebug.Log("callback failed");
             }
             else if (result == SimpleHttpResult.Success)
             {
                 VeerDebug.Log("callback success");
             }
         });
     }
     if (GUILayout.Button("Send"))
     {
         req.Send();
     }
     if (GUILayout.Button("Abort"))
     {
         req.Abort();
     }
 }
Exemplo n.º 17
0
        private void CreateTask(string taskName, List <string> taskDependent)
        {
            DependentTask task = new DependentTask().SetTaskRegion("null").SetTaskName(taskName).SetTaskAction((TaskExecuteCallback callback) =>
            {
                VeerDebug.Log(" task start : " + taskName);
                float duration = UnityEngine.Random.Range(1f, 4f);
                this.StartCoroutine(CoroutineUtils.WaitForSecond(duration, () =>
                {
                    VeerDebug.Log(" task finished : " + taskName + " , duration : " + duration);
                    callback(true, null, null);
                }));
            });

            if (taskDependent != null)
            {
                for (int i = 0; i < taskDependent.Count; i++)
                {
                    task.AddDependentTask(taskDependent[i]);
                }
            }

            task.RegisterTask();
        }
Exemplo n.º 18
0
 private void Test_JsonByEscapeInnerTextToString()
 {
     VeerDebug.Log(TestJsonByEscapeInnerJsonText.ToString());
 }
Exemplo n.º 19
0
 public void Test_ShowTaskListChecker()
 {
     VeerDebug.Log(" TaskListChecker : " + TaskListChecker.ListToString());
     VeerDebug.Log(" TaskCountChecker : " + TaskCountChecker.ToString());
 }
Exemplo n.º 20
0
 public void Test_TestTextAssetSizeAdvanceCalc()
 {
     ExampleText.text = TestTextAsset.text;
     TextLengthCalcHelper.SetTextConfig(ExampleText);
     VeerDebug.Log("Test_TestTextAssetSizeAdvanceCalc : " + TextLengthCalcHelper.CalculateLengthAdvance(TestTextAsset.text));
 }
Exemplo n.º 21
0
 public void Test_TestTextAssetSize()
 {
     ExampleText.text = TestTextAsset.text;
     TextLengthCalcHelper.SetTextConfig(ExampleText);
     VeerDebug.Log("Test_TestTextAssetSize : " + TextLengthCalcHelper.CalculatePreferredSize(TestTextAsset.text));
 }
Exemplo n.º 22
0
 public void Test_TestFunction2()
 {
     VeerDebug.Log("this is TestFunction2");
 }
Exemplo n.º 23
0
 private void Test_1_InnerEqualOuter()
 {
     VeerDebug.Log("InnerEqualOuter : " + (TestInnerJsonText == TestOuterJsonText).ToString());
 }
Exemplo n.º 24
0
 private void Test_2_ShowInnerJsonText()
 {
     VeerDebug.Log("Inner : " + TestInnerJsonText);
 }
Exemplo n.º 25
0
 private void Test_3_ShowEscapedJsonText()
 {
     VeerDebug.Log("Inner Escape : " + TestEscapeJsonText);
 }
Exemplo n.º 26
0
 private void Test_6_ShowOuterJsonText()
 {
     VeerDebug.Log("Outer : " + TestOuterJsonText);
 }
Exemplo n.º 27
0
 private void Test_4_ShowEscapeUnescapeJsonText()
 {
     VeerDebug.Log("Inner Unescape : " + TestEscapeUnescapeJsonText);
 }
Exemplo n.º 28
0
 private void Test_JsonByUnescapeOuterTextToString()
 {
     VeerDebug.Log(TestJsonByUnescapeOuterJsonText.ToString());
 }
Exemplo n.º 29
0
        public static void CallbackConvert(SimpleHttpReq simpleReq, HTTPResponse res, SimpleHttpCallback callback)
        {
            // 0.如果 callbacck 为 null 则直接 return
            if (callback == null)
            {
                return;
            }

            // 1.请求成功则直接 callback
            if (res != null)
            {
                if (res.StatusCode == 200 || res.StatusCode == 304)
                {
                    callback(SimpleHttpResult.Success, res, simpleReq.ReqId);
                    return;
                }
                else if (res.StatusCode == 400)
                {
                    // code 400 说明服务器正常 但是 数据有错误 所以 不需要再 retry 了
                    VeerDebug.LogWarning(" req failed with code 400 : " + simpleReq.Req.Uri + " error msg : " + res.Message);
                    callback(SimpleHttpResult.FailedFor400, res, simpleReq.ReqId);
                    return;
                }
                else if (res.StatusCode == 404)
                {
                    // code 404 地址不存在 不需要再 retry 了
                    //VeerDebug.LogWarning(" req failed with code 404 : " + simpleReq.Req.Uri + " error msg : " + res.Message);
                    callback(SimpleHttpResult.FailedForNetwork, res, simpleReq.ReqId);
                    return;
                }
            }

            // 2.Abort 则 直接 callback
            if (simpleReq.Req.State == HTTPRequestStates.Aborted)
            {
                callback(SimpleHttpResult.Abort, res, simpleReq.ReqId);
                return;
            }

            // 3.其它情况需要尝试 retry
            if (simpleReq._CurrentRetryCount < simpleReq._RetryCount)
            {
                simpleReq._CurrentRetryCount++;
                VeerDebug.Log(" retry http req time : " + simpleReq._CurrentRetryCount + " api : " + simpleReq.Req.Uri + " code : " + res.StatusCode);
                simpleReq.Send(true);
                return;
            }

            // 4.retry 结束后返回 callback
            if (simpleReq.Req.State == HTTPRequestStates.Error)
            {
                VeerDebug.Log(" request error : " + simpleReq.Req.Exception);

                callback(SimpleHttpResult.FailedForNetwork, res, simpleReq.ReqId);
                return;
            }

            if (simpleReq.Req.State == HTTPRequestStates.ConnectionTimedOut || simpleReq.Req.State == HTTPRequestStates.TimedOut)
            {
                VeerDebug.Log(" request time out ...");

                callback(SimpleHttpResult.FailedForNetwork, res, simpleReq.ReqId);
                return;
            }

            callback(SimpleHttpResult.FailedForNetwork, res, simpleReq.ReqId);
        }