Skip to content

Commit

Permalink
feat: Added useBaseState to StateTimeline
Browse files Browse the repository at this point in the history
  • Loading branch information
christides11 committed Apr 25, 2022
1 parent d034a07 commit 244add5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ namespace HnSF.Sample.TDAction
{
public class ADVManager : FighterManager
{
private void Start()
{
StateManager.ChangeState((int)BaseStateEnum.IDLE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,48 +31,47 @@ public int MovesetCount
[NonSerialized] public StateFunctionMapper functionMapperBase = new StateFunctionMapper();
[NonSerialized] public StateConditionMapper conditionMapperBase = new StateConditionMapper();

private void Awake()
{

}

public void Tick()
{
if (markedForStateChange)
{
ChangeState(nextState, 0, true);
}
if (CurrentState == 0) return;
ProcessState();
ProcessState(states[CurrentState], states[CurrentState].autoIncrement, states[CurrentState].autoLoop);
}
private void ProcessState()

private void ProcessState(StateTimeline state, bool onInterrupt = false, bool autoIncrement = false, bool autoLoop = false)
{
for (int i = 0; i < states[CurrentState].data.Length; i++)

while (true)
{
var valid = true;
for (int j = 0; j < states[CurrentState].data[i].FrameRanges.Length; j++)
int realFrame = onInterrupt ? state.totalFrames+1 : Mathf.Clamp(CurrentStateFrame, 0, state.totalFrames);
foreach (var d in state.data)
{
if (CurrentStateFrame < states[CurrentState].data[i].FrameRanges[j].x
|| CurrentStateFrame > states[CurrentState].data[i].FrameRanges[j].y)
var valid = true;
for (int j = 0; j < d.FrameRanges.Length; j++)
{
if (!(realFrame < d.FrameRanges[j].x) &&
!(realFrame > d.FrameRanges[j].y)) continue;
valid = false;
break;
}

if (!valid) continue;
if (!conditionMapperBase.TryCondition(d.Condition.FunctionMap, fighterManager, d.Condition)) continue;
functionMapperBase.functions[d.FunctionMap](fighterManager, d);
}

if (!valid) continue;
if (!conditionMapperBase.TryCondition(states[CurrentState].data[i].Condition.FunctionMap, fighterManager, states[CurrentState].data[i].Condition)) continue;
functionMapperBase.functions[states[CurrentState].data[i].FunctionMap](fighterManager, states[CurrentState].data[i]);
if (!state.useBaseState) break;
state = (StateTimeline)state.baseState;
}

if (states[CurrentState].autoIncrement)
if (onInterrupt != false || !autoIncrement) return;
IncrementFrame(1);
if (autoLoop && CurrentStateFrame > state.totalFrames)
{
IncrementFrame(1);
if (states[CurrentState].autoLoop && CurrentStateFrame > states[CurrentState].totalFrames)
{
SetFrame(1);
}
SetFrame(1);
}
}

Expand All @@ -95,15 +94,15 @@ public bool ChangeState(int state, int stateFrame = 0, bool callOnInterrupt = tr
if(callOnInterrupt && CurrentState != (int)FighterStateEnum.NULL)
{
SetFrame(states[CurrentState].totalFrames+1);
ProcessState();
ProcessState(states[CurrentState], true);
}

CurrentStateFrame = stateFrame;
CurrentState = state;
if(CurrentStateFrame == 0)
{
SetFrame(0);
ProcessState();
ProcessState(states[CurrentState]);
SetFrame(1);
}

Expand All @@ -128,7 +127,7 @@ public HnSF.StateTimeline GetState(int moveset, int state)

public void SetMoveset(int movesetIndex)
{
throw new NotImplementedException();
CurrentStateMoveset = movesetIndex;
}

public void SetFrame(int frame)
Expand Down
1 change: 1 addition & 0 deletions Assets/HnSF/State/StateTimeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace HnSF
{
public class StateTimeline : ScriptableObject
{
public bool useBaseState = false;
public StateTimeline baseState;
public int totalFrames = 10;
public bool autoIncrement = true;
Expand Down

0 comments on commit 244add5

Please sign in to comment.