Exemplo n.º 1
0
 public static void SetIfCdn(UITexture tex)
 {
     if (tex == null || tex.mainTexture == null || tex.GetComponent <TexSetter>() != null)
     {
         return;
     }
     /// Add TexSetter if texture is from CDN
     if (AssetBundlePath.inst.IsCdnAsset(tex.mainTexture))
     {
         TexLoader l = tex.GetComponentEx <TexLoader>();
         TexSetter s = l.GetComponentEx <TexSetter>();
         TexSetterInspector.CopyTexture(s, l);
     }
 }
Exemplo n.º 2
0
 public override void OnInspectorGUI()
 {
     if (GUILayout.Button("Tab"))
     {
         SetTab();
     }
     if (GUILayout.Button("Set Button Text Color"))
     {
         SetButtonTextColor();
     }
     EditorGUILayout.BeginHorizontal();
     if (GUILayout.Button("Clear TexSetter"))
     {
         TexSetterInspector.ClearAllTextures();
     }
     if (GUILayout.Button("Set TexSetter"))
     {
         TexSetterInspector.SetAllTextures();
     }
     EditorGUILayout.EndHorizontal();
 }
Exemplo n.º 3
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;
        }