Skip to content
Snippets Groups Projects
Commit 880f2f3f authored by Matthewit Dechatech's avatar Matthewit Dechatech
Browse files

Fix adding and deleting moves, rolling jump

parent 08753517
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -15,12 +15,6 @@ public class HedgehogControllerEditor : UnityEditor.Editor
[SerializeField] private SerializedObject _serializedInstance;
#endregion
#region Foldout Variables
protected static bool ShowCollision
{
get { return EditorPrefs.GetBool("HedgehogControllerEditor.ShowCollision", false); }
set { EditorPrefs.SetBool("HedgehogControllerEditor.ShowCollision", value); }
}
protected static bool ShowSensors
{
get { return EditorPrefs.GetBool("HedgehogControllerEditor.ShowSensors", false); }
Loading
Loading
@@ -130,13 +124,8 @@ public override void OnInspectorGUI()
 
HedgehogEditorGUIUtility.DrawProperties(serializedObject,
"MoveManager", "RendererObject", "Animator");
#region Collision Foldout
ShowCollision = EditorGUILayout.Foldout(ShowCollision, "Collision", foldoutStyle);
if (ShowCollision)
{
HedgehogEditorGUIUtility.DrawProperties(serializedObject, "Paths");
}
#endregion
HedgehogEditorGUIUtility.DrawProperties(serializedObject, "Paths");
#region Sensors Foldout
ShowSensors = EditorGUILayout.Foldout(ShowSensors, "Sensors", foldoutStyle);
if (ShowSensors)
Loading
Loading
Loading
Loading
@@ -107,10 +107,10 @@ private void OnAttach()
 
public override void SetAnimatorParameters()
{
if(HorizontalSpeedFloat.Length > 0)
if(!string.IsNullOrEmpty(HorizontalSpeedFloat))
Animator.SetFloat(HorizontalSpeedFloat, Controller.Velocity.x);
 
if(VerticalSpeedFloat.Length > 0)
if(!string.IsNullOrEmpty(VerticalSpeedFloat))
Animator.SetFloat(VerticalSpeedFloat, Controller.Velocity.y);
}
 
Loading
Loading
Loading
Loading
@@ -18,11 +18,11 @@ public override void OnInspectorGUI()
{
serializedObject.Update();
 
if (targets.Count() == 1)
{
var moveManager = target as MoveManager;
moveManager.GetComponents(moveManager.Moves);
}
var moveManager = target as MoveManager;
moveManager.GetComponents(moveManager.Moves);
serializedObject.ApplyModifiedProperties();
serializedObject.Update();
 
HedgehogEditorGUIUtility.DrawProperties(serializedObject,
"Controller", "Moves");
Loading
Loading
Loading
Loading
@@ -126,7 +126,10 @@ public override void OnActiveEnter(State previousState)
Controller.Detach();
Controller.Velocity += DMath.AngleToVector((Controller.SurfaceAngle + 90.0f)*Mathf.Deg2Rad)*ActivateSpeed;
 
if (Manager.IsActive<Roll>())
var roll = Manager.Get<Roll>();
if (roll == null) return;
if (roll.Active)
{
// Disable air control if jumping while rolling
Manager.End<AirControl>();
Loading
Loading
Loading
Loading
@@ -26,13 +26,23 @@ public class Move : MonoBehaviour
/// The move's current state.
/// </summary>
public State CurrentState;
public enum State
public enum State
{
Unavailable, // Can't be performed unless forced to.
Available, // Can be performed through player input.
Active, // Currently being performed.
}
 
/// <summary>
/// Whether the move is currently active.
/// </summary>
public bool Active
{
get { return CurrentState == State.Active; }
set { ChangeState(value ? State.Active : CurrentState == State.Active ? State.Available : CurrentState); }
}
/// <summary>
/// If the move is active, whether it was activated through player input.
/// </summary>
Loading
Loading
@@ -82,7 +92,7 @@ public virtual void Reset()
 
public virtual void Awake()
{
Controller = GetComponentInParent<HedgehogController>();
Controller = Controller ?? GetComponentInParent<HedgehogController>();
Animator = Controller.Animator;
Manager = Controller.MoveManager;
 
Loading
Loading
@@ -121,10 +131,10 @@ public virtual void Update()
/// </summary>
public virtual void SetAnimatorParameters()
{
if(ActiveBool.Length > 0)
if(!string.IsNullOrEmpty(ActiveBool))
Animator.SetBool(ActiveBool, CurrentState == State.Active);
 
if(AvailableBool.Length > 0)
if(!string.IsNullOrEmpty(AvailableBool))
Animator.SetBool(AvailableBool, CurrentState == State.Available);
}
 
Loading
Loading
Loading
Loading
@@ -86,6 +86,8 @@ public void Reset()
 
public void Awake()
{
GetComponents(Moves);
ActiveMoves = new List<Move>();
AvailableMoves = new List<Move>();
UnavailableMoves = new List<Move>(Moves);
Loading
Loading
@@ -100,9 +102,7 @@ public void Awake()
public void Update()
{
if (Controller.Interrupted)
{
return;
}
 
// List copying is used abundantly since a move may remove itself or others from its own list,
// causing iteration errors. There are faster ways to handle this, but at the moment the overhead
Loading
Loading
@@ -111,6 +111,13 @@ public void Update()
{
foreach (var move in new List<Move>(UnavailableMoves))
{
if (!move)
{
UnavailableMoves.Remove(move);
GetComponents(Moves);
continue;
}
if (!move.Available())
continue;
 
Loading
Loading
@@ -128,6 +135,13 @@ public void Update()
{
foreach (var move in new List<Move>(AvailableMoves))
{
if (!move)
{
AvailableMoves.Remove(move);
GetComponents(Moves);
continue;
}
if (!move.Available())
{
if (!AvailableMoves.Remove(move))
Loading
Loading
@@ -149,10 +163,16 @@ public void Update()
{
foreach (var move in new List<Move>(ActiveMoves))
{
if (!move)
{
ActiveMoves.Remove(move);
GetComponents(Moves);
continue;
}
if (move.InputDeactivate())
{
End(move);
OnAvailable.Invoke(move);
}
else
Loading
Loading
@@ -166,8 +186,15 @@ public void Update()
public void FixedUpdate()
{
if (Controller.Interrupted) return;
foreach (var move in new List<Move>(ActiveMoves))
{
if (!move)
{
GetComponents(Moves);
continue;
}
move.OnActiveFixedUpdate();
}
}
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment