示例#1
0
        void OnGUI()
        {
            if (GUI.Button(new Rect(10, 10, 80, 30), "New"))
            {
                OnDestroy();
                Clear();
                chatID = 1000 + PersuadeSystem.Instacne.persuadeGroup.persuadeGroup.Count;
                Repaint();
            }
            if (GUI.Button(new Rect(10, 50, 80, 30), "Open"))
            {
                ChatJsonWindow.Open(JsonWindow.Persuade);
            }
            if (GUI.Button(new Rect(10, 90, 80, 30), "Save"))
            {
                EditorPersuadeData editorPersuade = new EditorPersuadeData();
                SetPersuadeData(editorPersuade);
                editorPersuade.m_describe = m_describeLab;
                PersuadeSystem.Instacne.SaveEditorData(m_nodes, chatID, editorPersuade);
            }

            if (GUI.Button(new Rect(10, 130, 80, 30), "Ouput"))
            {
                EditorPersuadeData editorPersuade = new EditorPersuadeData();
                SetPersuadeData(editorPersuade);
                editorPersuade.m_describe = m_describeLab;
                PersuadeData persuadeData = new PersuadeData();
                SetPersuadeData(persuadeData);
                PersuadeSystem.Instacne.SaveData(m_nodes, chatID, editorPersuade, persuadeData);
            }
            GUI.BeginGroup(new Rect(100, 5, 500, 400));
            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("ID:", GUILayout.MaxWidth(150));
            chatID = EditorGUILayout.IntField(chatID);
            EditorGUILayout.EndHorizontal();
            //m_bgImg = EditorGUILayout.ObjectField(m_bgImg, typeof(Texture), GUILayout.MaxWidth(180)) as Texture;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("描述(策划看):", GUILayout.MaxWidth(150));
            m_describeLab = EditorGUILayout.TextArea(m_describeLab);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("名称:", GUILayout.MaxWidth(150));
            persuadeName = EditorGUILayout.TextArea(persuadeName);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("开头介绍:", GUILayout.MaxWidth(150));
            introduce = EditorGUILayout.TextArea(introduce);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("关键证人ID:", GUILayout.MaxWidth(150));
            npcId = EditorGUILayout.LongField(npcId);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("证据ID数组0,1,2:", GUILayout.MaxWidth(150));
            evidenceIds = EditorGUILayout.TextField(evidenceIds);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();
            GUI.EndGroup();
            //GUI.BeginGroup(new Rect(100, 15, 200, 50));
            //GUI.EndGroup();
            var nodesToRemove = new List <int>();

            for (int i = 0; i < m_nodes.Count; i++)
            {
                if (m_nodes[i] == null)
                {
                    nodesToRemove.Add(i);
                }
            }

            for (int i = 0; i < nodesToRemove.Count; i++)
            {
                m_nodes.RemoveAt(nodesToRemove[i] - i);
            }

            BeginWindows();

            for (int i = 0; i < m_nodes.Count; i++)
            {
                m_nodes[i].Draw();
            }

            EndWindows();

            bool       isConnectionSelected = false;
            Connection connectionSelected   = null;
            float      minDistance          = float.MaxValue;

            // Collect connections
            List <Connection> connections = new List <Connection>();
            int selectedConnection        = -1;

            for (int i = 0; i < m_nodes.Count; i++)
            {
                for (int j = 0; j < m_nodes[i].Lets.Count; j++)
                {
                    Let outlet = m_nodes[i].Lets[j];
                    if (outlet.Type == LetTypes.OUTLET)
                    {
                        for (int k = 0; k < outlet.Connections.Count; k++)
                        {
                            Connection connection = outlet.Connections[k];
                            connections.Add(connection);

                            List <Vector2> points = new List <Vector2>();
                            points.Add(new Vector2(connection.Inlet.Position.center.x, connection.Inlet.Position.center.y));
                            for (int l = 0; l < connection.Points.Length; l++)
                            {
                                points.Add(connection.Points[l]);
                            }
                            points.Add(new Vector2(connection.Outlet.Position.center.x, connection.Outlet.Position.center.y));

                            for (int l = 0; l < points.Count - 1; l++)
                            {
                                float distance = MouseDistanceToLine(points[l], points[l + 1]);

                                if (distance < 20.0f)
                                {
                                    if (distance < minDistance)
                                    {
                                        minDistance          = distance;
                                        isConnectionSelected = true;
                                        connectionSelected   = connection;
                                        selectedConnection   = connections.Count - 1;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Draw connections
            for (int i = 0; i < connections.Count; i++)
            {
                Connection connection = connections[i];

                List <Vector2> points = new List <Vector2>();
                points.Add(connection.Inlet.Position.center);
                for (int j = 0; j < connection.Points.Length; j++)
                {
                    points.Add(connection.Points[j]);
                }
                points.Add(connection.Outlet.Position.center);

                for (int j = 0; j < points.Count - 1; j++)
                {
                    if (i != selectedConnection)
                    {
                        DrawLine(points[j], points[j + 1], ConnectionColor);
                    }
                    else
                    {
                        DrawLine(points[j], points[j + 1], Color.blue);
                    }
                }
            }

            // Process events
            if (Event.current.type == EventType.MouseMove)
            {
                bool handled = false;
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    if (m_nodes[i].MouseOver(Event.current.mousePosition))
                    {
                        handled = true;

                        break;
                    }
                }

                if (!handled)
                {
                    // Do something
                }

                Repaint();
            }
            else if (Event.current.type == EventType.MouseDown && m_currentMouseMode != MouseModes.CONNECTING)
            {
                bool handled = false;
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    if (m_nodes[i].MouseDown(Event.current.mousePosition, Event.current.button))
                    {
                        handled = true;
                    }
                }

                if (!handled && Event.current.button == 1)
                {
                    if (!isConnectionSelected)
                    {
                        CreateNodeMenu();
                    }
                    else
                    {
                        BreakConnectionMenu(connectionSelected.Inlet, connectionSelected.Outlet);
                    }
                }
                else if (!handled && Event.current.button == 0)
                {
                    m_startMousePos = Event.current.mousePosition;
                }
            }
            else if (Event.current.type == EventType.MouseDown && m_currentMouseMode == MouseModes.CONNECTING)
            {
                if (Event.current.button == 0)
                {
                    m_livePoints.Add(Event.current.mousePosition);
                    Repaint();
                }
                else if (Event.current.button == 1)
                {
                    m_currentMouseMode = MouseModes.IDLE;
                    m_livePoints.Clear();
                }
            }
            else if (Event.current.type == EventType.MouseDrag)
            {
                bool handled = false;
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    if (m_nodes[i].MouseDrag(Event.current.mousePosition))
                    {
                        handled = true;
                        break;
                    }
                }

                if (!handled)
                {
                    if (Event.current.shift)
                    {
                        Vector2 offset = Event.current.mousePosition - m_startMousePos;
                        for (int i = 0; i < m_nodes.Count; i++)
                        {
                            m_nodes[i].Position += offset;
                        }

                        Repaint();

                        m_startMousePos = Event.current.mousePosition;
                        handled         = true;
                    }
                }
            }
            else if (Event.current.type == EventType.MouseUp)
            {
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    m_nodes[i].MouseUp(Event.current.mousePosition);
                }
            }

            if (m_currentMouseMode == MouseModes.CONNECTING)
            {
                List <Vector2> points = new List <Vector2>();
                points.Add(m_startMousePos);
                for (int i = 0; i < m_livePoints.Count; i++)
                {
                    points.Add(m_livePoints[i]);
                }
                points.Add(Event.current.mousePosition);

                for (int i = 0; i < points.Count - 1; i++)
                {
                    DrawConnectingCurve(points[i], points[i + 1]);
                }

                Repaint();
            }

            List <BaseNode> nodesToDelete = new List <BaseNode>();

            foreach (BaseNode node in m_nodes)
            {
                if (!node.Valid)
                {
                    nodesToDelete.Add(node);
                }
            }

            foreach (BaseNode node in nodesToDelete)
            {
                m_nodes.Remove(node);

                node.BreakAllLets();

                // DestroyImmediate(node.gameObject);
            }

            if (nodesToDelete.Count > 0)
            {
                Repaint();
            }
        }
示例#2
0
        void OnGUI()
        {
            if (GUI.Button(new Rect(10, 10, 80, 30), "New"))
            {
                OnDestroy();
                Clear();
                chatID = 1000 + ChatSystemManager.Instacne.chatGroup.m_chats.Count;
                Repaint();
            }
            if (GUI.Button(new Rect(10, 50, 80, 30), "Open"))
            {
                ChatJsonWindow.Open();
            }
            if (GUI.Button(new Rect(10, 90, 80, 30), "Save"))
            {
                string bgName = string.Empty;
                if (m_bgImg != null)
                {
                    bgName = UnityEditor.AssetDatabase.GetAssetPath(m_bgImg);
                }
                ChatSystemManager.Instacne.SaveEditorChatData(m_nodes, bgName, chatID, m_describeLab);
            }

            if (GUI.Button(new Rect(10, 130, 80, 30), "Ouput"))
            {
                //string bgName = string.Empty;
                //if (m_bgImg != null)
                //{
                //    bgName = m_bgImg.name + ".png";
                //}
                ChatSystemManager.Instacne.SaveChatData(m_nodes, m_bgImg, chatID, m_describeLab);
            }
            GUI.BeginGroup(new Rect(100, 5, 200, 200));
            EditorGUILayout.BeginVertical();
            chatID        = EditorGUILayout.IntField(chatID);
            m_bgImg       = EditorGUILayout.ObjectField(m_bgImg, typeof(Texture), GUILayout.MaxWidth(180)) as Texture;
            m_describeLab = EditorGUILayout.TextArea(m_describeLab);
            EditorGUILayout.EndVertical();
            GUI.EndGroup();
            //GUI.BeginGroup(new Rect(100, 15, 200, 50));
            //GUI.EndGroup();
            var nodesToRemove = new List <int>();

            for (int i = 0; i < m_nodes.Count; i++)
            {
                if (m_nodes[i] == null)
                {
                    nodesToRemove.Add(i);
                }
            }

            for (int i = 0; i < nodesToRemove.Count; i++)
            {
                m_nodes.RemoveAt(nodesToRemove[i] - i);
            }

            BeginWindows();

            for (int i = 0; i < m_nodes.Count; i++)
            {
                m_nodes[i].Draw();
            }

            EndWindows();

            bool       isConnectionSelected = false;
            Connection connectionSelected   = null;
            float      minDistance          = float.MaxValue;

            // Collect connections
            List <Connection> connections = new List <Connection>();
            int selectedConnection        = -1;

            for (int i = 0; i < m_nodes.Count; i++)
            {
                for (int j = 0; j < m_nodes[i].Lets.Count; j++)
                {
                    Let outlet = m_nodes[i].Lets[j];
                    if (outlet.Type == LetTypes.OUTLET)
                    {
                        for (int k = 0; k < outlet.Connections.Count; k++)
                        {
                            Connection connection = outlet.Connections[k];
                            connections.Add(connection);

                            List <Vector2> points = new List <Vector2>();
                            points.Add(new Vector2(connection.Inlet.Position.center.x, connection.Inlet.Position.center.y));
                            for (int l = 0; l < connection.Points.Length; l++)
                            {
                                points.Add(connection.Points[l]);
                            }
                            points.Add(new Vector2(connection.Outlet.Position.center.x, connection.Outlet.Position.center.y));

                            for (int l = 0; l < points.Count - 1; l++)
                            {
                                float distance = MouseDistanceToLine(points[l], points[l + 1]);

                                if (distance < 20.0f)
                                {
                                    if (distance < minDistance)
                                    {
                                        minDistance          = distance;
                                        isConnectionSelected = true;
                                        connectionSelected   = connection;
                                        selectedConnection   = connections.Count - 1;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Draw connections
            for (int i = 0; i < connections.Count; i++)
            {
                Connection connection = connections[i];

                List <Vector2> points = new List <Vector2>();
                points.Add(connection.Inlet.Position.center);
                for (int j = 0; j < connection.Points.Length; j++)
                {
                    points.Add(connection.Points[j]);
                }
                points.Add(connection.Outlet.Position.center);

                for (int j = 0; j < points.Count - 1; j++)
                {
                    if (i != selectedConnection)
                    {
                        DrawLine(points[j], points[j + 1], ConnectionColor);
                    }
                    else
                    {
                        DrawLine(points[j], points[j + 1], Color.blue);
                    }
                }
            }

            // Process events
            if (Event.current.type == EventType.MouseMove)
            {
                bool handled = false;
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    if (m_nodes[i].MouseOver(Event.current.mousePosition))
                    {
                        handled = true;

                        break;
                    }
                }

                if (!handled)
                {
                    // Do something
                }

                Repaint();
            }
            else if (Event.current.type == EventType.MouseDown && m_currentMouseMode != MouseModes.CONNECTING)
            {
                bool handled = false;
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    if (m_nodes[i].MouseDown(Event.current.mousePosition, Event.current.button))
                    {
                        handled = true;
                    }
                }

                if (!handled && Event.current.button == 1)
                {
                    if (!isConnectionSelected)
                    {
                        CreateNodeMenu();
                    }
                    else
                    {
                        BreakConnectionMenu(connectionSelected.Inlet, connectionSelected.Outlet);
                    }
                }
                else if (!handled && Event.current.button == 0)
                {
                    m_startMousePos = Event.current.mousePosition;
                }
            }
            else if (Event.current.type == EventType.MouseDown && m_currentMouseMode == MouseModes.CONNECTING)
            {
                if (Event.current.button == 0)
                {
                    m_livePoints.Add(Event.current.mousePosition);
                    Repaint();
                }
                else if (Event.current.button == 1)
                {
                    m_currentMouseMode = MouseModes.IDLE;
                    m_livePoints.Clear();
                }
            }
            else if (Event.current.type == EventType.MouseDrag)
            {
                bool handled = false;
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    if (m_nodes[i].MouseDrag(Event.current.mousePosition))
                    {
                        handled = true;
                        break;
                    }
                }

                if (!handled)
                {
                    if (Event.current.shift)
                    {
                        Vector2 offset = Event.current.mousePosition - m_startMousePos;
                        for (int i = 0; i < m_nodes.Count; i++)
                        {
                            m_nodes[i].Position += offset;
                        }

                        Repaint();

                        m_startMousePos = Event.current.mousePosition;
                        handled         = true;
                    }
                }
            }
            else if (Event.current.type == EventType.MouseUp)
            {
                for (int i = 0; i < m_nodes.Count; i++)
                {
                    m_nodes[i].MouseUp(Event.current.mousePosition);
                }
            }

            if (m_currentMouseMode == MouseModes.CONNECTING)
            {
                List <Vector2> points = new List <Vector2>();
                points.Add(m_startMousePos);
                for (int i = 0; i < m_livePoints.Count; i++)
                {
                    points.Add(m_livePoints[i]);
                }
                points.Add(Event.current.mousePosition);

                for (int i = 0; i < points.Count - 1; i++)
                {
                    DrawConnectingCurve(points[i], points[i + 1]);
                }

                Repaint();
            }

            List <BaseNode> nodesToDelete = new List <BaseNode>();

            foreach (BaseNode node in m_nodes)
            {
                if (!node.Valid)
                {
                    nodesToDelete.Add(node);
                }
            }

            foreach (BaseNode node in nodesToDelete)
            {
                m_nodes.Remove(node);

                node.BreakAllLets();

                // DestroyImmediate(node.gameObject);
            }

            if (nodesToDelete.Count > 0)
            {
                Repaint();
            }
        }