getYCorner() public method

public getYCorner ( ) : int
return int
Exemplo n.º 1
0
    public void regenerateUVs(Rect textureRect)
    {
        this.uvs = new Vector2[vertexIndex.Length];

        if (vertexIndex.Length == 4)
        {
            float heightLeft  = Vector3.Magnitude(SharedVertex [vertexIndex [3]] - SharedVertex [vertexIndex [0]]),
                  heightRight = Vector3.Magnitude(SharedVertex [vertexIndex [2]] - SharedVertex [vertexIndex [1]]);

            Vector2 topLeft  = new Vector2(textureRect.x, textureRect.y + textureRect.height);
            Vector2 topRight = new Vector2(textureRect.x + textureRect.width, textureRect.y + textureRect.height);
            Vector2 botLeft  = new Vector2(textureRect.x, textureRect.y);
            Vector2 botRight = new Vector2(textureRect.x + textureRect.width, textureRect.y);

            int cornerBotLeft  = 0,
                cornerBotRight = 1,
                cornerTopRight = 2,
                cornerTopLeft  = 3;

            if (textureMapping != null)
            {
                cornerBotLeft  = (cornerBotLeft + textureMapping.Rotation) % 4;
                cornerBotRight = (cornerBotRight + textureMapping.Rotation) % 4;
                cornerTopLeft  = (cornerTopLeft + textureMapping.Rotation) % 4;
                cornerTopRight = (cornerTopRight + textureMapping.Rotation) % 4;
            }

            uvs[cornerBotLeft]  = botLeft;
            uvs[cornerBotRight] = botRight;
            uvs[cornerTopRight] = topRight;
            uvs[cornerTopLeft]  = topLeft;


            if (textureMapping != null)
            {
                uvs[cornerBotLeft]  += new Vector2(0, textureRect.height * (1f - (textureMapping.getYCorner() / (textureMapping.getTexture().height *1.0f))));
                uvs[cornerBotRight] -= new Vector2(textureRect.width * (1f - (textureMapping.getOppositeXCorner() / (textureMapping.getTexture().width *1.0f))), 0);
                uvs[cornerTopRight] -= new Vector2(0, textureRect.height * (textureMapping.getOppositeYCorner() / (textureMapping.getTexture().height *1.0f)));
                uvs[cornerTopLeft]  += new Vector2(textureRect.width * (textureMapping.getXCorner() / (textureMapping.getTexture().width *1.0f)), 0);
            }
            // 0,1,2,3 are setted according to original values
            uvs [2] = (uvs [2] - uvs [1]) * heightRight + uvs [1];
            uvs [3] = (uvs [3] - uvs [0]) * heightLeft + uvs [0];
        }
        else if (vertexIndex.Length == 3)
        {
            Vector2 topRight = new Vector2(textureRect.x + textureRect.width, textureRect.y + textureRect.height);
            Vector2 botLeft  = new Vector2(textureRect.x, textureRect.y);
            Vector2 botRight = new Vector2(textureRect.x + textureRect.width, textureRect.y);

            int cornerBotLeft  = 2,
                cornerBotRight = 1,
                cornerTopRight = 0;

            if (textureMapping != null)
            {
                cornerBotLeft  = (cornerBotLeft + textureMapping.Rotation) % 3;
                cornerBotRight = (cornerBotRight + textureMapping.Rotation) % 3;
                cornerTopRight = (cornerTopRight + textureMapping.Rotation) % 3;
            }

            uvs[cornerBotLeft]  = botLeft;
            uvs[cornerBotRight] = botRight;
            uvs[cornerTopRight] = topRight;

            if (textureMapping != null)
            {
                uvs[cornerBotLeft]  += new Vector2(0, textureRect.height * (1f - (textureMapping.getYCorner() / (textureMapping.getTexture().height *1.0f))));
                uvs[cornerBotRight] -= new Vector2(textureRect.width * (1f - (textureMapping.getOppositeXCorner() / (textureMapping.getTexture().width *1.0f))), 0);
                uvs[cornerTopRight] -= new Vector2(0, textureRect.height * (textureMapping.getOppositeYCorner() / (textureMapping.getTexture().height *1.0f)));
            }
        }
    }
