Exemplo n.º 1
0
    static void RegisterCollection(tmTextureCollectionBase collection, List <tmTextureCollectionIndex> collections)
    {
        tmTextureCollectionIndex index = collections.Find(f => f.textureCollectionGUID.Equals(collection.collectionGuid));

        if (index == null)
        {
            index = new tmTextureCollectionIndex();
            collections.Add(index);
        }

        index.name                  = collection.name;
        index.assetGUID             = collection.assetGuid;
        index.textureCollectionGUID = collection.collectionGuid;
        //		index.editorLink = collection;

        collection.textureDefenitions.Sort((a, b) => (string.Compare(a.textureName, b.textureName, System.StringComparison.OrdinalIgnoreCase)));

        List <string> names = new List <string>();
        List <string> guids = new List <string>();

        foreach (tmTextureDefenition def in collection.textureDefenitions)
        {
            names.Add(def.textureName);
            guids.Add(def.assetGuid);
        }

        index.textureNames = names.ToArray();
        index.textureGUIDs = guids.ToArray();

        collections.Sort((a, b) => (string.Compare(a.name, b.name, System.StringComparison.OrdinalIgnoreCase)));
        UnityEditor.EditorUtility.SetDirty(tmIndex.Instance);
    }
    static bool TexturePopup(string label, tmTextureCollectionBase collection, ref string texureID)
    {
        int           entryIndex  = 0;
        List <string> texureNames = new List <string>();

        texureNames.Add("-");

        if (collection != null)
        {
            for (int i = 0; i < collection.textureDefenitions.Count; i++)
            {
                tmTextureDefenition def = collection.textureDefenitions[i];
                texureNames.Add(def.textureName);

                if (def.textureGuid.Equals(texureID))
                {
                    entryIndex = i + 1;
                }
            }
        }

        int lastIndex = entryIndex;

        entryIndex = EditorGUILayout.Popup(label, entryIndex, texureNames.ToArray());

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel(" ");
        Rect rect = EditorGUILayout.GetControlRect(GUILayout.Width(100), GUILayout.Height(100));

        EditorGUI.DrawRect(rect, Color.black);
        if (entryIndex != -1)
        {
            if (entryIndex == 0)
            {
                texureID = "";
            }
            else
            {
                tmTextureDefenition def = collection.textureDefenitions[entryIndex - 1];
                EditorGUI.DrawTextureTransparent(rect, def.texture, ScaleMode.ScaleToFit, def.texture == null ? 1f : (def.texture.width * 1f / def.texture.height));
                texureID = def.textureGuid;

                if (rect.Contains(Event.current.mousePosition))
                {
                    if (Event.current.clickCount == 1)
                    {
                        if (def.texture)
                        {
                            EditorGUIUtility.PingObject(def.texture);
                        }
                        Event.current.Use();
                    }
                }
            }
        }
        EditorGUILayout.EndHorizontal();

        return(lastIndex != entryIndex);
    }
Exemplo n.º 3
0
 public void RegisterPlatformCollection(tmTextureCollectionBase collection)
 {
     RegisterCollection(collection, tmIndex.Instance.TexturePlatformCollections);
 }