Inheritance: UnityEngine.ScriptableObject
Beispiel #1
0
    // ------------------------------------------------------------------
    /// \param _obj
    /// Check if the object is valid gui-border and open it in gui-border editor.
    // ------------------------------------------------------------------

    public void Edit(Object _obj)
    {
        // check if repaint
        if (curEdit != _obj)
        {
            // check if we have exGUIBorder in the same directory
            Object obj = _obj;
            if (obj != null)
            {
                string assetPath = AssetDatabase.GetAssetPath(obj);
                if (string.IsNullOrEmpty(assetPath) == false)
                {
                    string dirname  = Path.GetDirectoryName(assetPath);
                    string filename = Path.GetFileNameWithoutExtension(assetPath);
                    obj = (exGUIBorder)AssetDatabase.LoadAssetAtPath(Path.Combine(dirname, filename) + ".asset",
                                                                     typeof(exGUIBorder));
                }
                if (obj == null)
                {
                    obj = _obj;
                }
            }

            // if this is another bitmapfont, swtich to it.
            if (obj is exGUIBorder && obj != curEdit)
            {
                curEdit = obj as exGUIBorder;
                Init();

                Repaint();
                return;
            }
        }
    }
Beispiel #2
0
    // ------------------------------------------------------------------
    /// Clear the altas, material and mesh of the sprite, make it empty
    // ------------------------------------------------------------------

    public void Clear()
    {
        atlas_     = null;
        index_     = -1;
        guiBorder_ = null;

        if (GetComponent <Renderer>() != null)
        {
            GetComponent <Renderer>().sharedMaterial = null;
        }

        if (meshFilter)
        {
            DestroyImmediate(meshFilter_.sharedMesh, true);
            meshFilter_.sharedMesh = null;
        }
    }
Beispiel #3
0
    // ------------------------------------------------------------------
    /// Clear the altas, material and mesh of the sprite, make it empty
    // ------------------------------------------------------------------

    public void Clear()
    {
        atlas_     = null;
        index_     = -1;
        guiBorder_ = null;

        if (renderer != null)
        {
            renderer.sharedMaterial = null;
        }

        if (meshFilter)
        {
            DestroyImmediate(meshFilter_.sharedMesh, true);
            meshFilter_.sharedMesh = null;
        }
    }
Beispiel #4
0
    // ------------------------------------------------------------------
    /// \param _border the new gui-border
    /// \param _atlas the new atlas
    /// \param _index the index of the element in the new atlas
    /// Set a new picture in an atlas to this sprite
    // ------------------------------------------------------------------

    public void SetBorder(exGUIBorder _border, exAtlas _atlas, int _index)
    {
        // pre-check
        if (_border == null ||
            (_atlas != null &&
             (_atlas.elements == null ||
              _index < 0 ||
              _index >= _atlas.elements.Length)))
        {
            Debug.LogWarning("Invalid input in SetBorder.");
            return;
        }

        //
        if (guiBorder_ != _border)
        {
            if (guiBorder_ == null || guiBorder_.border != _border.border)
            {
                updateFlags |= UpdateFlags.Vertex;
            }
            guiBorder_ = _border;
        }

        //
        if (atlas_ != _atlas)
        {
            atlas_ = _atlas;
            if (atlas_)
            {
                GetComponent <Renderer>().sharedMaterial = _atlas.material;
            }
            updateFlags |= UpdateFlags.UV;
        }

        //
        if (index_ != _index)
        {
            index_       = _index;
            updateFlags |= UpdateFlags.UV;
        }
    }
    ///////////////////////////////////////////////////////////////////////////////
    // functions
    ///////////////////////////////////////////////////////////////////////////////

    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public static void UpdateAtlas(exSpriteBorder _spriteBorder,
                                   exAtlasDB.ElementInfo _elInfo)
    {
        // get atlas and index from textureGUID
        if (_elInfo != null)
        {
            if (_elInfo.guidAtlas != exEditorHelper.AssetToGUID(_spriteBorder.atlas) ||
                _elInfo.indexInAtlas != _spriteBorder.index)
            {
                _spriteBorder.SetBorder(_spriteBorder.guiBorder,
                                        exEditorHelper.LoadAssetFromGUID <exAtlas>(_elInfo.guidAtlas),
                                        _elInfo.indexInAtlas);
            }
        }
        else
        {
            exGUIBorder guiBorder = _spriteBorder.guiBorder;
            _spriteBorder.Clear();
            _spriteBorder.SetBorder(guiBorder, null, -1);
        }
    }