Exemplo n.º 2
0
    void OnGUI()
    {
        IsoTexture[] textures = TextureManager.getInstance().textureList();

        GUIStyle style = new GUIStyle(GUI.skin.button);
        style.padding = new RectOffset(5,5,5,5);

        GUIStyle s = new GUIStyle(GUIStyle.none);
        s.fontStyle = FontStyle.Bold;

        /* NO me gusta como se ve esto la verdad...
         * EditorGUILayout.BeginHorizontal();

            if(GUILayout.Button("New", style))
                TextureManager.getInstance().newTexture();

            if(GUILayout.Button("Delete", style))
                if(selected < textures.Length){
                    TextureManager.getInstance().deleteTexture(TextureManager.getInstance().textureList()[selected]);
                    selected = textures.Length;
                }

        EditorGUILayout.EndHorizontal();

        GUIContent[] texts = new GUIContent[textures.Length];
        for(int i = 0; i< textures.Length; i++){
            texts[i] = new GUIContent(textures[i].name);
        }

        EditorGUILayout.PrefixLabel("IsoTextures List", s);

        scrollPos = EditorGUILayout.BeginScrollView(scrollPos,GUILayout.Width(0), GUILayout.Height(60));
        selected = GUILayout.SelectionGrid(selected,texts,2,style,GUILayout.MaxWidth(auxWidth-25));
        EditorGUILayout.EndScrollView();
        */

        if(selected < textures.Length && textures[selected] != null)
            currentText = textures[selected];
        else
            currentText = null;

        EditorGUILayout.PrefixLabel("IsoTexture", s);
        currentText = EditorGUILayout.ObjectField(currentText, typeof(IsoTexture), false) as IsoTexture;
        for(int i = 0; i< textures.Length; i++)
            if(currentText == textures[i])
                selected = i;

        // Textura
        if(currentText != null){

            currentText.name = UnityEditor.EditorGUILayout.TextField("Name", currentText.name);
            currentText.setTexture(UnityEditor.EditorGUILayout.ObjectField("Base tile", currentText.getTexture(), typeof(Texture2D), true) as Texture2D);

            Texture2D texture = currentText.getTexture();

            if(texture != null){

                EditorGUILayout.PrefixLabel("Presets", s);

                if(GUILayout.Button("Top")){
                    currentText.Rotation = 0;
                    currentText.setXCorner(Mathf.RoundToInt(currentText.getTexture().width/2f));
                    currentText.setYCorner(Mathf.RoundToInt(currentText.getTexture().height/2f));
                }
                EditorGUILayout.BeginHorizontal();
                if(GUILayout.Button("Left")){
                    currentText.Rotation = 0;
                    currentText.setXCorner(0);
                    currentText.setYCorner(Mathf.RoundToInt((2f*currentText.getTexture().height)/3f));
                }
                if(GUILayout.Button("Right")){
                    currentText.Rotation = 3;
                    currentText.setXCorner(currentText.getTexture().width);
                    currentText.setYCorner(Mathf.RoundToInt(currentText.getTexture().height/3f));
                }

                EditorGUILayout.EndHorizontal();

                extra.target = EditorGUILayout.ToggleLeft("Advanced", extra.target);
                if (EditorGUILayout.BeginFadeGroup(extra.faded))

                {
                    EditorGUI.indentLevel++;

                    if(GUILayout.Button("Rotation: " + currentText.Rotation*90))
                        currentText.Rotation++;

                    EditorGUILayout.BeginHorizontal();
                    currentText.setXCorner(EditorGUILayout.IntField(currentText.getXCorner(),GUILayout.Width(30)));
                    currentText.setXCorner(Mathf.FloorToInt(GUILayout.HorizontalSlider(currentText.getXCorner(),0,texture.width,null)));
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    currentText.setYCorner(EditorGUILayout.IntField(currentText.getYCorner(),GUILayout.Width(30)));
                    currentText.setYCorner(Mathf.FloorToInt(GUILayout.HorizontalSlider(currentText.getYCorner(),0,texture.height,null)));
                    EditorGUILayout.EndHorizontal();

                    EditorGUI.indentLevel--;

                }

                EditorGUILayout.EndFadeGroup();

                if(extra.faded != lastValue)
                    this.Repaint();
                lastValue = extra.faded;

                EditorGUILayout.Space();
                Rect rect = GUILayoutUtility.GetLastRect();
                if(Event.current.type == EventType.repaint){
                    float w = position.width;
                    float h = position.height - rect.y;

                    float rh = (w / texture.width*1.0f ) * (texture.height*1.0f) - 10;
                    float rw = w - 10;

                    if(rh > h){
                        rw = (h / texture.height*1.0f ) * texture.width - 10;
                        rh = h - 10;
                    }

                    textureRect = new Rect(w/2f - rw/2f, rect.y + 5, rw, rh);
                }

                float converter = textureRect.width / texture.width;

                /*Rect auxRect = GUILayoutUtility.GetRect(auxWidth, auxHeight);
                auxRect.width = auxWidth;*/
                GUI.DrawTexture(textureRect,texture);

                Vector2 rectCorner = new Vector2(textureRect.x,textureRect.y);
                Vector2 xCorner = rectCorner + new Vector2( converter *currentText.getXCorner(), 0);
                Vector2 yCorner = rectCorner + new Vector2(0, converter * currentText.getYCorner());
                Vector2 xOtherCorner = rectCorner + new Vector2(converter * currentText.getOppositeXCorner(), textureRect.height);
                Vector2 yOtherCorner = rectCorner + new Vector2(textureRect.width, converter * currentText.getOppositeYCorner());

                Drawing.DrawLine(xCorner,yCorner, Color.yellow, 0.5f, true);
                Drawing.DrawLine(yCorner,xOtherCorner, Color.yellow, 0.5f, true);
                Drawing.DrawLine(xOtherCorner,yOtherCorner, Color.yellow, 0.5f, true);
                Drawing.DrawLine(yOtherCorner,xCorner, Color.yellow, 0.5f, true);

            }
            else
                EditorGUILayout.LabelField("Please asign a texture!");
        }else{
            EditorGUILayout.LabelField("Please select a texture o create a new one!", style);
        }

        //GUI
    }
