Пример #1
0
        private void DrawBezierToMouse()
        {
            Color colour = m_Color;

            if (m_selectedLeftNode != null)
            {
                Vector3 startPos     = m_selectedLeftNode.m_outputPoints[m_selectedOutput].center;
                Vector3 endPos       = NodeEditor.GetMousePosition();
                Vector3 startTangent = startPos + Vector3.right * 50;
                Vector3 endTangent   = endPos + Vector3.left * 50;

                if (m_selectedLeftNode is ConditionNode)
                {
                    if (m_selectedOutput == 0)
                    {
                        colour = Color.green;
                    }
                    else
                    {
                        colour = Color.red;
                    }
                }

                Handles.DrawBezier(startPos, endPos, startTangent, endTangent, colour, null, 2);
            }
            else if (m_selectedRightNode != null)
            {
                Vector3 startPos     = NodeEditor.GetMousePosition();
                Vector3 endPos       = m_selectedRightNode.m_inputPoint.center;
                Vector3 startTangent = startPos + Vector3.right * 50;
                Vector3 endTangent   = endPos + Vector3.left * 50;

                Handles.DrawBezier(startPos, endPos, startTangent, endTangent, colour, null, 2);
            }
        }
Пример #2
0
        public BaseNode AddNode(System.Type type, BaseNode nodeToCopy = null)
        {
            Scene currentScene = NodeEditor.GetScene();

            BaseNode node = ScriptableObject.CreateInstance(type) as BaseNode;

            if (nodeToCopy != null)
            {
                node.Copy(nodeToCopy, NodeEditor.GetMousePosition());
            }
            else
            {
                node.Init(NodeEditor.GetMousePosition());
            }

            if (type != typeof(StartNode))
            {
                Undo.RecordObject(currentScene.GetCurrentPage(), "Новый узелок");
                m_nodes.Add(node);

                Undo.RegisterCreatedObjectUndo(node, "Новый узелок");
            }

            ConnectionManager connectionManager = NodeEditor.GetConnectionManager();
            BaseNode          selectedLeftNode  = connectionManager.GetSelectedLeftNode();

            if (selectedLeftNode != null)
            {
                connectionManager.SetSelectedRightNode(node);
                connectionManager.CreateConnection();
                connectionManager.ClearConnectionSelection();
            }

            string path = AssetDatabase.GetAssetPath(currentScene);

            AssetDatabase.AddObjectToAsset(node, path);

            node.hideFlags = HideFlags.HideInHierarchy;
            AssetDatabase.SaveAssets();

            return(node);
        }