Пример #1
0
        private void InternalPlay(float delay)
        {
            this._totalTasks = 0;
            this._playing    = true;

            int cnt = this._items.Count;

            for (int i = 0; i < cnt; i++)
            {
                TransitionItem item = this._items[i];
                item.target = item.targetId.Length > 0 ? this._owner.GetChildById(item.targetId) : this._owner;
                if (item.target == null || item.target.disposed)
                {
                    this._items.RemoveAt(i);
                    --i;
                    --cnt;
                    continue;
                }

                item.completed = false;
                this._totalTasks++;

                if ((this._options & OPTION_IGNORE_DISPLAY_CONTROLLER) != 0)
                {
                    ++item.target.ignoreGearVisible;
                }

                float startTime = delay;
                if (this._reversed)
                {
                    startTime += (this._maxTime - item.time - item.duration);
                }
                else
                {
                    startTime += item.time;
                }

                if (item.tween)
                {
                    this.StartTween(item, delay);
                }
                else
                {
                    item.startValue.Copy(item.value);
                    TransitionValue startValue = item.startValue;
                    switch (item.type)
                    {
                    case TransitionActionType.XY:
                        if (!startValue.b1)
                        {
                            startValue.f.x += item.target.position.x;
                        }
                        if (!startValue.b2)
                        {
                            startValue.f.y += item.target.position.y;
                        }
                        break;

                    case TransitionActionType.Size:
                        if (!startValue.b1)
                        {
                            startValue.f.x += item.target.size.x;
                        }
                        if (!startValue.b2)
                        {
                            startValue.f.y += item.target.size.y;
                        }
                        break;

                    case TransitionActionType.Animation:
                        if (!startValue.b1)
                        {
                            startValue.f.x += (( IAnimationGear )item.target).frame;
                        }
                        break;
                    }
                    item.tweener = DOVirtual.DelayedCall(0, null).OnComplete(() =>
                    {
                        item.hook?.Invoke();
                        this.ApplyValue(item, startValue);
                        this.Complete(item);
                    });

                    if (startTime > 0)
                    {
                        item.tweener.SetDelay(startTime);
                    }
                    else
                    {
                        this.ApplyValue(item, startValue);
                    }
                }
            }

            if (this._totalTasks == 0)
            {
                this._playing = false;

                if (this._onComplete != null)
                {
                    PlayCompleteCallback func = this._onComplete;
                    this._onComplete = null;
                    func();
                }
            }
        }
Пример #2
0
        public void Setup(XML xml)
        {
            this.name     = xml.GetAttribute("name");
            this._options = xml.GetAttributeInt("options");
            this.autoPlay = xml.GetAttributeBool("autoPlay");
            if (this.autoPlay)
            {
                this.autoPlayRepeat = xml.GetAttributeInt("autoPlayRepeat", 1);
                this.autoPlayDelay  = xml.GetAttributeFloat("autoPlayDelay");
            }
            XMLList col = xml.Elements("item");

            foreach (XML cxml in col)
            {
                TransitionItem item = new TransitionItem();
                this._items.Add(item);

                item.time     = cxml.GetAttributeInt("time") / FRAME_RATE;
                item.targetId = cxml.GetAttribute("target", string.Empty);
                item.type     = FieldTypes.ParseTransitionActionType(cxml.GetAttribute("type"));
                item.tween    = cxml.GetAttributeBool("tween");
                item.label    = cxml.GetAttribute("label");
                if (item.tween)
                {
                    item.duration = cxml.GetAttributeInt("duration") / FRAME_RATE;
                    if (item.time + item.duration > this._maxTime)
                    {
                        this._maxTime = item.time + item.duration;
                    }

                    string ease = cxml.GetAttribute("ease");
                    if (ease != null)
                    {
                        item.easeType = FieldTypes.ParseEaseType(ease);
                    }

                    item.repeat = cxml.GetAttributeInt("repeat");
                    item.yoyo   = cxml.GetAttributeBool("yoyo");
                    item.label2 = cxml.GetAttribute("label2");

                    string v = cxml.GetAttribute("endValue");
                    if (v != null)
                    {
                        this.DecodeValue(item.type, cxml.GetAttribute("startValue", string.Empty), item.startValue);
                        this.DecodeValue(item.type, v, item.endValue);
                    }
                    else
                    {
                        item.tween = false;
                        this.DecodeValue(item.type, cxml.GetAttribute("startValue", string.Empty), item.value);
                    }
                }
                else
                {
                    if (item.time > this._maxTime)
                    {
                        this._maxTime = item.time;
                    }
                    this.DecodeValue(item.type, cxml.GetAttribute("value", string.Empty), item.value);
                    if (item.type == TransitionActionType.Shake)
                    {
                        item.tween = true;
                    }
                }
            }
        }
