Exemple #1
0
    public static List <SpriteInforGroup> GetAssetSpriteInfor(Texture2D tex)
    {
        List <SpriteInforGroup> _listGroup = new List <SpriteInforGroup>();
        string filePath = UnityEditor.AssetDatabase.GetAssetPath(tex);

        Object[] objects = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(filePath);

        List <SpriteInfor> _tempSprite = new List <SpriteInfor>();

        Vector2 _texSize = new Vector2(tex.width, tex.height);

        for (int i = 0; i < objects.Length; i++)
        {
            if (objects[i].GetType() != typeof(Sprite))
            {
                continue;
            }
            SpriteInfor temp   = new SpriteInfor();
            Sprite      sprite = objects[i] as Sprite;
            temp.ID     = i;
            temp.name   = sprite.name;
            temp.pivot  = sprite.pivot;
            temp.rect   = sprite.rect;
            temp.sprite = sprite;
            string tagName = sprite.name;
            if (_isAutoGroup)
            {
                tagName = getGroupName(tagName);
            }
            temp.tag = tagName;
            temp.uv  = GetSpriteUV(_texSize, sprite.rect);
            _tempSprite.Add(temp);
        }

        for (int i = 0; i < _tempSprite.Count; i++)
        {
            SpriteInforGroup _tempGroup = new SpriteInforGroup();
            _tempGroup.tag = _tempSprite[i].tag;
            //_tempGroup.size = 24.0f;
            //_tempGroup.width = 1.0f;
            _tempGroup.listSpriteInfor = new List <SpriteInfor>();
            _tempGroup.listSpriteInfor.Add(_tempSprite[i]);
            for (int j = i + 1; j < _tempSprite.Count; j++)
            {
                if (_tempGroup.tag == _tempSprite[j].tag)
                {
                    _tempGroup.listSpriteInfor.Add(_tempSprite[j]);
                    _tempSprite.RemoveAt(j);
                    j--;
                }
            }
            _listGroup.Add(_tempGroup);
            _tempSprite.RemoveAt(i);
            i--;
        }

        return(_listGroup);
    }
