Newer
Older
IsoRenderTest / Assets / IsoEditor.cs
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

[ExecuteInEditMode]
public class IsoEditor : MonoBehaviour {
    

    public Camera IsoCamera;

    private bool hasEvents = false;

    private void OnEnable()
    {
        EnableButtons();
    }

    // Update is called once per frame
    void Update ()
    {
	}

    private bool isoMode = false;
    private Vector3 lastCameraP;
    private Quaternion lastCameraQ;
    private bool lastOrtho;

    public void EnableButtons()
    {
        if (!hasEvents)
        {
            hasEvents = true;
            SceneView.onSceneGUIDelegate += OnSceneGUI;
            SceneView.RepaintAll();
        }
    }

    public void DisableButtons()
    {
        if (hasEvents)
        {
            hasEvents = false;
            SceneView.onSceneGUIDelegate -= OnSceneGUI;
            SceneView.RepaintAll();
        }
    }

    public void OnSceneGUI(SceneView sceneView)
    {
        Handles.BeginGUI();

        if (GUI.Button(new Rect(5, 5, 100, 20), "ISO Mode " + (isoMode ? "On" : "Off")))
        {
            isoMode = !isoMode;

            if (isoMode)
            {
                lastCameraP = sceneView.pivot;
                lastCameraQ = sceneView.rotation;
                lastOrtho = sceneView.orthographic;

                sceneView.AlignViewToObject(IsoCamera.transform);
                sceneView.orthographic = true;

            }
            else
            {
                sceneView.pivot = lastCameraP;
                sceneView.rotation = lastCameraQ;
                sceneView.orthographic = lastOrtho;
            }
        }
        Handles.EndGUI();
    }

    
}