Beispiel #6
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public static void TexturePreviewField(Rect _rect, exGUIBorder _guiBorder, Texture2D _texture)
    {
        if (_texture == null)
        {
            return;
        }

        float widthRatio  = _rect.width / _texture.width;
        float heightRatio = _rect.height / _texture.height;

        GUI.BeginGroup(_rect);
        GUI.DrawTexture(new Rect(0, 0, _rect.width, _rect.height), _texture);
        exEditorHelper.DrawRect(new Rect(0, 0, _rect.width, _rect.height), new Color(0.0f, 0.0f, 0.0f, 0.0f), Color.gray);
        // top line
        exEditorHelper.DrawLine(new Vector2(0, _guiBorder.border.top * heightRatio),
                                new Vector2(_rect.width, _guiBorder.border.top * heightRatio),
                                new Color(1.0f, 0.0f, 0.0f, 1.0f),
                                1.0f);

        // bottom line
        exEditorHelper.DrawLine(new Vector2(0, (_texture.height - _guiBorder.border.bottom) * heightRatio),
                                new Vector2(_rect.width, (_texture.height - _guiBorder.border.bottom) * heightRatio),
                                new Color(1.0f, 0.0f, 0.0f, 1.0f),
                                1.0f);

        // left line
        exEditorHelper.DrawLine(new Vector2(_guiBorder.border.left * widthRatio, 0),
                                new Vector2(_guiBorder.border.left * widthRatio, _rect.height),
                                new Color(1.0f, 0.0f, 0.0f, 1.0f),
                                1.0f);

        // right line
        exEditorHelper.DrawLine(new Vector2((_texture.width - _guiBorder.border.right) * widthRatio, 0),
                                new Vector2((_texture.width - _guiBorder.border.right) * widthRatio, _rect.height),
                                new Color(1.0f, 0.0f, 0.0f, 1.0f),
                                1.0f);
        GUI.EndGroup();
        GUILayoutUtility.GetRect(_rect.width, _rect.height);
    }
Beispiel #7
0
    // ------------------------------------------------------------------
    /// \param _path the directory path to save the atlas
    /// \param _name the name of the atlas
    /// \return the gui border
    /// create the gui border in the _path, save it as _name.
    // ------------------------------------------------------------------

    public static exGUIBorder Create(string _path, string _name)
    {
        //
        if (new DirectoryInfo(_path).Exists == false)
        {
            Debug.LogError("can't create asset, path not found");
            return(null);
        }
        if (string.IsNullOrEmpty(_name))
        {
            Debug.LogError("can't create asset, the name is empty");
            return(null);
        }
        string assetPath = Path.Combine(_path, _name + ".asset");

        //
        exGUIBorder newGUIBorder = ScriptableObject.CreateInstance <exGUIBorder>();

        AssetDatabase.CreateAsset(newGUIBorder, assetPath);
        Selection.activeObject = newGUIBorder;
        return(newGUIBorder);
    }
