Example #1
0
        /// <summary>
        /// Get the poi start speed based on the speed type
        /// </summary>
        /// <param name="speedType"></param>
        /// <returns></returns>
        public float GetStartSpeed(PegasusConstants.SpeedType speedType)
        {
            switch (speedType)
            {
            case PegasusConstants.SpeedType.ReallySlow:
                return(PegasusConstants.SpeedReallySlow);

            case PegasusConstants.SpeedType.Slow:
                return(PegasusConstants.SpeedSlow);

            case PegasusConstants.SpeedType.Medium:
                return(PegasusConstants.SpeedMedium);

            case PegasusConstants.SpeedType.Fast:
                return(PegasusConstants.SpeedFast);

            case PegasusConstants.SpeedType.ReallyFast:
                return(PegasusConstants.SpeedReallyFast);
            }
            return(m_startSpeed);
        }
Example #2
0
        /// <summary>
        /// Draw the POI gui
        /// </summary>
        public override void OnInspectorGUI()
        {
            //Get our poi
            m_poi = (PegasusPoi)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("Point of Interest", m_boxStyle);
            GUILayout.Space(20);
            EditorGUILayout.LabelField("The yellow sphere will be flown through, and the blue sphere is what the camera is looking at. If the blue sphere is not shown then the camera will look along the path of the flythrough.\n\nClick on POI in scene then...\nCTRL + Keys - Move selected POI.\nSHIFT+CTRL + Keys - Move selected LookAt.\nSee PegasusDefaults for Keys.", m_wrapStyle);
            GUILayout.EndVertical();

            EditorGUI.BeginChangeCheck();

            PegasusConstants.PoiType poiType = m_poi.m_poiType;

            GUILayout.Space(5);

            GUILayout.BeginVertical("Auto Roll", m_boxStyle);
            GUILayout.Space(20);
            bool autoRoll = EditorGUILayout.Toggle(GetLabel("Auto Roll"), m_poi.m_autoRollOn);

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

            GUILayout.Space(5);

            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);

            GUILayout.BeginVertical("Target Speed", m_boxStyle);
            GUILayout.Space(20);
            PegasusConstants.SpeedType speedType = (PegasusConstants.SpeedType)EditorGUILayout.EnumPopup(GetLabel("Type"), m_poi.m_startSpeedType);
            float startSpeed = m_poi.m_startSpeed;

            if (speedType != PegasusConstants.SpeedType.Custom)
            {
                EditorGUILayout.LabelField(GetLabel("Speed"), GetLabel(string.Format("{0:0.00} m/sec", startSpeed)));
            }
            else
            {
                startSpeed = EditorGUILayout.FloatField(GetLabel("Speed"), startSpeed);
                if (startSpeed < 0.0001f)
                {
                    startSpeed = 0.0001f;
                }
            }
            GUILayout.Space(3);
            GUILayout.EndVertical();

            GUILayout.Space(5);

            GUILayout.BeginVertical("Height Constraint", m_boxStyle);
            GUILayout.Space(20);
            PegasusConstants.PoiHeightCheckType heightCheckType = (PegasusConstants.PoiHeightCheckType)EditorGUILayout.EnumPopup(GetLabel("Min Height From"), m_poi.m_heightCheckType);
            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_poi.m_segmentDistance));
            EditorGUILayout.LabelField("Start Time", string.Format("{0}:{1:00}.{2:000}", m_poi.m_segmentStartTime.Minutes, m_poi.m_segmentStartTime.Seconds, m_poi.m_segmentStartTime.Milliseconds));
            EditorGUILayout.LabelField("Segment Time", string.Format("{0}:{1:00}.{2:000}", m_poi.m_segmentDuration.Minutes, m_poi.m_segmentDuration.Seconds, m_poi.m_segmentDuration.Milliseconds));
            EditorGUILayout.LabelField("Total Time", string.Format("{0}:{1:00}.{2:000}", m_poi.m_manager.m_totalDuration.Minutes, m_poi.m_manager.m_totalDuration.Seconds, m_poi.m_manager.m_totalDuration.Milliseconds));
            GUILayout.Space(3);
            GUILayout.EndVertical();

            PegasusConstants.EasingType velocityEasing = m_poi.m_velocityEasingType;
            PegasusConstants.EasingType rotationEasing = m_poi.m_rotationEasingType;
            PegasusConstants.EasingType positionEasing = m_poi.m_positionEasingType;

            GUILayout.Space(5);

            GUILayout.BeginVertical("Utilities", m_boxStyle);
            GUILayout.Space(20);

            if (GUILayout.Button(GetLabel("Select Manager")))
            {
                if (Selection.activeTransform != null)
                {
                    Selection.activeTransform = m_poi.m_manager.transform;
                }
            }
            if (GUILayout.Button(GetLabel("Select First POI")))
            {
                PegasusPoi poi = m_poi.m_manager.GetFirstPOI();
                if (poi != null)
                {
                    if (SceneView.lastActiveSceneView != null)
                    {
                        SceneView.lastActiveSceneView.pivot = poi.transform.position;
                    }
                    if (Selection.activeTransform != null)
                    {
                        Selection.activeTransform = poi.transform;
                    }
                    poi.m_manager.SelectPoi(poi);
                    poi.m_manager.MoveTargetToPoi(poi);
                }
            }

            GUILayout.BeginHorizontal();
            if (GUILayout.Button(GetLabel("Select Previous POI")))
            {
                PegasusPoi poi = m_poi.m_manager.GetPrevPOI(m_poi);
                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("Select Next POI")))
            {
                PegasusPoi poi = m_poi.m_manager.GetNextPOI(m_poi);
                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);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button(GetLabel("Add POI Before")))
            {
                PegasusPoi poi = m_poi.m_manager.AddPoiBefore(m_poi);
                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("Add POI After")))
            {
                PegasusPoi poi = m_poi.m_manager.AddPoiAfter(m_poi);
                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);
                }
            }
            GUILayout.EndHorizontal();

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

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

                m_poi.m_autoRollOn = autoRoll;

                if (m_poi.m_lookatType != lookatType && lookatType == PegasusConstants.LookatType.Target)
                {
                    lookAtHeight   = 0f;
                    lookAtDistance = 5f;
                }
                m_poi.m_lookatType = lookatType;

                if (heightCheckType != m_poi.m_heightCheckType)
                {
                    m_poi.m_heightCheckType = heightCheckType;
                    //m_poi.m_manager.UpdateSegmentWithDependencies(m_poi);
                }

                if (!PegasusPoi.ApproximatelyEqual(m_poi.m_lookAtAngle, lookAtAngle))
                {
                    m_poi.m_lookAtAngle       = lookAtAngle;
                    m_poi.m_lookatLocation    = m_poi.transform.position + (m_poi.transform.localRotation * Quaternion.AngleAxis(m_poi.m_lookAtAngle, Vector3.up)) * new Vector3(0f, 0f, -m_poi.m_lookAtDistance);
                    m_poi.m_lookatLocation    = m_poi.m_manager.GetLowestLookatPosition(m_poi.m_lookatLocation, m_poi.m_heightCheckType);
                    m_poi.m_lookatLocation.y += m_poi.m_lookAtHeight;
                }
                else if (!PegasusPoi.ApproximatelyEqual(m_poi.m_lookAtDistance, lookAtDistance))
                {
                    m_poi.m_lookAtDistance    = lookAtDistance;
                    m_poi.m_lookatLocation    = m_poi.transform.position + (m_poi.transform.localRotation * Quaternion.AngleAxis(m_poi.m_lookAtAngle, Vector3.up)) * new Vector3(0f, 0f, -m_poi.m_lookAtDistance);
                    m_poi.m_lookatLocation    = m_poi.m_manager.GetLowestLookatPosition(m_poi.m_lookatLocation, m_poi.m_heightCheckType);
                    m_poi.m_lookatLocation.y += m_poi.m_lookAtHeight;
                }
                else if (!PegasusPoi.ApproximatelyEqual(m_poi.m_lookAtHeight, lookAtHeight))
                {
                    m_poi.m_lookAtHeight      = lookAtHeight;
                    m_poi.m_lookatLocation    = m_poi.transform.position + (m_poi.transform.localRotation * Quaternion.AngleAxis(m_poi.m_lookAtAngle, Vector3.up)) * new Vector3(0f, 0f, -m_poi.m_lookAtDistance);
                    m_poi.m_lookatLocation    = m_poi.m_manager.GetLowestLookatPosition(m_poi.m_lookatLocation, m_poi.m_heightCheckType);
                    m_poi.m_lookatLocation.y += m_poi.m_lookAtHeight;
                }

                if (m_poi.m_startSpeedType != speedType)
                {
                    m_poi.m_startSpeedType = speedType;
                    m_poi.m_startSpeed     = m_poi.GetStartSpeed(speedType);
                }
                else
                {
                    if (!PegasusPoi.ApproximatelyEqual(m_poi.m_startSpeed, startSpeed))
                    {
                        m_poi.m_startSpeedType = PegasusConstants.SpeedType.Custom;
                        m_poi.m_startSpeed     = startSpeed;
                    }
                }

                m_poi.m_velocityEasingType = velocityEasing;
                m_poi.m_rotationEasingType = rotationEasing;
                m_poi.m_positionEasingType = positionEasing;

                //Update the segment
                m_poi.m_manager.UpdateSegmentWithDependencies(m_poi);

                //Mark it as dirty
                EditorUtility.SetDirty(m_poi);
            }
        }