Exemple #1
0
        /// <summary>
        /// Called when the trigger starts
        /// </summary>
        /// <param name="poi"></param>
        public override void OnStart(PegasusPoi poi)
        {
            if (poi == null)
            {
                Debug.LogWarning(string.Format("Poi was not supplied on {0} - exiting", name));
                return;
            }

            if (m_pegasus == null)
            {
                Debug.LogWarning(string.Format("Pegasus was not supplied on {0} - exiting", name));
                return;
            }

            if (m_disabled)
            {
                return;
            }

            if (m_triggerAtStart)
            {
                switch (m_actionOnStart)
                {
                case PegasusConstants.PoiPegasusTriggerAction.PlayPegasus:
                    if (poi.m_manager.m_displayDebug == true)
                    {
                        Debug.Log(string.Format("Started flythrough on {0} from {1}", poi.m_manager.name, poi.name));
                    }

                    //Stop playback of the calling pegasus if the new one has the same target
                    if (poi.m_manager.m_target != null && m_pegasus.m_target != null)
                    {
                        if (poi.m_manager.m_target.GetInstanceID() == m_pegasus.m_target.GetInstanceID())
                        {
                            poi.m_manager.StopFlythrough();
                        }
                    }
                    //And start the new one
                    if (m_pegasus.m_currentState == PegasusConstants.FlythroughState.Paused)
                    {
                        m_pegasus.ResumeFlythrough();
                    }
                    else
                    {
                        m_pegasus.StartFlythrough();
                    }
                    if (m_disableAfterActioned)
                    {
                        m_disabled = true;
                    }
                    break;

                case PegasusConstants.PoiPegasusTriggerAction.PausePegasus:
                    if (poi.m_manager.m_displayDebug == true)
                    {
                        Debug.Log(string.Format("Pausing flythrough on {0} from {1}", poi.m_manager.name, poi.name));
                    }
                    m_pegasus.PauseFlythrough();
                    if (m_disableAfterActioned)
                    {
                        m_disabled = true;
                    }
                    break;

                case PegasusConstants.PoiPegasusTriggerAction.ResumePegasus:
                    if (poi.m_manager.m_displayDebug == true)
                    {
                        Debug.Log(string.Format("Resuming flythrough on {0} from {1}", poi.m_manager.name, poi.name));
                    }
                    m_pegasus.ResumeFlythrough();
                    if (m_disableAfterActioned)
                    {
                        m_disabled = true;
                    }
                    break;

                case PegasusConstants.PoiPegasusTriggerAction.StopPegasus:
                    if (poi.m_manager.m_displayDebug == true)
                    {
                        Debug.Log(string.Format("Stopping flythrough on {0} from {1}", poi.m_manager.name, poi.name));
                    }
                    m_pegasus.StopFlythrough();
                    if (m_disableAfterActioned)
                    {
                        m_disabled = true;
                    }
                    break;

                case PegasusConstants.PoiPegasusTriggerAction.DoNothing:
                    if (poi.m_manager.m_displayDebug == true)
                    {
                        Debug.Log(string.Format("Doing nothing on {0} from {1}", poi.m_manager.name, poi.name));
                    }
                    break;
                }
            }
        }
        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);
            }
        }
Exemple #3
0
        /// <summary>
        /// Called when the trigger starts
        /// </summary>
        /// <param name="poi"></param>
        public override void OnStart(PegasusPoi poi)
        {
            if (poi == null)
            {
                Debug.LogWarning(string.Format("Poi was not supplied on {0} - exiting", name));
                return;
            }

            if (m_pegasus == null)
            {
                Debug.LogWarning(string.Format("Pegasus was not supplied on {0} - exiting", name));
                return;
            }

            if (m_triggerAtStart)
            {
                switch (m_actionOnStart)
                {
                case PegasusConstants.PoiPegasusTriggerAction.PlayPegasus:
                    if (poi.m_manager.m_displayDebug == true)
                    {
                        Debug.Log(string.Format("Started flythrough on {0} from {1}", poi.m_manager.name, poi.name));
                    }
                    if (m_pegasus.m_currentState == PegasusConstants.FlythroughState.Paused)
                    {
                        m_pegasus.ResumeFlythrough();
                    }
                    else
                    {
                        m_pegasus.StartFlythrough();
                    }
                    break;

                case PegasusConstants.PoiPegasusTriggerAction.PausePegasus:
                    if (poi.m_manager.m_displayDebug == true)
                    {
                        Debug.Log(string.Format("Pausing flythrough on {0} from {1}", poi.m_manager.name, poi.name));
                    }
                    m_pegasus.PauseFlythrough();
                    break;

                case PegasusConstants.PoiPegasusTriggerAction.ResumePegasus:
                    if (poi.m_manager.m_displayDebug == true)
                    {
                        Debug.Log(string.Format("Resuming flythrough on {0} from {1}", poi.m_manager.name, poi.name));
                    }
                    m_pegasus.ResumeFlythrough();
                    break;

                case PegasusConstants.PoiPegasusTriggerAction.StopPegasus:
                    if (poi.m_manager.m_displayDebug == true)
                    {
                        Debug.Log(string.Format("Stopping flythrough on {0} from {1}", poi.m_manager.name, poi.name));
                    }
                    m_pegasus.StopFlythrough();
                    break;

                case PegasusConstants.PoiPegasusTriggerAction.DoNothing:
                    if (poi.m_manager.m_displayDebug == true)
                    {
                        Debug.Log(string.Format("Doing nothing on {0} from {1}", poi.m_manager.name, poi.name));
                    }
                    break;
                }
            }
        }