Пример #3
0
        private void ApplyValue(TransitionItem item, TransitionValue value)
        {
            switch (item.type)
            {
            case TransitionActionType.XY:
            case TransitionActionType.Shake:
                item.target.SetGearState(GObject.GearState.Position, true);
                item.target.position = value.f;
                item.target.SetGearState(GObject.GearState.Position, false);
                break;

            case TransitionActionType.Size:
                item.target.SetGearState(GObject.GearState.Size, true);
                item.target.size = value.f;
                item.target.SetGearState(GObject.GearState.Size, false);
                break;

            case TransitionActionType.Pivot:
                item.target.pivot = value.f;
                break;

            case TransitionActionType.Alpha:
                item.target.SetGearState(GObject.GearState.Look, true);
                item.target.alpha = value.f.x;
                item.target.SetGearState(GObject.GearState.Look, false);
                break;

            case TransitionActionType.Rotation:
                item.target.SetGearState(GObject.GearState.Look, true);
                item.target.rotation = value.f.x;
                item.target.SetGearState(GObject.GearState.Look, false);
                break;

            case TransitionActionType.Scale:
                item.target.SetGearState(GObject.GearState.Size, true);
                item.target.scale = value.f;
                item.target.SetGearState(GObject.GearState.Size, false);
                break;

            case TransitionActionType.Color:
                item.target.SetGearState(GObject.GearState.Color, true);
                item.target.color = value.c;
                item.target.SetGearState(GObject.GearState.Color, false);
                break;

            case TransitionActionType.Animation:
                item.target.SetGearState(GObject.GearState.Animation, true);
                (( IAnimationGear )item.target).frame   = value.i;
                (( IAnimationGear )item.target).playing = value.b;
                item.target.SetGearState(GObject.GearState.Animation, false);
                break;

            case TransitionActionType.Visible:
                item.target.visible = value.b;
                break;

            case TransitionActionType.Controller:
                string[] arr = value.s.Split(',');
                foreach (string str in arr)
                {
                    string[]   arr2 = str.Split('=');
                    Controller cc   = (( GComponent )item.target).GetController(arr2[0]);
                    if (cc != null)
                    {
                        string str2 = arr2[1];
                        if (str2[0] == '$')
                        {
                            str2            = str.Substring(1);
                            cc.selectedPage = str2;
                        }
                        else
                        {
                            cc.selectedIndex = int.Parse(str2);
                        }
                    }
                }
                break;

            case TransitionActionType.Transition:
                Transition trans = (( GComponent )item.target).GetTransition(value.s);
                if (trans != null)
                {
                    if (value.i == 0)
                    {
                        trans.Stop();
                    }
                    else if (trans.playing)
                    {
                        trans._totalTimes = value.i == -1 ? int.MaxValue : value.i;
                    }
                    else
                    {
                        if (this._reversed)
                        {
                            trans.PlayReverse(value.i);
                        }
                        else
                        {
                            trans.Play(value.i);
                        }
                    }
                }
                break;

            case TransitionActionType.Sound:
                AudioClip sound = UIPackage.GetItemAssetByURL(value.s) as AudioClip;
                if (sound != null)
                {
                    Stage.inst.PlayOneShotSound(sound, value.f.x);
                }
                break;
            }
        }
