コード例 #1
0
        /// <summary>
        /// Draw Animation Action Runner editor
        /// </summary>
        /// <param name="aar"></param>
        /// <param name="s"></param>
        /// <returns>Whether "delete" was pressed</returns>
        bool DrawAAR(AnimationActionRunner aar, AnimationStep s)
        {
            //EditorGUILayout.LabelField("Element visibility: S=" + ae.unhideDelay.ToString("0.0") + " E= " + ae.hideDelay.ToString("0.0"));
            GUILayout.Space(8);
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label(aar.animationAction.name);
            bool delete = GUILayout.Button("Delete");

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Repeating");
            aar.repeating = EditorGUILayout.Toggle(aar.repeating);
            EditorGUILayout.EndHorizontal();


            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.BeginVertical();
                GUILayout.Label("Start");
                aar.startTime = EditorGUILayout.DelayedFloatField(aar.startTime);

                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical();
                GUILayout.Label("Length");
                aar.SetLength(EditorGUILayout.DelayedFloatField(aar.length));
                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical();
                GUILayout.Label("End");
                aar.SetEndTime(EditorGUILayout.DelayedFloatField(aar.endTime));
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndHorizontal();
            return(delete);
        }
コード例 #2
0
        void NewElement()
        {
            AnimationStep step = (AnimationStep)target;

            Selection.activeGameObject = AnimationElement.CreateEmpty(step, AnimationHolderEditor.aeName).gameObject;
            AnimationHolderEditor.InitLists();
        }
コード例 #3
0
        void NewStep()
        {
            AnimationHolder ah = (AnimationHolder)target;

            Selection.activeGameObject = AnimationStep.CreateEmpty(ah, defStepName).gameObject;
            InitLists();
        }
コード例 #4
0
ファイル: AnimationHolder.cs プロジェクト: jiripolcar/VAM
        private IEnumerator PositioningCamera(AnimationStep step, float time)
        {
            posCamEndPos   = step.cameraPosition.position;
            posCamEndEA    = step.cameraPosition.eulerAngles;
            posCamStartPos = cam.transform.localPosition;
            posCamStartEA  = cam.transform.localEulerAngles;
            posCamLerp     = 0;
            if (positioningCamera)
            {
                yield break;
            }
            positioningCamera = true;


            if (time > 0)
            {
                while (posCamLerp < 1 && positioningCamera)
                {
                    posCamLerp += Time.deltaTime / time;
                    cam.transform.localPosition    = Vector3.Lerp(posCamStartPos, posCamEndPos, posCamLerp);
                    cam.transform.localEulerAngles = Vector3.Lerp(posCamStartEA, posCamEndEA, posCamLerp);
                    yield return(0);
                }
            }
            cam.transform.localPosition    = posCamEndPos;
            cam.transform.localEulerAngles = posCamEndEA;
            positioningCamera = false;
        }
コード例 #5
0
        void LoadCameraPosition()
        {
            AnimationStep   step   = (AnimationStep)target;
            AnimationHolder holder = step.transform.parent.GetComponent <AnimationHolder>();

            step.cameraPosition.ApplyWorld(holder.cam);
            SceneView.lastActiveSceneView.AlignViewToObject(holder.cam.transform);
        }
コード例 #6
0
        // Update is called once per frame
        void Update()
        {
            AnimationStep currentStep = holder.CurrentStep;
            string        text        = "Step: " + holder.PlayingStepID;

            if (currentStep)
            {
                text += " = " + currentStep.name + " Time: " + currentStep.stepTime.ToString("0.0");
            }
            timeText.text = text;
        }
コード例 #7
0
ファイル: AnimationElement.cs プロジェクト: jiripolcar/VAM
        public static AnimationElement CreateEmpty(AnimationStep step, string name)
        {
            GameObject o = new GameObject();

            o.name                       = name;
            o.transform.parent           = step.transform;
            o.transform.localPosition    = Vector3.zero;
            o.transform.localEulerAngles = Vector3.zero;
            o.transform.localScale       = Vector3.one;
            return(o.AddComponent <AnimationElement>());
        }
