Inheritance: EditorWindow
示例#1
0
	public void AnalyzeNode(NodeEditor Node){
		if (Node is TaskEditor) {
			TaskEditor te = (TaskEditor)Node;
			foreach(TaskAttribute ta in te.MyTask.attributes){
				spawnPrefab(ta);
			}
		}else if(Node is BehaviourNodeEditor){
			BehaviourNodeEditor bne = (BehaviourNodeEditor)Node;

			foreach(NodeVis nv in bne.NV.childs){
				GameObject go = NGUITools.AddChild(gameObject, ChildDisplay.gameObject);
				//GameObject go = (GameObject)GameObject.Instantiate (ChildDisplay.gameObject);
				ChildNodeUI cnUI = go.GetComponent<ChildNodeUI>();
				//go.transform.parent = this.transform;
				//go.transform.localScale = Vector3.one;

				cnUI.node = nv.GetComponent<NodeEditor>();
				cnUI.NodeName.text = nv.node.Info;
				cnUI.ae = this;
			}
			{
				GameObject go = NGUITools.AddChild(gameObject, PopUplistPrefab.gameObject);

				//GameObject go = (GameObject)GameObject.Instantiate (PopUplistPrefab.gameObject);
				NewChildNodeUI ncnUI = go.GetComponent<NewChildNodeUI>();
				//go.transform.parent = this.transform;
				//go.transform.localScale = Vector3.one;
				ncnUI.Node = bne;
				ncnUI.ae = this;
				ncnUI.initList();
			}
		}
		//table.Reposition ();
		//delayedReposition = true;
	}
示例#2
0
	public void Update(){

		if (treevis.SelectedNode != oldSelectetNode) {
			oldSelectetNode = treevis.SelectedNode;	
			UpdateNodes();
		}


	}
    private void OnGUI()
    {
        // Initiation
        NodeEditor.checkInit(true);
        if (NodeEditor.InitiationError)
        {
            GUILayout.Label("Node Editor Initiation failed! Check console for more information!");
            return;
        }
        AssureSetup();

        // Start Overlay GUI for popups
        OverlayGUI.StartOverlayGUI("RTNodeEditor");

        // Begin Node Editor GUI and set canvas rect
        NodeEditorGUI.StartNodeGUI(false);
        canvasCache.editorState.canvasRect = new Rect(rect.x, rect.y + editorInterface.toolbarHeight, rect.width, rect.height - editorInterface.toolbarHeight);

        // Access custom state variable whenever you need
        canvasCache.editorState.myCustomStateVariable = 0;

        try
        {         // Perform drawing with error-handling
            NodeEditor.DrawCanvas(canvasCache.nodeCanvas, canvasCache.editorState);
        }
        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 exception in Draw!");
            Debug.LogException(e);
        }

        // Draw Interface
        GUILayout.BeginArea(rect);
        editorInterface.DrawToolbarGUI();
        GUILayout.EndArea();
        editorInterface.DrawModalPanel();

        // End Node Editor GUI
        NodeEditorGUI.EndNodeGUI();

        // End Overlay GUI and draw popups
        OverlayGUI.EndOverlayGUI();
    }
示例#4
0
 public void OnGUI()
 {
     if ((Object)canvas != (Object)null)
     {
         if ((Object)state == (Object)null)
         {
             NewEditorState();
         }
         NodeEditor.checkInit(true);
         if (!NodeEditor.InitiationError)
         {
             try
             {
                 if (!screenSize && specifiedRootRect.max != specifiedRootRect.min)
                 {
                     GUI.BeginGroup(specifiedRootRect, NodeEditorGUI.nodeSkin.box);
                 }
                 NodeEditorGUI.StartNodeGUI();
                 canvasRect        = ((!screenSize) ? specifiedCanvasRect : new Rect(0f, 0f, (float)Screen.width, (float)Screen.height));
                 canvasRect.width -= 200f;
                 state.canvasRect  = canvasRect;
                 NodeEditor.DrawCanvas(canvas, state);
                 GUILayout.BeginArea(new Rect(canvasRect.x + state.canvasRect.width, state.canvasRect.y, 200f, state.canvasRect.height), NodeEditorGUI.nodeSkin.box);
                 SideGUI();
                 GUILayout.EndArea();
                 NodeEditorGUI.EndNodeGUI();
                 if (!screenSize && specifiedRootRect.max != specifiedRootRect.min)
                 {
                     GUI.EndGroup();
                 }
             }
             catch (UnityException exception)
             {
                 NewNodeCanvas();
                 NodeEditor.ReInit(true);
                 Debug.LogError("Unloaded Canvas due to exception in Draw!");
                 Debug.LogException(exception);
             }
         }
         else
         {
             GUILayout.Label("Initiation failed! Check console for more information!");
         }
     }
 }
示例#5
0
    void nodeWindow(int id)
    {
        SecuenceNode myNode = nodos[id];

        string[] editorNames = NodeEditorFactory.Intance.CurrentNodeEditors;

        int preEditorSelected = NodeEditorFactory.Intance.NodeEditorIndex(myNode);
        int editorSelected    = EditorGUILayout.Popup(
            preEditorSelected,
            NodeEditorFactory.Intance.CurrentNodeEditors
            );

        NodeEditor editor = (editors.ContainsKey(myNode))?editors[myNode]:null;

        if (editor == null || preEditorSelected != editorSelected)
        {
            editor = NodeEditorFactory.Intance.createNodeEditorFor(editorNames[editorSelected]);
            editor.useNode(myNode);

            if (!editors.ContainsKey(myNode))
            {
                editors.Add(myNode, editor);
            }
            else
            {
                editors[myNode] = editor;
            }
        }


        editor.draw();

        nodos[id] = editor.Result;


        if (Event.current.type != EventType.layout)
        {
            Rect lastRect = GUILayoutUtility.GetLastRect();
            Rect myRect   = rects [myNode];
            myRect.height  = lastRect.y + lastRect.height;
            rects [myNode] = myRect;
            this.Repaint();
        }
        GUI.DragWindow();
    }
示例#6
0
 public void SideGUI()
 {
     GUILayout.Label(new GUIContent("Node Editor (" + canvas.name + ")", "The currently opened canvas in the Node Editor"));
     screenSize = GUILayout.Toggle(screenSize, "Adapt to Screen");
     GUILayout.Label("FPS: " + FPSCounter.currentFPS);
     GUILayout.Label(new GUIContent("Node Editor (" + canvas.name + ")"), NodeEditorGUI.nodeLabelBold);
     if (GUILayout.Button(new GUIContent("New Canvas", "Loads an empty Canvas")))
     {
         NewNodeCanvas();
     }
     GUILayout.Space(6f);
     GUILayout.BeginHorizontal();
     sceneCanvasName = GUILayout.TextField(sceneCanvasName, GUILayout.ExpandWidth(true));
     if (GUILayout.Button(new GUIContent("Save to Scene", "Saves the Canvas to the Scene"), GUILayout.ExpandWidth(false)))
     {
         SaveSceneNodeCanvas(sceneCanvasName);
     }
     GUILayout.EndHorizontal();
     if (GUILayout.Button(new GUIContent("Load from Scene", "Loads the Canvas from the Scene")))
     {
         GenericMenu genericMenu = new GenericMenu();
         string[]    sceneSaves  = NodeEditorSaveManager.GetSceneSaves();
         foreach (string text in sceneSaves)
         {
             genericMenu.AddItem(new GUIContent(text), false, LoadSceneCanvasCallback, text);
         }
         genericMenu.Show(loadScenePos, 40f);
     }
     if (Event.current.type == EventType.Repaint)
     {
         Rect lastRect = GUILayoutUtility.GetLastRect();
         loadScenePos = new Vector2(lastRect.x + 2f, lastRect.yMax + 2f);
     }
     GUILayout.Space(6f);
     if (GUILayout.Button(new GUIContent("Recalculate All", "Initiates complete recalculate. Usually does not need to be triggered manually.")))
     {
         NodeEditor.RecalculateAll(canvas);
     }
     if (GUILayout.Button("Force Re-Init"))
     {
         NodeEditor.ReInit(true);
     }
     NodeEditorGUI.knobSize = RTEditorGUI.IntSlider(new GUIContent("Handle Size", "The size of the Node Input/Output handles"), NodeEditorGUI.knobSize, 12, 20);
     state.zoom             = RTEditorGUI.Slider(new GUIContent("Zoom", "Use the Mousewheel. Seriously."), state.zoom, 0.6f, 2f);
 }
