Пример #1
0
 /// <summary>
 /// Called when user select a graph type to create
 /// </summary>
 /// <param name="data">graph data</param>
 private void OnNewGraph(object data)
 {
     ModuleData      = (GraphModuleAttribute)data;
     CurrentGUIState = 1;
 }
Пример #2
0
        /// <summary>
        /// Displays open graph panel
        /// </summary>
        /// <param name="scrollpoint">Open graph scroll point</param>
        /// <param name="searchfilter">Open graph search filter</param>
        /// <param name="Graphs">Graphs list</param>
        /// <param name="OnOpen">On open action</param>
        /// <param name="OnCancel">On cancel action</param>
        /// <param name="OnDelete">On delete action</param>
        public static void OpenGraphPanel(ref Vector2 scrollpoint, ref string searchfilter, NodeGraph[] Graphs,
                                          System.Action <NodeGraph> OnOpen, System.Action OnCancel, System.Action OnDelete)
        {
            Vector2 size = new Vector2(350, 320);

            Rect r = new Rect((Screen.width / 2) - (size.x / 2), (Screen.height / 2) - (size.y / 2), size.x, size.y);

            GUI.Box(r, "", GUI.skin.FindStyle("WindowBackground"));


            GUI.BeginGroup(r);

            GUI.Box(new Rect(0, 0, r.width - 50, 15), "", EditorStyles.toolbar);

            GUI.Label(new Rect(5, 0, 100, 20), "Open Graph");

            if (GUI.Button(new Rect(r.width - 50, 0, 50, 15), "Close", EditorStyles.toolbarButton))
            {
                OnCancel.Invoke();
            }

            Rect searchRect = new Rect(10, 28, r.width - 20, 15);

            searchfilter = MoonGUI.SearchTextField(searchRect, searchfilter);

            //EditorGUI.DrawRect(searchRect, Color.blue);

            Rect ScrollRect = new Rect(5, 50, r.width - 15, r.height - 60);

            GUI.Box(ScrollRect, "", GUI.skin.FindStyle("AnimationKeyframeBackground"));

            scrollpoint = GUI.BeginScrollView(ScrollRect, scrollpoint, new Rect(0, 0, ScrollRect.width - 20, Graphs.Length * 25), false, true);

            if (Graphs != null && Graphs.Length > 0)
            {
                for (int i = 0; i < Graphs.Length; i++)
                {
                    Rect baserect = new Rect(ScrollRect.x, i * 25, ScrollRect.width - 25, 20);

                    NodeGraph current = Graphs[i];

                    if (current != null)
                    {
                        GraphModuleAttribute module = MoonReflection.GetAttribute(current.GetType(), typeof(GraphModuleAttribute), true)
                                                      as GraphModuleAttribute;

                        if (module != null)
                        {
                            GUI.Box(baserect, "");

                            GUI.BeginGroup(baserect);

                            Rect labelrect = new Rect(5, 0, baserect.width * 0.8f, baserect.height);


                            Rect namerect = new Rect(labelrect.x, labelrect.y, labelrect.width * 0.55f, labelrect.height);

                            //EditorGUI.DrawRect(namerect, Color.blue);


                            GUI.Label(namerect, current.name);

                            Rect TypeRect = new Rect(namerect.xMax + 5, labelrect.y, labelrect.width * 0.45f, labelrect.height);

                            GUI.Label(TypeRect, module.Name, GUI.skin.FindStyle("PreToolbar"));

                            //EditorGUI.DrawRect(TypeRect, Color.red);

                            Rect loadrect = new Rect(TypeRect.xMax + 5, TypeRect.y + 2, 15, 15);

                            if (GUI.Button(loadrect, new GUIContent("", "Load"), GUI.skin.FindStyle("OL Plus")))
                            {
                                OnOpen.Invoke(current);
                            }

                            Rect removerect = new Rect(loadrect.xMax + 5, loadrect.y, 15, 15);

                            if (GUI.Button(removerect, new GUIContent("", "Remove"), GUI.skin.FindStyle("OL Minus")))
                            {
                                bool ok = EditorUtility.DisplayDialog("Delete", "Are you sure to DELETE the graph '" + current.name + "' ?",
                                                                      "Yes", "No");

                                if (ok)
                                {
                                    AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(current));
                                    OnDelete.Invoke();
                                }
                            }

                            GUI.EndGroup();
                        }
                    }
                    else
                    {
                        OnDelete.Invoke();
                    }
                }
            }
            GUI.EndScrollView();

            GUI.EndGroup();
        }