コード例 #1
0
ファイル: MadAtlasUtil.cs プロジェクト: tng2903/game1
 public static Texture2D GetItemOrigin(MadAtlas.Item item) {
     var path = AssetDatabase.GUIDToAssetPath(item.textureGUID);
     if (string.IsNullOrEmpty(path)) {
         return null;
     }
     
     return AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D;
 }
コード例 #2
0
    public static void Show(MadAtlas atlas, string currentGUID, Changed changedCallback)
    {
        //var window = ScriptableObject.CreateInstance<MadAtlasBrowser>();
        var browser = EditorWindow.GetWindow <MadAtlasBrowser>(true, "Atlas Browser", true);

        browser.atlas            = atlas;
        browser.changedCallback  = changedCallback;
        browser.selectedItemGUID = currentGUID;
    }
コード例 #3
0
    public static void RebuildAtlas(MadAtlas atlas)
    {
        List <MadAtlas.Item> liveItems = LiveItems(atlas);

        List <Texture2D> allTextures = new List <Texture2D>();

        allTextures.AddRange(from i in liveItems select MadAtlasUtil.GetItemOrigin(i));

        RebuildAtlas(atlas, allTextures, liveItems);
    }
コード例 #4
0
 public static void Show(MadAtlas atlas, SerializedProperty property)
 {
     if (property != null)
     {
         var currentGUID = property.stringValue;
         Show(atlas, currentGUID, (guid) => {
             property.serializedObject.UpdateIfDirtyOrScript();
             property.stringValue = guid;
             property.serializedObject.ApplyModifiedProperties();
         });
     }
     else
     {
         Show(atlas, "", null);
     }
 }
コード例 #5
0
ファイル: MadAtlasBuilder.cs プロジェクト: kewls74/game1
    public static void RemoveFromAtlas(MadAtlas atlas, MadAtlas.Item item)
    {
        var liveItems = LiveItems(atlas);
        var newItems  = (from el in liveItems where el != item select el).ToList();

        atlas.ClearItems();

        var allTextures = from el in newItems select MadAtlasUtil.GetItemOrigin(el);

        string atlasTexturePath = AssetDatabase.GetAssetPath(atlas.atlasTexture);

        PackTextures(allTextures.ToArray(), atlasTexturePath, ref newItems);

        atlas.ClearItems();
        atlas.AddItemRange(newItems);
    }
コード例 #6
0
    private static void RebuildAtlas(MadAtlas atlas, List <Texture2D> allTextures, List <MadAtlas.Item> liveItems)
    {
        var modified = MakeReadable(allTextures);

        try {
            string atlasTexturePath = AssetDatabase.GetAssetPath(atlas.atlasTexture);
            PackTextures(allTextures.ToArray(), atlasTexturePath, ref liveItems);

            atlas.ClearItems();
            atlas.AddItemRange(liveItems);

            EditorUtility.SetDirty(atlas);
        } finally {
            RevertReadable(modified);
            AssetDatabase.Refresh();
        }
    }
