Last active
March 9, 2018 02:37
-
-
Save PabloAlexandre/728ab4f32ba5b21edf3bdf7606a58be9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using UnityEditor; | |
| [CustomEditor(typeof(IsometricMap))] | |
| public class IsometricMapEditor : Editor { | |
| private IsometricMap map; | |
| void OnEnable() { | |
| map = (IsometricMap) target; | |
| } | |
| void OnSceneGUI(){ | |
| Event e = Event.current; | |
| Ray r = HandleUtility.GUIPointToWorldRay(new Vector2(e.mousePosition.x, e.mousePosition.y)); | |
| Vector3 mousePosition= r.origin; | |
| if (e.isMouse) { | |
| Tools.current = Tool.View; | |
| Tools.viewTool = ViewTool.FPS; | |
| SceneView.RepaintAll(); | |
| } | |
| Texture2D pattern = map.pattern; | |
| int pixelToUnit = map.pixelToUnit; | |
| Vector2 pixelSize = map.pixelSize; | |
| Vector2 tileSize = new Vector2(pixelSize .x / pixelToUnit, (pixelSize .y * .5f) / pixelToUnit); | |
| Vector2 tilePosition = new Vector2((int)(mousePosition.x / tileSize .x), (int)(mousePosition.y / tileSize .y)); | |
| Vector2 realPosition = new Vector2(tilePosition .x * tileSize .x, tilePosition .y * tileSize .y); | |
| Vector2 markerPosition = new Vector2(realPosition .x + tileSize .x / 2, realPosition .y + tileSize .y / 2); | |
| int localPointX = (int)((mousePosition.x % tileSize .x) * pixelToUnit); | |
| int localPointY = (int)((mousePosition.y % tileSize .y) * pixelToUnit); | |
| Color pixelColor = pattern.GetPixel(localPointX, localPointY); | |
| if (pixelColor == Color.red){ | |
| //Seleciona o tile que está na parte de cima do lado esquerdo | |
| markerPosition = new Vector2(markerPosition .x — tileSize .x / 2, markerPosition .y + tileSize .y / 2); | |
| } else if(pixelColor == Color.green){ | |
| //Seleciona o tile que está na parte de baixo do lado esquerdo | |
| markerPosition = new Vector2(markerPosition .x — tileSize .x / 2, markerPosition .y — tileSize .y / 2); | |
| } else if(pixelColor == Color.yellow){ | |
| //Seleciona o tile que está na parte de cima do lado direito | |
| markerPosition = new Vector2(markerPosition .x + tileSize .x / 2, markerPosition .y + tileSize .y / 2); | |
| } else if(pixelColor == Color.blue){ | |
| //Seleciona o tile que está na parte de baixo do lado direito | |
| markerPosition = new Vector2(markerPosition .x + tileSize .x / 2, markerPosition .y — tileSize .y / 2); | |
| } else { | |
| //Está no tile atual | |
| } | |
| map.markerPosition = markerPosition; | |
| if (e.type == EventType.MouseDown && e.button == 0 || e.type == EventType.MouseDrag && e.button == 0) { | |
| //Desenha tile selecionado. | |
| e.Use(); | |
| } | |
| if (e.type == EventType.MouseDown && e.button == 1 || e.type == EventType.MouseDrag && e.button == 1) { | |
| //Deleta Tile selecionado | |
| e.Use(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment