/// <summary>
 /// Start the rail movement
 /// </summary>
 /// <param name="rail">The rail platform.</param>
 virtual public bool ShouldBeAttachedToRail(RailPlatform rail)
 {
     // Is my parent
     if (character.ParentPlatform != rail)
     {
         return(false);
     }
     // Activated
     if (!rail.Activated)
     {
         return(false);
     }
     // Action button
     if (rail.requiredActionButton != -1 && character.Input.GetActionButtonState(rail.requiredActionButton) != ButtonState.HELD)
     {
         return(false);
     }
     // Must be grounded
     if (!character.Grounded)
     {
         return(false);
     }
     // Jump
     if (rail.allowJump && character.DefaultAirMovement.WantsJump())
     {
         return(false);
     }
     this.rail = rail;
     return(true);
 }
        /// <summary>
        /// Show the scene view editor for editing waypoints.
        /// </summary>
        virtual protected void ShowEditWaypoints(RailPlatform platform)
        {
            Undo.RecordObject(target, "Rail Platform Update");

            GUIStyle centeredLabelStyle = GUI.skin.GetStyle("Label");

            centeredLabelStyle.alignment = TextAnchor.UpperCenter;

            for (int i = 0; i < platform.waypoints.Count; i++)
            {
                if (Event.current.shift && platform.waypoints.Count > 2)
                {
                    if (DrawRemoveHandle(platform.waypoints[i]))
                    {
                        platform.waypoints.RemoveAt(i);
                        return;
                    }
                }
                else
                {
                    Vector2 newPosition = DrawMoveHandle(platform.waypoints[i]);
                    if (newPosition != platform.waypoints[i])
                    {
                        platform.waypoints[i] = newPosition;
                    }
                }
                if (i > 0)
                {
                    if (DrawAddHandle(platform.waypoints[i], platform.waypoints[i - 1]))
                    {
                        platform.waypoints.Insert(i, (platform.waypoints[i] + platform.waypoints[i - 1]) / 2.0f);
                    }
                }
//				else if (platform.moveType == WaypointMoveType.LOOP)
//				{
//					if (DrawAddHandle(platform.waypoints[i], platform.waypoints[platform.waypoints.Count - 1]))
//					{
//						platform.waypoints.Add((platform.waypoints[i] + platform.waypoints[platform.waypoints.Count - 1]) / 2.0f);
//					}
//
//				}
            }
            Undo.FlushUndoRecordObjects();
        }
 /// <summary>
 /// Gets a value indicating whether this movement wants to do a special move.
 /// </summary>
 /// <value><c>true</c> if this instance wants control; otherwise, <c>false</c>.</value>
 override public bool WantsSpecialMove()
 {
     if (rail != null)
     {
         if (ShouldBeAttachedToRail(rail))
         {
             return(true);
         }
         else
         {
             rail = null;
             return(false);
         }
     }
     if (character.ParentPlatform is RailPlatform)
     {
         if (((RailPlatform)character.ParentPlatform).CheckForActivate(character, this))
         {
             return(true);
         }
     }
     return(false);
 }
        /// <summary>
        /// Show the scene view editor for editing waypoints.
        /// </summary>
        virtual protected void ShowWaypoints(RailPlatform platform)
        {
            GUIStyle centeredLabelStyle = GUI.skin.GetStyle("Label");

            centeredLabelStyle.alignment = TextAnchor.UpperCenter;
            Handles.color = handleColor;
            for (int i = 0; i < platform.waypoints.Count; i++)
            {
//				if (i == 0 && platform.moveType == WaypointMoveType.LOOP)
//				{
//					Handles.DrawLine(platform.waypoints[platform.waypoints.Count - 1], platform.waypoints[i]);
//					Vector2 v = platform.waypoints[i] - platform.waypoints[platform.waypoints.Count - 1];
//					v = Vector3.Cross (v, Vector3.forward);
//					v.Normalize();
//					Vector2 a1 = (Vector2)(Quaternion.Euler(0,0,-60) * (0.5f * v)) + platform.waypoints[i];
//					Vector2 a2 = (Vector2)(Quaternion.Euler(0,0,60) * (-0.5f * v)) + platform.waypoints[i];
//					Handles.DrawLine( a1, platform.waypoints[i]);
//					Handles.DrawLine( a2, platform.waypoints[i]);
//				}
                if (i != 0)
                {
                    Handles.DrawLine(platform.waypoints[i - 1], platform.waypoints[i]);


                    //Handles.DrawLine( movement.wayPoints[i], a2);

                    Vector2 v = platform.waypoints[i] - platform.waypoints[i - 1];
                    v = Vector3.Cross(v, Vector3.forward);
                    v.Normalize();

                    Vector2 a1 = (Vector2)(Quaternion.Euler(0, 0, -60) * (0.5f * v)) + platform.waypoints[i];
                    Vector2 a2 = (Vector2)(Quaternion.Euler(0, 0, 60) * (-0.5f * v)) + platform.waypoints[i];
                    Handles.DrawLine(a1, platform.waypoints[i]);
                    Handles.DrawLine(a2, platform.waypoints[i]);
                }
            }
        }
 /// <summary>
 /// Called when the movement loses control. Override to do any reset type actions.
 /// </summary>
 override public void LosingControl()
 {
     character.SetVelocityX(0);
     character.SetVelocityY(0);
     rail = null;
 }