public override VisualElement CreateInspectorGUI()
        {
            var uxml = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(UXML);

            if (rootVisualElement == null)
            {
                rootVisualElement = new VisualElement();
            }
            else
            {
                rootVisualElement.Clear();
            }
            uxml.CloneTree(rootVisualElement);
            var behaviourTypeField = rootVisualElement.Q <PropertyField>("behaviourType");

            behaviourTypeField.SetEnabled(false);
            BehaviourGraphModel model = serializedObject?.targetObject as BehaviourGraphModel;

            if (model != null)
            {
                rootVisualElement.Q <Button>("editButton").clicked    += () => BehaviourGraphEditor.OnOpen(serializedObject.targetObject.GetInstanceID());
                rootVisualElement.Q <Button>("compileButton").clicked += CompileModel;
                rootVisualElement.Q <EnumField>("compileOptions").RegisterValueChangedCallback(e => UpdateSettings((CompileOptions)e.newValue));
            }
            return(rootVisualElement);
        }
 protected override bool Compile(BehaviourGraphModel model, string outputFile, out string error)
 {
     try {
         this.GetType().GetMethod(nameof(CompileModel)).MakeGenericMethod(model.BehaviourType.Value).Invoke(this, new object[] { model, outputFile });
         error = null;
         return(true);
     }
     catch (Exception e) {
         error = e.Message;
         return(false);
     }
 }
        private void CompileModel()
        {
            BehaviourGraphModel model = serializedObject?.targetObject as BehaviourGraphModel;

            if (model != null)
            {
                try {
                    (serializedObject.targetObject as BehaviourGraphModel)?.Compile(forceCompilation: true);
                    Debug.Log($"Successfully Compiled {model.name} to location '{model.outputDirectory}' as '{model.outputFileName}'");
                }
                catch (Exception e) {
                    Debug.LogError(e.Message);
                }
            }
        }
 private void InitVariables(BehaviourGraphModel model)
 {
     inspector.VariableContainer.Clear();
     if (model.Settings.variableDefinition.Value != null)
     {
         foreach (var variable in model.Settings.variableDefinition.Value.Decompose())
         {
             var blackboardField = new BlackboardField(ICON, $"{model.Settings.variableDefinition.Value.Name}.{variable.fullName}", $"{variable.type.Value.FullName}")
             {
                 capabilities = Capabilities.Selectable | Capabilities.Deletable | Capabilities.Droppable
             };
             blackboardField.userData = new VariableInfo {
                 fieldOffsetInfo = variable, model = model
             };
             blackboardField.AddToClassList(BEHAVIOUR_VARIABLE_CLASS);
             blackboardField.Q <Image>("icon").tintColor = variable.type.Value.GetColor();
             inspector.VariableContainer.Add(blackboardField);
         }
     }
 }
        public virtual void Compile(BehaviourGraphModel model, bool forceCompilation = false)
        {
            if (forceCompilation || !model.upToDate)
            {
                var outputDirectory = string.IsNullOrWhiteSpace(model.outputDirectory) ? model.Settings.outputDirectory : model.outputDirectory;
                if (string.IsNullOrWhiteSpace(outputDirectory))
                {
                    Debug.LogError($"Output Directory for Behaviour Graph {model.name} is null. Skipping.");
                    return;
                }
                var outputFileName = model.outputFileName;
                if (string.IsNullOrWhiteSpace(outputFileName))
                {
                    Debug.LogError($"Output File Name for Behaviour Graph {model.name} is null. Skipping.");
                    return;
                }

                Directory.CreateDirectory(outputDirectory);
                var outputFile = $"{outputDirectory}/{outputFileName}{(string.IsNullOrWhiteSpace(Extension) ? "" : $".{Extension}")}";
                var result     = Compile(model, outputFile, out string error);
                if (!string.IsNullOrWhiteSpace(error))
                {
                    Debug.LogError($"Error Compiling Behaviour Graph {model.name}: {error}");
                }
                if (!result)
                {
                    return;
                }
                var behaviourSettings = model.Settings;

/*                 var settings = AddressableAssetSettingsDefaultObject.Settings;
 *              settings.AddLabel(behaviourSettings.behaviourName);
 *              AddressableAssetGroup assetGroup = GetGroup();
 *              var entry = settings.CreateOrMoveEntry(AssetDatabase.AssetPathToGUID(outputFile), assetGroup);
 *              entry.address = $"Behaviour.{behaviourSettings.behaviourName}.{outputFileName}";
 *              entry.labels.Add(behaviourSettings.behaviourName); */
                AssetDatabase.Refresh();
                model.upToDate = true;
            }
 public static void CreateAsset()
 {
     BehaviourGraphModel.CreateInstance <BehaviourGraphModel, EffectDelegate>("Effect");
 }
 public unsafe string CompileModel <T>(BehaviourGraphModel model, string output) where T : Delegate
 {
     using var builder = new BlobBuilder(Allocator.Temp);
     ref BehaviourGraph <T> graph = ref builder.ConstructRoot <BehaviourGraph <T> >();
 public virtual void InitializeModel(BehaviourGraphModel model)
 {
     model.Entries.Add(new MasterEntry());
 }