Spaces:
Runtime error
Runtime error
File size: 2,279 Bytes
00437a9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
using System;
namespace Quantum
{
public enum AIParamSource
{
None,
Value,
Config,
Blackboard,
Function,
}
[Serializable]
public abstract unsafe class AIParam<T>
{
public AIParamSource Source = AIParamSource.Value;
public string Key;
public T DefaultValue;
/// <summary>
/// Use this to solve the AIParam value when the source of the value is unkown
/// </summary>
public T Resolve(Frame frame, EntityRef entity, AIBlackboardComponent* blackboard, AIConfig aiConfig)
{
if (Source == AIParamSource.Value || (Source != AIParamSource.Function && string.IsNullOrEmpty(Key) == true))
return DefaultValue;
switch (Source)
{
case AIParamSource.Blackboard:
BlackboardValue blackboardValue = blackboard->GetBlackboardValue(frame, Key);
return GetBlackboardValue(blackboardValue);
case AIParamSource.Config:
AIConfig.KeyValuePair configPair = aiConfig != null ? aiConfig.Get(Key) : null;
return configPair != null ? GetConfigValue(configPair) : DefaultValue;
case AIParamSource.Function:
return GetFunctionValue(frame, entity);
}
return default(T);
}
/// <summary>
/// Use this if the it is known that the AIParam stores specifically a Blackboard value
/// </summary>
public unsafe T ResolveBlackboard(Frame frame, AIBlackboardComponent* blackboard)
{
BlackboardValue blackboardValue = blackboard->GetBlackboardValue(frame, Key);
return GetBlackboardValue(blackboardValue);
}
/// <summary>
/// Use this if the it is known that the AIParam stores specifically a Config value
/// </summary>
public unsafe T ResolveConfig(Frame frame, AIConfig aiConfig)
{
AIConfig.KeyValuePair configPair = aiConfig != null ? aiConfig.Get(Key) : null;
return configPair != null ? GetConfigValue(configPair) : DefaultValue;
}
/// <summary>
/// Use this if the it is known that the AIParam stores specifically a Func
/// </summary>
public unsafe T ResolveFunction(Frame frame, EntityRef entity)
{
return GetFunctionValue(frame, entity);
}
protected abstract T GetBlackboardValue(BlackboardValue value);
protected abstract T GetConfigValue(AIConfig.KeyValuePair configPair);
protected abstract T GetFunctionValue(Frame frame, EntityRef entity);
}
}
|