Esempio n. 1
0
        static void main()
        {
            Object target = Selection.activeObject;

            if (target == null || target.GetType() != typeof(Texture2D))
            {
                return;
            }

            Texture2D sourceTex = target as Texture2D;
            //整体路径
            string filePathWithName = AssetDatabase.GetAssetPath(sourceTex);
            //带后缀的文件名
            string fileNameWithExtension = Path.GetFileName(filePathWithName);
            //不带后缀的文件名
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePathWithName);
            //不带文件名的路径
            string filePath = filePathWithName.Replace(fileNameWithExtension, "");

            SpriteAsset spriteAsset = AssetDatabase.LoadAssetAtPath(filePath + fileNameWithoutExtension + ".asset", typeof(SpriteAsset)) as SpriteAsset;
            bool        isNewAsset  = spriteAsset == null ? true : false;

            if (isNewAsset)
            {
                spriteAsset                 = ScriptableObject.CreateInstance <SpriteAsset>();
                spriteAsset.TexSource       = sourceTex;
                spriteAsset.ListSpriteGroup = GetAssetSpriteInfor(sourceTex);
                AssetDatabase.CreateAsset(spriteAsset, filePath + fileNameWithoutExtension + ".asset");
            }
        }
Esempio n. 2
0
        public void OnEnable()
        {
            _spriteAsset = (SpriteAsset)target;

            if (_spriteAsset)
            {
                SetDrawSpriteAsset(_spriteAsset);
            }
        }
Esempio n. 3
0
        public void OnEnable()
        {
            _spriteAsset = (SpriteAsset)target;

            _playSpeed = 6;

            Init();

            //     EditorApplication.update += RefreshFrameAnimation;
        }
Esempio n. 4
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");
     }
 }
Esempio n. 5
0
 //绘制信息的类
 private static void SetDrawSpriteAsset(SpriteAsset spriteAsset)
 {
     //添加
     if (_drawSpriteAsset == null)
     {
         _drawSpriteAsset = new DrawSpriteAsset(spriteAsset);
     }
     else
     {
         _drawSpriteAsset.SetSpriteAsset(spriteAsset);
     }
 }
Esempio n. 6
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);
         }
     }
 }
Esempio n. 7
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);
            }
        }
 /// <summary>
 /// 设置信息
 /// </summary>
 /// <param name="spriteAsset"></param>
 public void SetSpriteAsset(SpriteAsset spriteAsset)
 {
     _spriteAsset = spriteAsset;
 }
 public DrawSpriteAsset(SpriteAsset spriteAsset)
 {
     _spriteAsset = spriteAsset;
 }