Пример #1
0
 public DrawSpriteAsset(SpriteAsset spriteAsset)
 {
     _spriteAsset = spriteAsset;
     _payTexs     = new Texture[2];
     _payTexs[0]  = Resources.Load <Texture>("emoji-alipay");
     _payTexs[1]  = Resources.Load <Texture>("emoji-wechatpay");
 }
Пример #2
0
        public void OnEnable()
        {
            _spriteAsset = (SpriteAsset)target;

            if (_spriteAsset)
            {
                SetDrawSpriteAsset(_spriteAsset);
            }
        }
Пример #3
0
 /// <summary>
 /// 打开资源窗口
 /// </summary>
 /// <param name="spriteAsset"></param>
 public static void OpenAsset(SpriteAsset spriteAsset)
 {
     if (spriteAsset != null && spriteAsset.TexSource != null)
     {
         _spriteAsset = spriteAsset;
         _sourceTex   = (Texture2D)_spriteAsset.TexSource;
         SetDrawSpriteAsset(_spriteAsset);
         _assetPath = AssetDatabase.GetAssetPath(_spriteAsset);
         GetWindow <CreateSpriteAsset>("Asset Window");
     }
 }
Пример #4
0
 //绘制信息的类
 private void SetDrawSpriteAsset(SpriteAsset spriteAsset)
 {
     //添加
     if (_drawSpriteAsset == null)
     {
         _drawSpriteAsset = new DrawSpriteAsset(spriteAsset);
     }
     else
     {
         _drawSpriteAsset.SetSpriteAsset(spriteAsset);
     }
 }
Пример #5
0
 void Initialize()
 {
     for (int i = 0; i < _spriteGraphics.Count; i++)
     {
         SpriteAsset mSpriteAsset = _spriteGraphics[i].m_spriteAsset;
         if (!IndexSpriteInfo.ContainsKey(mSpriteAsset.Id))
         {
             Dictionary <string, SpriteInforGroup> spriteGroup = new Dictionary <string, SpriteInforGroup>();
             foreach (var item in mSpriteAsset.ListSpriteGroup)
             {
                 if (!spriteGroup.ContainsKey(item.Tag) && item.ListSpriteInfor != null && item.ListSpriteInfor.Count > 0)
                 {
                     spriteGroup.Add(item.Tag, item);
                 }
             }
             IndexSpriteInfo.Add(mSpriteAsset.Id, spriteGroup);
         }
     }
 }
Пример #6
0
 /// <summary>
 /// 设置信息
 /// </summary>
 /// <param name="spriteAsset"></param>
 public void SetSpriteAsset(SpriteAsset spriteAsset)
 {
     _spriteAsset = spriteAsset;
 }
Пример #7
0
 public DrawSpriteAsset(SpriteAsset spriteAsset)
 {
     _spriteAsset = spriteAsset;
 }
Пример #8
0
        private void OnGUI()
        {
            if (_sourceTex != null)
            {
                GUILayout.BeginHorizontal();
                //纹理渲染--------------
                _texScrollView = GUILayout.BeginScrollView(_texScrollView, "", GUILayout.Width(0.625f * Screen.width));
                GUILayout.Label(_sourceTex);
                GUILayout.EndScrollView();
                //参数设置---------------
                GUILayout.BeginVertical();
                GUILayout.BeginVertical("HelpBox");
                GUILayout.BeginHorizontal();
                GUILayout.Label("纹理名称", GUILayout.Width(80));
                GUILayout.Label(_sourceTex.name);
                GUILayout.FlexibleSpace();
                //加载 图片
                if (GUILayout.Button("Load"))
                {
                    string filePath = EditorUtility.OpenFilePanel("加载图集文件", "", "png");
                    if (!string.IsNullOrEmpty(filePath))
                    {
                        //绝对路径->相对路径
                        filePath = "Assets" + filePath.Replace(Application.dataPath, "");
                        Texture2D tex2d = AssetDatabase.LoadAssetAtPath <Texture2D>(filePath);
                        if (tex2d != null)
                        {
                            _sourceTex = tex2d;
                            if (_spriteAsset)
                            {
                                _spriteAsset.TexSource = _sourceTex;
                            }
                        }
                    }
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUILayout.Label("纹理分辨率", GUILayout.Width(80));
                GUILayout.Label(_sourceTex.width + " * " + _sourceTex.height);
                GUILayout.EndHorizontal();

                //保存
                GUILayout.BeginHorizontal();
                GUILayout.Label("配置文件路径", GUILayout.Width(80));
                GUILayout.Label(_assetPath);
                GUILayout.FlexibleSpace();
                if (GUILayout.Button(_spriteAsset == null ? "Save" : "Save As"))
                {
                    string filePath = EditorUtility.SaveFilePanelInProject("保存表情的序列化文件", _sourceTex.name, "asset", "保存表情的序列化文件");
                    if (!string.IsNullOrEmpty(filePath))
                    {
                        _assetPath = filePath;
                        //创建序列化文件
                        _spriteAsset                 = ScriptableObject.CreateInstance <SpriteAsset>();
                        _spriteAsset.TexSource       = _sourceTex;
                        _spriteAsset.ListSpriteGroup = new List <SpriteInforGroup>();
                        // spriteAsset.ListSpriteGroup = GetAssetSpriteInfor(sourceTex);
                        AssetDatabase.CreateAsset(_spriteAsset, _assetPath);

                        //设置精灵信息的绘制类
                        SetDrawSpriteAsset(_spriteAsset);
                    }
                }
                GUILayout.EndHorizontal();
                GUILayout.EndVertical();

                GUILayout.Space(5);

                //绘制属性
                if (_drawSpriteAsset != null)
                {
                    _drawSpriteAsset.Draw();
                }

                GUILayout.EndVertical();
                GUILayout.EndHorizontal();

                //非自动布局绘制------------------
                //绘制线
                DrawTextureLines();
            }

            //更新信息
            if (_drawSpriteAsset != null)
            {
                _drawSpriteAsset.UpdateSpriteGroup();
            }

            //保存序列化文件
            if (_spriteAsset)
            {
                EditorUtility.SetDirty(_spriteAsset);
            }
        }