コード例 #1
0
ファイル: SubTreeEditor.cs プロジェクト: RhythNS/RunAndGun
    public override void DrawInspector(SerializedObject serializedObject)
    {
        SubTreeNode        objectReference   = serializedObject.targetObject as SubTreeNode;
        SerializedProperty valuesToOverwrite = serializedObject.FindProperty("valuesToOverwrite");
        SerializedProperty treeProperty      = serializedObject.FindProperty("behaviourTree");

        EditorGUILayout.PropertyField(treeProperty);

        if (GUILayout.Button("Open Tree"))
        {
            BTreeEditor editor = ScriptableObject.CreateInstance <BTreeEditor>();
            editor.OpenSubTree(treeProperty.objectReferenceValue as BTree, objectReference.ClonedTree);
            editor.Show();
        }

        if (GUILayout.Button("Update ValueList"))
        {
            OnUpdateValueList(treeProperty, valuesToOverwrite, serializedObject);
        }

        // Draw the array
        for (int i = 0; i < valuesToOverwrite.arraySize; i++)
        {
            SerializedProperty element     = valuesToOverwrite.GetArrayElementAtIndex(i);
            SerializedProperty toOverwrite = element.FindPropertyRelative("toOverwrite");
            SerializedProperty newValue    = element.FindPropertyRelative("newValue");

            newValue.objectReferenceValue = EditorGUILayout.ObjectField(toOverwrite.objectReferenceValue.name, newValue.objectReferenceValue, typeof(Value), false);
        }
    }
コード例 #2
0
    public override Node Create(Vector2 _pos)
    {
        SubTreeNode node = CreateInstance <SubTreeNode> ();

        node.rect = new Rect(_pos.x, _pos.y, m_NodeWidth, m_NodeHeight);
        node.name = "SubTreeNode";
        node.CreateOutput("Texture", "TextureParam", NodeSide.Right, 50);

        return(node);
    }
コード例 #3
0
        [EventHandlerAttribute(EventType.DragPerform, 90)] // Priority over hundred to make it call after the GUI
        private static void HandleDragAndDrop(NodeEditorInputInfo inputInfo)
        {
            if (inputInfo.inputEvent.type == EventType.DragUpdated || (inputInfo.inputEvent.type == EventType.DragPerform))
            {
                //Debug.LogError("handle drag " + inputInfo.inputEvent.type);
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                if (inputInfo.inputEvent.type == EventType.DragPerform && DragAndDrop.objectReferences.Length > 0 &&
                    (DragAndDrop.objectReferences[0] is Texture2D))
                {
                    Debug.Log(" drag texture " + DragAndDrop.objectReferences[0]);
                    UnityTextureInput node =
                        (UnityTextureInput)
                        Node.Create("UnityTextureInput", NodeEditor.ScreenToCanvasSpace(inputInfo.inputPos));
                    node.m_Input = DragAndDrop.objectReferences[0] as Texture2D;
                    inputInfo.inputEvent.Use();
                }
                else if (inputInfo.inputEvent.type == EventType.DragPerform &&
                         DragAndDrop.GetGenericData("GenericDragColumnDragging") != null)
                {
                    DragAndDrop.AcceptDrag();
                    //Debug.Log("dragged generic data "+ DragAndDrop.GetGenericData("GenericDragColumnDragging"));
                    List <UnityEditor.IMGUI.Controls.TreeViewItem> _data =
                        DragAndDrop.GetGenericData("GenericDragColumnDragging") as
                        List <UnityEditor.IMGUI.Controls.TreeViewItem>;
                    var draggedElements = new List <TreeElement>();
                    foreach (var x in _data)
                    {
                        draggedElements.Add(((TreeViewItem <MyTreeElement>)x).data);
                    }

                    var srcItem = draggedElements[0] as MyTreeElement;
                    if (srcItem.m_Canvas)
                    {
                        SubTreeNode node =
                            (SubTreeNode)
                            Node.Create("SubTreeNode", NodeEditor.ScreenToCanvasSpace(inputInfo.inputPos));
                        node.SubCanvas = srcItem.m_Canvas;
                        string assetPath = AssetDatabase.GetAssetPath(node.SubCanvas);
                        //                    Debug.Log("drag and drop asset canvas path >" + assetPath + "<");
                        if (assetPath.Length > 0)
                        {
                            node.m_CanvasGuid = AssetDatabase.AssetPathToGUID(assetPath);
                            Debug.LogError(" set canvasGuid from asset >" + node.m_CanvasGuid + "<");
                            string fname = Path.GetFileName(assetPath);
                            fname     = Path.ChangeExtension(fname, "");
                            node.name = "Sub:" + fname;
                        }


                        node.OnLoadCanvas();
                    }
                    else
                    {
                        Node node = Node.Create(srcItem.m_NodeID, NodeEditor.ScreenToCanvasSpace(inputInfo.inputPos));
                    }
                    inputInfo.inputEvent.Use();
                }
                else if (inputInfo.inputEvent.type == EventType.DragPerform &&
                         DragAndDrop.objectReferences.Length > 0 && (DragAndDrop.objectReferences[0] is NodeCanvas))
                {
                    DragAndDrop.AcceptDrag();
                    //                    Debug.Log(" drag and drop " + DragAndDrop.objectReferences[0] + " co ord " + Event.current.mousePosition);
                    SubTreeNode node =
                        (SubTreeNode)
                        Node.Create("SubTreeNode", NodeEditor.ScreenToCanvasSpace(inputInfo.inputPos));
                    node.SubCanvas = (NodeCanvas)DragAndDrop.objectReferences[0];
                    string assetPath = AssetDatabase.GetAssetPath(node.SubCanvas);
                    //                    Debug.Log("drag and drop asset canvas path >" + assetPath + "<");
                    if (assetPath.Length > 0)
                    {
                        node.m_CanvasGuid = AssetDatabase.AssetPathToGUID(assetPath);
                        Debug.LogError(" set canvasGuid from asset >" + node.m_CanvasGuid + "<");
                        string fname = Path.GetFileName(assetPath);
                        fname     = Path.ChangeExtension(fname, "");
                        node.name = "Sub:" + fname;
                    }
                    inputInfo.inputEvent.Use();

                    node.OnLoadCanvas();
                }
            }
        }
