//変換
    EditorSkillTreeData.EditorNodeData ConvertFromEditorNode(EditorNode node)
    {
        EditorSkillTreeData.EditorNodeData nodeData = new EditorSkillTreeData.EditorNodeData();
        nodeData.position    = node.nodeDrawer.Position;
        nodeData.skillDataId = node.skillId;

        //元データと順番を変えないのでそのままidx保存する
        if (node.parents != null)
        {
            nodeData.parents = new List <EditorSkillTreeData.Conditions>();
            for (int i = 0; i < node.parents.Count; i++)
            {
                int idx = nodes.FindIndex((_) => _ == node.parents[i].node);
                EditorSkillTreeData.Conditions conditions = new EditorSkillTreeData.Conditions();
                conditions.lv  = node.parents[i].lv;
                conditions.idx = idx;
                nodeData.parents.Add(conditions);
            }
        }

        if (node.children != null)
        {
            nodeData.children = new List <int>();
            for (int i = 0; i < node.children.Count; i++)
            {
                int idx = nodes.FindIndex((_) => _ == node.children[i]);
                nodeData.children.Add(idx);
            }
        }

        return(nodeData);
    }
    //接続削除
    void DisConnectNode(EditorNode parent, EditorNode child)
    {
        if (parent == child)
        {
            return;
        }

        if (parent.children == null)
        {
            parent.children = new List <EditorNode>();
        }

        if (parent.parents == null)
        {
            parent.parents = new List <Conditions>();
        }

        if (child.parents == null)
        {
            child.parents = new List <Conditions>();
        }

        if (child.children == null)
        {
            child.children = new List <EditorNode>();
        }

        parent.children.Remove(child);
        int idx = child.parents.FindIndex((_) => _.node == parent);

        if (idx != -1)
        {
            child.parents.RemoveAt(idx);
        }
    }
예제 #3
0
    public bool RemoveNode(EditorNode _Node)
    {
        if (Nodes == null)
        {
            return(false);
        }

        int  NodeID   = _Node.ID;
        bool bSuccess = Nodes.Remove(_Node);

        if (bSuccess)
        {
            // remove all associated links
            for (int Index = Links.Count - 1; Index >= 0; --Index)
            {
                EditorLink Link = Links[Index];
                if (Link.NodeID_From == NodeID || Link.NodeID_To == NodeID)
                {
                    Links.RemoveAt(Index);
                }
            }

            _Node.OnNodeChanged -= NotifyGraphChange;
            NotifyGraphChange();
            return(true);
        }
        else
        {
            return(false);
        }
    }
예제 #4
0
    public void MoveNode(EditorNode node, Vector2 delta)
    {
        Vector2 position = node.GetNodePosition();

        node.SetNodePosition(position + delta);
        Repaint();
    }
    //ノード削除
    void DeleteNode()
    {
        //親子関係切
        if (currentEventTarget.parents != null)
        {
            for (int i = 0; i < currentEventTarget.parents.Count; i++)
            {
                currentEventTarget.parents[i].node.children.Remove(currentEventTarget);
            }
        }

        if (currentEventTarget.children != null)
        {
            for (int i = 0; i < currentEventTarget.children.Count; i++)
            {
                int idx = currentEventTarget.children[i].parents.FindIndex((_) => { return(_.node == currentEventTarget); });

                if (idx != -1)
                {
                    currentEventTarget.children[i].parents.RemoveAt(idx);
                }
            }
        }



        //デリート
        nodes.Remove(currentEventTarget);
        currentEventTarget = null;
        currentMouseEvent  = MouseEvent.None;
    }
예제 #6
0
    private void OnGUI()
    {
        DrawGrid(20, 0.2f, Color.gray);
        DrawGrid(100, 0.4f, Color.gray);

        ProcessEvents(Event.current);

        if (GraphToEdit == null)
        {
            Reset();
            return;
        }

        if (GraphToEdit != null)
        {
            if (RegisteredFunctionDictionary == null)
            {
                Reset();
            }
        }

        RenderGraph();
        // draw editors for selected node

        if (GraphToEdit != null && GraphToEdit.IsPinSelected())
        {
            EditorNode OwnerNode = GraphToEdit.GetSelectedNode();
            Vector2    PinPos    = OwnerNode.GetPinRect(GraphToEdit.GetSelectedElementID().PinID).center;
            EditorGraphDrawUtils.Line(PinPos, Event.current.mousePosition, Color.magenta);
        }
    }
