Ejemplo n.º 1
0
        public static void Test()
        {
                        #if UNITY_EDITOR
            System.Reflection.Assembly
            .GetAssembly(typeof(UnityEditor.SceneView))
            .GetType("UnityEditor.LogEntries")
            .GetMethod("Clear")
            .Invoke(new object(), null);
                        #endif

            var sw = new System.Diagnostics.Stopwatch(); sw.Stop(); sw.Reset(); sw.Start();
            Mem.Test();     Log("Mem test: {0:N0}", sw.ElapsedTicks);     sw.Reset(); sw.Start();
            Algo.Test();    Log("Algo test: {0:N0}", sw.ElapsedTicks);    sw.Reset(); sw.Start();

            Pool.Test();       Log("Pool2 test: {0:N0}", sw.ElapsedTicks);   sw.Reset(); sw.Start();
            PtrLst.Test();     Log("PtrLst2 test: {0:N0}", sw.ElapsedTicks); sw.Reset(); sw.Start();
            PtrIntDict.Test(); Log("NumDict test: {0:N0}", sw.ElapsedTicks); sw.Reset(); sw.Start();
        }
Ejemplo n.º 2
0
        public void Update(float deltaTime)
        {
            time += deltaTime;

            // execute commands
            if (time > waitEndTime)
            {
                while (time > waitEndTime && cmdQueue.Count > 0)
                {
                    var cmd = cmdQueue.Dequeue();

                    switch (cmd.GetType().Name)
                    {
                    case "WaitCmd":            Wait(cmd as WaitCmd); break;

                    case "AddImgCmd":          AddImg(cmd as AddImgCmd); break;

                    case "RmImgCmd":           RmImg(cmd as RmImgCmd); break;

                    case "SetImgAttrCmd":      SetImgAttr(cmd as SetImgAttrCmd); break;

                    case "SetImgAttrEasedCmd": SetImgAttrEased(cmd as SetImgAttrEasedCmd); break;

                    case "SetCamAttrCmd":      SetCamAttr(cmd as SetCamAttrCmd); break;

                    case "SetCamAttrEasedCmd": SetCamAttrEased(cmd as SetCamAttrEasedCmd); break;
                    }
                }
            }

            // execute easing jobs
            for (var node = esJobList.First; node != null;)
            {
                var next = node.Next;
                var job  = node.Value;
                if ((job.time += deltaTime) > job.duration)
                {
                    job.Finish();
                    esJobList.Remove(node);
                }
                else
                {
                    job.Apply(Es.Ease(job.esType, job.time / job.duration));
                }
                node = next;
            }

            // sort
            if (needDepthSort)
            {
                needDepthSort = false;
                Algo.MergeSort(spritePtrLst->arr, spritePtrLst->count, TpSprite.DepthCmp);
            }

            var arr = (TpSprite **)spritePtrLst->arr;

            // mouse (0 for left button, 1 for right button, 2 for the middle button)
            for (int m = 0; m <= 2; m += 1)
            {
                int phase = TchPhase.FromUnityMouse(m);
                if (phase == TchPhase.None)
                {
                    continue;
                }
                var   pos = cam.ScreenToWorldPoint(UnityEngine.Input.mousePosition);
                float x = pos.x, y = pos.y;
                for (int i = spritePtrLst->count - 1; i >= 0; i -= 1)
                {
                    int id = arr[i]->id;
                    if (nodeTouchHandlerDict.ContainsKey(id) && TpSprite.Raycast(arr[i], x, y))                        // has a handler && pos in sprite
                    {
                        nodeTouchHandlerDict[id].Invoke(TchPhase.FromUnityMouse(m), x, y);
                        break;
                    }
                }
            }

            // touch
            var touches = UnityEngine.Input.touches;

            foreach (var touch in touches)
            {
                var   pos = cam.ScreenToWorldPoint(touch.position);
                float x = pos.x, y = pos.y;
                for (int i = spritePtrLst->count - 1; i >= 0; i -= 1)
                {
                    int id = arr[i]->id;
                    if (nodeTouchHandlerDict.ContainsKey(id) && TpSprite.Raycast(arr[i], x, y))                        // has a handler && pos in sprite
                    {
                        nodeTouchHandlerDict[id].Invoke(TchPhase.FromUnityTouch(touch.phase), x, y);
                        break;
                    }
                }
            }

            // draw
            DrawCtx.Start();
            for (int i = 0, end = spritePtrLst->count; i < end; i += 1)
            {
                Node.Draw(arr[i], null, false);
            }
            DrawCtx.Finish();
        }