Пример #1
0
 /// <summary>
 /// Initiates a movement for this GameObject towards a given destination
 /// </summary>
 /// <param name="duration">Duration of the movement</param>
 /// <param name="durationType">Step: each step will take the same duration, Route: the given duration is for the entire route, MapLap: the duration is the time to cross entire map. Default duration type is 'Step'. Use 'MapLap' if you pass a custom set of non-continuous points to ensure a consistent speed of movement.</param>
 /// <returns><c>true</c>, if move is possible, <c>false</c> otherwise.</returns>
 public bool MoveTo(Vector2 destination, float duration, DURATION_TYPE durationType = DURATION_TYPE.Step)
 {
     if (terrainCapability != TERRAIN_CAPABILITY.Any)
     {
         // Get a route
         List <Vector2> route = FindRoute(destination);
         return(MoveTo(route, duration, durationType));
     }
     else
     {
         ClearOptions();
         if (isMoving)
         {
             Stop();
         }
         this.endingMap2DLocation = destination;
         if (map == null)
         {
             Init();
         }
         if (!map.VGOIsRegistered(this))
         {
             transform.position    = new Vector3(1000, -1000, 0);                        // prevents showing unit at wrong location the first frame
             _currentMap2DLocation = destination;
         }
         if (startingMap2DLocation == Misc.Vector2zero)
         {
             startingMap2DLocation = _currentMap2DLocation;
         }
         isMoving = true;
         StartCoroutine(StartMove(destination, duration));
     }
     return(true);
 }
Пример #2
0
        /// <summary>
        /// Initiates a movement for this GameObject along a predefined route
        /// </summary>
        /// <param name="duration">Duration of the movement</param>
        /// <param name="durationType">Step: each step will take the same duration, Route: the given duration is for the entire route, MapLap: the duration is the time to cross entire map. Default duration type is 'Step'. Use 'MapLap' if you pass a custom set of non-continuous points to ensure a consistent speed of movement.</param>
        /// <returns><c>true</c>, if move is possible, <c>false</c> otherwise.</returns>
        public bool MoveTo(List <Vector2> route, float duration, DURATION_TYPE durationType = DURATION_TYPE.Step)
        {
            ClearOptions();
            if (isMoving)
            {
                Stop();
            }
            this.route = route;
            if (route == null)
            {
                return(false);
            }
            int routeCount = route.Count;

            if (routeCount == 0)
            {
                return(false);
            }
            routeNextDestinationIndex = 1;
            this.destination          = routeCount > 1 ? route [1] : route [0];
            this.endingMap2DLocation  = route [routeCount - 1];
            if (map == null)
            {
                Init();
            }
            if (!map.VGOIsRegistered(this))
            {
                transform.position    = new Vector3(1000, -1000, 0);                    // prevents showing unit at wrong location the first frame
                _currentMap2DLocation = route [0];
            }
            if (startingMap2DLocation == Misc.Vector2zero)
            {
                startingMap2DLocation = _currentMap2DLocation;
            }

            // Duration?
            switch (durationType)
            {
            case DURATION_TYPE.Step:
                duration *= Mathf.Max(routeCount, 1);
                break;

            case DURATION_TYPE.MapLap:
                float   length  = 0;
                Vector2 prevPos = route [0];
                for (int k = 1; k < routeCount; k++)
                {
                    length += Vector3.Distance(prevPos, route [k]);
                    prevPos = route [k];
                }
                duration *= length;
                break;
            }
            // Starts first step
            isMoving = true;
            StartCoroutine(StartMove(destination, duration));
            return(true);
        }