예제 #7
0
    private void OnClickRemoveNode(EditorNode node)
    {
        if (connections != null)
        {
            List <EditorConnection> connectionsToRemove = new List <EditorConnection>();

            for (int i = 0; i < connections.Count; i++)
            {
                if ((node.inPoints != null && node.inPoints.Contains(connections[i].inPoint)) || (node.outPoints != null && node.outPoints.Contains(connections[i].outPoint)))
                {
                    connectionsToRemove.Add(connections[i]);
                }
            }

            for (int i = 0; i < connectionsToRemove.Count; i++)
            {
                connectionsToRemove[i].inPoint.connection  = null;
                connectionsToRemove[i].outPoint.connection = null;
                connections.Remove(connectionsToRemove[i]);
            }

            connectionsToRemove = null;
        }

        if (node.actualNode != null)
        {
            Undo.DestroyObjectImmediate(node.actualNode.gameObject);
        }

        nodes.Remove(node.actualNode);
    }
예제 #8
0
        private void SetupNode(EditorNode node, Action <Vector2> setPositionInModel)
        {
            Vector2 positionBeforeDrag = node.Position;

            node.GraphicalEventHandler.PointerDown += (sender, args) =>
            {
                positionBeforeDrag = node.Position;
            };

            node.GraphicalEventHandler.PointerUp += (sender, args) =>
            {
                if (Mathf.Abs((positionBeforeDrag - node.Position).sqrMagnitude) < 0.001f)
                {
                    return;
                }

                Vector2 positionAfterDrag          = node.Position;
                Vector2 closuredPositionBeforeDrag = positionBeforeDrag;

                RevertableChangesHandler.Do(new TrainingCommand(() =>
                {
                    setPositionInModel(positionAfterDrag);
                    MarkToRefresh();
                }, () =>
                {
                    setPositionInModel(closuredPositionBeforeDrag);
                    MarkToRefresh();
                }));
            };

            node.GraphicalEventHandler.PointerDrag += (sender, args) =>
            {
                node.RelativePosition += args.PointerDelta;
            };
        }
예제 #9
0
    private void OnClick_AddNode(System.Type LibraryType, string MethodName, Vector2 mousePos)
    {
        int        NodeID = GraphToEdit.AddNode(EditorNode.CreateFromFunction(GraphToEdit, LibraryType, MethodName, false, false));
        EditorNode Node   = GraphToEdit.GetNodeFromID(NodeID);

        Node.SetNodePosition(mousePos);
        Repaint();
    }
 public EditorConnectionPoint(EditorNode node, EditorconnectionPointType type, GUIStyle style, Action <EditorConnectionPoint> OnClickConnectionPoint)
 {
     this.Rect           = new Rect(0, 0, 10f, 20f);
     this.EditorNode     = node;
     this.ConnectionType = type;
     this.guiStyle       = style;
     this.onClick        = OnClickConnectionPoint;
 }
예제 #11
0
    public void attachBlockChild(Block child)
    {
        EditorNode childEditorNode = new EditorNode(child);

        childEditorNode.parents = this;
        children.Add(childEditorNode);

        golLangNode.addChild(childEditorNode.golLangNode);
    }
예제 #12
0
    public EditorConnectionPoint(EditorNode node, ConnectionPointType type, GUIStyle style, Action <EditorConnectionPoint> OnClickConnectionPoint, int id, string name)
    {
        this.node  = node;
        this.type  = type;
        this.style = style;
        this.OnClickConnectionPoint = OnClickConnectionPoint;
        this.name = name;
        this.id   = id;

        rect = new Rect(0, 0, 10f, 20f);
    }
예제 #13
0
    public void attachBlockSibling(Block sibling)
    {
        EditorNode siblingEditorNode = new EditorNode(sibling);

        siblingEditorNode.leftSibling = this;
        rightSibling = siblingEditorNode;

        siblingEditorNode.parents = parents;
        parents.children.Add(siblingEditorNode);

        parents.golLangNode.addChild(siblingEditorNode.golLangNode);
    }
