Exemple #1
0
 void SaveTexture()
 {
     if (textureInfo != null)
     {
         EditorTextureUtilities.ExportImage(textureInfo, false);
     }
 }
Exemple #2
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);
//			}
        }
Exemple #3
0
        //----EventManagement----(Textures)
        //	void EventManagement ()
        //	{
        //		Event guiEvent = Event.current;
        //
        //		if ((guiEvent.type == EventType.MouseDrag || guiEvent.type == EventType.MouseDown) && guiEvent.button == 0) {
        //			for (int i = 0; i < pixelRects.Length; i++) {
        //				if (pixelRects [i].Contains (guiEvent.mousePosition)) {
        //					pixelTextures [i].SetPixel (0, 0, leftMoseButtonColor);
        //					pixelTextures [i].Apply ();
        //					needsRepaint = true;
        //					break;
        //				}
        //			}
        //		}
        //		if ((guiEvent.type == EventType.MouseDrag || guiEvent.type == EventType.MouseDown) && guiEvent.button == 1) {
        //			for (int i = 0; i < pixelRects.Length; i++) {
        //				if (pixelRects [i].Contains (guiEvent.mousePosition)) {
        //					pixelTextures [i].SetPixel (0, 0, rightMouseButtonColor);
        //					pixelTextures [i].Apply ();
        //					needsRepaint = true;
        //					break;
        //				}
        //			}
        //		}
        //	}
        //
        //----EventManagement----(Rects)
        //	void EventManagement ()
        //	{
        //		Event guiEvent = Event.current;
        //
        //		if ((guiEvent.type == EventType.MouseDrag || guiEvent.type == EventType.MouseDown) && guiEvent.button == 0) {
        //			for (int i = 0; i < pixelRects.Length; i++) {
        //				if (pixels.pixelRects [i].Contains (guiEvent.mousePosition)) {
        //					pixels.pixelColors [i] = leftMoseButtonColor;
        //					needsRepaint = true;
        //					break;
        //				}
        //			}
        //		}
        //		if ((guiEvent.type == EventType.MouseDrag || guiEvent.type == EventType.MouseDown) && guiEvent.button == 1) {
        //			for (int i = 0; i < pixelRects.Length; i++) {
        //				if (pixels.pixelRects [i].Contains (guiEvent.mousePosition)) {
        //					pixels.pixelColors [i] = rightMouseButtonColor;
        //					needsRepaint = true;
        //					break;
        //				}
        //			}
        //		}
        //
        //	}

        #region UTILITY_METHODS

        void CalculateFilledRectangle(Texture2D texture, Vector2 firstPosition, Vector2 lastPosition, Color color)
        {
            Rect rectangle;

            EditorTextureUtilities.TransformToLeftTop(ref firstPosition, texture.height);
            EditorTextureUtilities.TransformToLeftTop(ref lastPosition, texture.height);

            if (firstPosition.x > lastPosition.x)
            {
                EditorTextureUtilities.SwapX(ref firstPosition, ref lastPosition);
            }
            if (firstPosition.y < lastPosition.y)
            {
                EditorTextureUtilities.SwapY(ref firstPosition, ref lastPosition);
            }

            rectangle = new Rect(firstPosition.x, firstPosition.y, Mathf.Abs(lastPosition.x - firstPosition.x), Mathf.Abs(lastPosition.y - firstPosition.y));

            for (int x = (int)rectangle.x; x <= rectangle.xMax; x++)
            {
                for (int y = (int)rectangle.y; y > rectangle.y - rectangle.height - 1; y--)
                {
                    texture.SetPixel(x, y, color);
                }
            }
            texture.Apply();
        }
Exemple #4
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();
        }
Exemple #5
0
        void OnDisable()
        {
            UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEngine.SceneManagement.SceneManager.GetActiveScene());
            if (textureInfo != null && (level != null || map == null) && (level == null || map != null) && (level.setUp != null || map.setUp != null))
            {
                Debug.Log("saved");
                EditorTextureUtilities.ExportImage(textureInfo, false);
            }

            if (newTexWin != null)
            {
                newTexWin.Close();
            }
        }
Exemple #6
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;
            }
        }
Exemple #7
0
    Texture2D Create()
    {
        int totalPixels = xSize * ySize;

        if (totalPixels <= 22500)
        {
            return(EditorTextureUtilities.CreateNewImage(xSize, ySize));
        }
        else
        {
            if (EditorUtility.DisplayDialog("Image is too big to edit", "Unity does not support big size images in editor, try a smaller size.", "OK"))
            {
                reTry = true;
            }
            return(null);
        }
    }
Exemple #8
0
        void SaveAsTexture()
        {
            if (textureInfo != null)
            {
                EditorTextureUtilities.ExportImage(textureInfo);

                if (type == GENERATOR_TO_EDIT.Level)
                {
                    level.setUp.editorGeneratorLevel = textureInfo;
                }
                if (type == GENERATOR_TO_EDIT.Map)
                {
                    map.setUp.editorGeneratorLevel = textureInfo;
                }

                AssetDatabase.Refresh();
            }
        }
Exemple #9
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;
 }