Exemplo n.º 3
0
    public void regenerateUVs(Rect textureRect)
    {
        this.uvs = new Vector2[vertexIndex.Length];

        if (vertexIndex.Length == 4)
        {
            Vector2 topLeft  = new Vector2(textureRect.x, textureRect.y + textureRect.height);
            Vector2 topRight = new Vector2(textureRect.x + textureRect.width, textureRect.y + textureRect.height);
            Vector2 botLeft  = new Vector2(textureRect.x, textureRect.y);
            Vector2 botRight = new Vector2(textureRect.x + textureRect.width, textureRect.y);

            int cornerBotLeft  = 0,
                cornerBotRight = 1,
                cornerTopRight = 2,
                cornerTopLeft  = 3;

            if (textureMapping != null)
            {
                cornerBotLeft  = (cornerBotLeft + textureMapping.Rotation) % 4;
                cornerBotRight = (cornerBotRight + textureMapping.Rotation) % 4;
                cornerTopLeft  = (cornerTopLeft + textureMapping.Rotation) % 4;
                cornerTopRight = (cornerTopRight + textureMapping.Rotation) % 4;
            }

            uvs[cornerBotLeft]  = botLeft;
            uvs[cornerBotRight] = botRight;
            uvs[cornerTopRight] = topRight;
            uvs[cornerTopLeft]  = topLeft;

            if (textureMapping != null)
            {
                uvs[cornerBotLeft]  += new Vector2(0, textureRect.height * (1f - (textureMapping.getYCorner() / (textureMapping.getTexture().height *1.0f))));
                uvs[cornerBotRight] -= new Vector2(textureRect.width * (1f - (textureMapping.getOppositeXCorner() / (textureMapping.getTexture().width *1.0f))), 0);
                uvs[cornerTopRight] -= new Vector2(0, textureRect.height * (textureMapping.getOppositeYCorner() / (textureMapping.getTexture().height *1.0f)));
                uvs[cornerTopLeft]  += new Vector2(textureRect.width * (textureMapping.getXCorner() / (textureMapping.getTexture().width *1.0f)), 0);
            }
        }
        else if (vertexIndex.Length == 3)
        {
            Vector2 topRight = new Vector2(textureRect.x + textureRect.width, textureRect.y + textureRect.height);
            Vector2 botLeft  = new Vector2(textureRect.x, textureRect.y);
            Vector2 botRight = new Vector2(textureRect.x + textureRect.width, textureRect.y);

            int cornerBotLeft  = 2,
                cornerBotRight = 1,
                cornerTopRight = 0;

            if (textureMapping != null)
            {
                cornerBotLeft  = (cornerBotLeft + textureMapping.Rotation) % 3;
                cornerBotRight = (cornerBotRight + textureMapping.Rotation) % 3;
                cornerTopRight = (cornerTopRight + textureMapping.Rotation) % 3;
            }

            uvs[cornerBotLeft]  = botLeft;
            uvs[cornerBotRight] = botRight;
            uvs[cornerTopRight] = topRight;

            if (textureMapping != null)
            {
                uvs[cornerBotLeft]  += new Vector2(0, textureRect.height * (1f - (textureMapping.getYCorner() / (textureMapping.getTexture().height *1.0f))));
                uvs[cornerBotRight] -= new Vector2(textureRect.width * (1f - (textureMapping.getOppositeXCorner() / (textureMapping.getTexture().width *1.0f))), 0);
                uvs[cornerTopRight] -= new Vector2(0, textureRect.height * (textureMapping.getOppositeYCorner() / (textureMapping.getTexture().height *1.0f)));
            }
        }
    }
