浏览代码

Restructuring & minor changes

/main
DeivSky 4 年前
当前提交
32e56490
共有 18 个文件被更改,包括 47 次插入33 次删除
  1. 28
      UOP1_Project/Assets/Scripts/StateMachine/Core/StateCondition.cs
  2. 6
      UOP1_Project/Assets/Scripts/StateMachine/Core/StateMachine.cs
  3. 16
      UOP1_Project/Assets/Scripts/StateMachine/ScriptableObjects/StateConditionSO.cs
  4. 14
      UOP1_Project/Assets/Scripts/StateMachine/Debugging/StateMachineDebugger.cs
  5. 8
      UOP1_Project/Assets/Scripts/StateMachine/Debugging.meta
  6. 8
      UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities.meta
  7. 0
      /UOP1_Project/Assets/Scripts/StateMachine/Debugging/StateMachineDebugger.cs
  8. 0
      /UOP1_Project/Assets/Scripts/StateMachine/Debugging/StateMachineDebugger.cs.meta
  9. 0
      /UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities/AddTransitionHelper.cs
  10. 0
      /UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities/AddTransitionHelper.cs.meta
  11. 0
      /UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities/ContentStyle.cs
  12. 0
      /UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities/ContentStyle.cs.meta
  13. 0
      /UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities/SerializedTransition.cs
  14. 0
      /UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities/SerializedTransition.cs.meta
  15. 0
      /UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities/TransitionDisplayHelper.cs.meta
  16. 0
      /UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities/TransitionDisplayHelper.cs

28
UOP1_Project/Assets/Scripts/StateMachine/Core/StateCondition.cs


using UnityEngine;
using UOP1.StateMachine.ScriptableObjects;
using UOP1.StateMachine.ScriptableObjects;
namespace UOP1.StateMachine
{

/// </summary>
internal bool GetStatement()
{
bool returnValue;
if (!_originSO.cacheResult)
return Statement();
if (_originSO.cacheResult && _isCached)
returnValue = _cachedStatement;
else
if (!_isCached)
returnValue = Statement();
if (_originSO.cacheResult)
{
_isCached = true;
_cachedStatement = returnValue;
}
_isCached = true;
_cachedStatement = Statement();
return returnValue;
return _cachedStatement;
}
internal void ClearStatementCache()

/// </summary>
public readonly struct StateCondition
{
internal readonly StateConditionSO _originSO;
public StateCondition(StateConditionSO originSO, StateMachine stateMachine, Condition condition, bool expectedResult)
public StateCondition(StateMachine stateMachine, Condition condition, bool expectedResult)
_originSO = originSO;
_condition._originSO = originSO;
_expectedResult = expectedResult;
}

bool isMet = statement == _expectedResult;
#if UNITY_EDITOR
_stateMachine._debugger.TransitionConditionResult(_originSO.name, statement, isMet);
_stateMachine._debugger.TransitionConditionResult(_condition._originSO.name, statement, isMet);
#endif
return isMet;
}

6
UOP1_Project/Assets/Scripts/StateMachine/Core/StateMachine.cs


#if UNITY_EDITOR
[Space]
[SerializeField]
internal StateMachineDebugger _debugger = default;
internal Debugging.StateMachineDebugger _debugger = default;
private State _currentState;
internal State _currentState;
private void Awake()
{

_debugger.Awake(this, _currentState._originSO.name);
_debugger.Awake(this);
#endif
}

16
UOP1_Project/Assets/Scripts/StateMachine/ScriptableObjects/StateConditionSO.cs


/// </summary>
internal StateCondition GetCondition(StateMachine stateMachine, bool expectedResult, Dictionary<ScriptableObject, object> createdInstances)
{
if (createdInstances.TryGetValue(this, out var cond))
return new StateCondition(this, stateMachine, (Condition)cond, expectedResult);
if (!createdInstances.TryGetValue(this, out var obj))
{
var condition = CreateCondition();
condition._originSO = this;
createdInstances.Add(this, condition);
condition.Awake(stateMachine);
var condition = new StateCondition(this, stateMachine, CreateCondition(), expectedResult);
createdInstances.Add(this, condition._condition);
condition._condition.Awake(stateMachine);
return condition;
obj = condition;
}
return new StateCondition(stateMachine, (Condition)obj, expectedResult);
}
protected abstract Condition CreateCondition();
}

14
UOP1_Project/Assets/Scripts/StateMachine/Debugging/StateMachineDebugger.cs


using System;
#if UNITY_EDITOR
using System;
namespace UOP1.StateMachine
namespace UOP1.StateMachine.Debugging
{
/// <summary>
/// Class specialized in debugging the state transitions, should only be used while in editor mode.

/// <summary>
/// Must be called together with <c>StateMachine.Awake()</c>
/// </summary>
internal void Awake(StateMachine stateMachine, string initialState)
internal void Awake(StateMachine stateMachine)
currentState = initialState;
currentState = stateMachine._currentState._originSO.name;
}
internal void TransitionEvaluationBegin(string targetState)

return;
_logBuilder.Clear();
_logBuilder.AppendLine($"{_stateMachine.gameObject.name} state changed");
_logBuilder.AppendLine($"{_stateMachine.name} state changed");
_logBuilder.AppendLine($"{currentState} {SHARP_ARROW} {_targetState}");
if (appendConditionsInfo)

}
}
}
#endif

8
UOP1_Project/Assets/Scripts/StateMachine/Debugging.meta


fileFormatVersion: 2
guid: ab3a7122d723d924e8995b844b175fe6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities.meta


fileFormatVersion: 2
guid: 2b3ebc49523a84d4b9c245e85b972956
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

/UOP1_Project/Assets/Scripts/StateMachine/Core/StateMachineDebugger.cs → /UOP1_Project/Assets/Scripts/StateMachine/Debugging/StateMachineDebugger.cs

/UOP1_Project/Assets/Scripts/StateMachine/Core/StateMachineDebugger.cs.meta → /UOP1_Project/Assets/Scripts/StateMachine/Debugging/StateMachineDebugger.cs.meta

/UOP1_Project/Assets/Scripts/StateMachine/Editor/AddTransitionHelper.cs → /UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities/AddTransitionHelper.cs

/UOP1_Project/Assets/Scripts/StateMachine/Editor/AddTransitionHelper.cs.meta → /UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities/AddTransitionHelper.cs.meta

/UOP1_Project/Assets/Scripts/StateMachine/Editor/ContentStyle.cs → /UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities/ContentStyle.cs

/UOP1_Project/Assets/Scripts/StateMachine/Editor/ContentStyle.cs.meta → /UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities/ContentStyle.cs.meta

/UOP1_Project/Assets/Scripts/StateMachine/Editor/SerializedTransition.cs → /UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities/SerializedTransition.cs

/UOP1_Project/Assets/Scripts/StateMachine/Editor/SerializedTransition.cs.meta → /UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities/SerializedTransition.cs.meta

/UOP1_Project/Assets/Scripts/StateMachine/Editor/TransitionDisplayHelper.cs.meta → /UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities/TransitionDisplayHelper.cs.meta

/UOP1_Project/Assets/Scripts/StateMachine/Editor/TransitionDisplayHelper.cs → /UOP1_Project/Assets/Scripts/StateMachine/Editor/Utilities/TransitionDisplayHelper.cs

正在加载...
取消
保存