示例#7
0
 public override void DrawCurves()
 {
     for (int i = 0; i < inputNodeRects.Length; i++)
     {
         if (inputNodes.Count > 0)
         {
             foreach (BaseNode node in inputNodes[i].nodes)
             {
                 Rect rect = windowRect;
                 rect.x     += inputNodeRects[i].x;
                 rect.y     += inputNodeRects[i].y + inputNodeRects[i].height / 2;
                 rect.width  = 1;
                 rect.height = 1;
                 NodeEditor.DrawNodeCurve(node.outputRect, rect);
             }
         }
     }
 }
示例#8
0
文件: BaseNode.cs 项目: c4kef/CNovell
        public virtual void Init(Vector2 position)
        {
            Scene scene = NodeEditor.GetScene();

            m_nodeID = scene.GetCurrentNodeID();
            scene.SetCurrentNodeID(m_nodeID + 1);

            m_Color = Color.white;

            m_rectangle = new Rect(position.x, position.y, 50, 100);

            m_inputs     = new List <int>();
            m_inputPoint = new Rect(0, 0, 10, 20);


            m_outputs      = new List <int>();
            m_outputPoints = new List <Rect>();
        }
示例#9
0
                private void GetChildren(NodeEditor node, List <NodeEditor> nodes)
                {
                    if (node != null)
                    {
                        var sockets = node.GetSockets().GetSockets(SocketIO.OUTPUT);
                        if (sockets != null)
                        {
                            var children = sockets.ConvertAll <NodeEditor> (x => x.connectedTo).Where(x => x != null);

                            nodes.AddRange(children);

                            foreach (var child in children)
                            {
                                GetChildren(child, nodes);
                            }
                        }
                    }
                }
示例#10
0
        public NodeGraphRunner(NodeGraph graph)
        {
            if (graph == null)
            {
                _logger.LogError <NodeGraphRunner>("Cannot run graph as it is null.");
                return;
            }

            _graph = graph;

            _logger          = NodeEditor.GetNewLoggerInstance();
            _logger.LogLevel = NodeEditorLogLevel.ErrorsAndWarnings;

            _graphEventCache  = new Dictionary <string, NodeGraphEvent>();
            _callbackRegister = new List <Action <Node> >();

            _runner = new NodeRunner(_graph.Helper, true);
        }
示例#11
0
                static private NodeData ToData(NodeEditor node, Dictionary <NodeEditor, int> instances)
                {
                    NodeData ret = new NodeData();
                    var      n   = node as NodeEditor;

                    ret.window  = n.GetWindow();
                    ret.title   = n.GetTitle();
                    ret.sockets = ToData(n.GetSockets(), instances);
                    ret.id      = instances[n];
                    ret.type    = node.GetType().ToString();

                    if (typeof(LeafEditor).Equals(node.GetType()))
                    {
                        var leaf = node as LeafEditor;
                        var keys = leaf.GetArgs();

                        Convert(keys, out ret.argsBool, out ret.argsNum, out ret.argsStr);


                        //ret.argsStr = Select<string> (keys);
                        // ret.argsNum = Select<float> (keys);
                        //ret.argsBool = Select<bool> (keys);



                        ret.handledLeaf = leaf.GetNode().GetType().ToString();
                    }
                    else if (typeof(ParallelEditor).Equals(node.GetType()) ||
                             typeof(ParallelRunningEditor).Equals(node.GetType()))
                    {
                        var parallel = node as ParallelEditor;
                        ret.reqFail = parallel.GetReqFail();
                        ret.reqSucc = parallel.GetReqSuccess();
                        ret.name    = parallel.GetName();
                    }
                    else if (typeof(CompositeEditor).Equals(node.GetType().BaseType))
                    {
                        var composite = node as CompositeEditor;

                        ret.name = composite.GetName();
                    }

                    return(ret);
                }