Beispiel #8
0
    static void Create()
    {
        string assetPath = exEditorHelper.GetCurrentDirectory();
        string assetName = "New GUIBorder";

        bool     doCreate = true;
        string   path     = Path.Combine(assetPath, assetName + ".asset");
        FileInfo fileInfo = new FileInfo(path);

        if (fileInfo.Exists)
        {
            doCreate = EditorUtility.DisplayDialog(assetName + " already exists.",
                                                   "Do you want to overwrite the old one?",
                                                   "Yes", "No");
        }
        if (doCreate)
        {
            exGUIBorder border = exGUIBorderUtility.Create(assetPath, assetName);
            Selection.activeObject = border;
            // EditorGUIUtility.PingObject(border);
        }
    }
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public override void OnInspectorGUI()
    {
        // ========================================================
        // Base GUI
        // ========================================================

        base.OnInspectorGUI();
        GUILayout.Space(20);

        // ========================================================
        // init values
        // ========================================================

        //
        bool needRebuild = false;

        // ========================================================
        // exGUIBorder object filed
        // ========================================================

        bool borderChanged = false;

        EditorGUI.indentLevel = 1;

        GUILayout.BeginHorizontal();
        GUI.enabled = !inAnimMode;
        exGUIBorder newGUIBorder = (exGUIBorder)EditorGUILayout.ObjectField("GUI Border"
                                                                            , editSpriteBorder.guiBorder
                                                                            , typeof(exGUIBorder)
                                                                            , false
                                                                            );

        if (newGUIBorder != editSpriteBorder.guiBorder)
        {
            borderChanged = true;
        }

        if (GUILayout.Button("Edit...", GUILayout.Width(40), GUILayout.Height(15)))
        {
            exGUIBorderEditor editor = exGUIBorderEditor.NewWindow();
            editor.Edit(editSpriteBorder.guiBorder);
        }
        GUI.enabled = true;
        GUILayout.EndHorizontal();
        GUILayout.Space(5);

        // get edit texture
        Texture2D editTexture = null;

        if (newGUIBorder)
        {
            editTexture = exEditorHelper.LoadAssetFromGUID <Texture2D>(newGUIBorder.textureGUID);

            // ========================================================
            // border preview
            // ========================================================

            Rect lastRect = GUILayoutUtility.GetLastRect();
            GUILayout.BeginHorizontal();
            GUILayout.Space(30);
            lastRect = GUILayoutUtility.GetLastRect();
            Rect previewRect = new Rect(lastRect.xMax,
                                        lastRect.yMax,
                                        Mathf.Max(100, newGUIBorder.border.horizontal),
                                        Mathf.Max(100, newGUIBorder.border.vertical));
            exGUIBorderEditor.TexturePreviewField(previewRect, newGUIBorder, editTexture);

            GUILayout.Space(10);
            lastRect    = GUILayoutUtility.GetLastRect();
            previewRect = new Rect(lastRect.x,
                                   lastRect.yMax,
                                   Mathf.Max(100, newGUIBorder.border.horizontal),
                                   Mathf.Max(100, newGUIBorder.border.vertical));
            exGUIBorderEditor.BorderPreviewField(previewRect, newGUIBorder, editTexture);

            if (GUILayout.Button("Select...", GUILayout.Width(60), GUILayout.Height(15)))
            {
                EditorGUIUtility.PingObject(editTexture);
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(5);
        }

        // ========================================================
        // get atlas element info from atlas database
        // ========================================================

        exAtlas editAtlas = null;
        int     editIndex = -1;

        exAtlasDB.ElementInfo elInfo = null;
        if (newGUIBorder)
        {
            elInfo = exAtlasDB.GetElementInfo(newGUIBorder.textureGUID);
        }

        if (elInfo != null)
        {
            editAtlas = exEditorHelper.LoadAssetFromGUID <exAtlas>(elInfo.guidAtlas);
            editIndex = elInfo.indexInAtlas;
        }
        bool useAtlas = editAtlas != null && editIndex != -1;

        // get atlas and index from textureGUID
        if (!EditorApplication.isPlaying)
        {
            // if we use atlas, check if the atlas,index changes
            if (useAtlas)
            {
                if (editAtlas != editSpriteBorder.atlas ||
                    editIndex != editSpriteBorder.index)
                {
                    borderChanged = true;
                }
            }
            // if we don't use atlas and current edit target use atlas, clear it.
            else
            {
                if (editSpriteBorder.useAtlas)
                {
                    borderChanged = true;
                }
            }

            // check if we are first time assignment
            if (useAtlas || editTexture != null)
            {
                if (isPrefab == false && editSpriteBorder.meshFilter.sharedMesh == null)
                {
                    needRebuild = true;
                }
            }
        }

        // set border
        if (borderChanged)
        {
            //
            if (newGUIBorder == null)
            {
                editSpriteBorder.Clear();
            }
            else
            {
                editSpriteBorder.SetBorder(newGUIBorder, editAtlas, editIndex);
                if (editSpriteBorder.useAtlas == false)
                {
                    editSpriteBorder.GetComponent <Renderer>().sharedMaterial = exEditorHelper.GetDefaultMaterial(editTexture, editTexture.name);
                    editSpriteBorder.updateFlags |= exPlane.UpdateFlags.UV;
                }
            }

            GUI.changed = true;
        }

        // ========================================================
        // color
        // ========================================================

        editSpriteBorder.color = EditorGUILayout.ColorField("Color", editSpriteBorder.color);

        // ========================================================
        // atlas & index
        // ========================================================

        GUILayout.BeginHorizontal();
        GUI.enabled = false;
        EditorGUILayout.ObjectField("Atlas"
                                    , editSpriteBorder.atlas
                                    , typeof(exAtlas)
                                    , false
                                    );
        GUI.enabled = true;

        GUI.enabled = !inAnimMode;
        if (GUILayout.Button("Edit...", GUILayout.Width(40), GUILayout.Height(15)))
        {
            exAtlasEditor editor = exAtlasEditor.NewWindow();
            editor.Edit(editSpriteBorder.atlas);
        }
        GUI.enabled = true;
        GUILayout.EndHorizontal();

        GUI.enabled = false;
        EditorGUILayout.IntField("Index", editSpriteBorder.index);
        GUI.enabled = true;

        // ========================================================
        // width & height
        // ========================================================

        GUI.enabled = !inAnimMode;
        // width
        float newWidth = EditorGUILayout.FloatField("Width", editSpriteBorder.width);

        if (newWidth != editSpriteBorder.width)
        {
            if (newWidth < 1.0f)
            {
                newWidth = 1.0f;
            }
            editSpriteBorder.width = newWidth;
        }

        // height
        float newHeight = EditorGUILayout.FloatField("Height", editSpriteBorder.height);

        if (newHeight != editSpriteBorder.height)
        {
            if (newHeight < 1.0f)
            {
                newHeight = 1.0f;
            }
            editSpriteBorder.height = newHeight;
        }
        GUI.enabled = true;

        // ========================================================
        // Rebuild button
        // ========================================================

        GUI.enabled = !inAnimMode;
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Rebuild...", GUILayout.Height(20)))
        {
            needRebuild = true;
        }
        GUILayout.EndHorizontal();
        GUI.enabled = true;
        GUILayout.Space(5);

        // if dirty, build it.
        if (!EditorApplication.isPlaying && !AnimationUtility.InAnimationMode())
        {
            if (needRebuild)
            {
                EditorUtility.ClearProgressBar();
                editSpriteBorder.Build(editTexture);
            }
            else if (GUI.changed)
            {
                if (editSpriteBorder.meshFilter.sharedMesh != null)
                {
                    editSpriteBorder.UpdateMesh(editSpriteBorder.meshFilter.sharedMesh);
                }
                EditorUtility.SetDirty(editSpriteBorder);
            }
        }
    }
Beispiel #10
0
    // ------------------------------------------------------------------
    /// \param _border the new gui-border
    /// \param _atlas the new atlas
    /// \param _index the index of the element in the new atlas
    /// Set a new picture in an atlas to this sprite 
    // ------------------------------------------------------------------
    public void SetBorder( exGUIBorder _border, exAtlas _atlas, int _index )
    {
        // pre-check
        if ( _border == null
             || ( _atlas != null
                  && ( _atlas.elements == null
                       || _index < 0
                       || _index >= _atlas.elements.Length ) ) )
        {
            Debug.LogWarning ( "Invalid input in SetBorder." );
            return;
        }

        //
        if ( guiBorder_ != _border ) {
            if ( guiBorder_ == null || guiBorder_.border != _border.border ) {
                updateFlags |= UpdateFlags.Vertex;
            }
            guiBorder_ = _border;
        }

        //
        if ( atlas_ != _atlas ) {
            atlas_ = _atlas;
            if ( atlas_ )
                renderer.sharedMaterial = _atlas.material;
            updateFlags |= UpdateFlags.UV;
        }

        //
        if ( index_ != _index ) {
            index_ = _index;
            updateFlags |= UpdateFlags.UV;
        }
    }
Beispiel #11
0
    // ------------------------------------------------------------------
    /// Clear the altas, material and mesh of the sprite, make it empty
    // ------------------------------------------------------------------
    public void Clear()
    {
        atlas_ = null;
        index_ = -1;
        guiBorder_ = null;

        if ( renderer != null )
            renderer.sharedMaterial = null;

        if ( meshFilter ) {
            DestroyImmediate( meshFilter_.sharedMesh, true );
            meshFilter_.sharedMesh = null;
        }
    }
Beispiel #12
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    public static void BorderPreviewField(Rect _rect, exGUIBorder _guiBorder, Texture2D _texture)
    {
        if (_texture == null)
        {
            return;
        }

        float curX                = _rect.x;
        float curY                = _rect.y;
        int   texCenterWidth      = _texture.width - _guiBorder.border.horizontal;
        int   texCenterHeight     = _texture.height - _guiBorder.border.vertical;
        int   previewCenterWidth  = (int)_rect.width - _guiBorder.border.horizontal;
        int   previewCenterHeight = (int)_rect.height - _guiBorder.border.vertical;

        float widthRatio  = (float)previewCenterWidth / (texCenterWidth != 0 ? (float)texCenterWidth : 0.1f);
        float heightRatio = (float)previewCenterHeight / (texCenterHeight != 0 ? (float)texCenterHeight : 0.1f);

        // ========================================================
        // top
        // ========================================================

        // left-top
        DrawGrid(new Rect(curX, curY,
                          _guiBorder.border.left,
                          _guiBorder.border.top),
                 new Rect(0, 0, 1, 1),
                 _texture);

        // mid-top
        curX += _guiBorder.border.left;
        DrawGrid(new Rect(curX, curY,
                          previewCenterWidth,
                          _guiBorder.border.top),
                 new Rect(_guiBorder.border.left,
                          0,
                          widthRatio,
                          1),
                 _texture);

        // right-top
        curX += previewCenterWidth;
        DrawGrid(new Rect(curX, curY,
                          _guiBorder.border.right,
                          _guiBorder.border.top),
                 new Rect(_texture.width - _guiBorder.border.right,
                          0,
                          1,
                          1),
                 _texture);

        // ========================================================
        curX  = _rect.x;
        curY += _guiBorder.border.top;
        // center
        // ========================================================

        // left-center
        DrawGrid(new Rect(curX, curY,
                          _guiBorder.border.left,
                          previewCenterHeight),
                 new Rect(0,
                          _guiBorder.border.top,
                          1,
                          heightRatio),
                 _texture);

        curX += _guiBorder.border.left;
        // mid-center
        DrawGrid(new Rect(curX, curY,
                          previewCenterWidth,
                          previewCenterHeight),
                 new Rect(_guiBorder.border.left,
                          _guiBorder.border.top,
                          widthRatio,
                          heightRatio),
                 _texture);

        // right-center
        curX += previewCenterWidth;
        DrawGrid(new Rect(curX, curY,
                          _guiBorder.border.right,
                          previewCenterHeight),
                 new Rect(_texture.width - _guiBorder.border.right,
                          _guiBorder.border.top,
                          1,
                          heightRatio),
                 _texture);

        // ========================================================
        curX  = _rect.x;
        curY += previewCenterHeight;
        // bottom
        // ========================================================

        // left-bottom
        DrawGrid(new Rect(curX, curY,
                          _guiBorder.border.left,
                          _guiBorder.border.bottom),
                 new Rect(0,
                          _texture.height - _guiBorder.border.bottom,
                          1,
                          1),
                 _texture);

        // mid-bottom
        curX += _guiBorder.border.left;
        DrawGrid(new Rect(curX, curY,
                          previewCenterWidth,
                          _guiBorder.border.bottom),
                 new Rect(_guiBorder.border.left,
                          _texture.height - _guiBorder.border.bottom,
                          widthRatio,
                          1),
                 _texture);

        // right-bottom
        curX += previewCenterWidth;
        DrawGrid(new Rect(curX, curY,
                          _guiBorder.border.right,
                          _guiBorder.border.bottom),
                 new Rect(_texture.width - _guiBorder.border.right,
                          _texture.height - _guiBorder.border.bottom,
                          1,
                          1),
                 _texture);

        //
        GUILayoutUtility.GetRect(_rect.width, _rect.height);
    }
Beispiel #13
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    static void OnWillSaveAssets(string[] _paths)
    {
        ex.onSavingAssets = true;
        List <exAtlasInfo>      rebuildAtlasInfos      = new List <exAtlasInfo>();
        List <exSpriteAnimClip> rebuildSpriteAnimClips = new List <exSpriteAnimClip>();
        List <exGUIBorder>      rebuildGuiBorders      = new List <exGUIBorder>();

        //
        foreach (string path in _paths)
        {
            // check if we are .ex2D_AtlasDB or .ex2D_SpriteAnimationDB
            if (string.Equals(path, exAtlasDB.dbPath, System.StringComparison.CurrentCultureIgnoreCase) ||
                string.Equals(path, exSpriteAnimationDB.dbPath, System.StringComparison.CurrentCultureIgnoreCase))
            {
                continue;
            }

            // check if we are asset
            if (Path.GetExtension(path) != ".asset")
            {
                continue;
            }

            Object obj = (Object)AssetDatabase.LoadAssetAtPath(path, typeof(Object));
            if (obj == null)
            {
                continue;
            }

            // ========================================================
            // build exAtlasInfo
            // ========================================================

            if (obj is exAtlasInfo)
            {
                exAtlasInfo atlasInfo = obj as exAtlasInfo;
                if (atlasInfo.needRebuild &&
                    rebuildAtlasInfos.IndexOf(atlasInfo) == -1)
                {
                    rebuildAtlasInfos.Add(atlasInfo);
                }
            }

            // ========================================================
            // build exSpriteAnimClip
            // ========================================================

            if (obj is exSpriteAnimClip)
            {
                exSpriteAnimClip spAnimClip = obj as exSpriteAnimClip;
                if (spAnimClip.editorNeedRebuild)
                {
                    rebuildSpriteAnimClips.Add(spAnimClip);
                }
            }

            // TODO {
            // // ========================================================
            // // build exBitmapFont
            // // ========================================================

            // if ( obj is exBitmapFont ) {
            //     exBitmapFont bitmapFont = obj as exBitmapFont;
            //     if ( bitmapFont.editorNeedRebuild )
            //         Object fontInfo = exEditorHelper.LoadAssetFromGUID(bitmapFont.fontinfoGUID);
            //         bitmapFont.Build( fontInfo );
            // }
            // } TODO end

            // ========================================================
            // build exGUIBorder
            // ========================================================

            if (obj is exGUIBorder)
            {
                exGUIBorder guiBorder = obj as exGUIBorder;
                if (guiBorder.editorNeedRebuild &&
                    rebuildGuiBorders.IndexOf(guiBorder) == -1)
                {
                    guiBorder.editorNeedRebuild = false;
                    EditorUtility.SetDirty(guiBorder);
                    rebuildGuiBorders.Add(guiBorder);
                }
            }
        }

        // NOTE: we need to make sure exAtlasInfo build before exSpriteAnimClip,
        //       because during build, exAtlasDB will update ElementInfo, and exSpriteAnimClip need this for checking error.

        // ========================================================
        // build exAtlasInfo first
        // ========================================================

        foreach (exAtlasInfo atlasInfo in rebuildAtlasInfos)
        {
            exAtlasInfoUtility.Build(atlasInfo);
            // build sprite animclip that used this atlasInfo
            exAtlasInfoUtility.BuildSpAnimClipsFromRebuildList(atlasInfo);
        }

        // ========================================================
        // build exSpriteAnimClip
        // ========================================================

        foreach (exSpriteAnimClip spAnimClip in rebuildSpriteAnimClips)
        {
            // NOTE: it could be built in BuildSpAnimClipsFromRebuildList above
            if (spAnimClip.editorNeedRebuild)
            {
                spAnimClip.Build();
            }
        }

        // ========================================================
        // post build
        // ========================================================

        // update scene sprites with rebuild atlasInfo list
        List <string> rebuildAtlasInfoGUIDs = new List <string>();

        foreach (exAtlasInfo atlasInfo in rebuildAtlasInfos)
        {
            rebuildAtlasInfoGUIDs.Add(exEditorHelper.AssetToGUID(atlasInfo));
        }
        exSceneHelper.UpdateSprites(rebuildAtlasInfoGUIDs);

        // update scene sprites with rebuild guiBorder list
        exSceneHelper.UpdateSpriteBorders(rebuildGuiBorders);

        // NOTE: without this you will got leaks message
        // EditorUtility.UnloadUnusedAssets();
        ex.onSavingAssets = false;
    }
Beispiel #14
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------
    public static void TexturePreviewField( Rect _rect, exGUIBorder _guiBorder, Texture2D _texture )
    {
        if ( _texture == null )
            return;

        float widthRatio = _rect.width/_texture.width;
        float heightRatio = _rect.height/_texture.height;
        GUI.BeginGroup(_rect);
            GUI.DrawTexture( new Rect( 0, 0, _rect.width, _rect.height), _texture );
            exEditorHelper.DrawRect( new Rect( 0, 0, _rect.width, _rect.height), new Color(0.0f, 0.0f, 0.0f, 0.0f), Color.gray );
            // top line
            exEditorHelper.DrawLine ( new Vector2( 0, _guiBorder.border.top * heightRatio ),
                                      new Vector2( _rect.width, _guiBorder.border.top * heightRatio ),
                                      new Color ( 1.0f, 0.0f, 0.0f, 1.0f ),
                                      1.0f );

            // bottom line
            exEditorHelper.DrawLine ( new Vector2( 0, (_texture.height - _guiBorder.border.bottom) * heightRatio ),
                                      new Vector2( _rect.width, (_texture.height - _guiBorder.border.bottom) * heightRatio ),
                                      new Color ( 1.0f, 0.0f, 0.0f, 1.0f ),
                                      1.0f );

            // left line
            exEditorHelper.DrawLine ( new Vector2( _guiBorder.border.left * widthRatio, 0 ),
                                      new Vector2( _guiBorder.border.left * widthRatio, _rect.height ),
                                      new Color ( 1.0f, 0.0f, 0.0f, 1.0f ),
                                      1.0f );

            // right line
            exEditorHelper.DrawLine ( new Vector2( (_texture.width - _guiBorder.border.right) * widthRatio, 0 ),
                                      new Vector2( (_texture.width - _guiBorder.border.right) * widthRatio, _rect.height ),
                                      new Color ( 1.0f, 0.0f, 0.0f, 1.0f ),
                                      1.0f );
        GUI.EndGroup();
        GUILayoutUtility.GetRect ( _rect.width, _rect.height );
    }
Beispiel #15
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------
    public static void BorderPreviewField( Rect _rect, exGUIBorder _guiBorder, Texture2D _texture )
    {
        if ( _texture == null )
            return;

        float curX = _rect.x;
        float curY = _rect.y;
        int texCenterWidth = _texture.width - _guiBorder.border.horizontal;
        int texCenterHeight = _texture.height - _guiBorder.border.vertical;
        int previewCenterWidth = (int)_rect.width - _guiBorder.border.horizontal;
        int previewCenterHeight = (int)_rect.height - _guiBorder.border.vertical;

        float widthRatio = (float)previewCenterWidth/(texCenterWidth != 0 ? (float)texCenterWidth : 0.1f);
        float heightRatio = (float)previewCenterHeight/(texCenterHeight != 0 ? (float)texCenterHeight : 0.1f);

        // ========================================================
        // top
        // ========================================================

        // left-top
        DrawGrid ( new Rect ( curX, curY,
                              _guiBorder.border.left,
                              _guiBorder.border.top ),
                   new Rect ( 0, 0, 1, 1 ),
                   _texture );

        // mid-top
        curX += _guiBorder.border.left;
        DrawGrid ( new Rect ( curX, curY,
                              previewCenterWidth,
                              _guiBorder.border.top ),
                   new Rect ( _guiBorder.border.left,
                              0,
                              widthRatio,
                              1 ),
                   _texture );

        // right-top
        curX += previewCenterWidth;
        DrawGrid ( new Rect ( curX, curY,
                              _guiBorder.border.right,
                              _guiBorder.border.top ),
                   new Rect ( _texture.width - _guiBorder.border.right,
                              0,
                              1,
                              1 ),
                   _texture );

        // ========================================================
        curX = _rect.x;
        curY += _guiBorder.border.top;
        // center
        // ========================================================

        // left-center
        DrawGrid ( new Rect ( curX, curY,
                              _guiBorder.border.left,
                              previewCenterHeight ),
                   new Rect ( 0,
                              _guiBorder.border.top,
                              1,
                              heightRatio ),
                   _texture );

        curX += _guiBorder.border.left;
        // mid-center
        DrawGrid ( new Rect ( curX, curY,
                              previewCenterWidth,
                              previewCenterHeight ),
                   new Rect ( _guiBorder.border.left,
                              _guiBorder.border.top,
                              widthRatio,
                              heightRatio ),
                   _texture );

        // right-center
        curX += previewCenterWidth;
        DrawGrid ( new Rect ( curX, curY,
                              _guiBorder.border.right,
                              previewCenterHeight ),
                   new Rect ( _texture.width - _guiBorder.border.right,
                              _guiBorder.border.top,
                              1,
                              heightRatio ),
                   _texture );

        // ========================================================
        curX = _rect.x;
        curY += previewCenterHeight;
        // bottom
        // ========================================================

        // left-bottom
        DrawGrid ( new Rect ( curX, curY,
                              _guiBorder.border.left,
                              _guiBorder.border.bottom ),
                   new Rect ( 0,
                              _texture.height - _guiBorder.border.bottom,
                              1,
                              1 ),
                   _texture );

        // mid-bottom
        curX += _guiBorder.border.left;
        DrawGrid ( new Rect ( curX, curY,
                              previewCenterWidth,
                              _guiBorder.border.bottom ),
                   new Rect ( _guiBorder.border.left,
                              _texture.height - _guiBorder.border.bottom,
                              widthRatio,
                              1 ),
                   _texture );

        // right-bottom
        curX += previewCenterWidth;
        DrawGrid ( new Rect ( curX, curY,
                              _guiBorder.border.right,
                              _guiBorder.border.bottom ),
                   new Rect ( _texture.width - _guiBorder.border.right,
                              _texture.height - _guiBorder.border.bottom,
                              1,
                              1 ),
                   _texture );

        //
        GUILayoutUtility.GetRect ( _rect.width, _rect.height );
    }
Beispiel #16
0
    // ------------------------------------------------------------------
    /// \param _obj
    /// Check if the object is valid gui-border and open it in gui-border editor.
    // ------------------------------------------------------------------
    public void Edit( Object _obj )
    {
        // check if repaint
        if ( curEdit != _obj ) {

            // check if we have exGUIBorder in the same directory
            Object obj = _obj;
            if ( obj != null ) {
                string assetPath = AssetDatabase.GetAssetPath(obj);
                if ( string.IsNullOrEmpty(assetPath) == false ) {
                    string dirname = Path.GetDirectoryName(assetPath);
                    string filename = Path.GetFileNameWithoutExtension(assetPath);
                    obj = (exGUIBorder)AssetDatabase.LoadAssetAtPath( Path.Combine( dirname, filename ) + ".asset",
                                                                      typeof(exGUIBorder) );
                }
                if ( obj == null ) {
                    obj = _obj;
                }
            }

            // if this is another bitmapfont, swtich to it.
            if ( obj is exGUIBorder && obj != curEdit ) {
                curEdit = obj as exGUIBorder;
                Init();

                Repaint ();
                return;
            }
        }
    }