Ejemplo n.º 1
0
 public static CodeGenerator.GeneratedData[] GenerateProjectScripts(
     bool force,
     string label = "Generating C# Scripts",
     bool clearProgressOnFinish = true)
 {
     try {
         List <UnityEngine.Object> objects = new List <UnityEngine.Object>();
         objects.AddRange(uNodeEditorUtility.FindPrefabsOfType <uNodeComponentSystem>());
         objects.AddRange(uNodeEditorUtility.FindAssetsByType <uNodeInterface>());
         int count   = 0;
         var scripts = objects.Select(g => {
             count++;
             if (g is GameObject gameObject)
             {
                 var graphs     = gameObject.GetComponents <uNodeRoot>();
                 var targetData = gameObject.GetComponent <uNodeData>();
                 if (targetData != null ||
                     graphs.Select(gr => GraphUtility.GetGraphSystem(gr)).All(s => !s.allowAutoCompile) ||
                     graphs.Any(gr => !gr.graphData.compileToScript))
                 {
                     return(null);
                 }
                 return(GenerateCSharpScript(gameObject, force, (progress, text) => {
                     EditorUtility.DisplayProgressBar($"{label} {count}-{objects.Count}", text, progress);
                 }));
             }
             else if (g is uNodeInterface iface)
             {
                 EditorUtility.DisplayProgressBar($"Generating interface {iface.name} {count}-{objects.Count}", "", 1);
                 return(GenerateCSharpScript(iface));
             }
             else
             {
                 throw new InvalidOperationException(g.GetType().FullName);
             }
         }).Where(s => s != null);
         return(scripts.ToArray());
     } finally {
         if (clearProgressOnFinish)
         {
             uNodeThreadUtility.QueueOnFrame(() => {
                 EditorUtility.ClearProgressBar();
             });
         }
     }
 }
Ejemplo n.º 2
0
 void OnGUI()
 {
     if (targetField == null && targetObject != null)
     {
         FindTargetField();
     }
     if (targetField == null || targetObject == null)
     {
         ShowNotification(new GUIContent("No target"));
         return;
     }
     if (targetField != null && targetObject != null)
     {
         scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
         if (targetField is UnityEngine.Object)
         {
             uNodeGUIUtility.EditUnityObject(targetField as UnityEngine.Object);
         }
         else
         {
             uNodeGUIUtility.ShowFields(targetField, targetObject);
             if (targetField is InterfaceFunction)
             {
                 var iFunc = targetField as InterfaceFunction;
                 VariableEditorUtility.DrawParameter(iFunc.parameters, targetObject, null, (PD) => {
                     iFunc.parameters = PD;
                 });
                 if (targetObject is uNodeRoot)
                 {
                     var system = GraphUtility.GetGraphSystem(targetObject as uNodeRoot);
                     if (system.supportGeneric)
                     {
                         VariableEditorUtility.DrawGenericParameter(iFunc.genericParameters, targetObject, (GPD) => {
                             iFunc.genericParameters = GPD.ToArray();
                         });
                     }
                 }
                 else if (targetObject is uNodeData)
                 {
                     VariableEditorUtility.DrawGenericParameter(iFunc.genericParameters, targetObject, (GPD) => {
                         iFunc.genericParameters = GPD.ToArray();
                     });
                 }
             }
             else if (targetField is Block)
             {
                 string des = (targetField as Block).GetDescription();
                 if (!string.IsNullOrEmpty(des))
                 {
                     EditorGUILayout.Space();
                     EditorGUILayout.HelpBox((targetField as Block).GetDescription(), MessageType.None, true);
                 }
             }
         }
         //if(targetField is EventAction) {
         //	System.Reflection.FieldInfo field = targetField.GetType().GetField("Name");
         //	uNodeEditorUtility.ShowField(field, targetField, targetObject);
         //}
         EditorGUILayout.EndScrollView();
         uNodeEditorUtility.MarkDirty(targetObject);
         if (!focus)
         {
             GUI.FocusControl(null);
             EditorGUI.FocusTextInControl(null);
             focus = true;
         }
         if (GUI.changed)
         {
             if (onChanged != null)
             {
                 onChanged(targetField);
             }
             uNodeGUIUtility.GUIChanged(targetObject);
         }
     }
 }
Ejemplo n.º 3
0
        public override void OnInspectorGUI()
        {
            uNodeRoot root = target as uNodeRoot;

            EditorGUI.BeginDisabledGroup(uNodeEditorUtility.IsPrefab(root));
            EditorGUI.BeginChangeCheck();
            CustomInspector.DrawGraphInspector(root);
            if (EditorGUI.EndChangeCheck())
            {
                uNodeEditor.GUIChanged();
            }
            EditorGUI.EndDisabledGroup();
            if (uNodeEditorUtility.IsPrefab(root))
            {
                if (root is uNodeRuntime)
                {
                    EditorGUILayout.HelpBox("Open Prefab to Edit Graph", MessageType.Info);
                }
                else
                {
                    if (GUILayout.Button(new GUIContent("Open uNode Editor", "Open uNode Editor to edit this uNode"), EditorStyles.toolbarButton))
                    {
                        uNodeEditor.ChangeTarget(target as uNodeRoot, true);
                    }
                    EditorGUILayout.HelpBox("Open uNode Editor to Edit values", MessageType.Info);
                }
            }
            else
            {
                if (GUILayout.Button(new GUIContent("Open uNode Editor", "Open uNode Editor to edit this uNode"), EditorStyles.toolbarButton))
                {
                    uNodeEditor.ChangeTarget(target as uNodeRoot, true);
                }
            }
            if (!Application.isPlaying && (root is uNodeRuntime || root is ISingletonGraph))
            {
                var type = root.GeneratedTypeName.ToType(false);
                if (type != null)
                {
                    EditorGUILayout.HelpBox("Run using Native C#", MessageType.Info);
                }
                else
                {
                    EditorGUILayout.HelpBox("Run using Reflection", MessageType.Info);
                }
            }
            else if (Application.isPlaying && root is uNodeComponentSingleton singleton && (singleton.runtimeBehaviour != null || singleton.runtimeInstance != null))
            {
                EditorGUI.DropShadowLabel(uNodeGUIUtility.GetRect(), "Runtime Component");
                if (singleton.runtimeBehaviour == null)
                {
                    uNodeGUIUtility.DrawVariablesInspector(singleton.runtimeInstance.Variables, singleton.runtimeInstance, null);
                }
                else if (singleton.runtimeBehaviour != null)
                {
                    Editor editor = Editor.CreateEditor(singleton.runtimeBehaviour);
                    if (editor != null)
                    {
                        editor.OnInspectorGUI();
                    }
                    else
                    {
                        uNodeGUIUtility.ShowFields(singleton.runtimeBehaviour, singleton.runtimeBehaviour);
                    }
                }
            }
            if (!Application.isPlaying && root is IIndependentGraph)
            {
                var system = GraphUtility.GetGraphSystem(root);
                if (system != null && system.allowAutoCompile && uNodeEditorUtility.IsPrefab(root))
                {
                    var actualGraph = root;
                    if (GraphUtility.HasTempGraphObject(root.gameObject))
                    {
                        actualGraph = GraphUtility.GetTempGraphObject(root);
                    }
                    uNodeGUIUtility.ShowField(new GUIContent("Compile to C#", "If true, the graph will be compiled to C# to run using native c# performance on build or in editor using ( Generate C# Scripts ) menu."), nameof(root.graphData.compileToScript), actualGraph.graphData, actualGraph);
                }
            }
        }