예제 #14
0
 public void Draw(EditorNode nodeData)
 {
     foreach (var item in nodeFields.GetFields(nodeData))
     {
         var node = item.Target as INode;
         node.DrawNodePropertyField(
             item.Property,
             new GUIContent(
                 item.Name,
                 item.Tooltip), true);
     }
 }
    //Editor読み出し
    void Load()
    {
        string path = EditorUtility.OpenFilePanel("読み込み", Application.dataPath, "asset");

        if (string.IsNullOrEmpty(path))
        {
            return;
        }

        nodes = new List <EditorNode>();

        path = path.Replace(Application.dataPath, "");

        path = "Assets" + path;

        var ins = AssetDatabase.LoadAssetAtPath <EditorSkillTreeData>(path);

        //作成
        //先にデータを作る
        for (int i = 0; i < ins.List.Count; i++)
        {
            var node = new EditorNode();
            node.skillId             = ins.List[i].skillDataId;
            node.nodeDrawer          = new SkillTreeEditorNodeDrawer();
            node.nodeDrawer.Position = ins.List[i].position;
            nodes.Add(node);
        }

        //親子関係生成
        //idx保存なので一気に接続
        for (int i = 0; i < ins.List.Count; i++)
        {
            nodes[i].children = new List <EditorNode>();
            nodes[i].parents  = new List <Conditions>();

            for (int j = 0; j < ins.List[i].children.Count; j++)
            {
                int idx = ins.List[i].children[j];
                nodes[i].children.Add(nodes[idx]);
            }

            for (int j = 0; j < ins.List[i].parents.Count; j++)
            {
                int idx = ins.List[i].parents[j].idx;

                Conditions cond = new Conditions();
                cond.node = nodes[idx];
                cond.lv   = ins.List[i].parents[j].lv;
                nodes[i].parents.Add(cond);
            }
        }
    }
예제 #16
0
    public EditorNode()
    {
        golLangNode = new GolLangNode(new GolLangLine());

        blocks = new List <Block>();

        parents = null;

        leftSibling = null;

        rightSibling = null;

        children = new List <EditorNode>();
    }
예제 #17
0
    //Battle



    public void Start()
    {
        interpreter = transform.GetComponent <GolLangInterpreter>();

        interpreter.monster = GameObject.Find("Enemy").GetComponent <Monster>();

        interpreter.golem = GameObject.Find("Golem").GetComponent <Golem>();

        Block b = transform.Find("StartHere").GetComponent <Block>();

        b.initBlock(Block.BlockKind.STARTHERE);

        firstLine = new EditorNode(b);
    }
예제 #18
0
    public void RenderLink(EditorGraph Graph)
    {
        EditorNode FromNode = Graph.GetNodeFromID(NodeID_From);
        EditorNode ToNode   = Graph.GetNodeFromID(NodeID_To);

        if (FromNode == null || ToNode == null)
        {
            return;
        }

        Rect FromRect = FromNode.GetPinRect(PinID_From);
        Rect ToRect   = ToNode.GetPinRect(PinID_To);

        EditorGraphDrawUtils.Line(FromRect.center, ToRect.center, Color.black);
    }