コード例 #4
0
        private void OnGUI()
        {
            if (wwwShader1 != null)
            {
                if (wwwShader1.isDone)
                {
                    string pathShader = "Assets/TextureWang/Shaders/TextureOps.shader";
                    pathShader = pathShader.Replace("/", "" + Path.DirectorySeparatorChar);

                    File.WriteAllBytes(pathShader, wwwShader1.bytes);
                    AssetDatabase.ImportAsset(pathShader, ImportAssetOptions.ForceSynchronousImport);
                    wwwShader1 = null;
                }
                Repaint();
                Debug.Log("repaint 2");
            }

            if (canvasCache.nodeCanvas.m_PreviewAnimation)
            {
                if (m_SW == null)
                {
                    m_SW = Stopwatch.StartNew();
                }
                m_AnimValue += (m_SW.ElapsedMilliseconds - m_LastTime) / 3000.0f;
                if (m_AnimValue < 0)
                {
                    m_AnimValue = 0;
                }
                m_LastTime = m_SW.ElapsedMilliseconds;
                if (m_AnimValue > 1.0f)
                {
                    m_AnimValue = 0.0f;
                }
                foreach (var x in canvasCache.nodeCanvas.nodes)
                {
                    if (x is InputNodeAnimated)
                    {
                        var ina = x as InputNodeAnimated;
                        ina.m_Value.Set(m_AnimValue);
                    }
                }
                NodeEditor.RecalculateAll(canvasCache.nodeCanvas);
                Repaint();
                Debug.Log("repaint 3");
            }
            else
            {
                m_AnimValue = 0;
            }

            if (m_ReplaceNode != null && !OverlayGUI.HasPopupControl() && ms_InputInfo != null)
            {
                NodeEditorInputSystem.ShowContextMenu(ms_InputInfo);
                ms_InputInfo = null;
            }

/*
 *          if (NodeEditor.curEditorState == null)
 *          {
 *              Debug.Log("OnGUI::TWWindow has no editor state " + NodeEditor.curEditorState+"actual editor state "+ canvasCache.editorState);
 *          }
 *          else if (NodeEditor.curEditorState.selectedNode == null)
 *          {
 *              Debug.Log("OnGUI::TWWindow has no Selected Node " + NodeEditor.curEditorState);
 *          }
 *          else
 *          {
 *              Debug.Log("OnGUI:: Selected Node " + NodeEditor.curEditorState.selectedNode);
 *          }
 */
            // Initiation
            NodeEditor.checkInit(true);
            if (NodeEditor.InitiationError)
            {
                GUILayout.Label("Node Editor Initiation failed! Check console for more information!");
                return;
            }
            AssureEditor();
            canvasCache.AssureCanvas();

            // Specify the Canvas rect in the EditorState
            canvasCache.editorState.canvasRect = canvasWindowRect;
            // If you want to use GetRect:
            //			Rect canvasRect = GUILayoutUtility.GetRect (600, 600);
            //			if (Event.current.type != EventType.Layout)
            //				mainEditorState.canvasRect = canvasRect;
            NodeEditorGUI.StartNodeGUI();

            // Perform drawing with error-handling
            try
            {
                if ((Event.current.keyCode >= KeyCode.A && Event.current.keyCode <= KeyCode.Z) || Event.current.keyCode == KeyCode.Escape)
                {
                    if (Event.current.keyCode == KeyCode.Escape)
                    {
                        PopupMenu.m_NameFilter = "";
                    }
                    else
                    {
                        int    ascii = ((int)Event.current.keyCode - (int)KeyCode.A) + 65;
                        string c     = Char.ConvertFromUtf32(ascii);
                        PopupMenu.m_NameFilter = c;
                    }

                    Debug.Log("m_NameFilter " + PopupMenu.m_NameFilter);
                    OverlayGUI.currentPopup = null;
                    NodeEditorInputInfo inputInfo = new NodeEditorInputInfo(canvasCache.editorState);

                    NodeEditorInputSystem.ShowContextMenu(inputInfo);
                }
                NodeEditor.DrawCanvas(canvasCache.nodeCanvas, canvasCache.editorState);


                if (canvasCache.editorState.selectedNode != null)
                {
                    if (canvasCache.editorState.selectedNode is TextureNode)
                    {
                        var tn = canvasCache.editorState.selectedNode as TextureNode;
                        if (tn.m_RequestRepaint)
                        {
                            tn.m_RequestRepaint = false;
                            Debug.Log("repaint 1");
                            Repaint();
                            m_InspectorWindow.Repaint();
                        }
                    }
                }


                if (wwwShader1 != null)
                {
                    GUI.Label(new Rect(100, 100, 500, 200), "One Time Shader Download in progress...");
                }
            }
            catch (UnityException e)
            { // on exceptions in drawing flush the canvas to avoid locking the ui.
                canvasCache.NewNodeCanvas();
                NodeEditor.ReInit(true);
                Debug.LogError("Unloaded Canvas due to an exception during the drawing phase!");
                Debug.LogException(e);
            }
            if (m_PostOnLoadCanvasFixup != null)
            {
//                m_PostOnLoadCanvasFixup.PostOnLoadCanvasFixup();
                m_PostOnLoadCanvasFixup = null;
            }


            // Draw Side Window
            //sideWindowWidth = Math.Min(600, Math.Max(200, (int)(position.width / 5)));
            //GUILayout.BeginArea(sideWindowRect, GUI.skin.box);
            //DrawSideWindow();
            //GUILayout.EndArea();


            NodeEditorGUI.EndNodeGUI();
//            if (Event.current.type == EventType.Repaint)
//                m_InspectorWindow.Repaint();

/*
 *          //if (Event.current.type == EventType.Repaint)
 *          {
 *              if (mainEditorState.selectedNode != mainEditorState.wantselectedNode)
 *              {
 *                  mainEditorState.selectedNode = mainEditorState.wantselectedNode;
 *                  NodeEditor.RepaintClients();
 *                  Repaint();
 *              }
 *
 *          }
 */

            if (!m_Docked && m_DockedRetry++ < 100 && m_InspectorWindow != null && m_NodeSelectionWindow != null)
            {
                try
                {
                    m_DockedRetry++;
                    Docker.Dock(this, m_InspectorWindow, Docker.DockPosition.Right);
                    Docker.Dock(this, m_NodeSelectionWindow, Docker.DockPosition.Left);
                }
                catch (Exception ex)
                {
                    Debug.LogError(" Dock failed " + ex);
                }
                m_Docked = true;
            }
        }