示例#12
0
    public override void NodeGUI()
    {
        GUILayout.BeginHorizontal();
        GUILayout.BeginVertical();

        if (Inputs [0].connection != null)
        {
            GUILayout.Label(Inputs [0].name);
        }
        else
        {
            Input1Val = RTEditorGUI.FloatField(GUIContent.none, Input1Val);
        }
        InputKnob(0);
        // --
        if (Inputs [1].connection != null)
        {
            GUILayout.Label(Inputs [1].name);
        }
        else
        {
            Input2Val = RTEditorGUI.FloatField(GUIContent.none, Input2Val);
        }
        InputKnob(1);

        GUILayout.EndVertical();
        GUILayout.BeginVertical();

        Outputs [0].DisplayLayout();

        GUILayout.EndVertical();
        GUILayout.EndHorizontal();

#if UNITY_EDITOR
        type = (CalcType)UnityEditor.EditorGUILayout.EnumPopup(new GUIContent("Calculation Type", "The type of calculation performed on Input 1 and Input 2"), type);
#else
        GUILayout.Label(new GUIContent("Calculation Type: " + type.ToString(), "The type of calculation performed on Input 1 and Input 2"));
#endif

        if (GUI.changed)
        {
            NodeEditor.RecalculateFrom(this);
        }
    }
        private void OnGUI()
        {
            // Initiation
            NodeEditor.checkInit(true);
            if (NodeEditor.InitiationError)
            {
                GUILayout.Label("Node Editor Initiation failed! Check console for more information!");
                return;
            }

            AssureEditor();
            AssureSetup();

            // ROOT: Start Overlay GUI for popups
            OverlayGUI.StartOverlayGUI("NodeEditorWindow");

            // Begin Node Editor GUI and set canvas rect
            NodeEditorGUI.StartNodeGUI(true);
            canvasCache.editorState.canvasRect = canvasWindowRect;

            try
            {
                // Perform drawing with error-handling
                NodeEditor.DrawCanvas(canvasCache.nodeCanvas, canvasCache.editorState);
            }
            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);
            }

            // Draw Interface
            editorInterface.DrawToolbarGUI(new Rect(0, 0, Screen.width, 0));
            editorInterface.DrawModalPanel();

            // End Node Editor GUI
            NodeEditorGUI.EndNodeGUI();

            // END ROOT: End Overlay GUI and draw popups
            OverlayGUI.EndOverlayGUI();
        }
