void MarkSpriteAsDirty()
    {
        var meshspritemaker = target as MeshSpriteMaker;

        MeshSprite[] sprites = CWALKEditorTools.FindActive <MeshSprite>();

        foreach (MeshSprite ms in sprites)
        {
            if (MeshSpriteMaker.CheckIfRelated(ms.meshSpriteMaker, meshspritemaker))
            {
                ms.UpdateMesh();
                EditorUtility.SetDirty(ms);
            }
        }
    }
    /// <summary>
    /// Get a previously saved object from settings.
    /// </summary>

    static public T Get <T> (string name, T defaultValue) where T : Object
    {
        string path = EditorPrefs.GetString(name);

        if (string.IsNullOrEmpty(path))
        {
            return(null);
        }
        T retVal = CWALKEditorTools.LoadAsset <T>(path);

        if (retVal == null)
        {
            int id;
            if (int.TryParse(path, out id))
            {
                return(EditorUtility.InstanceIDToObject(id) as T);
            }
        }
        return(retVal);
    }
    /// <summary>
    /// Integer vector field.
    /// </summary>

    static public IntVector IntPair(string prefix, string leftCaption, string rightCaption, int x, int y)
    {
        GUILayout.BeginHorizontal();

        if (string.IsNullOrEmpty(prefix))
        {
            GUILayout.Space(82f);
        }
        else
        {
            GUILayout.Label(prefix, GUILayout.Width(74f));
        }

        CWALKEditorTools.SetLabelWidth(48f);
        IntVector vec2 = new IntVector();

        vec2.x = EditorGUILayout.IntField(leftCaption, x, GUILayout.MinWidth(30f));
        vec2.y = EditorGUILayout.IntField(rightCaption, y, GUILayout.MinWidth(30f));

        CWALKEditorTools.SetLabelWidth(80f);

        GUILayout.EndHorizontal();
        return(vec2);
    }