예제 #19
0
    public static EditorNode CreateFromFunction(EditorGraph Owner, System.Type ClassType, string Methodname, bool bHasOutput = true, bool bHasInput = true)
    {
        EditorNode _Node = new EditorNode(Owner);

        if (ClassType != null)
        {
            MethodInfo methodInfo = ClassType.GetMethod(Methodname);

            if (methodInfo != null)
            {
                _Node.Name = SanitizeName(Methodname);
                //Debug.Log("Method name: " + _Node.Name);
                //Debug.Log("Return type: " + methodInfo.ReturnParameter.ParameterType.ToString());
                //Debug.Log("Return name: " + methodInfo.ReturnParameter.Name);

                if (bHasOutput)
                {
                    _Node.AddPin(EPinLinkType.Output, null, "");
                }
                if (bHasInput)
                {
                    _Node.AddPin(EPinLinkType.Input, null, "");
                }

                _Node.AddPin(EPinLinkType.Output, methodInfo.ReturnParameter.ParameterType, "Output");

                ParameterInfo[] Parameters = methodInfo.GetParameters();
                foreach (ParameterInfo Parameter in Parameters)
                {
                    //Debug.Log("Param type: " + Parameter.ParameterType.ToString());
                    //Debug.Log("Param name: " + Parameter.Name);

                    _Node.AddPin(EPinLinkType.Input, Parameter.ParameterType, Parameter.Name);
                }
            }
            else
            {
                Debug.LogError("Function '" + ClassType.ToString() + "." + Methodname + "' not found.");
            }
        }
        else
        {
            Debug.LogError("Tried to create node from function from an unknown class type.");
        }

        _Node.NotifyGraphChange();
        return(_Node);
    }
    //ノード接続
    void ConnectNode(EditorNode parent, EditorNode child)
    {
        //親=子供は許さない
        if (parent == child)
        {
            return;
        }

        //初期化済み出ない場合初期化
        if (parent.children == null)
        {
            parent.children = new List <EditorNode>();
        }

        if (parent.parents == null)
        {
            parent.parents = new List <Conditions>();
        }

        if (child.parents == null)
        {
            child.parents = new List <Conditions>();
        }

        if (child.children == null)
        {
            child.children = new List <EditorNode>();
        }

        //すでに存在している場合も許さない
        int idx1 = parent.children.FindIndex((_) => _ == child);
        int idx2 = child.children.FindIndex((_) => _ == parent);

        if (idx1 != -1 || idx2 != -1)
        {
            return;
        }

        parent.children.Add(child);

        Conditions cond = new Conditions();

        cond.lv   = 1;
        cond.node = parent;

        child.parents.Add(cond);
    }
예제 #21
0
    public int AddNode(EditorNode _Node)
    {
        if (Nodes == null)
        {
            Nodes = new List <EditorNode>();
        }
        if (NodeMap == null)
        {
            NodeMap = new Dictionary <int, EditorNode>();
        }

        NodeMap[_Node.ID] = _Node;
        Nodes.Add(_Node);
        _Node.OnNodeChanged += NotifyGraphChange;
        NotifyGraphChange();
        return(_Node.ID);
    }
예제 #22
0
        /// Clamps the position of the node on the background grid.
        private void SetNewPositionOnGrid(EditorNode node, Vector2 position, Vector2 delta)
        {
            // Add original delta pointer position onto the absolute position of the node.
            node.Position = position + delta;
            Vector2 newPos = node.RelativePosition;

            // Calculate x and y offset dependent on the size of the grid cells.
            float xOffset = newPos.x % gridCellSize;
            float addedX  = xOffset < gridCellSize / 2 ? -xOffset : gridCellSize - xOffset;

            float yOffset = newPos.y % gridCellSize;
            float addedY  = yOffset < gridCellSize / 2 ? -yOffset : gridCellSize - yOffset;

            // Add offsets and subtract bounding box offsets
            newPos += new Vector2(addedX, addedY);
            newPos -= new Vector2(node.LocalBoundingBox.x % gridCellSize, node.LocalBoundingBox.y % gridCellSize);

            node.RelativePosition = newPos;
        }
예제 #23
0
    public EditorNode(Block firstBlock)
    {
        golLangNode = new GolLangNode(new GolLangLine());



        golLangNode.line.keywords.Add(firstBlock.keyword);

        blocks = new List <Block>();
        blocks.Add(firstBlock);

        firstBlock.node = this;

        parents = null;

        leftSibling = null;

        rightSibling = null;

        children = new List <EditorNode>();
    }
    //メニュー時のイベント
    public bool ActionMenuEvent(EditorNode node, int mousebutton, Event ev)
    {
        if (currentMenuEvent == MenuEvent.None)
        {
            return(false);
        }

        switch (currentMenuEvent)
        {
        case MenuEvent.ConnectSelect:

            if (mousebutton == 0)
            {
                ConnectNode(currentEventTarget, node);
                return(true);
            }
            else if (mousebutton != -1 || (ev.type == EventType.MouseDown))
            {
                return(true);
            }

            break;

        case MenuEvent.DisConnectSelect:

            if (mousebutton == 0)
            {
                DisConnectNode(currentEventTarget, node);
                return(true);
            }
            else if (mousebutton != -1 || (ev.type == EventType.MouseDown))
            {
                return(true);
            }

            break;
        }

        return(false);
    }
