Example #1
0
        Node FindNode(SerializableEventNode eventNode)
        {
            foreach (var node in nodes.Values)
            {
                if (node.eventNode == eventNode)
                {
                    return(node);
                }
            }

            return(null);
        }
Example #2
0
        //---Nodeに対する処理-----------------------------------------------------------------------------------------

        void DeleteEventNode(SerializableEventNode eventNodeToDelete)
        {
            if (eventNodeToDelete.eventClip != null)
            {
                // 削除対象EventClipの所属情報(EventController)を初期化.
                eventNodeToDelete.eventClip.eventController = null;


                // Nodeから取り外し不可能なClipがある場合は, そのClipがついているGameObjectも削除する.
                if (eventNodeToDelete.eventClip is IUndetachableEventClip)
                {
                    GameObject.DestroyImmediate(eventNodeToDelete.eventClip.gameObject);
                }
            }
        }
Example #3
0
        //編集処理
        void Edit()
        {
            //userからの入力情報取得
            var currentEvent = Event.current;

            // graphAreaのサイズ
            graphAreaRect      = new Rect(sideAreaRect.xMax, sideAreaRect.yMin, position.width - sideAreaRect.xMax, position.height);
            MouseIsInGraphArea = graphAreaRect.Contains(currentEvent.mousePosition);
            //Debug.Log(GraphAreaRect);


            //---ノードグラフの描画---------------------------------------------------------------------------------------
            if (currentLayer != null)
            {
                //マウスの中央ボタンでノード全体をドラッグする
                if (currentEvent.type == EventType.MouseDrag && currentEvent.button == 2)
                {
                    foreach (var node in nodes.Values)
                    {
                        node.rect.position += currentEvent.delta;
                    }

                    //描画する
                    Repaint();
                }

                ConnectorManager.Update(Event.current.mousePosition);



                BeginWindows();
                foreach (var node in nodes.Values)
                {
                    node.Update();
                }
                EndWindows();


                // 決定中の接続がある場合は右クリックでキャンセル
                if (ConnectorManager.HasCurrent && currentEvent.type == EventType.MouseDown && currentEvent.button == 1)
                {
                    ConnectorManager.CancelConnecting();
                }

                if (ConnectorManager.HasCurrent)
                {
                    // 関連付けようとしている接続がある場合は描画する
                    Repaint();
                }
            }

            //----------------------------------------------------------------------------------------------------


            // --- Side Area -----------------------------------------------------------------------------------------------
            var sideAreaRectTemp = EditorGUILayout.BeginVertical("box", GUILayout.Width(200), GUILayout.Height(position.height - 6.0f));

            {
                // BeginVerticalの返り値でゼロのときがある. これは省く.
                if (sideAreaRectTemp.width != 0.0f && sideAreaRectTemp.height != 0.0f)
                {
                    sideAreaRect = sideAreaRectTemp;
                }
                //Debug.Log(sideAreaRect);


                //---レイヤーリスト--------------------------------------------------------------------------------

                EditorGUILayout.BeginVertical("box", GUILayout.ExpandHeight(true));

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("LayerList");

                GUI.enabled = !EditorApplication.isPlaying;
                if (GUILayout.Button("+", GUILayout.Width(30)))
                {
                    AddLayer(null);
                }
                GUI.enabled = true;
                EditorGUILayout.EndHorizontal();

                for (int i = 0; i < eventControllerUnderEditing.layerList.Count; i++)
                {
                    var layer = eventControllerUnderEditing.layerList[i];

                    EditorGUILayout.BeginHorizontal();

                    serializedCurrentEventCtrl.Update();
                    SerializedProperty serializedLayer = serializedCurrentLayerList.GetArrayElementAtIndex(i);
                    SerializedProperty textProperty    = serializedLayer.FindPropertyRelative("name");

                    //現在編集されているレイヤー名の前に'*'を表示
                    if (layer == currentLayer)
                    {
                        EditorGUILayout.LabelField("*", GUILayout.Width(10));
                    }

                    GUI.enabled = !EditorApplication.isPlaying;
                    textProperty.stringValue = EditorGUILayout.TextField(textProperty.stringValue);
                    GUI.enabled = true;

                    serializedCurrentEventCtrl.ApplyModifiedProperties();

                    if (GUILayout.Button("Select", GUILayout.Width(50)))
                    {
                        currentLayer = layer;
                        SetEditor();
                    }

                    GUI.enabled = !EditorApplication.isPlaying;
                    if (GUILayout.Button(string.Empty, GUILayout.Width(30)))
                    {
                        GenericMenu menu = new GenericMenu();
                        menu.AddItem(new GUIContent("Delete"), false, DeleteLayer, layer);
                        menu.ShowAsContext();
                    }
                    GUI.enabled = true;

                    EditorGUILayout.EndHorizontal();
                }

                EditorGUILayout.EndVertical();

                //レイヤーが選択されていない場合はここで終了する
                if (currentLayer == null)
                {
                    return;
                }

                //----------------------------------------------------------------------------------------

                //---ゲーム実行中-------------------------------------------------------------------------------------
                if (EditorApplication.isPlaying)
                {
                    if (currentLayer.currentEventNode != null && currentLayer.currentEventNode != currentEventNodePrev)
                    {
                        currentEventNodePrev = currentLayer.currentEventNode;

                        var node = FindNode(currentLayer.serializableEventNodeList[currentLayer.eventNodeList.IndexOf(currentLayer.currentEventNode)]);
                        NodeManager.running = node;
                        //if (currentLayer.currentEventNode.eventClip is IMessageableEventClip)
                        //{

                        //}
                    }

                    if (NodeManager.running != null)
                    {
                        if (NodeManager.running.eventNode.eventClip is IMessageableEventClip)
                        {
                            messageWindow.Position = new Vector2(NodeManager.running.rect.x, NodeManager.running.rect.y + NodeManager.running.rect.height + 10.0f);
                            messageWindow.message  = ((IMessageableEventClip)NodeManager.running.eventNode.eventClip).Message;
                            //Debug.Log(messageWindow.message);
                            messageWindow.Update();
                        }
                    }

                    Repaint();
                }

                // ゲーム実行中ではない場合
                else
                {
                    NodeManager.running = null;

                    //messageWindow.OnGUIEvent = null;
                }
                //-------------------------------------------------------------------------------------------------

                //---ノード詳細画面---------------------------------------------------------------------
                // ノードを作成するための左カラムを描画していく
                EditorGUILayout.BeginVertical("box", GUILayout.ExpandHeight(true));

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(currentLayer.name);
                EditorGUILayout.EndHorizontal();

                //Game再生中は編集させない
                GUI.enabled = !EditorApplication.isPlaying;
                {
                    // テキストを表示するノードの作成
                    EditorGUILayout.BeginHorizontal();
                    inputEventClip = EditorGUILayout.ObjectField("EventClip(from GameObject)", inputEventClip, typeof(BaseEventClip), true, GUILayout.ExpandWidth(true)) as BaseEventClip;
                    //inputMonoScript = EditorGUILayout.ObjectField("EventClip", inputMonoScript, typeof(MonoScript), true, GUILayout.ExpandWidth(true)) as MonoScript;
                    if (GUILayout.Button("Create", GUILayout.Width(60)))
                    {
                        if (inputEventClip == null)
                        {
                            var eventNode = new SerializableEventNode(inputEventClip);

                            currentLayer.serializableEventNodeList.Add(eventNode);

                            var node = new TextNode(eventNode, NodeColor.Green);
                            nodes.Add(node.Id, node);

                            inputEventClip = null;
                        }
                        else if (inputEventClip.eventController == null)
                        {
                            inputEventClip.eventController = eventControllerUnderEditing;
                            //inputEventClip.layer = currentLayer;


                            var eventNode = new SerializableEventNode(inputEventClip);
                            eventNode.name = inputEventClip.gameObject.name;
                            currentLayer.serializableEventNodeList.Add(eventNode);

                            var node = new TextNode(eventNode, NodeColor.Green);
                            nodes.Add(node.Id, node);

                            inputEventClip = null;
                        }

                        // 対象のeventclipがすでに割り当てられているとき
                        else
                        {
                            ShowNotification(new GUIContent("This EventClip has already been assigned. "));
                        }
                    }

                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    inputMonoScript = EditorGUILayout.ObjectField("EventClip(from MonoScript)", inputMonoScript, typeof(MonoScript), true, GUILayout.ExpandWidth(true)) as MonoScript;
                    if (GUILayout.Button("Create", GUILayout.Width(60)))
                    {
                        //Debug.Log(inputMonoScript.GetClass());
                        if (inputMonoScript != null && inputMonoScript.GetClass() != null && inputMonoScript.GetClass().IsSubclassOf(typeof(BaseEventClip)))
                        {
                            var name = inputMonoScript.GetClass().Name;


                            //Debug.Log(name);
                            GameObject go = new GameObject();
                            go.transform.parent = eventControllerUnderEditing.transform;
                            go.name             = name;
                            Undo.AddComponent(go, inputMonoScript.GetClass());
                            Undo.RegisterCreatedObjectUndo(go, "Create Event Node( " + name + " )");

                            var eventNode = new SerializableEventNode(go.GetComponent <BaseEventClip>());
                            eventNode.eventClip.eventController = eventControllerUnderEditing;
                            //eventNode.eventClip.layer = currentLayer;

                            eventNode.name = name;
                            currentLayer.serializableEventNodeList.Add(eventNode);

                            var node = new TextNode(eventNode, NodeColor.Green);
                            nodes.Add(node.Id, node);
                            //inputMonoScript = null;
                        }
                        else
                        {
                            ShowNotification(new GUIContent("This is not EventClip."));
                        }



                        //var eventNode = new EventController.SerializableEventNode(inputEventClip);
                        //currentLayer.serializableEventNodeList.Add(eventNode);

                        //var node = new TextNode(eventNode, NodeColor.Green);
                        //nodes.Add(node.Id, node);
                        //inputEventClip = null;
                    }
                }
                GUI.enabled = true;

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();

                EditorGUILayout.EndVertical();


                EditorGUILayout.BeginVertical("box", GUILayout.ExpandHeight(true));
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Node");
                EditorGUILayout.EndHorizontal();

                var selectedNode = NodeManager.selected;

                // 前回のNodeと異なるとき
                if (selectedNode != selectedNodePrev)
                {
                    GUI.FocusControl("");



                    selectedNodePrev = selectedNode;
                }

                if (selectedNode != null)
                {
                    if (NodeManager.message == "Edit")
                    {
                        EditorGUILayout.BeginHorizontal();
                        selectedNode.eventNode.name = EditorGUILayout.TextField("Name", selectedNode.eventNode.name);
                        EditorGUILayout.EndHorizontal();


                        // 取り外し不可能なEventClipの場合は差し替えを許さない
                        if (selectedNode.eventNode.eventClip is IUndetachableEventClip)
                        {
                            GUI.enabled = false;
                        }
                        EditorGUILayout.BeginHorizontal();



                        // Nodeに割り当てるClipの選択
                        {
                            var nextEventClip = EditorGUILayout.ObjectField(
                                "EventClip", selectedNode.eventNode.eventClip, typeof(BaseEventClip), true, GUILayout.ExpandWidth(true)) as BaseEventClip;

                            // 前回のCLipと異なるとき
                            if (nextEventClip != selectedNode.eventNode.eventClip)
                            {
                                // NullからClip
                                if (selectedNode.eventNode.eventClip == null && nextEventClip != null)
                                {
                                    if (nextEventClip.eventController == null)
                                    {
                                        nextEventClip.eventController = eventControllerUnderEditing;
                                        //nextEventClip.layer = currentLayer;
                                        selectedNode.eventNode.eventClip = nextEventClip;
                                    }
                                    else
                                    {
                                        ShowNotification(new GUIContent("This EventClip has already been assigned. "));
                                    }
                                }

                                // Clipから別のClip
                                else if (selectedNode.eventNode.eventClip != null && nextEventClip != null)
                                {
                                    if (nextEventClip.eventController == null)
                                    {
                                        selectedNode.eventNode.eventClip.eventController = null;

                                        nextEventClip.eventController = eventControllerUnderEditing;
                                        //nextEventClip.layer = currentLayer;
                                        selectedNode.eventNode.eventClip = nextEventClip;
                                    }
                                    else
                                    {
                                        ShowNotification(new GUIContent("This EventClip has already been assigned. "));
                                    }
                                }

                                // ClipからNull
                                else if (selectedNode.eventNode.eventClip != null && nextEventClip == null)
                                {
                                    selectedNode.eventNode.eventClip.eventController = null;
                                    selectedNode.eventNode.eventClip = nextEventClip;
                                }
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                        GUI.enabled = true;

                        //---EventClipのプロパティーを表示, 設定--------------------------------------------

                        //Game実行中でも編集可能
                        GUI.enabled = true;

                        eventClipSettingScroll = EditorGUILayout.BeginScrollView(eventClipSettingScroll);
                        selectedEventClip      = selectedNode.eventNode.eventClip;

                        if (selectedEventClip != null)
                        {
                            Selection.activeGameObject = selectedEventClip.gameObject;

                            //タイトル
                            //eventClipFoldout = EditorGUILayout.InspectorTitlebar(eventClipFoldout, selectedEventClip);

                            //SerializedObject target = null;
                            //SerializedProperty iterator = null;
                            //if (selectedEventClip != selectedEventClipPrev)
                            //{
                            //    target = new SerializedObject(selectedEventClip);
                            //    iterator = target.GetIterator();
                            //}

                            ////SerializedObjectとproperyが存在するとき
                            //if (target != null && iterator != null)
                            //{
                            //    if (eventClipFoldout && iterator.NextVisible(true))
                            //    {
                            //        EditorGUI.indentLevel++;

                            //        //再帰的にすべてのプロパティーを表示する
                            //        do
                            //        {
                            //            eventClipPropertyDrawer.DrawSerializedProperty(iterator);
                            //        }
                            //        while (iterator.NextVisible(false));

                            //        EditorGUI.indentLevel--;
                            //    }

                            //    //編集内容を保存
                            //    target.ApplyModifiedProperties();
                            //}
                        }
                        EditorGUILayout.EndScrollView();
                    }
                    else if (NodeManager.message == "Delete")
                    {
                        DeleteNode(selectedNode);
                        NodeManager.message = "(non)";
                        Repaint();
                    }
                }
                GUI.enabled = true;
                EditorGUILayout.EndVertical();
                //----------------------------------------------------------------------------

                //---パラメータ表示-----------------------------------------------------------

                EditorGUILayout.BeginVertical("box", GUILayout.ExpandHeight(true));

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Parameters");

                // Game実行中はパラメータの追加は認めない
                if (EditorApplication.isPlaying)
                {
                    GUI.enabled = false;
                }
                if (GUILayout.Button(string.Empty, GUILayout.Width(10)))
                {
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(new GUIContent("Add/Int"), false, AddInt, null);
                    menu.AddItem(new GUIContent("Add/Float"), false, AddFloat, null);
                    menu.AddItem(new GUIContent("Add/Bool"), false, AddBool, null);
                    menu.AddItem(new GUIContent("Add/Trigger"), false, AddTrigger, null);
                    menu.ShowAsContext();
                }
                GUI.enabled = true;


                EditorGUILayout.EndHorizontal();


                parameterListScroll = EditorGUILayout.BeginScrollView(parameterListScroll);

                UpdateEventCtrlParam();

                EditorGUILayout.EndScrollView();

                EditorGUILayout.EndVertical();
                // End パラメータ表示 -------------------------------------------------------------------------------------

                //---Conditions表示--------------------------------------------------------


                EditorGUILayout.BeginVertical("box", GUILayout.ExpandHeight(true));

                UpdateEventCtrlConditions();

                EditorGUILayout.EndVertical();
                //---------------------------------------------------------------------------
            }
            EditorGUILayout.EndVertical();
            // End SideArea ----------------


            //---グラフエリア内, 何もないところで右クリック選択解除-------------------------------------------------------------
            if (MouseIsInGraphArea && currentEvent.type == EventType.MouseDown && currentEvent.button == 0)
            {
                NodeManager.selected      = null;
                ConnectorManager.selected = null;



                GUI.FocusControl("");


                Repaint();
            }
            //-----------------------------------------------------------------------------------------------

            //EventControllerに変更適用
            UpdateEventCtrlNode();
        }
 public TextNode(SerializableEventNode eventNode, NodeColor color, Rect rect) : base(rect, color)
 {
     this.text      = eventNode.name;
     this.eventNode = eventNode;
 }
 public TextNode(SerializableEventNode eventNode, NodeColor color) : base(new Rect(310, 10, 150, 50), color)
 {
     this.text      = eventNode.name;
     this.eventNode = eventNode;
 }