示例#1
0
        private bool DrawRowHeader()
        {
            bool changed = false;

            EditorGUILayout.BeginVertical();
            changed |= EditorGUIUtil.ObjectField <UITableCell>(ref table.defaultPrefab, true, W_Option, H_Option);
            EditorGUILayout.LabelField("Align", EditorStyles.boldLabel, H_Option);
            EditorGUILayout.LabelField("Size", EditorStyles.boldLabel, H_Option);
            EditorGUILayout.LabelField("Index", EditorStyles.boldLabel, H_Option);
            int row = table.isVertical? table.GetMaxPerLine(): table.rowCount;

            table.InitArray();
            for (int r = 0; r < row; r++)
            {
                EditorGUILayout.BeginHorizontal();
                changed |= EditorGUIUtil.ObjectField <UITableCell>(ref table.rowPrefab[r], true, GUILayout.Width(WIDTH - 20), H_Option);
                changed |= EditorGUIUtil.Popup <UITableLayout.VAlign>(ref table.valigns[r], EnumUtil.Values <UITableLayout.VAlign>(), GUILayout.Width(40), H_Option);
                changed |= EditorGUIUtil.IntField(null, ref table.rowHeight[r], GUILayout.Width(WIDTH - 30), H_Option);
                EditorGUILayout.LabelField((r + 1).ToString(), EditorStyles.boldLabel, GUILayout.Width(20), H_Option);
                EditorGUILayout.EndHorizontal();
            }
            if (!IsHorizontal())
            {
                EditorGUILayout.LabelField("", W_Option);
                EditorGUILayout.LabelField("", W_Option);
                EditorGUILayout.LabelField("", W_Option);
            }
            EditorGUILayout.EndVertical();
            if (changed)
            {
                table.InitArray();
            }
            return(changed);
        }
示例#2
0
        private bool DrawColumn()
        {
            bool changed     = false;
            int  columnSize  = table.isHorizontal? table.GetMaxPerLine(): table.columnCount;
            int  contentSize = table.columnCount;

            for (int c = 0; c < columnSize; c++)
            {
                EditorGUILayout.BeginVertical();
                changed |= EditorGUIUtil.ObjectField <UITableCell>(ref table.columnPrefab[c], true, GUILayout.ExpandWidth(false), H_Option);
                changed |= EditorGUIUtil.Popup <UITableLayout.HAlign>(ref table.haligns[c], EnumUtil.Values <UITableLayout.HAlign>(), GUILayout.Width(WIDTH - 20), H_Option);
                changed |= EditorGUIUtil.IntField(null, ref table.columnWidth[c], GUILayout.Width(WIDTH - 20), H_Option);
                EditorGUILayout.LabelField(c.ToString(), EditorStyles.boldLabel, W_Option, H_Option);
                int row = table.rowCount;
                if (c < contentSize)
                {
                    for (int r = 0; r < row; r++)
                    {
                        changed |= DrawCell(r, c);
                    }

                    // Draw Column +/- buttons
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button(new GUIContent("A", "Add Selected"), GUILayout.ExpandWidth(false), H_Option))
                    {
                        AddSelected(c, UITableLayout.Arrangement.Vertical);
                        changed = true;
                    }
                    if (GUILayout.Button("+", GUILayout.ExpandWidth(false), H_Option))
                    {
                        #pragma warning disable 0618
                        table.AddColumn(c + 1, new UITableCell[table.rowCount]);
                        #pragma warning restore 0618
                        changed = true;
                    }
                    GUI.enabled = c >= table.columnHeader;
                    if (GUILayout.Button("-", GUILayout.ExpandWidth(false), H_Option))
                    {
                        if (EditorUtility.DisplayDialog("Confirm", "Delete column " + (c + 1), "OK", "Cancel"))
                        {
                            #pragma warning disable 0618
                            table.RemoveColumn(c);
                            #pragma warning restore 0618
                            table.Reposition();
                            changed = true;
                        }
                    }
                    GUI.enabled = true;
                    EditorGUILayout.EndHorizontal();
                }

                EditorGUILayout.EndVertical();
            }
            return(changed);
        }
 public override void OnFooterGUI()
 {
     if (atlasFrom != null && atlasTo != null)
     {
         if (duplicateSprites.Count > 0)
         {
             if (GUILayout.Button(atlasFrom.name + " -> " + atlasTo.name))
             {
                 SwitchAtlas();
             }
         }
         NGUIEditorTools.DrawSeparator();
         EditorGUILayout.BeginHorizontal();
         EditorGUILayout.BeginVertical();
         EditorGUIUtil.Popup <string>("Sprite From", ref spriteName1, atlasFrom.GetListOfSprites().ToArray());
         EditorGUIUtil.Popup <string>("Sprite To", ref spriteName2, atlasTo.GetListOfSprites().ToArray());
         EditorGUILayout.EndVertical();
         if (GUILayout.Button("Replace", GUILayout.ExpandWidth(false), GUILayout.Height(30)))
         {
             SwitchSprite(spriteName1, spriteName2);
         }
         EditorGUILayout.EndHorizontal();
     }
 }