コード例 #8
0
        void SaveCameraPosition()
        {
            AnimationStep   step   = (AnimationStep)target;
            AnimationHolder holder = step.transform.parent.GetComponent <AnimationHolder>();
            Transform       t      = holder.cam.transform;

            t.position                      = SceneView.lastActiveSceneView.camera.transform.position;
            t.eulerAngles                   = SceneView.lastActiveSceneView.camera.transform.eulerAngles;
            step.cameraPosition             = new TransformData();
            step.cameraPosition.position    = t.position;
            step.cameraPosition.eulerAngles = t.eulerAngles;
            step.cameraPosition.localScale  = t.localScale;
        }
コード例 #9
0
ファイル: AnimationHolder.cs プロジェクト: jiripolcar/VAM
 public void Initialize()
 {
     animationSteps = new List <AnimationStep>();
     foreach (Transform child in transform)
     {
         AnimationStep anistep = child.gameObject.GetComponent <AnimationStep>();
         if (!anistep)
         {
             Debug.LogError(name + ": Object " + child.name + " is not an AnimationElementObject");
         }
         animationSteps.Add(anistep);
         anistep.Initialize(this);
     }
 }
コード例 #10
0
ファイル: AnimationElement.cs プロジェクト: jiripolcar/VAM
 internal void Initialize(AnimationStep step, AnimationHolder holder)
 {
     this.step               = step;
     this.holder             = holder;
     animationElementObjects = new List <AnimationElementObject>();
     foreach (Transform child in transform)
     {
         AnimationElementObject aeo = child.gameObject.GetComponent <AnimationElementObject>();
         if (!aeo)
         {
             Debug.LogError(name + ": Object " + child.name + " is not an AnimationElementObject");
         }
         animationElementObjects.Add(aeo);
     }
 }
