コード例 #1
0
        public override void OnClick(Node source, Vector2 mousePosition)
        {
            ComparisonNode node = source as ComparisonNode;

            NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, (ConditionNode n) => {
                n.Condition.AddBlockRange(BlockUtility.GetConditionBlockFromNode(source));
                n.editorRect = node.editorRect;
                RefactorUtility.RetargetNode(node, n);
            });
            NodeEditorUtility.RemoveNode(graph.editorData, node);
            graph.Refresh();
        }
コード例 #2
0
        public override void OnClick(Node source, Vector2 mousePosition)
        {
            MultipurposeNode node = source as MultipurposeNode;

            NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, (NodeAction n) => {
                n.Action.AddBlockRange(BlockUtility.GetActionBlockFromNode(source));
                n.onFinished = node.onFinished;
                n.editorRect = node.editorRect;
                RefactorUtility.RetargetNode(node, n);
            });
            NodeEditorUtility.RemoveNode(graph.editorData, node);
            graph.Refresh();
        }
コード例 #3
0
ファイル: NodeIf.cs プロジェクト: hagusen/AI-Testing
        public override void OnClick(Node source, Vector2 mousePosition)
        {
            NodeIf node = source as NodeIf;

            NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, (NodeValidation n) => {
                var action    = new EqualityCompare();
                action.target = new MultipurposeMember(node.condition);
                action.value  = new MemberData(true);
                n.Validation.AddBlock(action, EventActionData.EventType.Event);
                n.onTrue     = node.onTrue;
                n.onFalse    = node.onFalse;
                n.onFinished = node.onFinished;
                n.editorRect = node.editorRect;
                RefactorUtility.RetargetNode(node, n);
            });
            NodeEditorUtility.RemoveNode(graph.editorData, node);
            graph.Refresh();
        }
コード例 #4
0
        public override void OnClick(Node source, Vector2 mousePosition)
        {
            MacroNode node = source as MacroNode;
            string    path = EditorUtility.SaveFilePanelInProject("Export to macro asset",
                                                                  "New Macro.prefab",
                                                                  "prefab",
                                                                  "Please enter a file name to save the macro to");

            if (path.Length != 0)
            {
                Undo.RegisterFullObjectHierarchyUndo(node, "");
                Undo.RegisterFullObjectHierarchyUndo(node.owner, "");
                var        tmpMacro = Object.Instantiate(node);
                GameObject go       = new GameObject("New Macro");
                var        macro    = go.AddComponent <uNodeMacro>();
                macro.Variables.AddRange(tmpMacro.Variables);
                if (macro.RootObject == null)
                {
                    macro.RootObject = new GameObject("Root");
                    macro.RootObject.transform.SetParent(macro.transform);
                }
                var behaviors = tmpMacro.GetComponentsInChildren <MonoBehaviour>(true);
                AnalizerUtility.RetargetNodeOwner(tmpMacro.owner, macro, behaviors, (obj) => {
                    MemberData member = obj as MemberData;
                    if (member != null && member.targetType == MemberData.TargetType.uNodeVariable && member.GetInstance() as Object == tmpMacro)
                    {
                        member.RefactorUnityObject(new Object[] { tmpMacro }, new Object[] { macro });
                    }
                });
                for (int i = 0; i < tmpMacro.transform.childCount; i++)
                {
                    tmpMacro.transform.GetChild(i).SetParent(macro.RootObject.transform);
                    i--;
                }
                macro.Refresh();
#if UNITY_2018_3_OR_NEWER
                GameObject prefab = PrefabUtility.SaveAsPrefabAsset(go, path);
#else
                GameObject prefab = PrefabUtility.CreatePrefab(path, go);
#endif
                AssetDatabase.SaveAssets();
                Object.DestroyImmediate(go);
                Object.DestroyImmediate(tmpMacro.gameObject);
                var macroAsset = prefab.GetComponent <uNodeMacro>();
                NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, (LinkedMacroNode n) => {
                    n.macroAsset = macroAsset;
                    n.editorRect = node.editorRect;
                    NodeEditorUtility.AddNewObject(graph.editorData.graph, "pins", n.transform, (pin) => {
                        n.pinObject = pin;
                        n.Refresh();
                        RefactorUtility.RetargetNode(node, n);
                        if (n.inputFlows.Count == node.inputFlows.Count)
                        {
                            for (int i = 0; i < n.inputFlows.Count; i++)
                            {
                                RefactorUtility.RetargetNode(node.inputFlows[i], n.inputFlows[i]);
                            }
                        }
                        if (n.inputValues.Count == node.inputValues.Count)
                        {
                            for (int i = 0; i < n.inputValues.Count; i++)
                            {
                                n.inputValues[i].target = new MemberData(node.inputValues[i].target);
                            }
                        }
                        if (n.outputFlows.Count == node.outputFlows.Count)
                        {
                            for (int i = 0; i < n.outputFlows.Count; i++)
                            {
                                n.outputFlows[i].target = new MemberData(node.outputFlows[i].target);
                            }
                        }
                        if (n.outputValues.Count == node.outputValues.Count)
                        {
                            for (int i = 0; i < n.outputValues.Count; i++)
                            {
                                RefactorUtility.RetargetNode(node.outputValues[i], n.outputValues[i]);
                            }
                        }
                    });
                });
                NodeEditorUtility.RemoveNode(graph.editorData, node);
            }
            graph.Refresh();
        }