コード例 #5
0
        private void OnGUI()
        {
            if (wwwShader1 != null)
            {
                if (wwwShader1.isDone)
                {
                    string pathShader = "Assets/TextureWang/Shaders/TextureOps.shader";
                    pathShader = pathShader.Replace("/", "" + Path.DirectorySeparatorChar);

                    File.WriteAllBytes(pathShader, wwwShader1.bytes);
                    AssetDatabase.ImportAsset(pathShader, ImportAssetOptions.ForceSynchronousImport);
                    wwwShader1 = null;
                }
                Repaint();
            }


            if (m_ReplaceNode != null && !OverlayGUI.HasPopupControl() && ms_InputInfo != null)
            {
                NodeEditorInputSystem.ShowContextMenu(ms_InputInfo);
                ms_InputInfo = null;
            }

/*
 *          if (NodeEditor.curEditorState == null)
 *          {
 *              Debug.Log("OnGUI::TWWindow has no editor state " + NodeEditor.curEditorState+"actual editor state "+ canvasCache.editorState);
 *          }
 *          else if (NodeEditor.curEditorState.selectedNode == null)
 *          {
 *              Debug.Log("OnGUI::TWWindow has no Selected Node " + NodeEditor.curEditorState);
 *          }
 *          else
 *          {
 *              Debug.Log("OnGUI:: Selected Node " + NodeEditor.curEditorState.selectedNode);
 *          }
 */
            // Initiation
            NodeEditor.checkInit(true);
            if (NodeEditor.InitiationError)
            {
                GUILayout.Label("Node Editor Initiation failed! Check console for more information!");
                return;
            }
            AssureEditor();
            canvasCache.AssureCanvas();

            // Specify the Canvas rect in the EditorState
            canvasCache.editorState.canvasRect = canvasWindowRect;
            // If you want to use GetRect:
            //			Rect canvasRect = GUILayoutUtility.GetRect (600, 600);
            //			if (Event.current.type != EventType.Layout)
            //				mainEditorState.canvasRect = canvasRect;
            NodeEditorGUI.StartNodeGUI();

            // Perform drawing with error-handling
            try
            {
                NodeEditor.DrawCanvas(canvasCache.nodeCanvas, canvasCache.editorState);


                if (canvasCache.editorState.selectedNode != null)
                {
                    if (canvasCache.editorState.selectedNode is TextureNode)
                    {
                        var tn = canvasCache.editorState.selectedNode as TextureNode;
                        if (tn.m_RequestRepaint)
                        {
                            tn.m_RequestRepaint = false;
                            Repaint();
                            m_InspectorWindow.Repaint();
                        }
                    }
                }
                if (wwwShader1 != null)
                {
                    GUI.Label(new Rect(100, 100, 500, 200), "One Time Shader Download in progress...");
                }
            }
            catch (UnityException e)
            { // on exceptions in drawing flush the canvas to avoid locking the ui.
                canvasCache.NewNodeCanvas();
                NodeEditor.ReInit(true);
                Debug.LogError("Unloaded Canvas due to an exception during the drawing phase!");
                Debug.LogException(e);
            }
            if (m_PostOnLoadCanvasFixup != null)
            {
//                m_PostOnLoadCanvasFixup.PostOnLoadCanvasFixup();
                m_PostOnLoadCanvasFixup = null;
            }


            // Draw Side Window
            //sideWindowWidth = Math.Min(600, Math.Max(200, (int)(position.width / 5)));
            //GUILayout.BeginArea(sideWindowRect, GUI.skin.box);
            //DrawSideWindow();
            //GUILayout.EndArea();


            NodeEditorGUI.EndNodeGUI();
//            if (Event.current.type == EventType.Repaint)
//                m_InspectorWindow.Repaint();

/*
 *          //if (Event.current.type == EventType.Repaint)
 *          {
 *              if (mainEditorState.selectedNode != mainEditorState.wantselectedNode)
 *              {
 *                  mainEditorState.selectedNode = mainEditorState.wantselectedNode;
 *                  NodeEditor.RepaintClients();
 *                  Repaint();
 *              }
 *
 *          }
 */

            if (!m_Docked && m_DockedRetry++ < 100 && m_InspectorWindow != null && m_NodeSelectionWindow != null)
            {
                try
                {
                    m_DockedRetry++;
                    Docker.Dock(this, m_InspectorWindow, Docker.DockPosition.Right);
                    Docker.Dock(this, m_NodeSelectionWindow, Docker.DockPosition.Left);
                }
                catch (Exception ex)
                {
                    Debug.LogError(" Dock failed " + ex);
                }
                m_Docked = true;
            }
        }