Пример #3
0
        /// <summary>
        /// Initiates a movement for this GameObject along a predefined route of cell indices (if using grid)
        /// </summary>
        /// <param name="duration">Duration of the movement</param>
        /// <param name="durationType">Step: each step will take the same duration, Route: the given duration is for the entire route, MapLap: the duration is the time to cross entire map. Default duration type is 'Step'. Use 'MapLap' if you pass a custom set of non-continuous points to ensure a consistent speed of movement.</param>
        /// <returns><c>true</c>, if move is possible, <c>false</c> otherwise.</returns>
        public bool MoveTo(List <int> route, float duration, DURATION_TYPE durationType = DURATION_TYPE.Step)
        {
            int            stepCount = route.Count;
            List <Vector2> vv        = new List <Vector2> (stepCount);

            for (int k = 0; k < stepCount; k++)
            {
                vv.Add(map.GetCell(route [k]).center);
            }
            return(MoveTo(vv, duration, durationType));
        }
Пример #4
0
        /// <summary>
        /// UIの点滅を行うための関数(Imageバージョン)
        /// </summary>
        /// <param name="image">点滅させるイメージ</param>
        /// <param name="ease">EaseFuncitonの設定</param>
        /// <param name="type">durationさせる速さのタイプ</param>
        /// <returns></returns>
        public static Sequence BlinkingUI(Image image, Ease ease = Ease.Linear, DURATION_TYPE type = DURATION_TYPE.SLOW)
        {
            var   seq             = DOTween.Sequence();
            float duration        = GetDurationInSec(type);
            var   textChacheColor = image.color;

            seq.OnStart(() => image.color = new Color(textChacheColor.r, textChacheColor.g, textChacheColor.b, 1.0f));
            seq.Append(DOTween.To(() => image.color.a, alpha => { image.color = new Color(textChacheColor.r, textChacheColor.g, textChacheColor.b, alpha); }, 0.0f, duration)).SetEase(ease);
            seq.Append(DOTween.To(() => image.color.a, alpha => { image.color = new Color(textChacheColor.r, textChacheColor.g, textChacheColor.b, alpha); }, 1.0f, duration)).SetEase(ease);
            seq.SetLoops(-1);
            return(seq);
        }
Пример #5
0
        /// <summary>
        /// FadeOutアニメーションを呼び出す関数
        /// </summary>
        /// <param name="image">FadeOutさせる画像</param>
        /// <param name="type">durationさせる速さのタイプ</param>
        /// <param name="alpha">FadeOutさせた後のAlpha値</param>
        /// <param name="ease">EaseFunctionの設定</param>
        /// <returns></returns>
        public static Sequence FadeOut(Image image, DURATION_TYPE type, float alpha = 0f, Ease ease = Ease.Linear)
        {
            var   seq         = DOTween.Sequence();
            float duration    = GetDurationInSec(type);
            var   chacheColor = image.color;

            seq.OnStart(() => { image.color = new Color(chacheColor.r, chacheColor.g, chacheColor.b, 1.0f); });
            seq.Append(DOTween.To(() => image.color, color =>
            {
                image.color = color;
            }, new Color(chacheColor.r, chacheColor.g, chacheColor.b, alpha), duration)).SetEase(ease);
            return(seq);
        }
Пример #6
0
        private static float GetDurationInSec(DURATION_TYPE type)
        {
            switch (type)
            {
            case DURATION_TYPE.VERY_FAST:
                return(0.1f);

            case DURATION_TYPE.FAST:
                return(0.25f);

            case DURATION_TYPE.NORMAL:
                return(0.5f);

            case DURATION_TYPE.SLOW:
                return(0.75f);

            case DURATION_TYPE.VERY_SLOW:
                return(1.5f);

            default:
                return(0.5f);
            }
        }
Пример #7
0
        /// <summary>
        /// Popダウンさせるイメージのアニメーション関数
        /// </summary>
        /// <param name="rectTransform">Popダウンさせるやつ</param>
        /// <param name="ease">EaseFunctionの設定</param>
        /// <param name="type">durationさせる速さのタイプ</param>
        /// <returns></returns>
        public static Sequence ImagePopDown(RectTransform rectTransform, Ease ease = Ease.Linear, DURATION_TYPE type = DURATION_TYPE.FAST)
        {
            var   seq      = DOTween.Sequence();
            float duration = GetDurationInSec(type);

            seq.OnStart(() => { rectTransform.localScale = new Vector3(1f, 1f, 1f); });
            seq.Append(rectTransform.DOScale(new Vector3(0f, 0f, 0f), duration)).SetEase(ease);
            return(seq);
        }
