public ActionAsset CreateActionAsset(ActionId actionId, string path)
        {
            if (!path.EndsWith($".{Extension}"))
            {
                path += $".{Extension}";
            }
            var file = new FileInfo(path);

            if (!file.Directory.Exists)
            {
                file.Directory.Create();
            }
            var model = new ActionAssetModel {
                id = actionId
            };

            using (var stream = file.Create()) {
                using (var writer = new StreamWriter(stream)) {
                    var jsonSettings = JsonConvert.DefaultSettings.Invoke();
                    jsonSettings.TypeNameHandling = TypeNameHandling.All;
                    writer.Write(JsonConvert.SerializeObject(model, jsonSettings));
                }
            }

            AssetDatabase.Refresh();
            return(AssetDatabase.LoadAssetAtPath <ActionAsset>(path));
        }
Пример #2
0
        public static void UpdateAsset(this ActionAsset asset, ActionAssetModel model)
        {
            var path = AssetDatabase.GetAssetPath(asset);

            using (var stream = File.Create(path)) {
                using (var writer = new StreamWriter(stream)) {
                    var jsonSettings = JsonConvert.DefaultSettings.Invoke();
                    jsonSettings.TypeNameHandling = TypeNameHandling.All;
                    writer.Write(JsonConvert.SerializeObject(model, jsonSettings));
                }
            }
            AssetDatabase.Refresh();
        }
 public unsafe static BlobAssetReference <ActionGraph <TAction> > Create <TAction>(ActionAssetModel model, ActionSchema actionSchema, FieldOperationSchema operationSchema, ActionDefinitionAsset definitionAsset, Allocator allocator = Allocator.Persistent) where TAction : Delegate
 {
     FormatData(model, definitionAsset, operationSchema, actionSchema, out var nodes, out var variables, out var roots, out var configLength, out var actionNodeCount, out var fieldOperationNodeCount);
     Type    variableType        = definitionAsset.variableType.IsCreated ? definitionAsset.variableType.Value : null;
     var     memoryMap           = GetConfigMemoryMap(nodes, variableType);
     var     builder             = new BlobBuilder(Unity.Collections.Allocator.Temp);
     ref var root                = ref builder.ConstructRoot <ActionGraph <TAction> >();
        public unsafe static UnsafeUntypedBlobAssetReference CreateUntyped <TAction>(ActionAssetModel model, ActionSchema actionSchema, FieldOperationSchema operationSchema, ActionDefinitionAsset definitionAsset, Allocator allocator = Allocator.Persistent) where TAction : Delegate
        {
            var blob = Create <TAction>(model, actionSchema, operationSchema, definitionAsset, allocator);

            return(UnsafeUntypedBlobAssetReference.Create(blob));
        }
 public unsafe static UnsafeUntypedBlobAssetReference CreateUntyped(ActionAssetModel model, ActionSchema actionSchema, FieldOperationSchema operationSchema, ActionDefinitionAsset definitionAsset, Allocator allocator = Allocator.Persistent)
 {
     return((UnsafeUntypedBlobAssetReference)typeof(ActionGraphSerializer).GetGenericMethod(nameof(ActionGraphSerializer.CreateUntyped), BindingFlags.Static | BindingFlags.Public).MakeGenericMethod(definitionAsset.delegateType).Invoke(null, new object[] { model, actionSchema, operationSchema, definitionAsset, Allocator.Temp }));
 }