コード例 #6
0
    public override void DrawInspector(SerializedObject serializedObject)
    {
        SubTreeNode        objectReference   = serializedObject.targetObject as SubTreeNode;
        SerializedProperty valuesToOverwrite = serializedObject.FindProperty("valuesToOverwrite");
        SerializedProperty treeProperty      = serializedObject.FindProperty("behaviourTree");

        EditorGUILayout.PropertyField(treeProperty);

        if (GUILayout.Button("Open Tree"))
        {
            BTreeEditor editor = ScriptableObject.CreateInstance <BTreeEditor>();
            editor.OpenSubTree(treeProperty.objectReferenceValue as BTree, objectReference.ClonedTree);
            editor.Show();
        }

        if (GUILayout.Button("Update ValueList"))
        {
            if (treeProperty.objectReferenceValue == null)
            {
                goto DrawArrayValues; // skip the button
            }
            UnityEngine.Object[] allObjects = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(treeProperty.objectReferenceValue));

            List <Value> values = new List <Value>();

            for (int i = 0; i < allObjects.Length; i++)
            {
                if (allObjects[i] is Value)
                {
                    values.Add(allObjects[i] as Value);
                }
            }

            for (int i = valuesToOverwrite.arraySize - 1; i > -1; i--)
            {
                // Get the element "valuesToOverwrite.toOverwrite"
                SerializedProperty element = valuesToOverwrite.GetArrayElementAtIndex(i).FindPropertyRelative("toOverwrite");

                // Go through both lists and remove all matching elements and remove elements which are not in allnames from the
                // serialized array
                bool found = false;
                for (int j = 0; j < values.Count; j++)
                {
                    if (values[j] == element.objectReferenceValue)
                    {
                        values.RemoveAt(j);
                        found = true;
                        break;
                    }
                }
                if (found == false)
                {
                    SerializableUtil.ArrayRemoveAtIndex(valuesToOverwrite, i);
                }
            }

            // save the index and grow the array
            int index = valuesToOverwrite.arraySize;
            valuesToOverwrite.arraySize += values.Count;

            for (int i = 0; i < values.Count; i++)
            {
                valuesToOverwrite.GetArrayElementAtIndex(index++).FindPropertyRelative("toOverwrite").objectReferenceValue = values[i];
            }

            serializedObject.ApplyModifiedProperties();
        }

DrawArrayValues:
        // Draw the array
        for (int i = 0; i < valuesToOverwrite.arraySize; i++)
        {
            SerializedProperty element     = valuesToOverwrite.GetArrayElementAtIndex(i);
            SerializedProperty toOverwrite = element.FindPropertyRelative("toOverwrite");
            SerializedProperty newValue    = element.FindPropertyRelative("newValue");

            newValue.objectReferenceValue = EditorGUILayout.ObjectField(toOverwrite.objectReferenceValue.name, newValue.objectReferenceValue, typeof(Value), false);
        }
    }
コード例 #7
0
 private SubTree <TContext> MapSubTreeNode(SubTreeNode <TContext> node)
 {
     return(new SubTree <TContext>(node.Name, node.SubBehaviour));
 }