Exemplo n.º 4
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        GUILayout.Space(6f);
        var meshsprite = target as MeshSprite;

        if (meshsprite != null)
        {
            s_meshSpriteMaker = meshsprite.meshSpriteMaker;

            CWALKEditorTools.BeginContents();
            CWALKEditorTools.RegisterUndo("Sprite Change", meshsprite);
            MeshSpriteMaker SpriteAssemble = EditorGUILayout.ObjectField("Mesh Sprite Maker:", s_meshSpriteMaker, typeof(MeshSpriteMaker), false) as MeshSpriteMaker;

            if (SpriteAssemble == null)
            {
                meshsprite.meshSpriteMaker = null;
                Color tempBgcolor = GUI.backgroundColor;
                GUI.backgroundColor = Color.red;
                EditorGUILayout.HelpBox("No MeshSpriteMaker file found,Please Check On", MessageType.Warning);
                GUI.backgroundColor = tempBgcolor;
                return;
            }
            else
            {
                if (SpriteAssemble != meshsprite.meshSpriteMaker)
                {
                    meshsprite.meshSpriteMaker = SpriteAssemble;
                }
            }

            if (meshsprite.material == null)
            {
                GUILayout.Space(6f);
                Color tempBgcolor = GUI.backgroundColor;
                GUI.backgroundColor = Color.red;
                EditorGUILayout.HelpBox("No Material On Render", MessageType.Warning);
                GUI.backgroundColor = tempBgcolor;
                return;
            }
            else
            {
                if (meshsprite.material.mainTexture == null)
                {
                    meshsprite.selectDefaultTex();
                }
            }

            CWALKEditorTools.RegisterUndo("Sprite Change", meshsprite);
            GUILayout.BeginHorizontal();
            if (CWALKEditorTools.DrawPrefixButton("Mesh Sprite"))
            {
                CWALKSettingTools.S_MeshSpriteMaker = meshsprite.meshSpriteMaker;
                if (meshsprite.mainTexture != null)
                {
                    CWALKSettingTools.S_SelectedSprite = meshsprite.mainTexture.name;
                }
                MeshSpriteSelector.Show(OnSelectAtlas);
            }

            GUILayout.Space(14f);
            if (meshsprite.mainTexture != null)
            {
                GUILayout.Label(meshsprite.mainTexture.name, "helpbox");
            }
            else
            {
                Color tempBgcolor = GUI.backgroundColor;
                GUI.backgroundColor = Color.red;
                GUILayout.Label("material texture is null", "helpbox");
                GUI.backgroundColor = tempBgcolor;
                //
            }

            GUILayout.EndHorizontal();

            //MeshSpriteMode meshmode = (MeshSpriteMode) EditorGUILayout.EnumPopup("Mesh Mode :", meshsprite.meshMode);
            CWALKEditorTools.RegisterUndo("Sprite Change", meshsprite);
            Color tempBgColor = GUI.backgroundColor;

            GUI.backgroundColor = Color.green;
            GUILayout.Space(5f);
            MeshSpriteMode meshmode = (MeshSpriteMode)EditorGUILayout.EnumPopup("Mesh Mode:", meshsprite.meshMode);
            GUILayout.Space(5f);
            CWALKEditorTools.RegisterUndo("Sprite Change", meshsprite);
            float spritewidth = EditorGUILayout.FloatField("Sprite Width:", meshsprite.Width);
            spritewidth = Mathf.Clamp(spritewidth, 1f, 1000f);

            float spriteheight = EditorGUILayout.FloatField("Sprite Height:", meshsprite.Height);
            spriteheight = Mathf.Clamp(spriteheight, 1f, 1000f);

            if (GUI.changed)
            {
                meshsprite.Width    = spritewidth;
                meshsprite.Height   = spriteheight;
                meshsprite.meshMode = meshmode;
                //		meshsprite.borderColor = _borderColor;
                EditorUtility.SetDirty(meshsprite);
            }

            GUI.backgroundColor = tempBgColor;
            CWALKEditorTools.EndContents();
        }
    }
    public override void OnInspectorGUI()
    {
        var meshspritemaker = target as MeshSpriteMaker;

        base.OnInspectorGUI();
        GUILayout.Space(6f);

        if (meshspritemaker != null)
        {
            Color tempBgcolor = GUI.backgroundColor;

            GUI.backgroundColor = Color.green;
            //First lets create a button that will save all of the item data
            if (GUILayout.Button(new GUIContent("Save Config")))
            {
                if (meshspritemaker != null)
                {
                    EditorUtility.SetDirty(meshspritemaker.gameObject);
                }
            }
            CWALKEditorTools.RegisterUndo("Sprite Maker Change", meshspritemaker);
            //Then lets create a button that will add a brand new MeshSpriteData to the list and add a toggle to the foldout list
            if (GUILayout.Button(new GUIContent("Add New Item")))
            {
                meshspritemaker.AddItem();
            }

            for (int i = 0; meshspritemaker.items != null && i < meshspritemaker.items.Count; i++)
            {
                GUI.backgroundColor = tempBgcolor;
                meshspritemaker.itemFoldouts [i] = EditorGUILayout.Foldout(meshspritemaker.itemFoldouts [i], new GUIContent(meshspritemaker.items [i].name + " Info"));
                if (meshspritemaker.itemFoldouts[i] == true)
                {
                    meshspritemaker.items [i].name = EditorGUILayout.TextField(new GUIContent("name"), meshspritemaker.items [i].name);
                    GUILayout.Space(5f);
                    meshspritemaker.items[i].Mode = (MeshSpriteMode)EditorGUILayout.EnumPopup("Mesh Mode :", meshspritemaker.items[i].Mode);

                    GUILayout.Space(5f);
                    CWALKEditorTools.IntVector dimensionVec = CWALKEditorTools.IntPair("Dimension", "Width:", "Height:",
                                                                                       meshspritemaker.items [i].texWidth,
                                                                                       meshspritemaker.items [i].texHeight);



                    GUI.backgroundColor = Color.blue;
                    GUILayout.Space(6f);
                    CWALKEditorTools.IntVector leftRightVec = CWALKEditorTools.IntPair("Set Border", "Left:", "Right:",
                                                                                       meshspritemaker.items [i].LeftBorder,
                                                                                       meshspritemaker.items [i].RightBorder);

                    CWALKEditorTools.IntVector topBottomVec = CWALKEditorTools.IntPair(" ", "Top:", "Bottom:",
                                                                                       meshspritemaker.items [i].BottomBorder,
                                                                                       meshspritemaker.items [i].TopBorder);



                    meshspritemaker.items [i].texWidth  = dimensionVec.x;
                    meshspritemaker.items [i].texHeight = dimensionVec.y;

                    meshspritemaker.items [i].LeftBorder   = leftRightVec.x;
                    meshspritemaker.items [i].RightBorder  = leftRightVec.y;
                    meshspritemaker.items [i].TopBorder    = topBottomVec.y;
                    meshspritemaker.items [i].BottomBorder = topBottomVec.x;

                    Texture2D t = EditorGUILayout.ObjectField("Sprite Tex", meshspritemaker.textureList[i], typeof(Texture2D), true) as Texture2D;

                    meshspritemaker.textureList[i] = t;

                    if (t != null)
                    {
                        if (t != meshspritemaker.textureList[i])
                        {
                            meshspritemaker.textureList[i] = t;
                        }
                        meshspritemaker.items[i].name      = t.name;
                        meshspritemaker.items[i].texWidth  = t.width;
                        meshspritemaker.items[i].texHeight = t.height;
                    }

                    if (t != null)
                    {
                        float changeFator = 1.0f;
                        if (maxLength < t.width ||
                            maxLength < t.height)
                        {
                            if (t.width > t.height)
                            {
                                changeFator = maxLength * 1.0f / t.width;
                            }
                            else
                            {
                                changeFator = maxLength * 1.0f / t.height;
                            }
                        }

                        int width  = Mathf.CeilToInt(t.width * changeFator);
                        int height = Mathf.CeilToInt(t.height * changeFator);

                        Rect rect = GUILayoutUtility.GetRect(width, height);
                        GUI.BeginGroup(rect);                        //clipping

                        Texture2D linetex = CWALKEditorTools.contrastTexture;
                        //Texture2D bgtex = CWALKEditorTools.backdropTexture;
                        GUI.color = Color.white;

                        GUI.Box(new Rect(0, 0, width, height), "");
                        GUI.DrawTexture(new Rect(0, 0, width, height), t);

                        if (meshspritemaker.items [i].LeftBorder > 0)
                        {
                            float x0 = (float)meshspritemaker.items [i].LeftBorder / meshspritemaker.items [i].texWidth * width - 1;
                            CWALKEditorTools.DrawTiledTexture(new Rect(x0, 0f, 1f, height), linetex);
                        }

                        if (meshspritemaker.items [i].RightBorder > 0)
                        {
                            float x1 = (float)(meshspritemaker.items[i].texWidth - meshspritemaker.items[i].RightBorder) / meshspritemaker.items[i].texWidth * width - 1;
                            CWALKEditorTools.DrawTiledTexture(new Rect(x1, 0f, 1f, height), linetex);
                        }

                        if (meshspritemaker.items [i].TopBorder > 0)
                        {
                            float y0 = (float)(meshspritemaker.items [i].texHeight - meshspritemaker.items [i].TopBorder) / meshspritemaker.items [i].texHeight * height - 1;
                            CWALKEditorTools.DrawTiledTexture(new Rect(0f, y0, width, 1f), linetex);
                        }

                        if (meshspritemaker.items [i].BottomBorder > 0)
                        {
                            float y1 = (float)meshspritemaker.items [i].BottomBorder / meshspritemaker.items [i].texHeight * height - 1;
                            CWALKEditorTools.DrawTiledTexture(new Rect(0f, y1, width, 1f), linetex);
                        }

                        GUI.EndGroup();
                    }
                    else
                    {
                        Color tempcolor1 = GUI.color;
                        GUI.color = Color.red;
                        GUILayout.Box("Perview Texture is null ", GUILayout.Width(maxLength), GUILayout.Height(maxLength));
                        GUI.color = tempcolor1;
                    }


                    GUI.backgroundColor = Color.red;
                    //We should also allow the user to remove the selected item so lets give them that option here
                    if (GUILayout.Button(new GUIContent("Remove Item"), GUILayout.Width(Screen.width * 0.87f)))
                    {
                        meshspritemaker.items.RemoveAt(i);
                        meshspritemaker.itemFoldouts.RemoveAt(i);
                        i--;
                    }
                    GUI.backgroundColor = tempBgcolor;
                }

                CWALKEditorTools.RegisterUndo("Sprite Maker Change", meshspritemaker);
            }
        }

        if (GUI.changed)
        {
            MarkSpriteAsDirty();
        }
    }