示例#4
0
        public override void OnInspectorGUI()
        {
            if (EditorUI.DrawHeader("Sprite -> Texture"))
            {
                EditorUI.BeginContents();
                EditorGUILayout.BeginHorizontal();
                EditorGUIUtil.ObjectField <Object>("Folder", ref texFolder, false);
                if (GUILayout.Button("Sprite -> Texture") && EditorUtility.DisplayDialog("Warning", "BackUp?", "OK", "Cancel"))
                {
                    ConvertToTexture(texFolder);
                }
                EditorGUILayout.EndHorizontal();
                EditorGUIUtil.ObjectFieldReorderList(texList);
                EditorUI.EndContents();
            }
            if (EditorUI.DrawHeader("Texture -> Sprite"))
            {
                EditorUI.BeginContents();
                EditorGUILayout.BeginHorizontal();
                ComponentSelector.Draw <UIAtlas>("Atlas", atlasToAdd, OnSelectAtlas, true, GUILayout.MinWidth(80f));
                if (GUILayout.Button("Add Selected"))
                {
                    foreach (Object o in Selection.objects)
                    {
                        if (o is GameObject)
                        {
                            OnSelectAtlas((o as GameObject).GetComponent <UIAtlas>());
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
                EditorGUIUtil.TextField("Search sprite", ref searchSpriteName);
                if (searchSpriteName.IsNotEmpty())
                {
                    List <UIAtlas> filtered = new List <UIAtlas>();
                    foreach (UIAtlas a in atlasRefs)
                    {
                        if (a.GetSprite(searchSpriteName) != null)
                        {
                            filtered.Add(a);
                        }
                    }
                    EditorGUIUtil.ObjectFieldReorderList(filtered);
                    EditorGUILayout.BeginHorizontal();
                    EditorGUIUtil.Popup("Change to", ref changeAtlas, filtered);
                    if (GUILayout.Button("Apply"))
                    {
                        BuildScript.ForEachPrefab((path, prefab) => {
                            ChangeAtlas(prefab, filtered, changeAtlas);
                            return(null);
                        });
                        BuildScript.ForEachScene(list => {
                            foreach (Transform t in list)
                            {
                                ChangeAtlas(t.gameObject, filtered, changeAtlas);
                            }
                            return(null);
                        });
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUIUtil.ObjectFieldReorderList(spriteList);
                }
                else
                {
                    if (EditorGUIUtil.ObjectFieldReorderList(atlasRefs))
                    {
                        SaveAtlasRefs();
                    }
                }
                if (dupSprites.IsNotEmpty())
                {
                    if (EditorUI.DrawHeader("Duplicate sprites"))
                    {
                        EditorUI.BeginContents();
                        float cellWidth = 200f;
                        float width     = GetWidth();
                        int   column    = Mathf.Max((int)(width / cellWidth), 1);
                        int   i         = 0;
                        foreach (string d in dupSprites)
                        {
                            if (i == 0)
                            {
                                EditorGUILayout.BeginHorizontal();
                            }
                            if (GUILayout.Button(d, GUILayout.Width(200)))
                            {
                                searchSpriteName = d;
                            }
                            i = i + 1;
                            if (i == column)
                            {
                                EditorGUILayout.EndHorizontal();
                                i = 0;
                            }
                        }
                        if (i != 0)
                        {
                            EditorGUILayout.EndHorizontal();
                        }
                        EditorUI.EndContents();
                    }
                }
                EditorGUILayout.BeginHorizontal();
                EditorGUIUtil.ObjectField("Target", ref targetObj, true);
                GUI.enabled = targetObj != null;
                if (GUILayout.Button("Convert to Sprite") && EditorUtility.DisplayDialog("Warning", "BackUp?", "OK"))
                {
                    ConvertToSprite();
                }
                if (GUILayout.Button("Set TexSetter"))
                {
                    foreach (UITexture tex in targetObj.GetComponentsInChildren <UITexture>(true))
                    {
                        TexSetterInspector.SetIfCdn(tex);
                    }
                }
                GUI.enabled = true;
                EditorGUILayout.EndHorizontal();
                // collect atlas
                GUI.enabled = targetObj != null;
                if (EditorUI.DrawHeader("Member Atlases"))
                {
                    EditorUI.BeginContents();
                    if (targetObj != null)
                    {
                        MultiMap <UIAtlas, UISprite> collect = new MultiMap <UIAtlas, UISprite>();
                        foreach (UISprite s in targetObj.GetComponentsInChildren <UISprite>(true))
                        {
                            collect.Add(s.atlas, s);
                        }
                        foreach (KeyValuePair <UIAtlas, List <UISprite> > pair in collect)
                        {
                            if (EditorGUILayout.Foldout(folding.Contains(pair.Key), pair.Key.name))
                            {
                                folding.Add(pair.Key);
                                EditorGUI.indentLevel++;
                                foreach (UISprite s in pair.Value)
                                {
                                    EditorGUILayout.ObjectField(s.gameObject, typeof(GameObject), true);
                                }
                                EditorGUI.indentLevel--;
                            }
                            else
                            {
                                folding.Remove(pair.Key);
                            }
                        }
                    }
                    EditorUI.EndContents();
                }
                if (EditorUI.DrawHeader("Orphan Texture"))
                {
                    EditorUI.BeginContents();
                    if (targetObj != null)
                    {
                        foreach (UITexture tex in targetObj.GetComponentsInChildren <UITexture>(true))
                        {
                            if (tex.GetComponent <TexLoader>() == null)
                            {
                                EditorGUILayout.BeginHorizontal();
                                EditorGUILayout.ObjectField(tex.gameObject, typeof(GameObject), true);
                                EditorGUILayout.ObjectField(tex.mainTexture, typeof(Texture), false);
                                EditorGUILayout.EndHorizontal();
                            }
                        }
                    }
                    EditorUI.EndContents();
                }
                GUI.enabled = true;

                EditorUI.EndContents();
            }
            if (EditorUI.DrawHeader("Find All Sprites"))
            {
                EditorUI.BeginContents();
                EditorGUILayout.BeginHorizontal();
                ComponentSelector.Draw <UIAtlas>("Atlas", atlas4Sprite, OnSelectAtlasForSprite, true, GUILayout.MinWidth(80f));
                if (GUILayout.Button("Find"))
                {
                    var list = Resources.FindObjectsOfTypeAll <UISprite>().ToList(i => i as UISprite);
                    s4a.Clear();
                    foreach (var s in list)
                    {
                        if (s.atlas == atlas4Sprite)
                        {
                            s4a.Add(s);
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
                EditorUI.EndContents();
            }
            GUI.enabled = true;
        }