示例#14
0
        private void AddPortField(Rect rect, XNode.NodePort port)
        {
            if (port == null)
            {
                return;
            }


            NodeEditor editor          = NodeEditor.GetEditor(port.node, NodeEditorWindow.current);
            Color      backgroundColor = editor.GetTint();
            Color      col             = NodeEditorWindow.current.graphEditor.GetPortColor(port);

            DrawPortHandle(rect, backgroundColor, col);

            // Register the handle position
            Vector2 portPos = rect.center;

            NodeEditor.portPositions[port] = portPos;
        }
        private void OnEnable()
        {
            Debug.Log("NodeEditorTWWindow enabled");
            _editor = this;
            NodeEditor.checkInit(false);

            NodeEditorCallbacks.OnLoadCanvas += OnLoadCanvas;

            NodeEditor.ClientRepaints -= Repaint;
            NodeEditor.ClientRepaints += Repaint;

            EditorLoadingControl.justLeftPlayMode -= NormalReInit;
            EditorLoadingControl.justLeftPlayMode += NormalReInit;
            // Here, both justLeftPlayMode and justOpenedNewScene have to act because of timing
            EditorLoadingControl.justOpenedNewScene -= NormalReInit;
            EditorLoadingControl.justOpenedNewScene += NormalReInit;

            SceneView.onSceneGUIDelegate -= OnSceneGUI;
            SceneView.onSceneGUIDelegate += OnSceneGUI;
            string assetPath = AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(this));

            if (assetPath.Length > 1)
            {
                Debug.LogError("asset path " + assetPath);
                string path = Path.GetDirectoryName(assetPath);
                // Setup Cache
                canvasCache = new NodeEditorUserCache(path);
            }
            else
            {
                Debug.LogError("UNKNOWN asset path " + assetPath);
                canvasCache = new NodeEditorUserCache(); //path);
            }
            canvasCache.SetupCacheEvents();

            m_NodeSelectionWindow = MultiColumnWindow.GetWindow(this);

            m_InspectorWindow          = NodeInspectorWindow.Init(this);
            NodeEditor.ClientRepaints += m_InspectorWindow.Repaint;
            StartTextureWangPopup.Init(this);

            m_InspectorWindow.m_Source = this;
        }
示例#16
0
    public override void NodeGUI()
    {
        GUILayout.BeginHorizontal();
        GUILayout.BeginVertical();

        if (Inputs [0].connection != null)
        {
            GUILayout.Label(Inputs [0].name);
        }
        else
        {
            Input1Val = (GameObject)GUIExt.ObjectField(Input1Val, this);
        }
        InputKnob(0);
        // --
        if (Inputs [1].connection != null)
        {
            GUILayout.Label(Inputs [1].name);
        }
        else
        {
            Input2Val = (GameObject)GUIExt.ObjectField(Input2Val, this);
        }
        InputKnob(1);

        objectMaterial = (Material)UnityEditor.EditorGUILayout.ObjectField(objectMaterial, typeof(Material));

        GUILayout.EndVertical();
        GUILayout.BeginVertical();

        Outputs [0].DisplayLayout();

        GUILayout.EndVertical();
        GUILayout.EndHorizontal();

        type = (CalcType)UnityEditor.EditorGUILayout.EnumPopup(
            new GUIContent("CSG Operation", "The type of calculation performed on Input 1 and Input 2"), type);

        if (GUI.changed)
        {
            NodeEditor.RecalculateFrom(this);
        }
    }
示例#17
0
    // 绘制节点
    private void DrawNodeWindows()
    {
        // 开始绘制节点
        // 注意:必须在  BeginWindows(); 和 EndWindows(); 之间 调用 GUI.Window 才能显示
        BeginWindows();
        for (int i = 0; i < nodeValueList.Count; i++)
        {
            NodeValue nodeValue = nodeValueList[i];
            string    name      = NodeEditor.GetTitle(nodeValue.NodeType); //Enum.GetName(typeof(NodeType), nodeValue.NodeType);
            nodeValue.position = GUI.Window(i, nodeValue.position, DrawNodeWindow, name);
            DrawToChildCurve(nodeValue);

            if (nodeValue.isRootNode)
            {
                rootNodeValue = nodeValue;
            }
        }
        EndWindows();
    }
            /// <summary>
            /// override-able node initialisation function
            /// </summary>
            /// <param name="position">the x-y co-ordinates to place the node</param>
            public virtual void Init(Vector2 position)
            {
                Scene scene = NodeEditor.GetScene();

                // assign node ID and increment
                m_nodeID = scene.GetCurrentNodeID();
                scene.SetCurrentNodeID(m_nodeID + 1);

                // initialise node window
                m_rectangle = new Rect(position.x, position.y, 50, 100);

                // initialize list of input nodes, and single input rect
                m_inputs     = new List <int>();
                m_inputPoint = new Rect(0, 0, 10, 20);

                // initialize list of output nodes, and list of output rect
                m_outputs      = new List <int>();
                m_outputPoints = new List <Rect>();
            }
