Exemplo n.º 1
0
        /// <summary>
        /// 更新信息
        /// </summary>
        public void UpdateSpriteGroup()
        {
            if (_spriteAsset && _spriteAsset.TexSource && _spriteAsset.Row > 1 && _spriteAsset.Column > 1)
            {
                int count = _spriteAsset.IsStatic ? _spriteAsset.Row * _spriteAsset.Column : _spriteAsset.Row;
                if (_spriteAsset.ListSpriteGroup.Count != count)
                {
                    _spriteAsset.ListSpriteGroup.Clear();
                    //更新
                    //----------------------------------
                    Vector2 texSize = new Vector2(_spriteAsset.TexSource.width, _spriteAsset.TexSource.height);
                    Vector2 size    = new Vector2((_spriteAsset.TexSource.width / (float)_spriteAsset.Column)
                                                  , (_spriteAsset.TexSource.height / (float)_spriteAsset.Row));

                    if (_spriteAsset.IsStatic)
                    {
                        int index = -1;
                        for (int i = 0; i < _spriteAsset.Row; i++)
                        {
                            for (int j = 0; j < _spriteAsset.Column; j++)
                            {
                                index++;
                                SpriteInforGroup inforGroup = Pool <SpriteInforGroup> .Get();

                                SpriteInfor infor = GetSpriteInfo(index, i, j, size, texSize);

                                //inforGroup.Tag = "emoji_" + infor.Id;
                                inforGroup.Tag = string.Format("{0:00}", infor.Id + 1);
                                inforGroup.ListSpriteInfor.Add(infor);
                                _spriteAsset.ListSpriteGroup.Add(inforGroup);
                            }
                        }
                    }
                    else
                    {
                        int index = -1;
                        for (int i = 0; i < _spriteAsset.Row; i++)
                        {
                            SpriteInforGroup inforGroup = Pool <SpriteInforGroup> .Get();

                            //inforGroup.Tag = "emoji_" + (index + 1);
                            inforGroup.Tag = string.Format("{0:00}", index + 1);
                            for (int j = 0; j < _spriteAsset.Column; j++)
                            {
                                index++;

                                SpriteInfor infor = GetSpriteInfo(index, i, j, size, texSize);

                                inforGroup.ListSpriteInfor.Add(infor);
                            }
                            _spriteAsset.ListSpriteGroup.Add(inforGroup);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
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;
                temp.Tag    = sprite.name;
                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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 新增标签
        /// </summary>
        private void AddTagSure()
        {
            SpriteInforGroup sig = new SpriteInforGroup();

            sig.Tag             = _addTagName;
            sig.ListSpriteInfor = new List <SpriteInfor>();

            _spriteAsset.ListSpriteGroup.Insert(0, sig);

            Init();

            EditorUtility.SetDirty(_spriteAsset);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        //根据正则规则更新文本
        private string GetOutputText(string inputText)
        {
            //回收各种对象
            ReleaseSpriteTageInfo();
            ReleaseHrefInfos();

            if (string.IsNullOrEmpty(inputText))
            {
                return("");
            }

            _textBuilder.Remove(0, _textBuilder.Length);
            int textIndex = 0;

            foreach (Match match in _inputTagRegex.Matches(inputText))
            {
                int tempId = 0;
                if (!string.IsNullOrEmpty(match.Groups[1].Value) && !match.Groups[1].Value.Equals("-"))
                {
                    tempId = int.Parse(match.Groups[1].Value);
                }
                string tempTag = match.Groups[2].Value;
                //更新超链接
                if (tempId < 0)
                {
                    _textBuilder.Append(inputText.Substring(textIndex, match.Index - textIndex));
                    _textBuilder.Append("<color=blue>");
                    int startIndex = _textBuilder.Length * 4;
                    _textBuilder.Append("[" + match.Groups[2].Value + "]");
                    int endIndex = _textBuilder.Length * 4 - 1;
                    _textBuilder.Append("</color>");


                    var hrefInfo = Pool <HrefInfo> .Get();

                    hrefInfo.Id         = Mathf.Abs(tempId);
                    hrefInfo.StartIndex = startIndex;                    // 超链接里的文本起始顶点索引
                    hrefInfo.EndIndex   = endIndex;
                    hrefInfo.Name       = match.Groups[2].Value;
                    _listHrefInfos.Add(hrefInfo);
                }
                //更新表情
                else
                {
                    if (_inlineManager == null || !_inlineManager.IndexSpriteInfo.ContainsKey(tempId) ||
                        !_inlineManager.IndexSpriteInfo[tempId].ContainsKey(tempTag))
                    {
                        continue;
                    }

                    SpriteInforGroup tempGroup = _inlineManager.IndexSpriteInfo[tempId][tempTag];

                    _textBuilder.Append(inputText.Substring(textIndex, match.Index - textIndex));
                    int tempIndex = _textBuilder.Length * 4;
                    _textBuilder.Append(@"<quad size=" + tempGroup.Size + " width=" + tempGroup.Width + " />");

                    //清理标签
                    SpriteTagInfo tempSpriteTag = Pool <SpriteTagInfo> .Get();

                    tempSpriteTag.Index = tempIndex;
                    tempSpriteTag.Id    = tempId;
                    tempSpriteTag.Tag   = tempTag;
                    tempSpriteTag.Size  = new Vector2(tempGroup.Size * tempGroup.Width, tempGroup.Size);
                    tempSpriteTag.UVs   = tempGroup.ListSpriteInfor[0].Uv;

                    //添加正则表达式的信息
                    _spriteInfo.Add(tempSpriteTag);
                }
                textIndex = match.Index + match.Length;
            }

            _textBuilder.Append(inputText.Substring(textIndex, inputText.Length - textIndex));
            return(_textBuilder.ToString());
        }
Exemplo n.º 6
0
        public override void OnInspectorGUI()
        {
            _ve2ScorllView = GUILayout.BeginScrollView(_ve2ScorllView);

            #region 标题栏
            EditorGUILayout.HelpBox("Number Of Tags:" + _spriteAsset.ListSpriteGroup.Count + "     Number Of Group:" + _spriteAsset.ListSpriteGroup.Count, MessageType.Info);

            GUILayout.BeginVertical("HelpBox");
            GUILayout.BeginHorizontal();
            _spriteAsset.Id = EditorGUILayout.IntField("ID:", _spriteAsset.Id);
            //  _playSpeed = EditorGUILayout.FloatField("FrameSpeed", _playSpeed);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            _spriteAsset.IsStatic = EditorGUILayout.Toggle("Static:", _spriteAsset.IsStatic);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("New Tag"))
            {
                _addTag = !_addTag;
            }
            GUILayout.EndHorizontal();
            if (_addTag)
            {
                GUILayout.BeginHorizontal();
                _addTagName = EditorGUILayout.TextField(_addTagName);
                if (GUILayout.Button("sure", "minibutton"))
                {
                    if (_addTagName == "")
                    {
                        Debug.Log("请输入新建标签的名称!");
                    }
                    else
                    {
                        SpriteInforGroup spriteInforGroup = _spriteAsset.ListSpriteGroup.Find(
                            delegate(SpriteInforGroup sig)
                        {
                            return(sig.Tag == _addTagName);
                        });

                        if (spriteInforGroup != null)
                        {
                            Debug.Log("该标签已存在!");
                        }
                        else
                        {
                            AddTagSure();
                        }
                    }
                }
                GUILayout.EndHorizontal();
            }

            if (GUILayout.Button("Add Tag"))
            {
                GenericMenu gm = new GenericMenu();
                for (int n = 0; n < _tags.Count; n++)
                {
                    string newTag = _tags[n];
                    gm.AddItem(new GUIContent(_tags[n]), false,
                               delegate()
                    {
                        List <SpriteInforGroup> selectGroup = new List <SpriteInforGroup>();
                        foreach (var item in _selectSpriteGroup)
                        {
                            if (item.Value)
                            {
                                selectGroup.Add(item.Key);
                            }
                        }

                        for (int j = 0; j < selectGroup.Count; j++)
                        {
                            for (int i = 0; i < selectGroup[j].ListSpriteInfor.Count; i++)
                            {
                                ChangeTag(newTag, selectGroup[j].ListSpriteInfor[i]);
                            }
                        }
                    });
                }
                gm.ShowAsContext();
            }
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Clear Tag"))
            {
                ClearTag();
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Label("");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            #endregion

            for (int i = 0; i < _spriteAsset.ListSpriteGroup.Count; i++)
            {
                GUILayout.BeginHorizontal("HelpBox");
                _selectSpriteGroup[_spriteAsset.ListSpriteGroup[i]] = GUILayout.Toggle(_selectSpriteGroup[_spriteAsset.ListSpriteGroup[i]], "");
                #region 展开与收缩按钮
                if (GUILayout.Button(_spriteAsset.ListSpriteGroup[i].Tag, _showIndex == i ? "OL Minus" : "OL Plus"))
                {
                    if (_showIndex == i)
                    {
                        _showIndex = -1;
                    }
                    else
                    {
                        _showIndex = i;
                    }
                }
                #endregion

                GUILayout.BeginHorizontal();
                GUILayout.Label("Size:", GUILayout.Width(40));
                _spriteAsset.ListSpriteGroup[i].Size = EditorGUILayout.FloatField("", _spriteAsset.ListSpriteGroup[i].Size, GUILayout.Width(40));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Width:", GUILayout.Width(40));
                _spriteAsset.ListSpriteGroup[i].Width = EditorGUILayout.FloatField("", _spriteAsset.ListSpriteGroup[i].Width, GUILayout.Width(40));
                GUILayout.EndHorizontal();

                #region 未展开的sprite组,播放序列帧动画(帧数大于1的序列帧动画才播放)
                if (_showIndex != i && _spriteAsset.ListSpriteGroup[i].ListSpriteInfor.Count > 0)
                {
                    if (_playIndexs[i] >= _spriteAsset.ListSpriteGroup[i].ListSpriteInfor.Count)
                    {
                        _playIndexs[i] = 0;
                    }

                    GUI.enabled = false;
                    EditorGUILayout.ObjectField("", _spriteAsset.ListSpriteGroup[i].ListSpriteInfor[_playIndexs[i]].Sprite, typeof(Sprite), false);
                    GUI.enabled = true;
                }
                #endregion
                GUILayout.EndHorizontal();

                #region 展开的sprite组,显示所有sprite属性
                if (_showIndex == i)
                {
                    for (int j = 0; j < _spriteAsset.ListSpriteGroup[i].ListSpriteInfor.Count; j++)
                    {
                        GUILayout.BeginHorizontal("sprite" + j, "window");
                        _spriteAsset.ListSpriteGroup[i].ListSpriteInfor[j].Sprite = EditorGUILayout.ObjectField("", _spriteAsset.ListSpriteGroup[i].ListSpriteInfor[j].Sprite, typeof(Sprite), false, GUILayout.Width(80)) as Sprite;

                        GUILayout.FlexibleSpace();

                        GUILayout.BeginVertical();

                        GUI.enabled = false;

                        GUILayout.BeginHorizontal();
                        GUILayout.Label("ID:", GUILayout.Width(50));
                        _spriteAsset.ListSpriteGroup[i].ListSpriteInfor[j].Id = EditorGUILayout.IntField(_spriteAsset.ListSpriteGroup[i].ListSpriteInfor[j].Id);
                        GUILayout.EndHorizontal();

                        GUILayout.BeginHorizontal();
                        GUILayout.Label("Name:", GUILayout.Width(50));
                        _spriteAsset.ListSpriteGroup[i].ListSpriteInfor[j].Name = EditorGUILayout.TextField(_spriteAsset.ListSpriteGroup[i].ListSpriteInfor[j].Name);
                        GUILayout.EndHorizontal();

                        GUI.enabled = true;

                        GUILayout.BeginHorizontal();
                        GUILayout.Label("Tag:", GUILayout.Width(50));
                        if (GUILayout.Button(_spriteAsset.ListSpriteGroup[i].ListSpriteInfor[j].Tag, "MiniPopup"))
                        {
                            GenericMenu gm = new GenericMenu();
                            for (int n = 0; n < _tags.Count; n++)
                            {
                                int i2 = i;
                                int j2 = j;
                                int n2 = n;
                                gm.AddItem(new GUIContent(_tags[n2]), false,
                                           delegate()
                                {
                                    ChangeTag(_tags[n2], _spriteAsset.ListSpriteGroup[i2].ListSpriteInfor[j2]);
                                });
                            }
                            gm.ShowAsContext();
                        }
                        GUILayout.EndHorizontal();

                        GUI.enabled = false;

                        GUILayout.BeginHorizontal();
                        GUILayout.Label("Pivot:", GUILayout.Width(50));
                        EditorGUILayout.Vector2Field("", _spriteAsset.ListSpriteGroup[i].ListSpriteInfor[j].Pivot);
                        GUILayout.EndHorizontal();

                        GUILayout.BeginHorizontal();
                        GUILayout.Label("Rect:", GUILayout.Width(50));
                        EditorGUILayout.RectField("", _spriteAsset.ListSpriteGroup[i].ListSpriteInfor[j].Rect);
                        GUILayout.EndHorizontal();

                        for (int m = 0; m < _spriteAsset.ListSpriteGroup[i].ListSpriteInfor[j].Uv.Length; m++)
                        {
                            GUILayout.BeginHorizontal();
                            GUILayout.Label("UV" + m + ":", GUILayout.Width(50));
                            EditorGUILayout.Vector2Field("", _spriteAsset.ListSpriteGroup[i].ListSpriteInfor[j].Uv[m]);
                            GUILayout.EndHorizontal();
                        }

                        GUI.enabled = true;

                        GUILayout.EndVertical();

                        GUILayout.EndHorizontal();
                    }
                }
                #endregion
            }

            GUILayout.EndScrollView();
            //unity
            EditorUtility.SetDirty(_spriteAsset);
        }