Exemplo n.º 4
0
    void OnGUI()
    {
        IsoTexture[] textures = TextureManager.getInstance().textureList();

        GUIStyle style = new GUIStyle(GUI.skin.button);

        style.padding = new RectOffset(5, 5, 5, 5);

        GUIStyle s = new GUIStyle(GUIStyle.none);

        s.fontStyle = FontStyle.Bold;

        /* NO me gusta como se ve esto la verdad...
         * EditorGUILayout.BeginHorizontal();
         *
         *      if(GUILayout.Button("New", style))
         *              TextureManager.getInstance().newTexture();
         *
         *
         *      if(GUILayout.Button("Delete", style))
         *              if(selected < textures.Length){
         *                      TextureManager.getInstance().deleteTexture(TextureManager.getInstance().textureList()[selected]);
         *                      selected = textures.Length;
         *              }
         *
         * EditorGUILayout.EndHorizontal();
         *
         *
         * GUIContent[] texts = new GUIContent[textures.Length];
         * for(int i = 0; i< textures.Length; i++){
         *      texts[i] = new GUIContent(textures[i].name);
         * }
         *
         * EditorGUILayout.PrefixLabel("IsoTextures List", s);
         *
         * scrollPos = EditorGUILayout.BeginScrollView(scrollPos,GUILayout.Width(0), GUILayout.Height(60));
         * selected = GUILayout.SelectionGrid(selected,texts,2,style,GUILayout.MaxWidth(auxWidth-25));
         * EditorGUILayout.EndScrollView();
         */

        if (selected < textures.Length && textures[selected] != null)
        {
            currentText = textures[selected];
        }
        else
        {
            currentText = null;
        }

        EditorGUILayout.PrefixLabel("IsoTexture", s);
        currentText = EditorGUILayout.ObjectField(currentText, typeof(IsoTexture), false) as IsoTexture;
        for (int i = 0; i < textures.Length; i++)
        {
            if (currentText == textures[i])
            {
                selected = i;
            }
        }

        // Textura
        if (currentText != null)
        {
            currentText.name = UnityEditor.EditorGUILayout.TextField("Name", currentText.name);
            currentText.setTexture(UnityEditor.EditorGUILayout.ObjectField("Base tile", currentText.getTexture(), typeof(Texture2D), true) as Texture2D);

            Texture2D texture = currentText.getTexture();

            if (texture != null)
            {
                EditorGUILayout.PrefixLabel("Presets", s);

                if (GUILayout.Button("Top"))
                {
                    currentText.Rotation = 0;
                    currentText.setXCorner(Mathf.RoundToInt(currentText.getTexture().width / 2f));
                    currentText.setYCorner(Mathf.RoundToInt(currentText.getTexture().height / 2f));
                }
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Left"))
                {
                    currentText.Rotation = 0;
                    currentText.setXCorner(0);
                    currentText.setYCorner(Mathf.RoundToInt((2f * currentText.getTexture().height) / 3f));
                }
                if (GUILayout.Button("Right"))
                {
                    currentText.Rotation = 3;
                    currentText.setXCorner(currentText.getTexture().width);
                    currentText.setYCorner(Mathf.RoundToInt(currentText.getTexture().height / 3f));
                }

                EditorGUILayout.EndHorizontal();

                extra.target = EditorGUILayout.ToggleLeft("Advanced", extra.target);
                if (EditorGUILayout.BeginFadeGroup(extra.faded))

                {
                    EditorGUI.indentLevel++;

                    if (GUILayout.Button("Rotation: " + currentText.Rotation * 90))
                    {
                        currentText.Rotation++;
                    }

                    EditorGUILayout.BeginHorizontal();
                    currentText.setXCorner(EditorGUILayout.IntField(currentText.getXCorner(), GUILayout.Width(30)));
                    currentText.setXCorner(Mathf.FloorToInt(GUILayout.HorizontalSlider(currentText.getXCorner(), 0, texture.width, null)));
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    currentText.setYCorner(EditorGUILayout.IntField(currentText.getYCorner(), GUILayout.Width(30)));
                    currentText.setYCorner(Mathf.FloorToInt(GUILayout.HorizontalSlider(currentText.getYCorner(), 0, texture.height, null)));
                    EditorGUILayout.EndHorizontal();

                    EditorGUI.indentLevel--;
                }

                EditorGUILayout.EndFadeGroup();

                if (extra.faded != lastValue)
                {
                    this.Repaint();
                }
                lastValue = extra.faded;

                EditorGUILayout.Space();
                Rect rect = GUILayoutUtility.GetLastRect();
                if (Event.current.type == EventType.repaint)
                {
                    float w = position.width;
                    float h = position.height - rect.y;

                    float rh = (w / texture.width * 1.0f) * (texture.height * 1.0f) - 10;
                    float rw = w - 10;

                    if (rh > h)
                    {
                        rw = (h / texture.height * 1.0f) * texture.width - 10;
                        rh = h - 10;
                    }

                    textureRect = new Rect(w / 2f - rw / 2f, rect.y + 5, rw, rh);
                }

                float converter = textureRect.width / texture.width;

                /*Rect auxRect = GUILayoutUtility.GetRect(auxWidth, auxHeight);
                 * auxRect.width = auxWidth;*/
                GUI.DrawTexture(textureRect, texture);

                Vector2 rectCorner   = new Vector2(textureRect.x, textureRect.y);
                Vector2 xCorner      = rectCorner + new Vector2(converter * currentText.getXCorner(), 0);
                Vector2 yCorner      = rectCorner + new Vector2(0, converter * currentText.getYCorner());
                Vector2 xOtherCorner = rectCorner + new Vector2(converter * currentText.getOppositeXCorner(), textureRect.height);
                Vector2 yOtherCorner = rectCorner + new Vector2(textureRect.width, converter * currentText.getOppositeYCorner());

                Drawing.DrawLine(xCorner, yCorner, Color.yellow, 0.5f, true);
                Drawing.DrawLine(yCorner, xOtherCorner, Color.yellow, 0.5f, true);
                Drawing.DrawLine(xOtherCorner, yOtherCorner, Color.yellow, 0.5f, true);
                Drawing.DrawLine(yOtherCorner, xCorner, Color.yellow, 0.5f, true);
            }
            else
            {
                EditorGUILayout.LabelField("Please asign a texture!");
            }
        }
        else
        {
            EditorGUILayout.LabelField("Please select a texture o create a new one!", style);
        }

        //GUI
    }