示例#19
0
        public void OnGUI()
        {
            cache.AssureCanvas();
            NodeEditor.checkInit(true);
            if (NodeEditor.InitiationError)
            {
                GUILayout.Label("Initiation failed! Check console for more information!");
                return;
            }

            try
            {
                if (!screenSize && specifiedRootRect.max != specifiedRootRect.min)
                {
                    GUI.BeginGroup(specifiedRootRect, NodeEditorGUI.nodeSkin.box);
                }

                NodeEditorGUI.StartNodeGUI();

                canvasRect                   = screenSize? new Rect(0, 0, Screen.width, Screen.height) : specifiedCanvasRect;
                canvasRect.width            -= 200;
                cache.editorState.canvasRect = canvasRect;
                NodeEditor.DrawCanvas(cache.nodeCanvas, cache.editorState);

                GUILayout.BeginArea(new Rect(canvasRect.x + cache.editorState.canvasRect.width, cache.editorState.canvasRect.y, 200, cache.editorState.canvasRect.height), NodeEditorGUI.nodeSkin.box);
                SideGUI();
                GUILayout.EndArea();

                NodeEditorGUI.EndNodeGUI();

                if (!screenSize && specifiedRootRect.max != specifiedRootRect.min)
                {
                    GUI.EndGroup();
                }
            }
            catch (UnityException e)
            {             // on exceptions in drawing flush the canvas to avoid locking the ui.
                cache.NewNodeCanvas();
                NodeEditor.ReInit(true);
                Debug.LogError("Unloaded Canvas due to exception in Draw!");
                Debug.LogException(e);
            }
        }
示例#20
0
        private void RemoveBranch()
        {
            if (m_branches.Count <= 2)
            {
                return;
            }

            int removalIndex = m_branches.Count - 1;

            m_branches.RemoveAt(removalIndex);

            if (m_outputs[removalIndex] != -1)
            {
                NodeEditor.GetConnectionManager().RemoveConnection(this, removalIndex);
            }

            m_outputPoints.RemoveAt(removalIndex);
            m_outputs.RemoveAt(removalIndex);
        }
示例#21
0
 public override void UpdateView(Rect size, Rect percentageSize, Event e)
 {
     base.UpdateView(size, percentageSize, e);
     ProcessEvent(e);
     GUI.Box(ViewRect, Title, ViewSkin.GetStyle("TriggerEditorCanvas"));
     GUILayout.BeginArea(ViewRect);
     {
         if (e.button == 1 && e.type == EventType.mouseDown)
         {
             menu = NodeEditor.GetGenericMenu();//需要修改 装入InputControls中
             menu.ShowAsContext();
         }
         if (TriggerEditorUtility.CheckInit())
         {
             NodeEditor.DrawCanvas(ViewRect);
         }
     }
     GUILayout.EndArea();
 }
        public void Draw()
        {
            bool flag = DrawGroup(position, menuItems);

            while (groupToDraw != null && !close)
            {
                MenuItem menuItem = groupToDraw;
                groupToDraw = null;
                if (menuItem.group && DrawGroup(menuItem.groupPos, menuItem.subItems))
                {
                    flag = true;
                }
            }
            if (!flag || close)
            {
                OverlayGUI.currentPopup = null;
            }
            NodeEditor.RepaintClients();
        }
