コード例 #1
0
        void UpdateTextures()
        {
            if (type == GENERATOR_TO_EDIT.Map && map.setUp.editorGeneratorLevel != null)
            {
                textureInfo = map.setUp.editorGeneratorLevel;
            }
            else if (type == GENERATOR_TO_EDIT.Level && level.setUp.editorGeneratorLevel != null)
            {
                textureInfo = level.setUp.editorGeneratorLevel;
            }
            else
            {
                textureInfo = null;
            }
            if (textureInfo != null)
            {
                textureInfo.filterMode = FilterMode.Point;
                textureInfo.wrapMode   = TextureWrapMode.Clamp;

                xSize = textureInfo.width;
                ySize = textureInfo.height;
            }

//			if (!texturesInitiated) {
            if (toDrawTexture == null)
            {
                toDrawTexture            = new Texture2D(xSize, ySize);
                toDrawTexture.filterMode = FilterMode.Point;
                toDrawTexture.wrapMode   = TextureWrapMode.Clamp;
                EditorTextureUtilities.ClearTexture(toDrawTexture, true);
            }
//			else
//				toDrawTexture.Resize (xSize, ySize);
//			}
        }
コード例 #2
0
        void DrawBody()
        {
            GUILayout.BeginArea(body.GetRect());
            {
                if (textureInfo == null)
                {
                    return;
                }

                float   aspectRatio = (float)ySize / (float)xSize;
                float   scaleX      = body.GetRect().width *scaleFactor;
                float   scaleY      = scaleX * aspectRatio;
                Vector2 position    = new Vector2((body.GetRect().width / 2 - scaleX / 2) - xOffsetImage, (body.GetRect().center.y - scaleY / 2) - windowSettings.GetRect().height - yOffsetImage);
                Vector2 size        = new Vector2(scaleX, scaleY);

                bodyTextureRect = new Rect(position, size);

                cellWidth  = bodyTextureRect.width / xSize;
                cellHeight = bodyTextureRect.height / ySize;

                EditorGUI.DrawTextureTransparent(bodyTextureRect, textureInfo);
                GUI.DrawTexture(bodyTextureRect, toDrawTexture);
                DrawGrid(bodyTextureRect);
                EditorTextureUtilities.ClearTexture(toDrawTexture);
            }
            GUILayout.EndArea();
        }
コード例 #3
0
        void FilledRectangle(Event e)
        {
            Vector2 pixelCoord = EditorTextureUtilities.CalculatePixel(e.mousePosition, body.GetRect().position, bodyTextureRect, cellWidth, cellHeight);

            helper = toDrawTexture;
            if (e.control)
            {
                if (e.type == EventType.MouseDown)
                {
                    downMousePosition = EditorTextureUtilities.CalculatePixel(e.mousePosition, body.GetRect().position, bodyTextureRect, cellWidth, cellHeight);
                    if (e.button == 0)
                    {
                        CalculateFilledRectangle(helper, downMousePosition, pixelCoord, new Color(leftMoseButtonColor.r, leftMoseButtonColor.g, leftMoseButtonColor.b, 0.5f));
                    }
                    if (e.button == 1)
                    {
                        CalculateFilledRectangle(helper, downMousePosition, pixelCoord, new Color(1 - leftMoseButtonColor.r, 1 - leftMoseButtonColor.g, 1 - leftMoseButtonColor.b, 0.5f));
                    }
                }
                if (e.type == EventType.MouseDrag)
                {
                    if (e.button == 0)
                    {
                        CalculateFilledRectangle(helper, downMousePosition, pixelCoord, new Color(leftMoseButtonColor.r, leftMoseButtonColor.g, leftMoseButtonColor.b, 0.5f));
                    }
                    if (e.button == 1)
                    {
                        CalculateFilledRectangle(helper, downMousePosition, pixelCoord, new Color(1 - leftMoseButtonColor.r, 1 - leftMoseButtonColor.g, 1 - leftMoseButtonColor.b, 0.5f));
                    }
                }
                if (e.type == EventType.MouseUp)
                {
                    upMousePosition = EditorTextureUtilities.CalculatePixel(e.mousePosition, body.GetRect().position, bodyTextureRect, cellWidth, cellHeight);
                    if (e.button == 0)
                    {
                        CalculateFilledRectangle(textureInfo, downMousePosition, upMousePosition, leftMoseButtonColor);
                    }
                    if (e.button == 1)
                    {
                        CalculateFilledRectangle(textureInfo, downMousePosition, upMousePosition, rightMouseButtonColor);
                    }
                    EditorTextureUtilities.ClearTexture(helper, true);
                }
            }
            else
            {
                return;
            }
        }
コード例 #4
0
 void PaintErase(Event e)
 {
     helper = toDrawTexture;
     if (body.GetRect().Contains(e.mousePosition))
     {
         mouseToPixel = EditorTextureUtilities.CalculatePixel(e.mousePosition, body.GetRect().position, bodyTextureRect, cellWidth, cellHeight);
         if (mouseToPixel.x < 0 || mouseToPixel.y < 0 || mouseToPixel.x >= toDrawTexture.width || mouseToPixel.y >= toDrawTexture.height)
         {
             needsRepaint = true;
             if (helper != null)
             {
                 EditorTextureUtilities.ClearTexture(helper, true);
             }
             return;
         }
         if ((e.type == EventType.MouseDrag || e.type == EventType.MouseDown))
         {
             if (e.button == 0)
             {
                 textureInfo.SetPixel((int)mouseToPixel.x, toDrawTexture.height - (int)mouseToPixel.y - 1, leftMoseButtonColor);
             }
             if (e.button == 1)
             {
                 textureInfo.SetPixel((int)mouseToPixel.x, toDrawTexture.height - (int)mouseToPixel.y - 1, rightMouseButtonColor);
             }
         }
         else
         {
             helper.SetPixel((int)mouseToPixel.x, toDrawTexture.height - (int)mouseToPixel.y - 1, new Color(leftMoseButtonColor.r, leftMoseButtonColor.g, leftMoseButtonColor.b, 0.5f));
             helper.Apply();
         }
     }
     else
     {
         mouseToPixel = new Vector2(0, 0);
         if (helper != null)
         {
             EditorTextureUtilities.ClearTexture(helper, true);
         }
     }
     needsRepaint = true;
 }