コード例 #7
0
ファイル: MadAtlasUtil.cs プロジェクト: tng2903/game1
    public static void AtlasField(string guid, MadAtlas atlas, string label, MadAtlasBrowser.Changed callback) {
        string spriteName = "";
        if (!string.IsNullOrEmpty(guid)) {
            var guids = atlas.ListItemGUIDs();
            var index = guids.FindIndex((s) => s == guid);

            if (index != -1) {
                spriteName = atlas.items[index].name;
            }
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.TextField(label, spriteName);
        if (GUILayout.Button("Browse", GUILayout.Width(55))) {
            MadAtlasBrowser.Show(atlas, guid, callback);
        }
        EditorGUILayout.EndHorizontal();
    }
コード例 #8
0
ファイル: MadAtlasUtil.cs プロジェクト: tng2903/game1
    public static void AtlasField(SerializedProperty textureField, MadAtlas atlas, string label) {
        string guid = textureField.stringValue;
        string spriteName = "";
        if (!string.IsNullOrEmpty(guid) && atlas != null) {
            var item = atlas.GetItem(guid);
            if (item != null) {
                spriteName = item.name;
            }
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.TextField(label, spriteName);
        MadGUI.ConditionallyEnabled(atlas != null, () => {
            if (GUILayout.Button("Browse", GUILayout.Width(55))) {
                MadAtlasBrowser.Show(atlas, textureField);
            }
        });
        EditorGUILayout.EndHorizontal();
    }
コード例 #9
0
    public static void AtlasField(string guid, MadAtlas atlas, string label, MadAtlasBrowser.Changed callback, ScriptableObject parent)
    {
        string spriteName = "";

        if (!string.IsNullOrEmpty(guid))
        {
            var guids = atlas.ListItemGUIDs();
            var index = guids.FindIndex((s) => s == guid);

            if (index != -1)
            {
                spriteName = atlas.items[index].name;
            }
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.TextField(label, spriteName);
        if (GUILayout.Button("Browse", GUILayout.Width(55)))
        {
            MadAtlasBrowser.Show(atlas, guid, callback, parent);
        }
        EditorGUILayout.EndHorizontal();
    }
コード例 #10
0
ファイル: MadAtlasBuilder.cs プロジェクト: kewls74/game1
    public static void AddToAtlas(MadAtlas atlas, Texture2D[] textures)
    {
        List <MadAtlas.Item> liveItems   = LiveItems(atlas);
        List <Texture2D>     allTextures = new List <Texture2D>();

        allTextures.AddRange(from i in liveItems select MadAtlasUtil.GetItemOrigin(i));
        allTextures.AddRange(textures);

        var modified = MakeReadable(allTextures);

        try {
            string atlasTexturePath = AssetDatabase.GetAssetPath(atlas.atlasTexture);
            PackTextures(allTextures.ToArray(), atlasTexturePath, ref liveItems);

            atlas.ClearItems();
            atlas.AddItemRange(liveItems);

            EditorUtility.SetDirty(atlas);
        } finally {
            RevertReadable(modified);
            AssetDatabase.Refresh();
        }
    }
コード例 #11
0
    public static void AtlasField(SerializedProperty textureField, MadAtlas atlas, string label, ScriptableObject parent)
    {
        string guid       = textureField.stringValue;
        string spriteName = "";

        if (!string.IsNullOrEmpty(guid) && atlas != null)
        {
            var item = atlas.GetItem(guid);
            if (item != null)
            {
                spriteName = item.name;
            }
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.TextField(label, spriteName);
        MadGUI.ConditionallyEnabled(atlas != null, () => {
            if (GUILayout.Button("Browse", GUILayout.Width(55)))
            {
                MadAtlasBrowser.Show(atlas, textureField, parent);
            }
        });
        EditorGUILayout.EndHorizontal();
    }
コード例 #12
0
    public static void RemoveFromAtlas(MadAtlas atlas, MadAtlas.Item item)
    {
        var liveItems = LiveItems(atlas);
        var newItems  = (from el in liveItems where el != item select el).ToList();

        atlas.ClearItems();

        var allTextures = from el in newItems select MadAtlasUtil.GetItemOrigin(el);

        var modified = MakeReadable(allTextures);

        try {
            string atlasTexturePath = AssetDatabase.GetAssetPath(atlas.atlasTexture);
            PackTextures(allTextures.ToArray(), atlasTexturePath, ref newItems);

            atlas.ClearItems();
            atlas.AddItemRange(newItems);

            EditorUtility.SetDirty(atlas);
        } finally {
            RevertReadable(modified);
            AssetDatabase.Refresh();
        }
    }
コード例 #13
0
 public static void AddToAtlas(MadAtlas atlas, Texture2D texture) {
     AddToAtlas(atlas, new Texture2D[] { texture });
 }
コード例 #14
0
ファイル: MadAtlasInspector.cs プロジェクト: tng2903/game1
    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================

    // ===========================================================
    // Methods
    // ===========================================================
    
    void OnEnable() {
        atlas = target as MadAtlas;
    
        textureDragDrop = Resources.Load("Mad2D/Textures/icon_drag_drop") as Texture;
    }
コード例 #15
0
 public static void Show(MadAtlas atlas, SerializedProperty property, ScriptableObject parent) {
     if (property != null) {
         var currentGUID = property.stringValue;
         Show(atlas, currentGUID, (guid) => {
             if (parent != null) {
                 property.serializedObject.UpdateIfDirtyOrScript();
                 property.stringValue = guid;
                 property.serializedObject.ApplyModifiedProperties();
             }}, parent);
     } else {
         Show(atlas, "", null, parent);
     }
 }
コード例 #16
0
ファイル: MadAtlasBuilder.cs プロジェクト: kewls74/game1
 private static List <MadAtlas.Item> LiveItems(MadAtlas atlas)
 {
     return((from item in atlas.items where MadAtlasUtil.GetItemOrigin(item) != null select item).ToList());
 }
コード例 #17
0
ファイル: MadText.cs プロジェクト: soluclea/LoonaProject
 Vector2 FixUV(Vector2 uv, MadAtlas.Item item) {
     if (item != null) {
         var region = item.region;
         return new Vector2(region.x + region.width * uv.x, region.y + region.height * uv.y);
     } else {
         return uv;
     }
 }
コード例 #18
0
ファイル: MadAtlasBuilder.cs プロジェクト: tng2903/game1
 public static void RemoveFromAtlas(MadAtlas atlas, MadAtlas.Item item) {
     var liveItems = LiveItems(atlas);
     var newItems = (from el in liveItems where el != item select el).ToList();
     
     atlas.ClearItems();
     
     var allTextures = from el in newItems select MadAtlasUtil.GetItemOrigin(el);
     
     string atlasTexturePath = AssetDatabase.GetAssetPath(atlas.atlasTexture);
     PackTextures(allTextures.ToArray(), atlasTexturePath, ref newItems);
     
     atlas.ClearItems();
     atlas.AddItemRange(newItems);
 }
コード例 #19
0
ファイル: MadAtlasBuilder.cs プロジェクト: tng2903/game1
    public static void AddToAtlas(MadAtlas atlas, Texture2D[] textures) {
        List<MadAtlas.Item> liveItems = LiveItems(atlas);
        List<Texture2D> allTextures = new List<Texture2D>();

        allTextures.AddRange(from i in liveItems select MadAtlasUtil.GetItemOrigin(i));
        allTextures.AddRange(textures);

        var modified = MakeReadable(allTextures);
        try {
            string atlasTexturePath = AssetDatabase.GetAssetPath(atlas.atlasTexture);
            PackTextures(allTextures.ToArray(), atlasTexturePath, ref liveItems);

            atlas.ClearItems();
            atlas.AddItemRange(liveItems);

            EditorUtility.SetDirty(atlas);
        } finally {
            RevertReadable(modified);
            AssetDatabase.Refresh();
        }
    }
コード例 #20
0
ファイル: MadAtlasBuilder.cs プロジェクト: kewls74/game1
 public static void AddToAtlas(MadAtlas atlas, Texture2D texture)
 {
     AddToAtlas(atlas, new Texture2D[] { texture });
 }
コード例 #21
0
    public static void RebuildAtlas(MadAtlas atlas) {
        List<MadAtlas.Item> liveItems = LiveItems(atlas);

        List<Texture2D> allTextures = new List<Texture2D>();
        allTextures.AddRange(from i in liveItems select MadAtlasUtil.GetItemOrigin(i));

        RebuildAtlas(atlas, allTextures, liveItems);
    }
コード例 #22
0
    private static void RebuildAtlas(MadAtlas atlas, List<Texture2D> allTextures, List<MadAtlas.Item> liveItems) {
        var modified = MakeReadable(allTextures);
        try {
            string atlasTexturePath = AssetDatabase.GetAssetPath(atlas.atlasTexture);
            PackTextures(allTextures.ToArray(), atlasTexturePath, ref liveItems);

            atlas.ClearItems();
            atlas.AddItemRange(liveItems);

            EditorUtility.SetDirty(atlas);
        } finally {
            RevertReadable(modified);
            AssetDatabase.Refresh();
        }
    }
コード例 #23
0
    public static void RemoveFromAtlas(MadAtlas atlas, MadAtlas.Item item) {
        var liveItems = LiveItems(atlas);
        var newItems = (from el in liveItems where el != item select el).ToList();
        
        atlas.ClearItems();
        
        var allTextures = from el in newItems select MadAtlasUtil.GetItemOrigin(el);

        var modified = MakeReadable(allTextures);
        try {
            string atlasTexturePath = AssetDatabase.GetAssetPath(atlas.atlasTexture);
            PackTextures(allTextures.ToArray(), atlasTexturePath, ref newItems);

            atlas.ClearItems();
            atlas.AddItemRange(newItems);

            EditorUtility.SetDirty(atlas);
        } finally {
            RevertReadable(modified);
            AssetDatabase.Refresh();
        }
    }
コード例 #24
0
    Vector2 DrawTile(MadAtlas.Item item, Vector2 position, ref Vector2 bounds) {
        // apply search filter
        if (!string.IsNullOrEmpty(searchFilter)) {
            if (!item.name.ToUpper().Contains(searchFilter.ToUpper())) {
                return position;
            }
        }

        // check for click event
        var allRect = new Rect(position.x, position.y, tileSize.x, tileSize.y);

        if (Event.current.type == EventType.MouseDown && Event.current.button == 0) {
            if (allRect.Contains(Event.current.mousePosition)) {

                // handle double click
                if (selectedItemGUID == item.textureGUID && (DateTime.Now - lastClickTime).TotalMilliseconds < 200) {
                    Close();
                }
                lastClickTime = DateTime.Now;

                Select(item.textureGUID);
            }
        }

        // draw texture
        if (item != noneItem) {
            var textureRect = new Rect(position.x, position.y, textureSize.x, textureSize.y);
            var texturesCoords = item.region;

            textureRect = KeepRatio(textureRect, item.pixelsWidth, item.pixelsHeight);

            GUI.DrawTextureWithTexCoords(textureRect, atlas.atlasTexture, texturesCoords);
        }

        // draw label
        var labelRect = new Rect(position.x, position.y + textureSize.y, labelSize.x, labelSize.y);

        if (selectedItemGUID == item.textureGUID) {
            if (EditorGUIUtility.isProSkin) {
                GUI.color = new Color(63 / 255f, 92 / 255f, 133 / 255f);
            } else {
                GUI.color = new Color(63 / 255f, 132 / 255f, 230 / 255f);
            }
            
            GUI.DrawTexture(labelRect, whiteTexture);
            GUI.color = Color.white;
        }

        GUI.Label(labelRect, item.name);

        // update bounds
        bounds = new Vector2(Mathf.Max(bounds.x, labelRect.xMax), Mathf.Max(bounds.y, labelRect.yMax));

        // calculate next position
        Vector2 newPosition = position + new Vector2(tileSize.x + tileMargin.x, 0);
        if (newPosition.x + tileSize.x > Screen.width) {
            newPosition = new Vector2(0, position.y + tileSize.y + tileMargin.y);
        }

        return newPosition;
    }
コード例 #25
0
 private static List<MadAtlas.Item> LiveItems(MadAtlas atlas) {
     return (from item in atlas.items where MadAtlasUtil.GetItemOrigin(item) != null select item).ToList();
 }
コード例 #26
0
 public static void Show(MadAtlas atlas, string currentGUID, Changed changedCallback, ScriptableObject parent) {
     //var window = ScriptableObject.CreateInstance<MadAtlasBrowser>();
     var browser = EditorWindow.GetWindow<MadAtlasBrowser>(true, "Atlas Browser", true);
     browser.atlas = atlas;
     browser.changedCallback = changedCallback;
     browser.selectedItemGUID = currentGUID;
     browser.parent = parent;
 }
コード例 #27
0
ファイル: MadAtlasUtil.cs プロジェクト: tng2903/game1
    // ===========================================================
    // Constants
    // ===========================================================

    // ===========================================================
    // Fields
    // ===========================================================

    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================

    // ===========================================================
    // Methods
    // ===========================================================

    public static string GetItemOriginPath(MadAtlas.Item item) {
        var path = AssetDatabase.GUIDToAssetPath(item.textureGUID);
        return path;
    }