Exemplo n.º 6
0
    /// <summary>
    /// Draw the custom wizard.
    /// </summary>

    void OnGUI()
    {
        CWALKEditorTools.SetLabelWidth(80f);

        if (CWALKSettingTools.S_MeshSpriteMaker == null)
        {
            GUILayout.Label("No config selected.", "LODLevelNotifyText");
        }
        else
        {
            bool close = false;
            CWALKEditorTools.DrawSeparator();

            List <Texture2D> texturelist = CWALKSettingTools.S_MeshSpriteMaker.textureList;

            if (texturelist == null)
            {
                return;
            }
            float size    = 80f;
            float padded  = size + 10f;
            int   columns = Mathf.FloorToInt(Screen.width / padded);
            if (columns < 1)
            {
                columns = 1;
            }

            int  offset = 0;
            Rect rect   = new Rect(10f, 0, size, size);

            GUILayout.Space(10f);
            mPos = GUILayout.BeginScrollView(mPos);
            int rows = 1;

            while (offset < texturelist.Count)
            {
                GUILayout.BeginHorizontal();
                {
                    int col = 0;
                    rect.x = 10f;

                    for (; offset < texturelist.Count; ++offset)
                    {
                        Texture tex = texturelist[offset];

                        if (tex == null)
                        {
                            continue;
                        }

                        // Button comes first
                        if (GUI.Button(rect, ""))
                        {
                            if (Event.current.button == 0)
                            {
                                float delta = Time.realtimeSinceStartup - mClickTime;
                                mClickTime = Time.realtimeSinceStartup;

                                if (CWALKSettingTools.S_SelectedSprite != tex.name)
                                {
                                    if (mSprite != null)
                                    {
                                        mSprite.mainTexture = tex;
                                        EditorUtility.SetDirty(mSprite.gameObject);
                                    }

                                    CWALKSettingTools.S_SelectedSprite = tex.name;
                                    if (mCallback != null)
                                    {
                                        mCallback(tex);
                                    }
                                }
                                else if (delta < 0.5f)
                                {
                                    close = true;
                                }
                            }
                            else
                            {
                            }
                        }

                        if (Event.current.type == EventType.Repaint)
                        {
                            // Calculate the texture's scale that's needed to display the sprite in the clipped area
                            float scaleX = rect.width / tex.width;
                            float scaleY = rect.height / tex.height;

                            // Stretch the sprite so that it will appear proper
                            float aspect   = (scaleY / scaleX) / ((float)tex.height / tex.width);
                            Rect  clipRect = rect;

                            if (aspect != 1f)
                            {
                                if (aspect < 1f)
                                {
                                    // The sprite is taller than it is wider
                                    float padding = size * (1f - aspect) * 0.5f;
                                    clipRect.xMin += padding;
                                    clipRect.xMax -= padding;
                                }
                                else
                                {
                                    // The sprite is wider than it is taller
                                    float padding = size * (1f - 1f / aspect) * 0.5f;
                                    clipRect.yMin += padding;
                                    clipRect.yMax -= padding;
                                }
                            }

                            GUI.DrawTexture(clipRect, tex);

                            // Draw the selection
                            if (CWALKSettingTools.S_SelectedSprite == tex.name)
                            {
                                CWALKEditorTools.DrawOutline(rect, new Color(0.4f, 1f, 0f, 1f));
                            }
                        }

                        GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f);
                        GUI.contentColor    = new Color(1f, 1f, 1f, 0.7f);
                        GUI.Label(new Rect(rect.x, rect.y + rect.height, rect.width, 32f), tex.name, "ProgressBarBack");
                        GUI.contentColor    = Color.white;
                        GUI.backgroundColor = Color.white;

                        if (++col >= columns)
                        {
                            ++offset;
                            break;
                        }
                        rect.x += padded;
                    }
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(padded);
                rect.y += padded + 26;
                ++rows;
            }
            GUILayout.Space(rows * 26);
            GUILayout.EndScrollView();

            if (close)
            {
                Close();
            }
        }
    }