Пример #4
0
        public void SetValue(string label, params object[] aParams)
        {
            int cnt = this._items.Count;

            for (int i = 0; i < cnt; i++)
            {
                TransitionItem item = this._items[i];
                if (item.label == null && item.label2 == null)
                {
                    continue;
                }

                TransitionValue value;
                if (item.label == label)
                {
                    value = item.tween ? item.startValue : item.value;
                }
                else if (item.label2 == label)
                {
                    value = item.endValue;
                }
                else
                {
                    continue;
                }

                switch (item.type)
                {
                case TransitionActionType.XY:
                case TransitionActionType.Size:
                case TransitionActionType.Pivot:
                case TransitionActionType.Scale:
                    value.b1  = true;
                    value.b2  = true;
                    value.f.x = Convert.ToSingle(aParams[0]);
                    value.f.y = Convert.ToSingle(aParams[1]);
                    break;

                case TransitionActionType.Alpha:
                    value.f.x = Convert.ToSingle(aParams[0]);
                    break;

                case TransitionActionType.Rotation:
                    value.i = Convert.ToInt32(aParams[0]);
                    break;

                case TransitionActionType.Color:
                    value.c = ( Color )aParams[0];
                    break;

                case TransitionActionType.Animation:
                    value.i = Convert.ToInt32(aParams[0]);
                    if (aParams.Length > 1)
                    {
                        value.b = Convert.ToBoolean(aParams[1]);
                    }
                    break;

                case TransitionActionType.Visible:
                    value.b = Convert.ToBoolean(aParams[0]);
                    break;

                case TransitionActionType.Controller:
                    value.s = ( string )aParams[0];
                    break;

                case TransitionActionType.Sound:
                    value.s = ( string )aParams[0];
                    if (aParams.Length > 1)
                    {
                        value.f.x = Convert.ToSingle(aParams[1]);
                    }
                    break;

                case TransitionActionType.Transition:
                    value.s = ( string )aParams[0];
                    if (aParams.Length > 1)
                    {
                        value.i = Convert.ToInt32(aParams[1]);
                    }
                    break;

                case TransitionActionType.Shake:
                    value.f.x = Convert.ToSingle(aParams[0]);
                    if (aParams.Length > 1)
                    {
                        value.f.y = Convert.ToSingle(aParams[1]);
                    }
                    break;
                }
            }
        }
Пример #5
0
        private void StartTween(TransitionItem item, float delay)
        {
            Vector2 startValue = item.startValue.f;
            Vector2 endValue   = item.endValue.f;

            switch (item.type)
            {
            case TransitionActionType.XY:
                if (!item.startValue.b1)
                {
                    startValue.x += item.target.position.x;
                }
                if (!item.startValue.b2)
                {
                    startValue.y += item.target.position.y;
                }
                if (!item.endValue.b1)
                {
                    endValue.x += item.target.position.x;
                }
                if (!item.endValue.b2)
                {
                    endValue.y += item.target.position.y;
                }
                break;

            case TransitionActionType.Size:
                if (!item.startValue.b1)
                {
                    startValue.x += item.target.size.x;
                }
                if (!item.startValue.b2)
                {
                    startValue.y += item.target.size.y;
                }
                if (!item.endValue.b1)
                {
                    endValue.x += item.target.size.x;
                }
                if (!item.endValue.b2)
                {
                    endValue.y += item.target.size.y;
                }
                break;

            case TransitionActionType.Animation:
                if (!item.startValue.b1)
                {
                    startValue.x += (( IAnimationGear )item.target).frame;
                }
                if (!item.endValue.b1)
                {
                    endValue.x += (( IAnimationGear )item.target).frame;
                }
                break;
            }

            float startTime = delay;

            if (this._reversed)
            {
                Vector2 tmp = startValue;
                startValue = endValue;
                endValue   = tmp;
                startTime += (this._maxTime - item.time - item.duration);
            }
            else
            {
                startTime += item.time;
            }

            switch (item.type)
            {
            case TransitionActionType.Shake:
            {
                item.tweener = DOTween.Shake(() => item.target.position, v => item.endValue.f = v, item.value.f.y, item.value.f.x,
                                             10 /*频率*/, 90, true, true)
                               .OnUpdate(() => this.ApplyValue(item, item.endValue));
            }
            break;

            case TransitionActionType.Color:
            {
                item.tweener = DOTween.To(() => item.startValue.c,
                                          v => { item.value.c = v; }, item.endValue.c, item.duration)
                               .OnUpdate(() => this.ApplyValue(item, item.value));
            }
            break;

            default:
            {
                item.tweener = DOTween.To(() => startValue,
                                          v => { item.value.f = v; }, endValue, item.duration)
                               .OnUpdate(() => this.ApplyValue(item, item.value));
            }
            break;
            }
            item.tweener
            .SetUpdate(true)
            .SetEase(item.easeType)
            .OnStart(() =>
            {
                item.hook?.Invoke();
            })
            .OnComplete(() =>
            {
                item.hook2?.Invoke();
                this.Complete(item);
            });

            if (item.repeat != 0)
            {
                item.tweener.SetLoops(item.repeat == -1 ? int.MaxValue : (item.repeat + 1), item.yoyo ? LoopType.Yoyo : LoopType.Restart);
            }

            if (startTime > 0)
            {
                item.tweener.SetDelay(startTime);
            }
            else
            {
                item.value.f = startValue;
                this.ApplyValue(item, item.value);
            }
        }