using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEditor; using UnityEngine; public class IsoTextureEditor : EditorWindow { private Texture texture; private Vector2 textureOffset; private IsoEditor editor; private float pixelsPerUnit; private void Awake() { } private void OnDestroy() { } public void Init(Texture texture, Vector2 textureOffset, float pixelsPerUnit) { this.texture = texture; titleContent = new GUIContent(texture.name + ": Iso Boxes"); minSize = new Vector2(texture.width, texture.height + 30); editor = FindObjectOfType<IsoEditor>(); this.textureOffset = textureOffset; this.pixelsPerUnit = pixelsPerUnit; } private static float ControlPointSize = 6f; private void DrawControlPoint(Color color, Vector2 pos) { EditorGUI.DrawRect(new Rect(pos.x - ControlPointSize * 0.5f, pos.y - ControlPointSize * 0.5f, ControlPointSize, ControlPointSize), color); } private void RenderCube(Color color, Vector2 origin, Vector3 size) { DrawControlPoint(color, origin); DrawControlPoint(color, origin + (editor.IsoProject(new Vector3(-size.x, 0, 0)) * pixelsPerUnit).OverY(y => -y)); DrawControlPoint(color, origin + (editor.IsoProject(new Vector3(0, 0, size.z)) * pixelsPerUnit).OverY(y => -y)); DrawControlPoint(color, origin + (editor.IsoProject(new Vector3(0, size.y, 0)) * pixelsPerUnit).OverY(y => -y)); DrawControlPoint(color, origin + (editor.IsoProject(new Vector3(-size.x, size.y, 0)) * pixelsPerUnit).OverY(y => -y)); DrawControlPoint(color, origin + (editor.IsoProject(new Vector3(0, size.y, size.z)) * pixelsPerUnit).OverY(y => -y)); } private void OnGUI() { if (texture != null) { GUI.DrawTexture(new Rect(0, 0, texture.width, texture.height), texture); if (GUI.Button(new Rect(5, texture.height + 5, 80, 25), "Save")) { } RenderCube(Color.red, -textureOffset, new Vector3(1f, 1.5f, 2.1f)); } } }