예제 #1
0
        public void Dispose()
        {
            cmdQueue.Clear();
            esJobList.Clear();
            PtrIntDict.Decon(nodeDict); Mem.Free(nodeDict); nodeDict         = null;
            Pool.Decon(spritePool); Mem.Free(spritePool); spritePool         = null;
            PtrLst.Decon(spritePtrLst); Mem.Free(spritePtrLst); spritePtrLst = null;
            DrawCtx.Dispose();

            Debug.Log("Clean up GPC");
        }
예제 #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();
        }