示例#23
0
 void OnGUI()
 {
     // The actual window code goes here
     if (NodePopupEditor <T> .node != null)
     {
         if (editor == null)
         {
             editor = NodeEditor.CreateEditor(NodePopupEditor <T> .node.GetType());
         }
         if (editor.target != NodePopupEditor <T> .node)                                              //How to add target to editor??? or subclass the Node Editor
         {
             editor.DrawNode(NodePopupEditor <T> .node);
         }
         else
         {
             editor.OnInspectorGUI();
         }
     }
 }
示例#24
0
 void OnGUI()
 {
     // The actual window code goes here
     if (SendEventNormalizedNodeEditorWindow.node != null)
     {
         if (editor == null)
         {
             editor = NodeEditor.CreateEditor(SendEventNormalizedNodeEditorWindow.node.GetType());
         }
         if (editor.target != SendEventNormalizedNodeEditorWindow.node)                                                //How to add target to editor??? or subclass the Node Editor
         {
             editor.DrawNode(SendEventNormalizedNodeEditorWindow.node);
         }
         else
         {
             editor.OnInspectorGUI();
         }
     }
 }
示例#25
0
        private void OnEnable()
        {
            _editor = this;
            NodeEditor.checkInit(false);

            NodeEditor.ClientRepaints -= Repaint;
            NodeEditor.ClientRepaints += Repaint;

            EditorLoadingControl.justLeftPlayMode -= NormalReInit;
            EditorLoadingControl.justLeftPlayMode += NormalReInit;
            // Here, both justLeftPlayMode and justOpenedNewScene have to act because of timing
            EditorLoadingControl.justOpenedNewScene -= NormalReInit;
            EditorLoadingControl.justOpenedNewScene += NormalReInit;

            // Setup Cache
            tempSessionPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(this)));
            SetupCacheEvents();
            LoadCache();
        }
示例#26
0
 void CheckMouseObject()
 {
     if (Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out RaycastHit hitInfo, 1000))
     {
         if (hitInfo.collider.gameObject.TryGetComponent(out NodeInput nodeInput))
         {
             if (nodeInput.inputType == NodeEditor.IOTYPE.ANY)
             {
                 nodeInput.value = value;
                 nodeInput.used  = true;
                 lineReferences[lineReferences.Count - 1].FinishLine(nodeInput);
                 NodeEditor.Refresh();
                 return;
             }
             else
             {
                 if (!nodeInput.used)
                 {
                     if (outputType == nodeInput.inputType)
                     {
                         nodeInput.value = value;
                         nodeInput.used  = true;
                         lineReferences[lineReferences.Count - 1].FinishLine(nodeInput);
                         NodeEditor.Refresh();
                         return;
                     }
                     else
                     {
                         ErrorLogger.ThrowErrorMessage("Output type does not match input type.");
                     }
                 }
                 else
                 {
                     ErrorLogger.ThrowErrorMessage("Input is already connected.");
                 }
             }
         }
     }
     Destroy(lineReferences[lineReferences.Count - 1].gameObject);
     lineReferences.RemoveAt(lineReferences.Count - 1);
     NodeEditor.Refresh();
 }
