protected override void AllocateData(ref BlobBuilder builder, ref BlobVariable <T> blobVariable, INodeDataBuilder self, ITreeNode <INodeDataBuilder>[] tree) { var type = ScriptableObject.GetType(); FieldInfo fieldInfo = null; PropertyInfo propertyInfo = null; if (ScriptableObject != null) { fieldInfo = type.GetField(ScriptableObjectValueName, FIELD_BINDING_FLAGS); } if (fieldInfo == null) { propertyInfo = type.GetProperty(ScriptableObjectValueName, FIELD_BINDING_FLAGS); } if ((fieldInfo == null || fieldInfo.FieldType != typeof(T)) && (propertyInfo == null || !propertyInfo.CanRead || propertyInfo.PropertyType != typeof(T))) { Debug.LogError($"{ScriptableObject.name}.{ScriptableObjectValueName} is not valid"); throw new ArgumentException(); } var value = fieldInfo?.GetValue(ScriptableObject) ?? propertyInfo?.GetValue(ScriptableObject); builder.Allocate(ref blobVariable, (T)value); }
public override void Allocate(ref BlobBuilder builder, ref BlobVariable <T> blobVariable, INodeDataBuilder self, ITreeNode <INodeDataBuilder>[] tree) { var index = Array.FindIndex(tree, node => ReferenceEquals(node.Value, NodeObject)); if (!NodeObject || index < 0) { Debug.LogError($"Invalid `NodeObject` {NodeObject}", (UnityEngine.Object)self); throw new ArgumentException(); } var nodeType = VirtualMachine.GetNodeType(NodeObject.NodeId); if (string.IsNullOrEmpty(ValueFieldName) && nodeType == typeof(T)) { builder.Allocate(ref blobVariable, new DynamicNodeRefData { Index = index, Offset = 0 }); return; } var fieldInfo = nodeType.GetField(ValueFieldName, FIELD_BINDING_FLAGS); if (fieldInfo == null) { Debug.LogError($"Invalid `ValueFieldName` {ValueFieldName}", (UnityEngine.Object)self); throw new ArgumentException(); } var fieldOffset = Marshal.OffsetOf(nodeType, ValueFieldName).ToInt32(); builder.Allocate(ref blobVariable, new DynamicNodeRefData { Index = index, Offset = fieldOffset }); var fieldType = fieldInfo.FieldType; if (fieldType == typeof(T)) { blobVariable.VariableId = AccessRuntimeData ? _ID_RUNTIME_NODE : _ID_DEFAULT_NODE; } else if (fieldType == typeof(BlobVariable <T>)) { blobVariable.VariableId = AccessRuntimeData ? _ID_RUNTIME_NODE_VARIABLE : _ID_DEFAULT_NODE_VARIABLE; } else { Debug.LogError($"Invalid type of `ValueFieldName` {ValueFieldName} {fieldType}", (UnityEngine.Object)self); throw new ArgumentException(); } }
protected override void AllocateData(ref BlobBuilder builder, ref BlobVariable <T> blobVariable, INodeDataBuilder self, ITreeNode <INodeDataBuilder>[] tree) { var data = GetTypeHashAndFieldOffset(ComponentValueName); if (data.Type != typeof(T) || data.Hash == 0) { Debug.LogError($"ComponentVariable({ComponentValueName}) is not valid, fallback to ConstantValue", (UnityEngine.Object)self); throw new ArgumentException(); } if (CopyToLocalNode) { builder.Allocate(ref blobVariable, new CopyToLocalComponentData { StableHash = data.Hash, Offset = data.Offset, LocalValue = default }); } else { builder.Allocate(ref blobVariable, new DynamicComponentData { StableHash = data.Hash, Offset = data.Offset }); } }
private static ref T GetDataRef <TNodeBlob, TBlackboard>(ref BlobVariable <T> blobVariable, int index, ref TNodeBlob blob, ref TBlackboard bb) where TNodeBlob : struct, INodeBlob where TBlackboard : struct, IBlackboard { return(ref blobVariable.Value <T>()); }
private static unsafe ref T GetValue(ref BlobVariable <T> blobVariable, Func <int, IntPtr> ptrFunc) { ref var data = ref blobVariable.Value <DynamicNodeRefData>();
private static ref T GetDefaultNodeDataRef <TNodeBlob, TBlackboard>(ref BlobVariable <T> blobVariable, int index, ref TNodeBlob blob, ref TBlackboard bb) where TNodeBlob : struct, INodeBlob where TBlackboard : struct, IBlackboard { return(ref GetValue(ref blobVariable, blob.GetDefaultDataPtr)); }
protected override void AllocateData(ref BlobBuilder builder, ref BlobVariable <T> blobVariable) { builder.Allocate(ref blobVariable, CustomValue); }
public virtual void Allocate(ref BlobBuilder builder, ref BlobVariable <T> blobVariable, [NotNull] INodeDataBuilder self, [NotNull] ITreeNode <INodeDataBuilder>[] tree) { blobVariable.VariableId = VariablePropertyTypeId; AllocateData(ref builder, ref blobVariable, self, tree); }
protected override void AllocateData(ref BlobBuilder builder, ref BlobVariable <T> blobVariable, INodeDataBuilder self, ITreeNode <INodeDataBuilder>[] tree) { builder.Allocate(ref blobVariable, CustomValue); }
private static ref T GetDataRefThrow <TNodeBlob, TBlackboard>(ref BlobVariable <T> _, int __, ref TNodeBlob ___, ref TBlackboard ____) where TNodeBlob : struct, INodeBlob where TBlackboard : struct, IBlackboard => throw new NotImplementedException() ;
protected virtual void AllocateData(ref BlobBuilder builder, ref BlobVariable <T> blobVariable) { }
public virtual void Allocate(ref BlobBuilder builder, ref BlobVariable <T> blobVariable) { blobVariable.VariableId = VariablePropertyTypeId; AllocateData(ref builder, ref blobVariable); }
private static ref T GetDefaultNodeDataRef(ref BlobVariable <T> blobVariable, int index, INodeBlob blob, IBlackboard bb) { return(ref GetValue(ref blobVariable, blob.GetDefaultDataPtr)); }
private static T GetDefaultNodeData(ref BlobVariable <T> blobVariable, int index, INodeBlob blob, IBlackboard bb) { return(GetDefaultNodeDataRef(ref blobVariable, index, blob, bb)); }
private static IEnumerable <ComponentType> GetComponentAccessDefault(ref BlobVariable <T> _) => Enumerable.Empty <ComponentType>();
private static ref T GetDataRefThrow(ref BlobVariable <T> _, int __, INodeBlob ___, IBlackboard ____) => throw new NotImplementedException();
private static T GetData <TNodeBlob, TBlackboard>(ref BlobVariable <T> blobVariable, int index, ref TNodeBlob blob, ref TBlackboard bb) where TNodeBlob : struct, INodeBlob where TBlackboard : struct, IBlackboard { ref var data = ref blobVariable.Value <DynamicComponentData>();
protected virtual void AllocateData(ref BlobBuilder builder, ref BlobVariable <T> blobVariable, INodeDataBuilder self, ITreeNode <INodeDataBuilder>[] tree) { }
private static T GetDefaultNodeData <TNodeBlob, TBlackboard>(ref BlobVariable <T> blobVariable, int index, ref TNodeBlob blob, ref TBlackboard bb) where TNodeBlob : struct, INodeBlob where TBlackboard : struct, IBlackboard { return(GetDefaultNodeDataRef(ref blobVariable, index, ref blob, ref bb)); }
private static ref T GetDataRef(ref BlobVariable <T> blobVariable, int index, INodeBlob blob, IBlackboard bb) { return(ref blobVariable.Value <T>()); }
private static T GetData(ref BlobVariable <T> blobVariable, int index, INodeBlob blob, IBlackboard bb) { ref var data = ref blobVariable.Value <DynamicComponentData>();