/// <summary>
        /// Detect and handle events for current spawner
        /// </summary>
        void OnSceneGUI()
        {
            //Exit if we dont have a manager
            if (m_manager == null)
            {
                return;
            }

            if (Event.current == null)
            {
                return;
            }

            if (Event.current.type == EventType.Layout || Event.current.type == EventType.Repaint)
            {
                return;
            }

            //Scroll wheel - pan back and forward along the line
            if (Event.current.control == true && Event.current.type == EventType.scrollWheel)
            {
                GUIUtility.hotControl = m_editor_control_id;
                if (Event.current.delta.y < 0f)
                {
                    m_manager.StepTargetBackward(Event.current.delta.y * -1f);
                }
                else
                {
                    m_manager.StepTargetForward(Event.current.delta.y);
                }
                Event.current.Use();
                GUIUtility.hotControl = 0;
                return;
            }



            //Check for the ctrl + left mouse button event - spawn
            if (Event.current.control == true && Event.current.isMouse == true)
            {
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
                {
                    GUIUtility.hotControl = m_editor_control_id;

                    Ray        ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                    RaycastHit hitInfo;
                    if (Physics.Raycast(ray, out hitInfo, 10000f))
                    {
                        if (m_manager.m_poiList.Count == 0)
                        {
                            if (!(hitInfo.collider is TerrainCollider)) //Lets assume we arent in an environment that uses terrains
                            {
                                m_manager.m_heightCheckType = PegasusConstants.HeightCheckType.Collision;
                            }
                        }
                        Vector3 newPoint = m_manager.GetValidatedPoiPosition(hitInfo.point);
                        if (newPoint != m_lastHitPoint)
                        {
                            m_lastHitPoint = newPoint;
                            m_manager.AddPOI(m_lastHitPoint, m_lastHitPoint);
                        }
                    }
                    else
                    {
                        if (SceneView.lastActiveSceneView != null)
                        {
                            float dist = Vector3.Distance(ray.origin, SceneView.lastActiveSceneView.pivot);
                            m_lastHitPoint = Vector3.MoveTowards(ray.origin, SceneView.lastActiveSceneView.pivot, dist / 2f);
                        }
                        else
                        {
                            m_lastHitPoint = ray.origin;
                        }
                        if (m_manager.m_poiList.Count == 0) //Lets assume we are in space
                        {
                            m_manager.m_heightCheckType = PegasusConstants.HeightCheckType.None;
                        }
                        m_manager.AddPOI(m_lastHitPoint, m_lastHitPoint);
                    }
                    SceneView.RepaintAll();
                }
                else if (GUIUtility.hotControl == m_editor_control_id && Event.current.type == EventType.MouseUp && Event.current.button == 0)
                {
                    GUIUtility.hotControl = 0;
                }
                return;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initialise this POI's settings, leveraging the manager
        /// </summary>
        public void Initialise(bool updateSegments = true)
        {
            //Make sure prev and next set up - if not then exit
            if (m_prevPoi == null || m_nextPoi == null)
            {
                return;
            }

            //Move us if we are below the minimum height on the terrain
            transform.position = m_manager.GetValidatedPoiPosition(transform.position, m_heightCheckType);

            //Set up easing calculators
            switch (m_velocityEasingType)
            {
            case PegasusConstants.EasingType.Linear:
                m_velocityEasingCalculator = new Easing(EaseLinear);
                break;

            case PegasusConstants.EasingType.EaseIn:
                m_velocityEasingCalculator = new Easing(EaseIn);
                break;

            case PegasusConstants.EasingType.EaseOut:
                m_velocityEasingCalculator = new Easing(EaseOut);
                break;

            case PegasusConstants.EasingType.EaseInOut:
                m_velocityEasingCalculator = new Easing(EaseInOut);
                break;
            }
            switch (m_rotationEasingType)
            {
            case PegasusConstants.EasingType.Linear:
                m_rotationEasingCalculator = new Easing(EaseLinear);
                break;

            case PegasusConstants.EasingType.EaseIn:
                m_rotationEasingCalculator = new Easing(EaseIn);
                break;

            case PegasusConstants.EasingType.EaseOut:
                m_rotationEasingCalculator = new Easing(EaseOut);
                break;

            case PegasusConstants.EasingType.EaseInOut:
                m_rotationEasingCalculator = new Easing(EaseInOut);
                break;
            }
            switch (m_positionEasingType)
            {
            case PegasusConstants.EasingType.Linear:
                m_positionEasingCalculator = new Easing(EaseLinear);
                break;

            case PegasusConstants.EasingType.EaseIn:
                m_positionEasingCalculator = new Easing(EaseIn);
                break;

            case PegasusConstants.EasingType.EaseOut:
                m_positionEasingCalculator = new Easing(EaseOut);
                break;

            case PegasusConstants.EasingType.EaseInOut:
                m_positionEasingCalculator = new Easing(EaseInOut);
                break;
            }

            //Now move things around and update variables based on lookat type
            switch (m_lookatType)
            {
            case PegasusConstants.LookatType.Path:
                m_lookatLocation = CalculatePositionSpline(0.005f);
                GetRelativeOffsets(transform.position, m_lookatLocation, out m_lookAtDistance, out m_lookAtHeight, out m_lookAtAngle);
                break;

            case PegasusConstants.LookatType.Target:
                GetRelativeOffsets(transform.position, m_lookatLocation, out m_lookAtDistance, out m_lookAtHeight, out m_lookAtAngle);
                break;
            }

            //Setup the start and end rotations - required for progression calculations - note this assumes that the next poi lookat location has been calculated already
            Vector3 rotationDir = m_lookatLocation - transform.position;

            if (rotationDir != Vector3.zero)
            {
                m_rotationStart = Quaternion.LookRotation(m_lookatLocation - transform.position) * transform.localRotation;
            }
            else
            {
                m_rotationStart = transform.localRotation;
            }
            rotationDir = m_nextPoi.m_lookatLocation - m_nextPoi.transform.position;
            if (rotationDir != Vector3.zero)
            {
                m_rotationEnd = Quaternion.LookRotation(rotationDir) * m_nextPoi.transform.localRotation;
            }
            else
            {
                m_rotationEnd = m_nextPoi.transform.localRotation;
            }

            //Speed
            switch (m_startSpeedType)
            {
            case PegasusConstants.SpeedType.ReallySlow:
                m_startSpeed = PegasusConstants.SpeedReallySlow;
                break;

            case PegasusConstants.SpeedType.Slow:
                m_startSpeed = PegasusConstants.SpeedSlow;
                break;

            case PegasusConstants.SpeedType.Medium:
                m_startSpeed = PegasusConstants.SpeedMedium;
                break;

            case PegasusConstants.SpeedType.Fast:
                m_startSpeed = PegasusConstants.SpeedFast;
                break;

            case PegasusConstants.SpeedType.ReallyFast:
                m_startSpeed = PegasusConstants.SpeedReallyFast;
                break;
            }

            //Update travel distance for the segment
            if (updateSegments)
            {
                UpdateSegment();
            }

            //Get the POI triggers
            m_poiTriggers.Clear();
            m_poiTriggers.AddRange(gameObject.GetComponentsInChildren <TriggerBase>());
        }
Esempio n. 3
0
        /// <summary>
        /// Initialise this POI's settings, leveraging the manager
        /// </summary>
        /// <param name="updateSegments">Update the segments</param>
        public void Initialise(bool updateSegments)
        {
            //Make sure prev and next set up - if not then exit
            if (m_prevPoi == null || m_nextPoi == null)
            {
                return;
            }

            //Move us if we are below the minimum height on the terrain
            transform.position = m_manager.GetValidatedPoiPosition(transform.position, m_heightCheckType);

            //Update last rotation
            m_lastRotation = transform.rotation.eulerAngles;

            //Set up easing calculators
            switch (m_velocityEasingType)
            {
            case PegasusConstants.EasingType.Linear:
                m_velocityEasingCalculator = new Easing(EaseLinear);
                break;

            case PegasusConstants.EasingType.EaseIn:
                m_velocityEasingCalculator = new Easing(EaseIn);
                break;

            case PegasusConstants.EasingType.EaseOut:
                m_velocityEasingCalculator = new Easing(EaseOut);
                break;

            case PegasusConstants.EasingType.EaseInOut:
                m_velocityEasingCalculator = new Easing(EaseInOut);
                break;
            }
            switch (m_rotationEasingType)
            {
            case PegasusConstants.EasingType.Linear:
                m_rotationEasingCalculator = new Easing(EaseLinear);
                break;

            case PegasusConstants.EasingType.EaseIn:
                m_rotationEasingCalculator = new Easing(EaseIn);
                break;

            case PegasusConstants.EasingType.EaseOut:
                m_rotationEasingCalculator = new Easing(EaseOut);
                break;

            case PegasusConstants.EasingType.EaseInOut:
                m_rotationEasingCalculator = new Easing(EaseInOut);
                break;
            }
            switch (m_positionEasingType)
            {
            case PegasusConstants.EasingType.Linear:
                m_positionEasingCalculator = new Easing(EaseLinear);
                break;

            case PegasusConstants.EasingType.EaseIn:
                m_positionEasingCalculator = new Easing(EaseIn);
                break;

            case PegasusConstants.EasingType.EaseOut:
                m_positionEasingCalculator = new Easing(EaseOut);
                break;

            case PegasusConstants.EasingType.EaseInOut:
                m_positionEasingCalculator = new Easing(EaseInOut);
                break;
            }

            //Now move things around and update variables based on lookat type
            switch (m_lookatType)
            {
            case PegasusConstants.LookatType.Path:
                m_lookatLocation = CalculatePositionSpline(0.005f);
                GetRelativeOffsets(transform.position, m_lookatLocation, out m_lookAtDistance, out m_lookAtHeight, out m_lookAtAngle);
                break;

            case PegasusConstants.LookatType.Target:
                GetRelativeOffsets(transform.position, m_lookatLocation, out m_lookAtDistance, out m_lookAtHeight, out m_lookAtAngle);
                break;
            }

            //Setup the start and end rotations - required for progression calculations - note this assumes that the next poi lookat location has been calculated already

            //Handle auto roll - overrides the z rotation
            if (m_autoRollOn)
            {
                if (m_manager.m_flythroughType == PegasusConstants.FlythroughType.Looped || (!m_isFirstPOI && !m_isLastPOI))
                {
                    Vector3 posPrev   = m_prevPoi.transform.position;
                    Vector3 posOrigin = transform.position;
                    Vector3 posTarget = m_nextPoi.transform.position;
                    //float distOriginTarget = Vector3.Distance(posOrigin, posTarget);

                    //Create forward location and heading based on prev location to current location -> project it forward
                    Vector3 hdgPrevOrigin = posOrigin - posPrev;
//                    hdgPrevOrigin.Normalize();
//                    Vector3 posForward = posOrigin + Quaternion.Euler(transform.localEulerAngles) * (hdgPrevOrigin * distOriginTarget);
                    Quaternion qOriginForward = Quaternion.identity;
                    if (hdgPrevOrigin != Vector3.zero)
                    {
                        qOriginForward = Quaternion.LookRotation(hdgPrevOrigin);
                    }

                    //Origin to target
                    Vector3    hdgOriginTarget = posTarget - posOrigin;
                    Quaternion qOriginTarget   = Quaternion.identity;
                    if (hdgOriginTarget != Vector3.zero)
                    {
                        qOriginTarget = Quaternion.LookRotation(hdgOriginTarget);
                    }

                    //Scale things
                    float angle       = qOriginTarget.eulerAngles.y - qOriginForward.eulerAngles.y;
                    float scaledSpeed = Mathf.Clamp(m_startSpeed, PegasusConstants.SpeedReallySlow, m_manager.m_autoRollMaxSpeed) / m_manager.m_autoRollMaxSpeed;
                    float scaledAngle = angle;
                    if (angle < 0f)
                    {
                        scaledAngle = Mathf.Clamp(angle, -90f, 0f) / 90f;
                    }
                    else
                    {
                        scaledAngle = Mathf.Clamp(angle, 0f, 90f) / 90f;
                    }
                    float z = scaledAngle * scaledSpeed * m_manager.m_autoRollMaxAngle * -1f;
                    transform.localRotation = Quaternion.Euler(0f, 0f, z);
                    m_lastRotation          = transform.localEulerAngles;



                    /*
                     *                  Vector3 pos1 = new Vector3(m_prevPoi.transform.position.x, 0f, m_prevPoi.transform.position.z);
                     *                  Vector3 pos2 = new Vector3(transform.position.x, 0f, transform.position.z);
                     *                  Vector3 pos3 = new Vector3(m_nextPoi.transform.position.x, 0f, m_nextPoi.transform.position.z);
                     *                  Vector3 hdg12 = pos2 - pos1;
                     *                  Vector3 hdg13 = pos3 - pos1;
                     *                  Quaternion q1 = Quaternion.identity;
                     *                  if (hdg12 != Vector3.zero)
                     *                  {
                     *                      q1 = Quaternion.LookRotation(hdg12);
                     *                  }
                     *                  Quaternion q2 = Quaternion.identity;
                     *                  if (hdg13 != Vector3.zero)
                     *                  {
                     *                      q2 = Quaternion.LookRotation(hdg13);
                     *
                     *                  }
                     *                  float angle = q1.eulerAngles.y - q2.eulerAngles.y;
                     *                  float scaledSpeed = Mathf.Clamp(m_startSpeed, PegasusConstants.SpeedReallySlow, m_manager.m_autoRollMaxSpeed) / m_manager.m_autoRollMaxSpeed;
                     *                  float scaledAngle = angle;
                     *                  if (angle < 0f)
                     *                  {
                     *                      scaledAngle = Mathf.Clamp(angle, -90f, 0f) / 90f;
                     *                  }
                     *                  else
                     *                  {
                     *                      scaledAngle = Mathf.Clamp(angle, 0f, 90f) / 90f;
                     *                  }
                     *                  float z = scaledAngle*scaledSpeed*m_manager.m_autoRollMaxAngle;
                     *                  transform.localRotation = Quaternion.Euler(0f, 0f, z);
                     *                  m_lastRotation = transform.localEulerAngles;
                     */
                }
            }

            //Then set up the rest of the rotations
            Vector3 rotationDir = m_lookatLocation - transform.position;

            if (rotationDir != Vector3.zero)
            {
                m_rotationStart = Quaternion.LookRotation(m_lookatLocation - transform.position) * transform.localRotation;
            }
            else
            {
                m_rotationStart = transform.localRotation;
            }
            rotationDir = m_nextPoi.m_lookatLocation - m_nextPoi.transform.position;
            if (rotationDir != Vector3.zero)
            {
                m_rotationEnd = Quaternion.LookRotation(rotationDir) * m_nextPoi.transform.localRotation;
            }
            else
            {
                m_rotationEnd = m_nextPoi.transform.localRotation;
            }

            //Speed
            switch (m_startSpeedType)
            {
            case PegasusConstants.SpeedType.ReallySlow:
                m_startSpeed = PegasusConstants.SpeedReallySlow;
                break;

            case PegasusConstants.SpeedType.Slow:
                m_startSpeed = PegasusConstants.SpeedSlow;
                break;

            case PegasusConstants.SpeedType.Medium:
                m_startSpeed = PegasusConstants.SpeedMedium;
                break;

            case PegasusConstants.SpeedType.Fast:
                m_startSpeed = PegasusConstants.SpeedFast;
                break;

            case PegasusConstants.SpeedType.ReallyFast:
                m_startSpeed = PegasusConstants.SpeedReallyFast;
                break;

            case PegasusConstants.SpeedType.Stratospheric:
                m_startSpeed = PegasusConstants.SpeedStratospheric;
                break;
            }

            //Update travel distance for the segment
            if (updateSegments)
            {
                UpdateSegment();
            }

            //Get the POI triggers
            m_poiTriggers.Clear();
            m_poiTriggers.AddRange(gameObject.GetComponentsInChildren <TriggerBase>());
        }