Beispiel #1
0
 public void GoTo(int targetWayPoint)
 {
     if (Time.time < this.m_NextAllowedMoveTime)
     {
         return;
     }
     if (this.PathType != vp_MovingPlatform.PathMoveType.Target)
     {
         return;
     }
     this.m_TargetedWayPoint = this.GetValidWaypoint(targetWayPoint);
     if (targetWayPoint > this.m_NextWaypoint)
     {
         if (this.PathDirection != vp_MovingPlatform.Direction.Direct)
         {
             this.PathDirection = vp_MovingPlatform.Direction.Forward;
         }
     }
     else if (this.PathDirection != vp_MovingPlatform.Direction.Direct)
     {
         this.PathDirection = vp_MovingPlatform.Direction.Backwards;
     }
     this.m_Moving = true;
 }
Beispiel #2
0
    private void UpdatePath()
    {
        if (this.m_Waypoints.Count < 2)
        {
            return;
        }
        if (this.GetDistanceLeft() < 0.01f && Time.time >= this.m_NextAllowedMoveTime)
        {
            switch (this.PathType)
            {
            case vp_MovingPlatform.PathMoveType.PingPong:
                if (this.PathDirection == vp_MovingPlatform.Direction.Backwards)
                {
                    if (this.m_NextWaypoint == 0)
                    {
                        this.PathDirection = vp_MovingPlatform.Direction.Forward;
                    }
                }
                else if (this.m_NextWaypoint == this.m_Waypoints.Count - 1)
                {
                    this.PathDirection = vp_MovingPlatform.Direction.Backwards;
                }
                this.OnArriveAtWaypoint();
                this.GoToNextWaypoint();
                break;

            case vp_MovingPlatform.PathMoveType.Loop:
                this.OnArriveAtWaypoint();
                this.GoToNextWaypoint();
                break;

            case vp_MovingPlatform.PathMoveType.Target:
                if (this.m_NextWaypoint == this.m_TargetedWayPoint)
                {
                    if (this.m_Moving)
                    {
                        this.OnStop();
                    }
                    else if (this.m_NextWaypoint != 0)
                    {
                        this.OnArriveAtDestination();
                    }
                }
                else
                {
                    if (this.m_Moving)
                    {
                        if (this.m_PhysicsCurrentMoveVelocity == 0f)
                        {
                            this.OnStart();
                        }
                        else
                        {
                            this.OnArriveAtWaypoint();
                        }
                    }
                    this.GoToNextWaypoint();
                }
                break;
            }
        }
    }
    /// <summary>
    ///
    /// </summary>
    public virtual void DoPathFoldout()
    {
        m_PathFoldout = EditorGUILayout.Foldout(m_PathFoldout, "Path");

        if (m_PathFoldout)
        {
            if (string.IsNullOrEmpty(PathInfo))
            {
                PathInfo        = StandardPathInfo;
                PathMessageType = MessageType.Info;
            }

            if (m_WaypointCount < 2)
            {
                GUI.enabled = false;
            }
            m_Component.PathType = (vp_MovingPlatform.PathMoveType)EditorGUILayout.EnumPopup("Type", m_Component.PathType);
            GUI.enabled          = true;

            m_Component.PathWaypoints = (GameObject)EditorGUILayout.ObjectField("Waypoints", m_Component.PathWaypoints, typeof(GameObject), true);
            if ((m_Component.PathWaypoints) == null || (m_WaypointCount < 2))
            {
                GUI.enabled = false;
            }
            GUILayout.BeginHorizontal();

            // gizmo tool
            EditorGUILayout.PrefixLabel(" ");
            if (GUILayout.Button("Generate Gizmos"))
            {
                if (EditorUtility.DisplayDialog("Headsup!", "This will remove every component under the chosen 'Waypoints' object in favor of pretty new gizmos.", "OK", "Later"))
                {
                    // remove all components under waypoint container and add a
                    // gizmo to each transform
                    foreach (Transform t in m_Component.PathWaypoints.transform)
                    {
                        foreach (Component c in t.GetComponentsInChildren(typeof(Component)))
                        {
                            if (c.GetType() != typeof(Transform))
                            {
                                Object.DestroyImmediate(c);
                            }
                        }
                        t.gameObject.AddComponent(typeof(vp_WaypointGizmo));
                    }
                }
            }
            GUILayout.Space(18);
            GUILayout.EndHorizontal();

            if (m_Component.PathType == vp_MovingPlatform.PathMoveType.Target)
            {
                // special logic to get rid of nullref in case waypoint list is empty
                int waypoints = 0;
                if (m_Component != null && m_Component.PathWaypoints != null && m_Component.PathWaypoints.transform.childCount > 1)
                {
                    waypoints = m_Component.PathWaypoints.transform.childCount - 1;
                }

                m_Component.MoveAutoStartTarget = EditorGUILayout.IntSlider((m_Component.MoveAutoStartTarget == 0 ? "Auto Start (OFF)" : "Auto Start Target"), m_Component.MoveAutoStartTarget, 0, waypoints);
                m_Component.MoveReturnDelay     = EditorGUILayout.Slider("Return Delay" + (m_Component.MoveReturnDelay == 0 ? " (OFF)" : ""), m_Component.MoveReturnDelay, 0.0f, 30.0f);
                m_Component.MoveCooldown        = EditorGUILayout.Slider("Cooldown" + (m_Component.MoveCooldown == 0 ? " (OFF)" : ""), m_Component.MoveCooldown, 0.0f, 30.0f);
            }
            vp_MovingPlatform.Direction previousPathDirection = m_Component.PathDirection;
            m_Component.PathDirection = (vp_MovingPlatform.Direction)EditorGUILayout.EnumPopup("Direction", m_Component.PathDirection);
            if (m_Component.PathDirection == vp_MovingPlatform.Direction.Direct &&
                (m_Component.PathType != vp_MovingPlatform.PathMoveType.Target))
            {
                PathInfo                  = "Direction:Direct requires the Manual path type.";
                PathMessageType           = MessageType.Warning;
                m_Component.PathDirection = previousPathDirection;
                if (previousPathDirection == vp_MovingPlatform.Direction.Direct)
                {
                    m_Component.PathDirection = vp_MovingPlatform.Direction.Forward;
                }
            }
            else if (m_Component.PathDirection != previousPathDirection)
            {
                PathInfo = "";
            }


            GUI.enabled = true;

            if (m_WaypointCount > 1)
            {
                PathMessageType = MessageType.Info;
                switch (m_Component.PathType)
                {
                case vp_MovingPlatform.PathMoveType.Target:
                    PathInfo = "In Target Mode, the platform will stand still, but go to a target waypoint when player stands on it. If Auto Start is OFF, the platform must be operated via the script's public GoTo method.";
                    break;

                case vp_MovingPlatform.PathMoveType.PingPong:
                    PathInfo = "In PingPong mode, the platform will go to the last waypoint via all waypoints - then back the same way.";
                    break;

                case vp_MovingPlatform.PathMoveType.Loop:
                    PathInfo = "In Loop mode, the platform will continuously move through all the waypoints without changing direction.";
                    break;
                }
            }

            GUILayout.BeginHorizontal();
            GUILayout.Space(10);
            EditorGUILayout.HelpBox(PathInfo, PathMessageType);
            GUILayout.Space(10);
            GUILayout.EndHorizontal();
        }
    }