Ejemplo n.º 1
0
        public static void PushIn(GameObject obj, float duration, TransitionDirection direction, Action completion = null)
        {
            var sign = direction == TransitionDirection.Backward ? 1 : -1;

            var screenLocation = Camera.main.WorldToScreenPoint(obj.transform.position);
            var x = Screen.width / 2 + (sign * Screen.width);

            Debug.Log("X = " + x);
            var sourceScreen     = new Vector3(x, screenLocation.y * 0.8f, screenLocation.z * 0.8f);
            var sourceWorld      = Camera.main.ScreenToWorldPoint(sourceScreen);
            var destinationWorld = obj.transform.position;

            obj.transform.position = sourceWorld;

            var moveAnimation = ABAnimation.MoveTo(destinationWorld, duration);

            moveAnimation.Timing = ABAnimationTiming.EaseOut;

            var destinationAngles = obj.transform.eulerAngles;
            var rotateAnimation   = ABAnimation.RotateTo(destinationAngles, duration);

            rotateAnimation.Timing    = ABAnimationTiming.EaseInEaseOut;
            obj.transform.eulerAngles = new Vector3(destinationAngles.x, destinationAngles.y + (sign * 90), destinationAngles.z);


            var list = new List <ABAnimation> (2);

            list.Add(moveAnimation);
            list.Add(rotateAnimation);
            var group = ABAnimation.Group(list);

            ABAnimationSystem.RunAnimation(group, obj, completion);
        }