示例#27
0
    /// <summary>
    /// Draws all <see cref="transitions"/> curves for the <see cref="FSM"/>
    /// </summary>
    public override void DrawCurves()
    {
        foreach (TransitionGUI elem in transitions)
        {
            if (elem.fromNode is null || elem.toNode is null)
            {
                continue;
            }

            if (elem.isExit && !(this.parent is BehaviourTree || this.parent is UtilitySystem))
            {
                DeleteTransition(elem);
                break;
            }

            bool isDouble = false;
            bool isLoop   = false;
            bool isExit   = false;

            Rect fromNodeRect = new Rect(elem.fromNode.windowRect);
            Rect toNodeRect   = new Rect(elem.toNode.windowRect);

            if (transitions.Exists(t => t.fromNode.Equals(elem.toNode) && t.toNode.Equals(elem.fromNode)))
            {
                isDouble = true;
            }

            if (elem.fromNode.Equals(elem.toNode))
            {
                isLoop = true;
            }

            if (elem.isExit)
            {
                isExit   = true;
                isLoop   = false;
                isDouble = false;
            }

            NodeEditor.DrawNodeCurve(fromNodeRect, toNodeRect, editor.focusedObjects.Contains(elem), isDouble, isLoop, isExit);
        }
    }
            /// <summary>
            /// function which determines the start and end point, using this and another node's
            /// input/output points and draws a bezier between them
            /// </summary>
            void DrawBeziers()
            {
                Color colour = Color.white;

                for (int i = 0; i < m_outputs.Count; i++)
                {
                    if (m_outputs[i] == -1)
                    {
                        continue; // skip empty outputs
                    }
                    BaseNode outputNode = NodeEditor.GetNodeManager().FindNode(m_outputs[i]);

                    // define positional variables
                    Vector3 startPos     = m_outputPoints[i].center;
                    Vector3 endPos       = outputNode.m_inputPoint.center;
                    Vector3 startTangent = startPos + Vector3.right * 50;
                    Vector3 endTangent   = endPos + Vector3.left * 50;

                    // different bezier colours for condition nodes
                    if (this is ConditionNode)
                    {
                        if (i == 0)
                        {
                            colour = Color.green; // true
                        }
                        else
                        {
                            colour = Color.red; // false
                        }
                    }

                    // draw the connection
                    Handles.color = colour;
                    Handles.DrawBezier(startPos, endPos, startTangent, endTangent, Handles.color, null, 2);

                    // draw a square on bezier to handle connection removal
                    if (Handles.Button((startPos + endPos) * 0.5f, Quaternion.identity, 4, 8, Handles.RectangleHandleCap))
                    {
                        NodeEditor.GetConnectionManager().RemoveConnection(this, i);
                    }
                }
            }
            /// <summary>
            /// overridden draw function, gets all existing pages and lists them in a popup for the user to select
            /// </summary>
            /// <param name="id">the node window ID</param>
            protected override void DrawNodeWindow(int id)
            {
                // draw "Jump To:" label
                EditorGUILayout.LabelField("Jump To:");

                // get a string list of all pages
                string[] pages = new string[NodeEditor.GetScene().GetPages().Count];
                for (int i = 0; i < pages.Length; i++)
                {
                    pages[i] = "Page " + (i + 1);
                }

                // draw page list popup
                m_pageNumber = EditorGUILayout.Popup(m_pageNumber, pages);

                // perform clamp to prevent any index out of range errors
                m_pageNumber = Mathf.Clamp(m_pageNumber, 0, pages.Length - 1);

                base.DrawNodeWindow(id);
            }
示例#30
0
        protected override void NodeGUI() //protected internal override void NodeGUI()
        {
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();

            GUILayout.Box(Preview);

            GUILayout.EndVertical();
            GUILayout.BeginVertical();

            Outputs[0].DisplayLayout();

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();

            if (GUI.changed)
            {
                NodeEditor.RecalculateFrom(this);
            }
        }
示例#31
0
    private void Awake()
    {
        if (string.IsNullOrEmpty(saveName))
        {
            Debug.LogError("CRITICAL: CraftingInterface has no save name");
            return;
        }

        canvas = NodeEditorSaveManager.LoadSceneNodeCanvas(saveName, false);
        NodeEditor.RecalculateAll(canvas);

        if (canvas != null)
        {
            Debug.Log("NodeGraph loaded.");
        }
        else
        {
            Debug.Log("Good job, no NodeGraph found.");
        }
    }
示例#32
0
        private void OnGUI()
        {
            // 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);
            }
            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);
            }

            // 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();
        }
示例#33
0
 public SelectionProxy(SyntaxTreeViewer syntax, NodeEditor nodeeditor, List<Elem> selected)
 {
     m_syntax = syntax;
     m_nodeeditor = nodeeditor;
     m_selected = selected;
 }