Example #1
0
        public override void OnInspectorGUI()
        {
            if (_spriteAsset == null)
            {
                return;
            }

            if (_drawSpriteAsset != null)
            {
                _drawSpriteAsset.Draw();
                _drawSpriteAsset.UpdateSpriteGroup();
            }

            EditorUtility.SetDirty(_spriteAsset);
        }
        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);
            }
        }