コード例 #11
0
        public static void DrawAETimes(AnimationElement ae, AnimationStep s, bool displayNameAndType = true)
        {
            GUILayout.Space(8);

            float animationEndDelay = ae.animationStartDelay + ae.animationLength;

            if (displayNameAndType)
            {
                EditorGUILayout.LabelField(ae.name + " - " + ae.animationElementType.ToString());
            }
            EditorGUILayout.LabelField("unhide:" + ae.unhideDelay.ToString("0.0") +
                                       " start:" + ae.animationStartDelay.ToString("0.0") +
                                       " length:" + ae.animationLength.ToString("0.0") +
                                       " end:" + animationEndDelay.ToString("0.0") +
                                       " hide:" + ae.hideDelay.ToString("0.0"));
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.BeginVertical();
                {
                    //EditorGUILayout.LabelField("Element visibility: S=" + ae.unhideDelay.ToString("0.0") + " E= " + ae.hideDelay.ToString("0.0"));
                    EditorGUILayout.MinMaxSlider(ref ae.unhideDelay, ref ae.hideDelay, 0, s.stepLength);
                    EditorGUILayout.BeginHorizontal();
                    {
                        ae.unhideDelay = EditorGUILayout.DelayedFloatField(ae.unhideDelay);
                        ae.hideDelay   = EditorGUILayout.DelayedFloatField(ae.hideDelay);
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical();
                {
                    //EditorGUILayout.LabelField("Animation duration: S=" + ae.animationStartDelay.ToString("0.0") + " L= " + ae.animationLength.ToString("0.0") + " E= " + animationEndDelay.ToString("0.0"));
                    EditorGUILayout.MinMaxSlider(ref ae.animationStartDelay, ref animationEndDelay, 0, s.stepLength);
                    EditorGUILayout.BeginHorizontal();
                    {
                        ae.animationStartDelay = EditorGUILayout.DelayedFloatField(ae.animationStartDelay);
                        animationEndDelay      = EditorGUILayout.DelayedFloatField(animationEndDelay);
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndVertical();


                ae.animationLength = animationEndDelay - ae.animationStartDelay;
            }
            EditorGUILayout.EndHorizontal();
        }
コード例 #12
0
 public static void TimePoint(float time, AnimationStep s, AnimationElement e)
 {
     if (time > e.unhideDelay && time < e.hideDelay)
     {
         e.ReInstantiate();
         if (time > e.animationStartDelay && time < e.animationStartDelay + e.animationLength)
         {
             e.SetLerp((time - e.animationStartDelay) / e.animationLength);
         }
         else if (time < e.animationStartDelay)
         {
             e.SetLerp(0);
         }
         else
         {
             e.SetLerp(1);
         }
     }
     else
     {
         e.Hide();
     }
 }
コード例 #13
0
        public override void OnInspectorGUI()
        {
            AnimationElement e = element;

            if (e.animationElementType != lastType)
            {
                lastType = e.animationElementType;
                e.InitializeParametersLists();
            }

            AnimationStep s = step;

            GUILayout.TextArea("Place and position objects of the Animation Element. Then, either select them and initialize them or drop them in the field.");
            if (GUILayout.Button("Init selected objects"))
            {
                InitFromSelection();
            }
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Init drop:");
            objToInit = (GameObject)EditorGUILayout.ObjectField(objToInit, typeof(GameObject), true);
            if (objToInit)
            {
                InitFromField();
            }
            EditorGUILayout.EndHorizontal();
            if (GUILayout.Button("Set initial position"))
            {
                e.ReinitAEOs();
            }
            GUILayout.TextArea("After initialization, place the objects in correct positions and set up the parameters based on the selected animation type.\n" +
                               "Also, set the durations of this animation element.");
            if (e.animationElementType != AnimationElementType.Empty)
            {
                GUILayout.Label("Animation type: " + e.animationElementType.ToString());
            }

            switch (e.animationElementType)
            {
            case AnimationElementType.Empty:
                GUILayout.TextArea("Set up Animation Element Type");
                e.animationElementType = (AnimationElementType)EditorGUILayout.EnumPopup((System.Enum)e.animationElementType);
                break;

            case AnimationElementType.DelayedVisible:
                GUILayout.TextArea("Set up the times.");
                GUILayout.Label("Fill list of animation actions or drop one in field below.");
                break;

            case AnimationElementType.Translate:
                GUILayout.TextArea("Translates between two given position. Place the objects in start/end position and press corresponding buttons.");
                if (GUILayout.Button("Set start"))
                {
                    e.Translate_SetStart();
                }
                if (GUILayout.Button("Set end"))
                {
                    e.Translate_SetEnd();
                }
                if (GUILayout.Button("Switch start & end"))
                {
                    e.Translate_Switch();
                }
                break;

            case AnimationElementType.TranslateLocal:
                GUILayout.TextArea("Translates between start position and start position + this AnimationElement holder local position." +
                                   "\nThat means, place this object in relative offset position.\n" +
                                   "You can also switch the positions.");
                if (GUILayout.Button("Set start"))
                {
                    e.Translate_SetStart();
                }
                if (GUILayout.Button("Switch start & end"))
                {
                    TranslateLocal_Switch();
                }
                break;

            case AnimationElementType.TranslateUp:
                GUILayout.TextArea("Translates in direction of this Animation Element with the speed of parameters[0].");
                EditorGUILayout.LabelField("Set speed and direction (parameter[0])");
                if (e.parameters == null || e.parameters.Length < 1)
                {
                    EditorGUILayout.LabelField("WARNING: Parameters not set.");
                }
                if (GUILayout.Button("Switch start & end"))
                {
                    TranslateUp_Switch();
                }
                break;

            case AnimationElementType.Rotate:
                GUILayout.TextArea("Rotates around this object's origin and green axis with parameters[0] angular speed.");
                EditorGUILayout.LabelField("Set this object's position and rotation and angular speed (parameter[0]");
                if (e.parameters == null || e.parameters.Length < 1 || Mathf.Abs(e.parameters[0]) < float.Epsilon)
                {
                    EditorGUILayout.LabelField("Warning: Parameters[0] not set.");
                }
                break;

            case AnimationElementType.RotateLocal:
                GUILayout.TextArea("Rotates around target object's origin in direction of this object's axis with parameters[0] angular speed.");
                EditorGUILayout.LabelField("Set this object's rotation and angular speed (parameter[0]");
                if (e.parameters == null || e.parameters.Length < 1 || Mathf.Abs(e.parameters[0]) < float.Epsilon)
                {
                    EditorGUILayout.LabelField("Warning: Parameters[0] not set.");
                }
                break;

            case AnimationElementType.RotateAdvanced:
                GUILayout.TextArea("Rotates AEO around this object's origin and green axis from starting rotation final specified angle.");
                //if (GUILayout.Button("Set start")) e.RotateAdvanced_SetStart();

                if (e.parameters == null || e.parameters.Length < 1)
                {
                    e.parameters = new float[1];
                }
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Angle:");
                e.parameters[0] = EditorGUILayout.FloatField(e.parameters[0]);
                EditorGUILayout.EndHorizontal();
                //|| Mathf.Abs(e.parameters[0]) < float.Epsilon) EditorGUILayout.LabelField("Warning: Parameters[0] not set.");
                break;

            case AnimationElementType.Screw:
                GUILayout.TextArea("Rotates around object's up axis and travels in the direction of the object's down axis.");
                EditorGUILayout.LabelField("Place the object in the FINAL, screwed in position.");
                if (GUILayout.Button("Set final position"))
                {
                    Screw_SetFinal();
                }
                EditorGUILayout.LabelField("You can set the start position by computing the screwing in movement or compute the parameters based on speed and initial - final positions difference.");
                if (GUILayout.Button("Compute start"))
                {
                    Screw_ComputeStart();
                }
                if (GUILayout.Button("Compute parameters"))
                {
                    Screw_ComputeParams();
                }
                break;


            default:
                EditorGUILayout.LabelField("Sorry, not implemented yet.");
                break;
            }

            AnimationStepEditor.DrawAETimes(e, step, false);
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("To init position on step start");
            e.positionOnReset = EditorGUILayout.Toggle(e.positionOnReset);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("To init position on unhide");
            e.toInitialPositionOnUnhide = EditorGUILayout.Toggle(e.toInitialPositionOnUnhide);
            EditorGUILayout.EndHorizontal();

            /*
             * EditorGUILayout.LabelField("");
             * EditorGUILayout.LabelField("Element visibility: S=" + e.unhideDelay.ToString("0.0") + " E= " + e.hideDelay.ToString("0.0"));
             * EditorGUILayout.MinMaxSlider(ref e.unhideDelay, ref e.hideDelay, 0, s.stepLength);
             * EditorGUILayout.LabelField("Animation duration: S=" + e.animationStartDelay.ToString("0.0") + " L= " + e.animationLength.ToString("0.0") + " E= " + animationEndDelay.ToString("0.0"));
             * animationEndDelay = e.animationStartDelay + e.animationLength;
             * EditorGUILayout.MinMaxSlider(ref e.animationStartDelay, ref animationEndDelay, 0, s.stepLength);
             * e.animationLength = animationEndDelay - e.animationStartDelay;
             * EditorGUILayout.Space();
             */

            EditorGUILayout.LabelField("Preview:");
            if (GUILayout.Button(tryAnimation ? "Viewing animation" : "Viewing init/start/end poses"))
            {
                tryAnimation = !tryAnimation;
                if (!tryAnimation)
                {
                    e.Hide();
                }
            }
            if (tryAnimation)
            {
                animationLerpView = EditorGUILayout.Slider(animationLerpView, 0, s.stepLength);
                TimePoint(animationLerpView, s, e);
            }
            else
            {
                if (GUILayout.Button("Instantiate & preview Init"))
                {
                    e.ReInstantiate();
                }
                EditorGUILayout.BeginHorizontal();
                {
                    if (GUILayout.Button("Preview start"))
                    {
                        e.SetLerp(0);
                    }
                    if (GUILayout.Button("Preview end"))
                    {
                        e.SetLerp(1);
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.Space();

            GUILayout.Label("Drop to init Animation Action");

            /*EditorGUILayout.BeginHorizontal();
             * {*/
            aaToInit = (GameObject)EditorGUILayout.ObjectField(aaToInit, typeof(GameObject), true);
            if (aaToInit)
            {
                AnimationAction[] aas = aaToInit.GetComponents <AnimationAction>();
                if (e.animationActions == null)
                {
                    e.animationActions = new List <AnimationActionRunner>();
                }
                foreach (AnimationAction aa in aas)
                {
                    e.animationActions.Add(AnimationActionRunner.FromAnimationAction(aa));
                }
            }
            aaToInit = null;

            /*if (GUILayout.Button("Clear list of Animation Actions")) e.animationActions = new List<AnimationActionRunner>();
             * }
             * EditorGUILayout.EndHorizontal();*/
            int actions = e.animationActions == null ? 0 : e.animationActions.Count;

            if (actions > 0 && showAARs)
            {
                if (GUILayout.Button("Hide Animation Actions"))
                {
                    showAARs = false;
                }


                AnimationActionRunner toDelete = null;
                e.animationActions.ForEach((aar) =>
                {
                    if (aar != null)
                    {
                        if (DrawAAR(aar, step))
                        {
                            toDelete = aar;
                        }
                    }
                }
                                           );
                if (toDelete != null)
                {
                    e.animationActions.Remove(toDelete);
                }
            }
            else
            {
                if (actions > 0)
                {
                    if (GUILayout.Button("Show Animation Actions"))
                    {
                        showAARs = true;
                    }
                }
                else
                {
                    GUILayout.Label("Contains " + (e.animationActions == null ? "no" : e.animationActions.Count.ToString()) + " Animation Actions");
                }
            }

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            if (showDefaultInspector)
            {
                if (GUILayout.Button("Hide default inspector"))
                {
                    showDefaultInspector = false;
                }
                base.OnInspectorGUI();
            }
            else
            {
                if (GUILayout.Button("Show default inspector"))
                {
                    showDefaultInspector = true;
                }
            }
        }
コード例 #14
0
        void Unload()
        {
            AnimationStep step = (AnimationStep)target;

            step.KillInEditor();
        }
コード例 #15
0
        void ResetObjects()
        {
            AnimationStep step = (AnimationStep)target;

            step.ResetInEditor();
        }
コード例 #16
0
        public override void OnInspectorGUI()
        {
            AnimationStep step = (AnimationStep)target;

            GUILayout.TextArea(
                "Place static step objects under the AR and Non-AR corresponding Animation Object Parent GameObjects.\n" +
                "If you intend using AR, the Non-AR objects will be hidden when tracking is found. If you don't intend to, place everything under the AR GameObject.\n"
                );

            if (GUILayout.Button("Setup Static Objects"))
            {
                step.SetupStaticObjects();
            }

            GUILayout.TextArea("Set up the Camera position.");
            if (GUILayout.Button("SAVE Camera Position"))
            {
                SaveCameraPosition();
            }
            if (GUILayout.Button("LOAD Camera Position"))
            {
                LoadCameraPosition();
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Step length:");
            step.stepLength = EditorGUILayout.DelayedFloatField(step.stepLength);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("End style");
            step.stepEnd = (StepEndAction)EditorGUILayout.EnumPopup((System.Enum)step.stepEnd);
            EditorGUILayout.EndHorizontal();

            GUILayout.TextArea("After you've aligned the static objects, create animation elements.");
            if (GUILayout.Button("Create AnimationElement"))
            {
                NewElement();
            }

            GUILayout.TextArea("Preview mode: You can load static objects and preview the animation.");
            if (GUILayout.Button("Reload static objects"))
            {
                ResetObjects();
            }
            if (GUILayout.Button("Unload static objects"))
            {
                Unload();
            }

            GUILayout.Space(16);

            if (previewMode && !stepTimingMode)
            {
                if (GUILayout.Button("Turn OFF preview"))
                {
                    previewMode = false;
                }

                GUILayout.Label("Preview time:");
                currentStepTime = EditorGUILayout.FloatField("", currentStepTime);
                currentStepTime = GUILayout.HorizontalSlider(currentStepTime, 0, step.stepLength);
                step.Animate(currentStepTime);
            }
            else
            {
                if (GUILayout.Button("Turn ON preview"))
                {
                    previewMode    = true;
                    stepTimingMode = false;
                }
            }


            if (stepTimingMode && !previewMode)
            {
                if (GUILayout.Button("Turn OFF Step Timing Mode"))
                {
                    stepTimingMode = false;
                }

                step.animationElements.ForEach((ae) => DrawAETimes(ae, step));
            }
            else
            {
                if (GUILayout.Button("Turn ON Step Timing Mode"))
                {
                    previewMode    = false;
                    stepTimingMode = true;
                }
            }

            GUILayout.Space(16);


            if (showDefaultInspector)
            {
                if (GUILayout.Button("Hide default inspector"))
                {
                    showDefaultInspector = false;
                }
                base.OnInspectorGUI();
            }
            else
            {
                if (GUILayout.Button("Show default inspector"))
                {
                    showDefaultInspector = true;
                }
            }
        }