示例#1
0
        void SetImgAttr(SetImgAttrCmd cmd)
        {
                        #if FDB
            Should.True("nodeIdxDict.ContainsKey(cmd.id)", PtrIntDict.Contains(nodeDict, cmd.id));
            Should.InRange("cmd.imgAttrId", cmd.imgAttrId, 0, ImgAttr.End - 1);
                        #endif
            var img  = (TpSprite *)PtrIntDict.Get(nodeDict, cmd.id);
            var args = cmd.args;
            switch (cmd.imgAttrId)
            {
            case ImgAttr.Interactable: SetImgInteractable(cmd); break;

            case ImgAttr.Position:     TpSprite.SetPosition(img, (float)args[0], (float)args[1], (float)args[2]); needDepthSort = true; break;

            case ImgAttr.Rotation:     TpSprite.SetRotation(img, (float)args[0]); break;

            case ImgAttr.Scale:        TpSprite.SetScale(img, (float)args[0], (float)args[1]); break;

            case ImgAttr.Alpha:        TpSprite.SetAlpha(img, (float)args[0]); break;

            case ImgAttr.Tint:         TpSprite.SetTint(img, (float)args[0], (float)args[1], (float)args[2]); break;

            case ImgAttr.ImgId:        TpSprite.SetMeta(img, Res.GetSpriteMeta((int)args[0])); break;
            }
        }
示例#2
0
        void AddImg(AddImgCmd cmd)
        {
                        #if FDB
            Should.False("nodeIdxDict.ContainsKey(cmd.id)", PtrIntDict.Contains(nodeDict, cmd.id));
            Should.True("Res.HasSpriteMeta(cmd.imgId)", Res.HasSpriteMeta(cmd.imgId));
                        #endif
            var node = (TpSprite *)Pool.Alloc(spritePool, sizeof(TpSprite));
            TpSprite.Init(node, Res.GetSpriteMeta(cmd.imgId));
            node->id = cmd.id;

            if (spritePool->shift != 0)
            {
                PtrLst.ShiftBase(spritePtrLst, spritePool->shift);
                PtrIntDict.ShiftBase(nodeDict, spritePool->shift);
                foreach (var esJob in esJobList)
                {
                    if (esJob is EsImgJob)
                    {
                        var esTpSpriteJob = (EsImgJob)esJob;
                        esTpSpriteJob.node = (TpSprite *)((byte *)esTpSpriteJob.node + spritePool->shift);
                    }
                }
                needDepthSort     = true;
                spritePool->shift = 0;
            }
            PtrLst.Push(spritePtrLst, node);
            PtrIntDict.Set(nodeDict, cmd.id, node);
        }
示例#3
0
 public override void Finish()
 {
     TpSprite.SetTint(node, r + dr, g + dg, b + db);
 }
示例#4
0
 class EsSetImgTintJob : EsImgJob { public float r, g, b, dr, dg, db; public override void Apply(float step)
                                    {
                                        TpSprite.SetTint(node, r + dr * step, g + dg * step, b + db * step);
                                    }
示例#5
0
 public override void Finish()
 {
     TpSprite.SetAlpha(node, a + da);
 }
示例#6
0
 class EsSetImgAlphaJob : EsImgJob { public float a, da;               public override void Apply(float step)
                                     {
                                         TpSprite.SetAlpha(node, a + da * step);
                                     }
示例#7
0
 public override void Finish()
 {
     TpSprite.SetScale(node, x + dx, y + dy);
 }
示例#8
0
 class EsSetImgScaleJob : EsImgJob { public float x, dx, y, dy;        public override void Apply(float step)
                                     {
                                         TpSprite.SetScale(node, x + dx * step, y + dy * step);
                                     }
示例#9
0
 public override void Finish()
 {
     TpSprite.SetRotation(node, r + dr);
 }
示例#10
0
 class EsSetImgRotationJob : EsImgJob { public float r, dr;               public override void Apply(float step)
                                        {
                                            TpSprite.SetRotation(node, r + dr * step);
                                        }
示例#11
0
 public override void Finish()
 {
     TpSprite.SetPosition(node, x + dx, y + dy, z + dz);
 }
示例#12
0
 class EsSetImgPositionJob : EsImgJob { public float x, y, z, dx, dy, dz; public override void Apply(float step)
                                        {
                                            TpSprite.SetPosition(node, x + dx * step, y + dy * step, z + dz * step);
                                        }
示例#13
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();
        }