Exemple #2
0
 static public int get_pivot(IntPtr l)
 {
     try {
         SpriteInfor self = (SpriteInfor)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.pivot);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemple #3
0
 static public int constructor(IntPtr l)
 {
     try {
         SpriteInfor o;
         o = new SpriteInfor();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemple #4
0
 static public int set_name(IntPtr l)
 {
     try {
         SpriteInfor   self = (SpriteInfor)checkSelf(l);
         System.String v;
         checkType(l, 2, out v);
         self.name = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemple #5
0
 static public int set_uv(IntPtr l)
 {
     try {
         SpriteInfor           self = (SpriteInfor)checkSelf(l);
         UnityEngine.Vector2[] v;
         checkArray(l, 2, out v);
         self.uv = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemple #6
0
 static public int set_sprite(IntPtr l)
 {
     try {
         SpriteInfor        self = (SpriteInfor)checkSelf(l);
         UnityEngine.Sprite v;
         checkType(l, 2, out v);
         self.sprite = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemple #7
0
    public static List <SpriteInforGroup> GetAssetSpriteInfor(Texture2D tex, bool isStatic)
    {
        string filePath = UnityEditor.AssetDatabase.GetAssetPath(tex);

        Object[] objects = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(filePath);

        List <SpriteInfor> _tempSprite = new List <SpriteInfor>();

        Vector2 _texSize = new Vector2(tex.width, tex.height);

        for (int i = 0; i < objects.Length; i++)
        {
            if (objects[i].GetType() != typeof(Sprite))
            {
                continue;
            }
            SpriteInfor temp   = new SpriteInfor();
            Sprite      sprite = objects[i] as Sprite;
            temp.Id     = i;
            temp.Name   = sprite.name;
            temp.Pivot  = sprite.pivot;
            temp.Rect   = sprite.rect;
            temp.Sprite = sprite;
            temp.Tag    = sprite.name;
            temp.Uv     = GetSpriteUV(_texSize, sprite.rect);
            _tempSprite.Add(temp);
        }

        List <SpriteInforGroup> _listGroup = null;

        try
        {
            if (isStatic)
            {
                _listGroup = GetStaticList(_tempSprite);
            }
            else
            {
                _listGroup = GetAnimationList(_tempSprite);
            }
        }
        catch (System.Exception e)
        {
            Debug.LogError(e);
        }

        return(_listGroup);
    }
Exemple #8
0
    public static List <SpriteInforGroup> GetAssetSpriteInfor(Texture2D tex)
    {
        List <SpriteInforGroup> _listGroup = new List <SpriteInforGroup>();
        string filePath = UnityEditor.AssetDatabase.GetAssetPath(tex);

        Object[] objects = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(filePath);

        List <SpriteInfor> _tempSprite = new List <SpriteInfor>();

        for (int i = 0; i < objects.Length; i++)
        {
            if (objects[i].GetType() != typeof(Sprite))
            {
                continue;
            }
            SpriteInfor temp   = new SpriteInfor();
            Sprite      sprite = objects[i] as Sprite;
            temp.ID     = i;
            temp.name   = sprite.name;
            temp.pivot  = sprite.pivot;
            temp.rect   = sprite.rect;
            temp.sprite = sprite;
            temp.tag    = sprite.name;
            _tempSprite.Add(temp);
        }

        for (int i = 0; i < _tempSprite.Count; i++)
        {
            SpriteInforGroup _tempGroup = new SpriteInforGroup();
            _tempGroup.tag             = _tempSprite[i].tag;
            _tempGroup.listSpriteInfor = new List <SpriteInfor>();
            _tempGroup.listSpriteInfor.Add(_tempSprite[i]);
            for (int j = 0; j < _tempSprite.Count; j++)
            {
                if (j > i && _tempGroup.tag == _tempSprite[j].tag)
                {
                    _tempGroup.listSpriteInfor.Add(_tempSprite[j]);
                    _tempSprite.RemoveAt(j);
                    j--;
                }
            }
            _listGroup.Add(_tempGroup);
            _tempSprite.RemoveAt(i);
            i--;
        }

        return(_listGroup);
    }
Exemple #9
0
    /// <summary>
    /// 改变sprite隶属的组
    /// </summary>
    private void ChangeTag(string newTag, SpriteInfor si)
    {
        if (newTag == si.tag)
        {
            return;
        }

        //从旧的组中移除
        SpriteInforGroup oldSpriteInforGroup = spriteAsset.listSpriteGroup.Find(
            delegate(SpriteInforGroup sig)
        {
            return(sig.tag == si.tag);
        });

        if (oldSpriteInforGroup != null && oldSpriteInforGroup.listSpriteInfor.Contains(si))
        {
            oldSpriteInforGroup.listSpriteInfor.Remove(si);
        }

        //如果旧的组为空,则删掉旧的组
        if (oldSpriteInforGroup.listSpriteInfor.Count <= 0)
        {
            spriteAsset.listSpriteGroup.Remove(oldSpriteInforGroup);
            Init();
        }

        si.tag = newTag;
        //添加到新的组
        SpriteInforGroup newSpriteInforGroup = spriteAsset.listSpriteGroup.Find(
            delegate(SpriteInforGroup sig)
        {
            return(sig.tag == newTag);
        });

        if (newSpriteInforGroup != null)
        {
            newSpriteInforGroup.listSpriteInfor.Add(si);
            newSpriteInforGroup.listSpriteInfor.Sort((a, b) => a.ID.CompareTo(b.ID));
        }

        EditorUtility.SetDirty(spriteAsset);
    }
    public static List <SpriteInfor> GetSpritesInfor(Texture2D tex)
    {
        List <SpriteInfor> m_sprites = new List <SpriteInfor>();

        string filePath = UnityEditor.AssetDatabase.GetAssetPath(tex);

        Object[] objects = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(filePath);

        for (int i = 0; i < objects.Length; i++)
        {
            if (objects[i].GetType() == typeof(Sprite))
            {
                SpriteInfor temp   = new SpriteInfor();
                Sprite      sprite = objects[i] as Sprite;
                temp.ID     = i;
                temp.name   = sprite.name;
                temp.pivot  = sprite.pivot;
                temp.rect   = sprite.rect;
                temp.sprite = sprite;
                m_sprites.Add(temp);
            }
        }
        return(m_sprites);
    }
    public static List <SpriteInforGroup> GetAssetSpriteInfor(Texture2D tex, bool isstatic = true)
    {
        if (isstatic == false)
        {
            taglist.Clear();
        }
        List <SpriteInforGroup> _listGroup = new List <SpriteInforGroup>();
        string filePath = UnityEditor.AssetDatabase.GetAssetPath(tex);

        Object[] objects = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(filePath);

        List <SpriteInfor> _tempSprite = new List <SpriteInfor>();

        Vector2 _texSize = new Vector2(tex.width, tex.height);

        for (int i = 0; i < objects.Length; i++)
        {
            if (objects[i].GetType() != typeof(Sprite))
            {
                continue;
            }
            SpriteInfor temp     = new SpriteInfor();
            Sprite      sprite   = objects[i] as Sprite;
            string      nametemp = sprite.name.Split('_')[0];
            if (isstatic == false)
            {
                /* if (taglist.Contains(nametemp))
                 *   continue;
                 * taglist.Add(nametemp);*/
                temp.tag = nametemp;//prite.name;
            }
            else
            {
                temp.tag = sprite.name;
            }
            temp.ID     = i;
            temp.name   = sprite.name;
            temp.pivot  = sprite.pivot;
            temp.rect   = sprite.rect;
            temp.sprite = sprite;

            temp.uv = GetSpriteUV(_texSize, sprite.rect);
            _tempSprite.Add(temp);
        }

        for (int i = 0; i < _tempSprite.Count; i++)
        {
            SpriteInforGroup _tempGroup = new SpriteInforGroup();
            _tempGroup.tag = _tempSprite[i].tag;
            //_tempGroup.size = 24.0f;
            //_tempGroup.width = 1.0f;
            _tempGroup.listSpriteInfor = new List <SpriteInfor>();
            _tempGroup.listSpriteInfor.Add(_tempSprite[i]);
            for (int j = i + 1; j < _tempSprite.Count; j++)
            {
                if (_tempGroup.tag == _tempSprite[j].tag)
                {
                    _tempGroup.listSpriteInfor.Add(_tempSprite[j]);
                    _tempSprite.RemoveAt(j);
                    j--;
                }
            }
            _listGroup.Add(_tempGroup);
            _tempSprite.RemoveAt(i);
            i--;
        }

        return(_listGroup);
    }