Пример #8
0
        /// <summary>
        /// UIの点滅を行うための関数(CanvasGroupバージョン)
        /// </summary>
        /// <param name="canvasGroup">点滅させるCanvasGroup</param>
        /// <param name="ease">EaseFuncitonの設定</param>
        /// <param name="type">durationさせる速さのタイプ</param>
        /// <returns></returns>
        public static Sequence BlinkingUI(CanvasGroup canvasGroup, Ease ease = Ease.Linear, DURATION_TYPE type = DURATION_TYPE.SLOW)
        {
            var   seq      = DOTween.Sequence();
            float duration = GetDurationInSec(type);

            seq.OnStart(() => canvasGroup.alpha = 1.0f);
            seq.Append(canvasGroup.DOFade(0.0f, duration)).SetEase(ease);
            seq.Append(canvasGroup.DOFade(1.0f, duration)).SetEase(ease);
            seq.SetLoops(-1);
            return(seq);
        }
        /// <summary>
        /// Smoothly moves this game object to given map destination along route of points.
        /// </summary>
        /// <param name="durationType">Step: each step will take the same duration, Route: the given duration is for the entire route, MapLap: the duration is the time to cross entire map. Default duration type is 'Step'. Use 'MapLap' if you pass a custom set of non-continuous points to ensure a consistent speed of movement.</param>
        public static GameObjectAnimator WMSK_MoveTo(this GameObject o, List <Vector2> route, float duration, DURATION_TYPE durationType = DURATION_TYPE.Step)
        {
            GameObjectAnimator anim = o.GetComponent <GameObjectAnimator>() ?? o.AddComponent <GameObjectAnimator>();

            anim.MoveTo(route, duration, durationType);
            return(anim);
        }
        /// <summary>
        /// Smoothly moves this game object to given map position with options.
        /// </summary>
        /// <returns>The GameObjectAnimator component.</returns>
        /// <param name="destination">destination in -0.5 ... 0.5 range for X/Y coordinates</param>
        /// <param name="duration">duration in seconds</param>
        /// <param name="durationType">Step: each step will take the same duration, Route: the given duration is for the entire route, MapLap: the duration is the time to cross entire map. Default duration type is 'Step'. Use 'MapLap' if you pass a custom set of non-continuous points to ensure a consistent speed of movement.</param>
        /// <param name="scaleOnZoom">If set to <c>true</c> the gameobject will increase/decrease its scale when zoomin in/out.</param>
        public static GameObjectAnimator WMSK_MoveTo(this GameObject o, Vector2 destination, float duration = 0, DURATION_TYPE durationType = DURATION_TYPE.Step, bool scaleOnZoom = true, float altitude = 0)
        {
            GameObjectAnimator anim = o.GetComponent <GameObjectAnimator>() ?? o.AddComponent <GameObjectAnimator>();

            if (altitude == 0)
            {
                anim.heightMode = HEIGHT_OFFSET_MODE.RELATIVE_TO_GROUND;
            }
            else
            {
                anim.heightMode = HEIGHT_OFFSET_MODE.ABSOLUTE_CLAMPED;
                anim.altitude   = altitude;
            }
            anim.autoScale = scaleOnZoom;
            anim.MoveTo(destination, duration, durationType);
            return(anim);
        }
 /// <summary>
 /// Smoothly moves this game object to given map position with duration in seconds.
 /// <param name="durationType">Step: each step will take the same duration, Route: the given duration is for the entire route, MapLap: the duration is the time to cross entire map. Default duration type is 'Step'. Use 'MapLap' if you pass a custom set of non-continuous points to ensure a consistent speed of movement.</param>
 /// </summary>
 /// <returns>The GameObjectAnimator component.</returns>
 public static GameObjectAnimator WMSK_MoveTo(this GameObject o, float x, float y, float duration, DURATION_TYPE durationType = DURATION_TYPE.Step)
 {
     return(WMSK_MoveTo(o, new Vector2(x, y), duration, durationType));
 }