/////////////////////////////// // StateValues /////////////////////////////// // Use to set value-type StateValue public void SetStateValue <T>(StateValue <T> aStateValue, T aValue) { if (!IsStateValueInResetterList(aStateValue)) { mStateValueResetters.Add(new StateValueResetterT <T>(aStateValue)); } aStateValue.__ValueToBeAccessedByStateMachineOnly = aValue; }
private bool IsStateValueInResetterList <T>(StateValue <T> aStateValue) { if (mStateValueResetters == null) // First time, lazily create list { mStateValueResetters = new List <IStateValueResetter>(); } else { foreach (var resetter in mStateValueResetters) { if (resetter is StateValueResetterT <T> r && r.StateValue == aStateValue) { return(true); } } } return(false); }
public StateValueResetterT(StateValue <T> aStateValue) { mStateValue = aStateValue; mOriginalValue = aStateValue.__ValueToBeAccessedByStateMachineOnly; }
public override void Reset() { mStateValue.__ValueToBeAccessedByStateMachineOnly = mOriginalValue; mStateValue = null; //@TODO: Add Dispose (or Finalize) that asserts that this is null (that Reset got called) }
public void SetAttribute <T>(StateValue <T> aStateValue, T aValue) where T : struct { }