public override void ProcessFrame(Playable playable, FrameData info, object playerData)
        {
            //Get our inputs
            int inputCount = playable.GetInputCount();

            //Calculate blended progress
            float          blendedProgress = 0;
            float          totalWeight     = 0;
            PegasusManager manager         = null;

            for (int i = 0; i < inputCount; i++)
            {
                float inputWeight = playable.GetInputWeight(i);
                ScriptPlayable <PegasusBehaviour> inputPlayable = (ScriptPlayable <PegasusBehaviour>)playable.GetInput(i);
                PegasusBehaviour input = inputPlayable.GetBehaviour();

                if (manager == null)
                {
                    manager = input.pegasusManager;
                }

                blendedProgress += input.pegasusProgress * inputWeight;
                totalWeight     += inputWeight;
            }

            //We will only update if we got some weights i.e. we are being affected by the timeline
            if (!Mathf.Approximately(totalWeight, 0f))
            {
                if (manager != null)
                {
                    manager.MoveTargetTo(blendedProgress);
                }
            }
        }
        public void CreatePegasusFromPath()
        {
            //Exit if nothing to do
            if (m_path.Count == 0)
            {
                return;
            }

            GameObject     pegasusGo = new GameObject("Pegasus Manager");
            PegasusManager pegasus   = pegasusGo.AddComponent <PegasusManager>();

            pegasus.SetDefaults();
            pegasus.m_heightCheckType       = PegasusConstants.HeightCheckType.None;
            pegasus.m_minHeightAboveTerrain = 0.1f;
            pegasus.m_flythroughType        = PegasusConstants.FlythroughType.SingleShot;

            PegasusPoint p = null;

            for (int i = 0; i < m_path.Count; i++)
            {
                p = m_path[i];
                pegasus.AddPOI(p.m_location, p.m_location + Quaternion.Euler(p.m_rotationEuler) * (Vector3.forward * 2f));
            }

            pegasus.SetSpeed(m_defaultSpeed);

            #if UNITY_EDITOR
            Selection.activeObject = pegasusGo;
            #endif
        }
        public static void AddPegasusToScene(MenuCommand menuCommand)
        {
            GameObject     pegasusGo = new GameObject("Pegasus Manager");
            PegasusManager manager   = pegasusGo.AddComponent <PegasusManager>();

            manager.m_defaults = GetDefaults();

            // Ensure it gets reparented if this was a context click (otherwise does nothing)
            GameObjectUtility.SetParentAndAlign(pegasusGo, menuCommand.context as GameObject);
            // Register the creation in the undo system
            Undo.RegisterCreatedObjectUndo(pegasusGo, "Created " + pegasusGo.name);
            Selection.activeObject = pegasusGo;
        }
        public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
        {
            // Set the display name of the clip to match the pegasus manager
            foreach (var c in GetClips())
            {
                PegasusClip    pegasus = (PegasusClip)c.asset;
                PegasusManager manager = pegasus.PegasusManager.Resolve(graph.GetResolver());
                c.displayName = manager == null ? "Pegasus" : manager.name;
            }

            var mixer = ScriptPlayable <PegasusMixerBehaviour> .Create(graph);

            mixer.SetInputCount(inputCount);
            return(mixer);
        }