예제 #25
0
    public EditorPin GetPinFromID(EditorPinIdentifier PinIdentifier)
    {
        if (PinMap == null)
        {
            PinMap = new Dictionary <EditorPinIdentifier, EditorPin>();
        }
        else if (PinMap.ContainsKey(PinIdentifier))
        {
            return(PinMap[PinIdentifier]);
        }

        EditorNode _Node = GetNodeFromID(PinIdentifier.NodeID);

        if (_Node != null)
        {
            EditorPin Pin = _Node.GetPin(PinIdentifier.PinID);
            PinMap[PinIdentifier] = Pin;
            return(Pin);
        }

        return(null);
    }
예제 #26
0
    private void OnClickAddNode(Vector2 mousePosition, Type type, Dictionary <string, object> data = null)
    {
        //Actually adding it to the scene
        GameObject actualObject = new GameObject();

        Undo.RegisterCreatedObjectUndo(actualObject, "create cutscene node");
        BaseCutsceneNode actualNode = Undo.AddComponent(actualObject, type).GetComponent <BaseCutsceneNode>();

        actualNode.cutsceneManager = cutsceneManager;
        actualNode.transform.SetParent(cutsceneManager.transform);
        actualNode.transform.position = cutsceneManager.transform.position;
        actualNode.name = "New " + type.Name;

        EditorNode node = new EditorNode(this, actualNode, mousePosition, headerStyle, nodeStyle)
        {
            OnRemoveNode = OnClickRemoveNode
        };

        node.PrepareConnections(inPointStyle, outPointStyle, OnClickInPoint, OnClickOutPoint);

        nodes.Add(actualNode, node);
        node.SyncEditorNodePosition();
    }
예제 #27
0
        private void SetupNode(EditorNode node, Action <Vector2> setPositionInModel)
        {
            Vector2 positionBeforeDrag = node.Position;
            Vector2 deltaOnPointerDown = Vector2.zero;

            node.GraphicalEventHandler.PointerDown += (sender, args) =>
            {
                positionBeforeDrag = node.Position;
                deltaOnPointerDown = node.Position - args.PointerPosition;
            };

            node.GraphicalEventHandler.PointerUp += (sender, args) =>
            {
                if (Mathf.Abs((positionBeforeDrag - node.Position).sqrMagnitude) < 0.001f)
                {
                    return;
                }

                Vector2 positionAfterDrag          = node.Position;
                Vector2 closuredPositionBeforeDrag = positionBeforeDrag;

                RevertableChangesHandler.Do(new CourseCommand(() =>
                {
                    setPositionInModel(positionAfterDrag);
                    MarkToRefresh();
                }, () =>
                {
                    setPositionInModel(closuredPositionBeforeDrag);
                    MarkToRefresh();
                }));
            };

            node.GraphicalEventHandler.PointerDrag += (sender, args) =>
            {
                SetNewPositionOnGrid(node, args.PointerPosition, deltaOnPointerDown);
            };
        }
    private void OnClickRemoveNode(EditorNode node)
    {
        if (connections != null)
        {
            List <EditorConnection> connectionsToRemove = new List <EditorConnection>();

            for (int i = 0; i < connections.Count; i++)
            {
                if (connections[i].inPoint == node.inPoint || connections[i].outPoint == node.outPoint)
                {
                    connectionsToRemove.Add(connections[i]);
                }
            }

            for (int i = 0; i < connectionsToRemove.Count; i++)
            {
                connections.Remove(connectionsToRemove[i]);
            }

            connectionsToRemove = null;
        }

        nodes.Remove(node);
    }
        public IReadOnlyList <PropertyEditorData> GetFields(EditorNode editorNode)
        {
            var serializedObject = editorNode.Source;
            var parent           = editorNode.Parent;
            var node             = editorNode.Node;

            if (_cachedProperties.TryGetValue(node, out var propertyEditorData))
            {
                return(propertyEditorData);
            }

            var targetProperty = serializedObject == null ?
                                 editorNode.Property :
                                 serializedObject.GetIterator();

            var items = node.
                        GetProperties(targetProperty, parent).
                        Where(x => IsItemVisible(x.Type, x.Name)).
                        ToList();

            _cachedProperties[node] = items;

            return(items);
        }
예제 #30
0
 protected override EditorNodeConnection CreateConnection(EditorNode editorNode, EditorNode to)
 {
     return(new ExampleNodeConnection());
 }