Ejemplo n.º 2
0
        public static void PushOut(GameObject obj, float duration, TransitionDirection direction, Action completion = null)
        {
            var sign = direction == TransitionDirection.Backward ? -1 : 1;

            var screenLocation = Camera.main.WorldToScreenPoint(obj.transform.position);
            var x = Screen.width / 2 + (sign * Screen.width * 1.25f);
//			Debug.Log ("X = " + x);
            var destinationScreen = new Vector3(x, screenLocation.y * 0.8f, screenLocation.z * 0.8f);
            var destinationWorld  = Camera.main.ScreenToWorldPoint(destinationScreen);

            var moveAnimation = ABAnimation.MoveTo(destinationWorld, duration);

            moveAnimation.Timing = ABAnimationTiming.EaseIn;

            var deltaAngle      = sign * 90;
            var rotateAnimation = ABAnimation.RotateBy(new Vector3(0, deltaAngle, 0), duration);

            rotateAnimation.Timing = ABAnimationTiming.EaseInEaseOut;

            var list = new List <ABAnimation> (2);

            list.Add(moveAnimation);
            list.Add(rotateAnimation);
            var group = ABAnimation.Group(list);

            ABAnimationSystem.RunAnimation(group, obj, completion);
        }
 private void showValueDurationControls(ABAnimation animation, string vectorLabel = "Value", float low = 0, float high = 1, bool showRepeats = true)
 {
     animation.Value    = EditorGUILayout.Slider(vectorLabel, animation.Value, low, high);
     animation.Duration = EditorGUILayout.FloatField("Duration", animation.Duration);
     animation.Timing   = timingModeChooser(animation.Timing);
     if (showRepeats)
     {
         animation.RepeatsCount = repeatsCountChooser(animation.RepeatsCount);
     }
 }
 void showVector2DurationControls(ABAnimation animation, string vectorLabel = "Vector", bool showRepeats = true)
 {
     animation.Vector   = EditorGUILayout.Vector2Field(vectorLabel, animation.Vector);
     animation.Duration = EditorGUILayout.FloatField("Duration", animation.Duration);
     animation.Timing   = timingModeChooser(animation.Timing);
     if (showRepeats)
     {
         animation.RepeatsCount = repeatsCountChooser(animation.RepeatsCount);
     }
 }
        void showPreviewAnimationButtonIfExists(ABAnimation animation, string label = "Preview Animation")
        {
            if (animation == null || animation.Type == ABAnimationType.None || animation.Type == ABAnimationType.Wait)
            {
                return;
            }

            if (GUILayout.Button(label))
            {
                ABAnimationSystem.PreviewAnimation(animation, CurrentPicture.GameObject);
            }
        }
        private int foldableAnimationsCount(ABAnimation animation)
        {
            int count = 0;

            foreach (var item in animation.Animations)
            {
                if (item.Type == ABAnimationType.Group ||
                    item.Type == ABAnimationType.Sequence)
                {
                    count += 1 + foldableAnimationsCount(item);
                }
            }
            return(count);
        }
        void showChooseAnimationControls(ABAnimation animation)
        {
            EditorGUILayout.BeginHorizontal();

            var index    = ABAnimationTypeHelper.IndexOfAnimation(animation);
            var newIndex = EditorGUILayout.Popup(index, ABAnimationTypeHelper.TypeDescriptions());

            if (newIndex != index)
            {
                var type = (ABAnimationType)newIndex;
                Debug.Log(newIndex + " is " + ABAnimationTypeHelper.TypeDescription(type));
                animation.Type = type;
            }

            showPreviewAnimationButtonIfExists(animation, "Preview");

            EditorGUILayout.EndHorizontal();
        }
        void showAnimationControls(ABAnimation animation)
        {
            switch (animation.Type)
            {
            case ABAnimationType.MoveBy:
//				GUILayout.Label ("Move By", EditorStyles.boldLabel);
                showVector3DurationControls(animation, "Delta vector");
                break;

            case ABAnimationType.MoveTo:
//				GUILayout.Label ("Move To", EditorStyles.boldLabel);
                showVector3DurationControls(animation, "Final position", false);
                break;

            case ABAnimationType.RotateBy:
//				GUILayout.Label ("Rotate By", EditorStyles.boldLabel);
                showVector3DurationControls(animation, "Delta angle");
                break;

            case ABAnimationType.RotateTo:
//				GUILayout.Label ("Rotate To", EditorStyles.boldLabel);
                showVector3DurationControls(animation, "Final angle", false);
                break;

            case ABAnimationType.ScaleBy:
//				GUILayout.Label ("Scale By", EditorStyles.boldLabel);
                showVector2DurationControls(animation, "Delta values");
                break;

            case ABAnimationType.ScaleTo:
//				GUILayout.Label ("Scale To", EditorStyles.boldLabel);
                showVector2DurationControls(animation, "Final values", false);
                break;

            case ABAnimationType.Group:
                showGroupControls(animation, "Animation Group");
                break;

            case ABAnimationType.Sequence:
                showGroupControls(animation, "Animation Sequence");
                break;

            case ABAnimationType.FadeAlphaBy:
                showValueDurationControls(animation, "Delta Alpha", -1, 1);
                break;

            case ABAnimationType.FadeAlphaTo:
                showValueDurationControls(animation, "Final Alpha", 0, 1, false);
                break;

            case ABAnimationType.FadeIn:
            case ABAnimationType.FadeOut:
                showDurationTimingControls(animation);
                break;

            case ABAnimationType.Wait:
                animation.Duration = EditorGUILayout.FloatField("Duration", animation.Duration);
                break;

            default:
                break;
            }
        }
 private void showDurationTimingControls(ABAnimation animation)
 {
     animation.Duration = EditorGUILayout.FloatField("Duration", animation.Duration);
     animation.Timing   = timingModeChooser(animation.Timing);
 }
        void showGroupControls(ABAnimation animation, string foldLabel = "Animations")
        {
            if (animation.Animations == null)
            {
                animation.Animations = new List <ABAnimation> ();
                animation.Animations.Add(new ABAnimation(ABAnimationType.None));
            }

            if (foldIndex == foldsEnablers.Count)
            {
                foldsEnablers.Add(true);
            }

            EditorGUILayout.BeginHorizontal();

            foldsEnablers [foldIndex] = EditorGUILayout.Foldout(foldsEnablers[foldIndex], foldLabel);

            // Show Add & Remove buttons
            var count = animation.Animations.Count;

            if (foldsEnablers [foldIndex])
            {
                if (GUILayout.Button("Add"))
                {
                    animation.Animations.Add(new ABAnimation(ABAnimationType.None));
                    count++;
                }
                GUI.enabled = count > 1;
                if (GUILayout.Button("Remove"))
                {
                    animation.Animations.RemoveAt(count - 1);
                    count--;
                }
                GUI.enabled = true;
            }

            EditorGUILayout.EndHorizontal();

            // Show Animation controls
            if (foldsEnablers [foldIndex])
            {
                foldIndex++;
                EditorGUI.indentLevel++;

                animation.RepeatsCount = repeatsCountChooser(animation.RepeatsCount);

                for (int index = 0; index < count; ++index)
                {
                    EditorGUILayout.LabelField("Animation " + (index + 1));
                    var item = animation.Animations [index];
                    showChooseAnimationControls(item);
                    showAnimationControls(item);
                    EditorGUILayout.Separator();
                }

                EditorGUI.indentLevel--;
                EditorGUILayout.Separator();
            }
            else
            {
                foldIndex += 1 + foldableAnimationsCount(animation);
            }
        }