public ActionInfo(ActionDefinitionAsset definitionAsset) { id = definitionAsset.id; @delegate = definitionAsset.delegateType; name = definitionAsset.Name; fieldOperations = definitionAsset.useFieldOperations; }
public override VisualElement CreateInspectorGUI() { rootElement = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(Uxml).CloneTree(); rootElement.Query <TextField>(null, "requires-editor-dll-rebuild").ForEach(ele => { ele.isDelayed = true; ele.RegisterValueChangedCallback(e => { /* AssetDatabase.SaveAssets(); * ActionEditorUtilityProducer.CreateAssembly(); */ }); }); var delegateType = rootElement.Q <PropertyField>("delegateType"); delegateType.RegisterCallback <ChangeEvent <SerializableType> >(evt => { if (evt.newValue != evt.previousValue) { if (ActionDefinitionAsset.LoadAll().Any(a => a != serializedObject.targetObject && a.delegateType == evt.newValue)) { Debug.LogError("ActionDefinitions must have unique delegates."); ((ActionDefinitionAsset)serializedObject.targetObject).delegateType = evt.previousValue; EditorUtility.SetDirty(serializedObject.targetObject); } } }); rootElement.Query <PropertyField>(null, "requires-dll-rebuild--type").ForEach(ele => ele.RegisterCallback <ChangeEvent <SerializableType> >(evt => UpdateAssemblyData())); rootElement.Query <PropertyField>(null, "requires-dll-rebuild--method").ForEach(ele => ele.RegisterCallback <ChangeEvent <SerializableMethod> >(evt => UpdateAssemblyData())); rootElement.Query <PropertyField>(null, "requires-dll-rebuild--bool").ForEach(ele => ele.RegisterValueChangeCallback(evt => UpdateAssemblyData())); var aggregator = rootElement.Q <PropertyField>("aggregator"); BindAggregatorField(delegateType, aggregator); return(rootElement); }
private static List <ActionId> GetItems() { var items = ActionDefinitionAsset.LoadAll().Select(definition => definition.id).ToList(); items.Insert(0, default); return(items); }
public Entry(ActionDefinitionAsset asset) { @delegate = asset.delegateType; variable = asset.variableType; destroyEntitiesEntityCommandBufferSystem = asset.destroyEntitiesUsing; fieldOperations = asset.useFieldOperations; aggregator = asset.aggregator; }
public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { var settings = ProjectUtility.GetOrCreateProjectSettings <ActionGraphGlobalSettings>(); var actionSchema = ProjectUtility.GetOrCreateProjectAsset <ActionSchema>(); var fieldOperationSchema = ProjectUtility.GetOrCreateProjectAsset <FieldOperationSchema>(); foreach (var path in importedAssets.Where(importedAsset => importedAsset.EndsWith($".{ActionGraphGlobalSettings.Extension}"))) { var importer = AssetImporter.GetAtPath(path); var userData = importer.userData; string artifactFile; if (string.IsNullOrWhiteSpace(userData)) { artifactFile = settings.CreateArtifactPath(); } else { artifactFile = AssetDatabase.GUIDToAssetPath(userData); if (string.IsNullOrEmpty(artifactFile)) { artifactFile = settings.CreateArtifactPath(); } } var actionAsset = AssetDatabase.LoadAssetAtPath <ActionAsset>(path); var actionDefinitionAsset = ActionDefinitionAsset.Load(actionAsset.actionId); if (actionDefinitionAsset?.delegateType.IsCreated == true) { var guid = (string)typeof(ActionGraphSerializer).GetMethod(nameof(ActionGraphSerializer.WriteArtifact), System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static) .MakeGenericMethod(actionDefinitionAsset.delegateType) .Invoke(null, new object[] { artifactFile, actionSchema, fieldOperationSchema, actionAsset, actionDefinitionAsset }); if (guid != importer.userData) { importer.userData = guid; importer.SaveAndReimport(); } } else { AssetDatabase.DeleteAsset(artifactFile); } } foreach (var path in deletedAssets.Where(deletedAsset => deletedAsset.EndsWith($".{ActionGraphGlobalSettings.Extension}"))) { var userData = AssetImporter.GetAtPath(path).userData; if (!string.IsNullOrWhiteSpace(userData)) { var artifactPath = AssetDatabase.GUIDToAssetPath(userData); if (!string.IsNullOrEmpty(artifactPath)) { AssetDatabase.DeleteAsset(artifactPath); } } } AssetDatabase.Refresh(); }
public override VisualElement CreateInspectorGUI() { var rootElement = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(Uxml).CloneTree(); var openButton = rootElement.Q <Button>("open"); openButton.clicked += () => { if (serializedObject?.targetObject is ActionAsset asset) { ActionGraphWindow.ShowWindow(asset); } }; openButton.SetEnabled(((ActionAsset)serializedObject.targetObject).actionId.IsCreated); var id = rootElement.Q <ActionIdField>("id"); if (settings != null) { if (serializedObject.targetObject is ActionAsset actionAsset) { try { id.value = actionAsset.actionId; } catch (Exception) { Debug.LogError($"Error setting Action Id. Consider Reimporting {AssetDatabase.GetAssetPath(actionAsset)}"); } } id.RegisterValueChangedCallback(evt => { var previousInfo = evt.previousValue.IsCreated ? ActionDefinitionAsset.Load(evt.previousValue) : null; var self = (ActionIdField)evt.target; var newInfo = evt.newValue.IsCreated ? ActionDefinitionAsset.Load(evt.previousValue) : null; var asset = (ActionAsset)serializedObject.targetObject; var model = asset.CreateModel(); bool retainNodes = false; if (previousInfo == null || model.nodes.Count == 0 || ConfirmActionTypeChange(previousInfo, newInfo, out retainNodes)) { model.id = evt.newValue; if (!retainNodes) { model.nodes.Clear(); model.masterNodeLayout = default; } asset.UpdateAsset(model); openButton.SetEnabled(evt.newValue.IsCreated); } else { self.SetValueWithoutNotify(evt.previousValue); } }); } return(rootElement); }
public override VisualElement CreatePropertyGUI(SerializedProperty property) { var field = new ActionAssetField(); var attr = fieldInfo.GetCustomAttribute <ActionTypeAttribute>(); var settings = ProjectUtility.GetProjectAsset <ActionGraphGlobalSettings>(); if (attr != null && ActionDefinitionAsset.Load(attr.type, out var info)) { field.ActionId = info.id; } field.Label = property.displayName; field.BindProperty(property); return(field); }
public override VisualElement CreatePropertyGUI(SerializedProperty property) { var settings = ProjectUtility.GetProjectSettings <ActionGraphGlobalSettings>(); var definitions = ActionDefinitionAsset.LoadAll().ToArray(); List <string> guids = definitions.Select(a => a.id.guid).ToList(); guids.Insert(0, string.Empty); var popup = new PopupField <string>(property.displayName, guids, property.FindPropertyRelative("guid").stringValue, (choice) => FormatCell(definitions, choice) , (choice) => FormatCell(definitions, choice) ); popup.SetEnabled(settings != null); popup.BindProperty(property.FindPropertyRelative("guid")); return(popup); }
private string FormatCell(ActionId actionId) { if (settings == null) { return(ActionId.UnknownActionName); } if (!actionId.IsCreated) { return(ActionId.NullActionName); } if (ActionDefinitionAsset.Load(actionId, out var info)) { return(info.Name); } else { return(ActionId.UnknownActionName); } }
private bool ConfirmActionTypeChange(ActionDefinitionAsset previousInfo, ActionDefinitionAsset newInfo, out bool retainNodes) { retainNodes = false; string message; string okMessage; if (newInfo == null) { message = $"Are you sure you want to clear ${serializedObject.targetObject.name}'s Action Type? This operation will clear this asset's node data."; okMessage = "Clear Action Type"; } else if (newInfo.delegateType != previousInfo.delegateType) { message = $"Are you sure you want to change ${serializedObject.targetObject.name}'s Action Type from '${previousInfo.Name}' to '${newInfo.Name}'? This operation will clear this asset's node data."; okMessage = "Change Action Type"; } else { retainNodes = true; return(true); } return(EditorUtility.DisplayDialog("Change Action Type?", message, okMessage, "Cancel")); }
public static string WriteArtifact <TAction>(string artifactFile, ActionSchema actionSchema, FieldOperationSchema operationSchema, ActionAsset actionAsset, ActionDefinitionAsset actionDefinitionAsset) where TAction : Delegate { using var blob = Create <TAction>(actionAsset.CreateModel(), actionSchema, operationSchema, actionDefinitionAsset, Unity.Collections.Allocator.Temp); return(DoWriteArtifact <TAction>(artifactFile, blob)); }
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 })); }
public static bool Load(ActionId id, out ActionDefinitionAsset actionDefinitionAsset) { actionDefinitionAsset = AssetDatabase.FindAssets($"t:{nameof(ActionDefinitionAsset)}").Select(guid => AssetDatabase.LoadAssetAtPath <ActionDefinitionAsset>(AssetDatabase.GUIDToAssetPath(guid))).FirstOrDefault(asset => asset.id == id); return(actionDefinitionAsset != null); }