Exemple #5
0
        private void OnEnable()
        {
            //Check for target
            if (target == null)
            {
                return;
            }

            //Get the control id
            m_editor_control_id = GUIUtility.GetControlID(this.GetHashCode(), FocusType.Passive);

            //Get our manager
            m_manager = (PegasusManager)target;

            //Set up the default camera if we can
            if (m_manager.m_target == null)
            {
                if (Camera.main != null)
                {
                    m_manager.m_target = Camera.main.gameObject;
                    if (m_manager.m_target == null)
                    {
                        m_manager.name = "Pegasus Manager";
                    }
                    else
                    {
                        m_manager.name = "Pegasus Manager - " + m_manager.m_target.name;
                    }
                    EditorUtility.SetDirty(m_manager);
                }
            }

            //Set up any segments / Update segments for the manager
            if (!Application.isPlaying)
            {
                m_manager.InitialiseFlythrough();
            }

            //And select nothing
            m_manager.SelectPoi(null);

            //And add Pegasus to the environment
            SetPegasusDefines();
        }
        public static void AddPegasusToSceneHelios2D()
        {
            //Locate the helios prefab
            string[] heliosGuids = AssetDatabase.FindAssets("Helios2D_For_Pegasus");
            if (heliosGuids.Length == 0)
            {
                Debug.LogWarning("Unable to locate Helios 2D for Pegasus.");
                return;
            }
            string heliosPath = AssetDatabase.GUIDToAssetPath(heliosGuids[0]);

            if (string.IsNullOrEmpty(heliosPath))
            {
                Debug.LogWarning("Unable to locate path of Helios 2D for Pegasus.");
                return;
            }
            GameObject heliosPrefab = AssetDatabase.LoadAssetAtPath <GameObject>(heliosPath);

            if (heliosPrefab == null)
            {
                Debug.LogWarning("Unable to locate load prefab for Helios 2D for Pegasus.");
                return;
            }
            GameObject helios = PrefabUtility.InstantiatePrefab(heliosPrefab) as GameObject;

            if (helios == null)
            {
                Debug.LogWarning("Unable to instantiate Helios 2D Camera");
                return;
            }
            GameObject pegasusGo = new GameObject("Pegasus Manager H2D");

            Selection.activeGameObject = pegasusGo;
            PegasusManager pm = pegasusGo.AddComponent <PegasusManager>();

            pm.m_flythroughType      = PegasusConstants.FlythroughType.SingleShot;
            pm.m_flythroughEndAction = PegasusConstants.FlythroughEndAction.QuitApplication;
            pm.m_target = helios;

            Debug.Log("Pegasus : Make sure you add your Camera FX to the Front camera. It is a child of the Helios 2D Camera.");
        }
        /// <summary>
        /// Draw the POI gui
        /// </summary>
        public override void OnInspectorGUI()
        {
            //Get our trigger
            m_trigger = (TriggerControlPegasus)target;

            //Set up the box style
            if (m_boxStyle == null)
            {
                m_boxStyle = new GUIStyle(GUI.skin.box);
                m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
                m_boxStyle.fontStyle        = FontStyle.Bold;
                m_boxStyle.alignment        = TextAnchor.UpperLeft;
            }

            //Setup the wrap style
            if (m_wrapStyle == null)
            {
                m_wrapStyle          = new GUIStyle(GUI.skin.label);
                m_wrapStyle.wordWrap = true;
            }

            //Create a nice text intro
            GUILayout.BeginVertical("Pegasus Control Trigger", m_boxStyle);
            GUILayout.Space(20);
            EditorGUILayout.LabelField("This trigger controls other Pegasus.", m_wrapStyle);
            GUILayout.EndVertical();

            EditorGUI.BeginChangeCheck();

            GUILayout.Space(5);

            PegasusManager poiTarget = (PegasusManager)EditorGUILayout.ObjectField(GetLabel("Target Pegasus"), m_trigger.m_pegasus, typeof(PegasusManager), true);

            PegasusConstants.PoiPegasusTriggerAction actionOnStart = m_trigger.m_actionOnStart;
            PegasusConstants.PoiPegasusTriggerAction actionOnEnd   = m_trigger.m_actionOnEnd;

            if (poiTarget != null)
            {
                actionOnStart = (PegasusConstants.PoiPegasusTriggerAction)EditorGUILayout.EnumPopup(GetLabel("Action On Start"), actionOnStart);
                actionOnEnd   = (PegasusConstants.PoiPegasusTriggerAction)EditorGUILayout.EnumPopup(GetLabel("Action On End"), actionOnEnd);
            }


            /*
             * GUILayout.BeginVertical("Target Lookat", m_boxStyle);
             *  GUILayout.Space(20);
             *  PegasusConstants.LookatType lookatType = (PegasusConstants.LookatType)EditorGUILayout.EnumPopup(GetLabel("Target"), m_poi.m_lookatType);
             *  float lookAtAngle = m_poi.m_lookAtAngle;
             *  float lookAtDistance = m_poi.m_lookAtDistance;
             *  float lookAtHeight = m_poi.m_lookAtHeight;
             *  if (lookatType == PegasusConstants.LookatType.Path)
             *  {
             *      GUI.enabled = false;
             *  }
             *  lookAtAngle = EditorGUILayout.Slider(GetLabel("  Angle"), m_poi.m_lookAtAngle, 0f, 359.9f);
             *  lookAtDistance = EditorGUILayout.FloatField(GetLabel("  Distance"), m_poi.m_lookAtDistance);
             *  lookAtHeight = EditorGUILayout.FloatField(GetLabel("  Height"), m_poi.m_lookAtHeight);
             *  GUI.enabled = true;
             *  GUILayout.Space(3);
             * GUILayout.EndVertical();
             */

            GUILayout.Space(5);

            //Check for changes, make undo record, make changes and let editor know we are dirty
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(m_trigger, "Made trigger changes");

                m_trigger.m_triggerAtStart  = true;
                m_trigger.m_triggerOnUpdate = false;
                m_trigger.m_triggerAtEnd    = true;
                m_trigger.m_pegasus         = poiTarget;
                m_trigger.m_actionOnStart   = actionOnStart;
                m_trigger.m_actionOnEnd     = actionOnEnd;

                //Mark it as dirty
                EditorUtility.SetDirty(m_trigger);
            }
        }
        public override void OnInspectorGUI()
        {
            //Get our manager
            m_manager = (PegasusManager)target;

            //Set up the box style
            if (m_boxStyle == null)
            {
                m_boxStyle = new GUIStyle(GUI.skin.box);
                m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor;
                m_boxStyle.fontStyle        = FontStyle.Bold;
                m_boxStyle.alignment        = TextAnchor.UpperLeft;
            }

            //Setup the wrap style
            if (m_wrapStyle == null)
            {
                m_wrapStyle           = new GUIStyle(GUI.skin.label);
                m_wrapStyle.fontStyle = FontStyle.Normal;
                m_wrapStyle.wordWrap  = true;
            }

            //Text intro
            GUILayout.BeginVertical(string.Format("Pegasus ({0}.{1})", PegasusConstants.MajorVersion, PegasusConstants.MinorVersion), m_boxStyle);
            GUILayout.Space(20);
            EditorGUILayout.LabelField("Welcome to Pegasus!\nTo visualise flythrough in editor mode select Window->Layouts->2 x 3 so that both Scene & Game windows are showing.\nCtrl + Left Click: Add POI.\nCrtl + ScrollWheel: Scrub timeline.", m_wrapStyle);
            GUILayout.EndVertical();

            EditorGUI.BeginChangeCheck();

            GUILayout.Space(5);

            GUILayout.BeginVertical("Configuration", m_boxStyle);
            GUILayout.Space(20);
            GameObject poiTarget = (GameObject)EditorGUILayout.ObjectField(GetLabel("Target Object"), m_manager.m_target, typeof(GameObject), true);

            PegasusConstants.FlythroughType      flythroughType      = (PegasusConstants.FlythroughType)EditorGUILayout.EnumPopup(GetLabel("Flythrough Type"), m_manager.m_flythroughType);
            PegasusConstants.FlythroughEndAction flythroughEndAction = m_manager.m_flythroughEndAction;
            PegasusManager nextPegasus = m_manager.m_nextPegasus;

            if (flythroughType == PegasusConstants.FlythroughType.SingleShot)
            {
                flythroughEndAction = (PegasusConstants.FlythroughEndAction)EditorGUILayout.EnumPopup(GetLabel("Flythrough End"), flythroughEndAction);
                if (flythroughEndAction == PegasusConstants.FlythroughEndAction.PlayNextPegasus)
                {
                    nextPegasus = (PegasusManager)EditorGUILayout.ObjectField(GetLabel("Next Pegasus"), nextPegasus, typeof(PegasusManager), true);
                }
            }
            bool autoStartAtRuntime = EditorGUILayout.Toggle(GetLabel("Play On Start"), m_manager.m_autoStartAtRuntime);

            PegasusConstants.TargetFrameRate targetFrameRateType = m_manager.m_targetFramerateType;
            PegasusConstants.HeightCheckType heightCheckType     = m_manager.m_heightCheckType;
            float minHeightAboveTerrain = m_manager.m_minHeightAboveTerrain;
            float collisionHeightOffset = m_manager.m_collisionHeightOffset;
            float rotationDamping       = m_manager.m_rotationDamping;
            float positionDamping       = m_manager.m_positionDamping;
            float poiSize = m_manager.m_poiGizmoSize;

            bool showAdvanced = EditorGUILayout.BeginToggleGroup(GetLabel(" Advanced"), m_manager.m_showAdvanced);

            if (showAdvanced)
            {
                EditorGUI.indentLevel++;
                targetFrameRateType = (PegasusConstants.TargetFrameRate)EditorGUILayout.EnumPopup(GetLabel("Framerate"), m_manager.m_targetFramerateType);
                heightCheckType     = (PegasusConstants.HeightCheckType)EditorGUILayout.EnumPopup(GetLabel("Check Height"), m_manager.m_heightCheckType);
                if (heightCheckType != PegasusConstants.HeightCheckType.None)
                {
                    if (heightCheckType == PegasusConstants.HeightCheckType.Collision)
                    {
                        collisionHeightOffset = EditorGUILayout.FloatField(GetLabel("Collision Offset"), collisionHeightOffset);
                    }
                    minHeightAboveTerrain = EditorGUILayout.FloatField(GetLabel("Min POI Height"), minHeightAboveTerrain);
                }
                rotationDamping = EditorGUILayout.Slider(GetLabel("Rotation Damping"), m_manager.m_rotationDamping, 0f, 3f);
                positionDamping = EditorGUILayout.Slider(GetLabel("Position Damping"), m_manager.m_positionDamping, 0f, 3f);
                poiSize         = EditorGUILayout.Slider(GetLabel("Gizmo Size"), poiSize, 0.1f, 5f);
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.EndToggleGroup();
            GUILayout.Space(3);

            GUILayout.Space(3);
            GUILayout.EndVertical();

            GUILayout.Space(5);

            GUILayout.BeginVertical("Statistics", m_boxStyle);
            GUILayout.Space(20);
            EditorGUILayout.LabelField("Distance", string.Format("{0:0.00m}", m_manager.m_totalDistance));
            EditorGUILayout.LabelField("Duration", string.Format("{0}:{1:00}.{2:000}", m_manager.m_totalDuration.Minutes, m_manager.m_totalDuration.Seconds, m_manager.m_totalDuration.Milliseconds));
            GUILayout.Space(3);
            GUILayout.EndVertical();

            GUILayout.Space(5);

            GUILayout.BeginVertical(m_boxStyle);
            float scrubber = m_manager.m_totalDistanceTravelledPct;

            m_manager.m_showScrubber = EditorGUILayout.BeginToggleGroup(GetLabel(" Visualisation"), m_manager.m_showScrubber);
            bool showDebug        = m_manager.m_displayDebug;
            bool alwaysShowGizmos = m_manager.m_alwaysShowGizmos;

            if (m_manager.m_showScrubber)
            {
                EditorGUILayout.LabelField("Switch to Game View and use the Scrubber and Step controls to visualise the flythrough path while in edit mode. This will physically move your Target in the scene so make sure you put it back to its original location afterwards.", m_wrapStyle);
                scrubber = EditorGUILayout.Slider(GetLabel("Scrubber"), scrubber, 0f, 1f);
                GUILayout.BeginHorizontal();
                if (GUILayout.Button(GetLabel("Step Backward")))
                {
                    m_manager.StepTargetBackward(1f);
                    scrubber = m_manager.m_totalDistanceTravelledPct;
                }
                if (GUILayout.Button(GetLabel("Step Forward")))
                {
                    m_manager.StepTargetForward(1f);
                    scrubber = m_manager.m_totalDistanceTravelledPct;
                }
                GUILayout.EndHorizontal();
                alwaysShowGizmos = EditorGUILayout.Toggle(GetLabel("Show Gizmos"), alwaysShowGizmos);
                showDebug        = EditorGUILayout.Toggle(GetLabel("Show debug"), showDebug);
            }
            EditorGUILayout.EndToggleGroup();
            GUILayout.Space(3);
            GUILayout.EndVertical();

            GUILayout.Space(5);

            GUILayout.BeginVertical(m_boxStyle);
            m_manager.m_showPOIHelpers = EditorGUILayout.BeginToggleGroup(GetLabel(" Utilities"), m_manager.m_showPOIHelpers);
            if (m_manager.m_showPOIHelpers)
            {
                if (GUILayout.Button(GetLabel("Go To First POI")))
                {
                    PegasusPoi poi = m_manager.GetPOI(0);
                    if (poi != null)
                    {
                        if (Selection.activeTransform != null)
                        {
                            Selection.activeTransform = poi.transform;
                        }
                        if (SceneView.lastActiveSceneView != null)
                        {
                            SceneView.lastActiveSceneView.pivot = poi.transform.position;
                        }
                        poi.m_manager.SelectPoi(poi);
                        poi.m_manager.MoveTargetToPoi(poi);
                    }
                }
                if (GUILayout.Button(GetLabel("Set POI To Min Height")))
                {
                    m_manager.SetPoiToMinHeight();
                }
                if (GUILayout.Button(GetLabel("Show Debug On POI")))
                {
                    m_manager.CreateDebugObjects();
                }
                if (GUILayout.Button(GetLabel("Hide Debug on POI")))
                {
                    m_manager.DeleteDebugObjects();
                }
            }
            EditorGUILayout.EndToggleGroup();
            GUILayout.Space(3);
            GUILayout.EndVertical();

            GUILayout.Space(5);

            //Display some playback controls
            if (EditorApplication.isPlaying)
            {
                GUILayout.BeginVertical("Playback Status", m_boxStyle);
                GUILayout.Space(20);
                EditorGUILayout.LabelField("Status", m_manager.m_currentState.ToString());
                if (m_manager.m_currentState == PegasusConstants.FlythroughState.Started)
                {
                    EditorGUILayout.LabelField("Delta Time", string.Format("{0:0.000}", m_manager.m_frameUpdateTime));
                    EditorGUILayout.LabelField("Delta Dist", string.Format("{0:0.000}", m_manager.m_frameUpdateDistance));
                    EditorGUILayout.LabelField("Current Speed", string.Format("{0:0.00}", m_manager.m_currentVelocity));
                    EditorGUILayout.LabelField("Distance Travelled", string.Format("{0:0.00}", m_manager.m_totalDistanceTravelled));
                    EditorGUILayout.LabelField("Total Distance", string.Format("{0:0.00}", m_manager.m_totalDistance));
                }
                else
                {
                    EditorGUILayout.LabelField("Delta Time", string.Format("{0:0.000}", 0f));
                    EditorGUILayout.LabelField("Delta Dist", string.Format("{0:0.000}", 0f));
                    EditorGUILayout.LabelField("Current Speed", string.Format("{0:0.00}", 0f));
                    EditorGUILayout.LabelField("Distance Travelled", string.Format("{0:0.00}", m_manager.m_totalDistanceTravelled));
                    EditorGUILayout.LabelField("Total Distance", string.Format("{0:0.00}", m_manager.m_totalDistance));
                }

                if (m_manager.m_currentState == PegasusConstants.FlythroughState.Stopped)
                {
                    if (GUILayout.Button(GetLabel("Play")))
                    {
                        m_manager.StartFlythrough();
                    }
                }
                else
                {
                    GUILayout.BeginHorizontal();
                    if (m_manager.m_currentState == PegasusConstants.FlythroughState.Paused)
                    {
                        if (GUILayout.Button(GetLabel("Resume")))
                        {
                            m_manager.ResumeFlythrough();
                        }
                    }
                    else if (m_manager.m_currentState == PegasusConstants.FlythroughState.Started)
                    {
                        if (GUILayout.Button(GetLabel("Pause")))
                        {
                            m_manager.PauseFlythrough();
                        }
                    }
                    if (GUILayout.Button(GetLabel("Stop")))
                    {
                        m_manager.StopFlythrough();
                    }
                    GUILayout.EndHorizontal();
                }
                GUILayout.Space(3);
                GUILayout.EndVertical();
            }

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(m_manager, "Made changes");
                m_manager.m_autoStartAtRuntime    = autoStartAtRuntime;
                m_manager.m_displayDebug          = showDebug;
                m_manager.m_alwaysShowGizmos      = alwaysShowGizmos;
                m_manager.m_collisionHeightOffset = collisionHeightOffset;
                m_manager.m_showAdvanced          = showAdvanced;
                m_manager.m_poiGizmoSize          = poiSize;

                if (m_manager.m_flythroughType != flythroughType)
                {
                    m_manager.m_flythroughType = flythroughType;
                    m_manager.InitialiseFlythrough();
                }
                m_manager.m_nextPegasus = nextPegasus;

                if (m_manager.m_heightCheckType != heightCheckType)
                {
                    m_manager.m_heightCheckType = heightCheckType;
                    m_manager.InitialiseFlythrough();
                }
                m_manager.m_flythroughEndAction = flythroughEndAction;
                m_manager.m_target = poiTarget;

                if (m_manager.m_targetFramerateType != targetFrameRateType)
                {
                    m_manager.ChangeFramerate(targetFrameRateType);
                }
                if (!PegasusPoi.ApproximatelyEqual(scrubber, m_manager.m_totalDistanceTravelledPct))
                {
                    m_manager.MoveTargetTo(scrubber);
                }
                if (!PegasusPoi.ApproximatelyEqual(minHeightAboveTerrain, m_manager.m_minHeightAboveTerrain))
                {
                    m_manager.m_minHeightAboveTerrain = minHeightAboveTerrain;
                    m_manager.InitialiseFlythrough();
                }
                m_manager.m_rotationDamping = rotationDamping;
                m_manager.m_positionDamping = positionDamping;

                EditorUtility.SetDirty(m_manager);
            }
        }