예제 #1
0
 public static void ChangeTexture(Texture srcTex, Texture dstTex)
 {
     EditorTraversal.ForEachAsset <GameObject>(FileType.Prefab, (path, popup) => {
         foreach (UITexture t in popup.GetComponentsInChildren <UITexture>(true))
         {
             if (t.mainTexture == srcTex)
             {
                 t.mainTexture = dstTex;
                 EditorUtil.SetDirty(t);
             }
         }
     });
     EditorTraversal.ForEachScene(s => {
         foreach (var r in s.GetRootGameObjects())
         {
             var root = r.transform;
             foreach (UITexture t in root.GetComponentsInChildren <UITexture>(true))
             {
                 if (t.mainTexture == srcTex)
                 {
                     t.mainTexture = dstTex;
                     EditorUtil.SetDirty(t);
                 }
             }
         }
         return(null);
     });
 }
예제 #2
0
    public static string FindTextKey(string keys)
    {
        HashSet <string> keySet = new HashSet <string>(keys.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries));
        StringBuilder    result = new StringBuilder();

        result.Append("[From Resource]\n");
        EditorTraversal.ForEachAsset <GameObject>(FileType.Prefab, (path, popup) => {
            foreach (UIText l in popup.GetComponentsInChildren <UIText>(true))
            {
                if (!l.textKey.IsEmpty() && keySet.Contains(l.textKey))
                {
                    result.AppendFormat("{0}: {1}\n", l.textKey, l.transform.GetScenePath());
                }
            }
        });
        EditorTraversal.ForEachScene(s => {
            result.AppendFormat("[Scene {0}]\n", SceneManager.GetActiveScene().path);
            foreach (var r in s.GetRootGameObjects())
            {
                var root = r.transform;
                foreach (UIText l in root.GetComponentsInChildren <UIText>(true))
                {
                    if (!l.textKey.IsEmpty() && keySet.Contains(l.textKey))
                    {
                        result.AppendFormat("{0}: {1}\n", l.textKey, l.transform.GetScenePath());
                    }
                }
            }
            return(null);
        });
        return(result.ToString());
    }
예제 #3
0
 private void TranslateLanguage()
 {
     ReloadTable();
     EditorTraversal.ForEachScene(s =>
     {
         foreach (var r in s.GetRootGameObjects())
         {
             var root = r.transform;
             foreach (UIText l in root.GetComponentsInChildren <UIText>(true))
             {
                 TranslateLabel(l);
             }
         }
         return(null);
     });
     EditorTraversal.ForEachAsset <GameObject>(FileType.Prefab, (path, popup) =>
     {
         foreach (UIText l in popup.GetComponentsInChildren <UIText>(true))
         {
             TranslateLabel(l);
         }
     });
 }
예제 #4
0
        public override void OnInspectorGUI()
        {
            if (EditorUI.DrawHeader("Sprite -> Texture"))
            {
                EditorUI.BeginContents();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayoutUtil.ObjectField <Object>("Folder", ref texFolder, false);
                if (GUILayout.Button("Sprite -> Texture") && EditorUtility.DisplayDialog("Warning", "BackUp?", "OK", "Cancel"))
                {
                    ConvertToTexture(texFolder);
                }
                EditorGUILayout.EndHorizontal();
                var drawer = new ListDrawer <UITexture>(texList, new ObjListItemDrawer <UITexture>());
                drawer.Draw();
                EditorUI.EndContents();
            }
            if (EditorUI.DrawHeader("Texture -> Sprite"))
            {
                EditorUI.BeginContents();
                EditorGUILayout.BeginHorizontal();
                ComponentSelector.Draw <NGUIAtlas>("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 <NGUIAtlas>());
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayoutUtil.TextField("Search sprite", ref searchSpriteName);
                if (!searchSpriteName.IsEmpty())
                {
                    List <NGUIAtlas> filtered = new List <NGUIAtlas>();
                    foreach (NGUIAtlas a in atlasRefs)
                    {
                        if (a.GetSprite(searchSpriteName) != null)
                        {
                            filtered.Add(a);
                        }
                    }
                    var drawer = new ListDrawer <NGUIAtlas>(filtered, new ObjListItemDrawer <NGUIAtlas>());
                    drawer.Draw();
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayoutUtil.Popup("Change to", ref changeAtlas, filtered);
                    if (GUILayout.Button("Apply"))
                    {
                        EditorTraversal.ForEachAsset <GameObject>(FileType.Prefab, (path, prefab) => {
                            ChangeAtlas(prefab, filtered, changeAtlas);
                        });
                        EditorTraversal.ForEachScene(s => {
                            foreach (var r in s.GetRootGameObjects())
                            {
                                ChangeAtlas(r.gameObject, filtered, changeAtlas);
                            }
                            return(null);
                        });
                    }
                    EditorGUILayout.EndHorizontal();
                    var spriteDrawer = new ListDrawer <UISprite>(spriteList, new ObjListItemDrawer <UISprite>());
                    spriteDrawer.Draw();
                }
                else
                {
                    var drawer = new ListDrawer <NGUIAtlas>(atlasRefs, new ObjListItemDrawer <NGUIAtlas>());
                    if (drawer.Draw())
                    {
                        SaveAtlasRefs();
                    }
                }
                if (!dupSprites.IsEmpty())
                {
                    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();
                EditorGUILayoutUtil.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 <NGUIAtlas, UISprite> collect = new MultiMap <NGUIAtlas, UISprite>();
                        foreach (UISprite s in targetObj.GetComponentsInChildren <UISprite>(true))
                        {
                            collect.Add(s.atlas as NGUIAtlas, s);
                        }
                        foreach (KeyValuePair <NGUIAtlas, 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 <NGUIAtlas>("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;
        }