You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
4.3 KiB
132 lines
4.3 KiB
using System;
|
|
using uc;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
[CustomEditor(typeof(FMCRControl))]
|
|
[CanEditMultipleObjects]
|
|
public class MeshFilterPreview : Editor
|
|
{
|
|
private PreviewRenderUtility _previewRenderUtility;
|
|
|
|
SerializedProperty composerSettings;
|
|
SerializedProperty transposerSettings;
|
|
|
|
private void OnEnable()
|
|
{
|
|
composerSettings = serializedObject.FindProperty("composerSettings");
|
|
transposerSettings = serializedObject.FindProperty("transposerSettings");
|
|
}
|
|
|
|
private Editor _editor;
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
serializedObject.Update();
|
|
DrawDefaultInspector();
|
|
serializedObject.ApplyModifiedProperties();
|
|
|
|
FMCRControl fmcr = target as FMCRControl;
|
|
if (fmcr == null)
|
|
return;
|
|
CreateCachedEditor(composerSettings.objectReferenceValue, null, ref _editor);
|
|
if (_editor != null)
|
|
{
|
|
EditorGUILayout.Separator();
|
|
EditorGUILayout.BeginVertical("Box");
|
|
EditorGUILayout.LabelField(composerSettings.displayName, EditorStyles.boldLabel);
|
|
_editor.OnInspectorGUI();
|
|
EditorGUILayout.EndVertical();
|
|
}
|
|
CreateCachedEditor(transposerSettings.objectReferenceValue, null, ref _editor);
|
|
if (_editor != null)
|
|
{
|
|
EditorGUILayout.Separator();
|
|
EditorGUILayout.BeginVertical("Box");
|
|
EditorGUILayout.LabelField(transposerSettings.displayName, EditorStyles.boldLabel);
|
|
_editor.OnInspectorGUI();
|
|
EditorGUILayout.EndVertical();
|
|
}
|
|
}
|
|
|
|
private void ValidateData()
|
|
{
|
|
if (_previewRenderUtility == null)
|
|
_previewRenderUtility = new PreviewRenderUtility(true);
|
|
}
|
|
|
|
public override bool HasPreviewGUI()
|
|
{
|
|
FMCRControl fmcrControl = target as FMCRControl;
|
|
ValidateData();
|
|
return fmcrControl.FMCR != null;
|
|
}
|
|
|
|
public override bool RequiresConstantRepaint()
|
|
{
|
|
if (Application.isPlaying == true)
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
|
|
public override void OnPreviewGUI(Rect r, GUIStyle background)
|
|
{
|
|
FMCRControl fmcrControl = target as FMCRControl;
|
|
if (fmcrControl == null || fmcrControl.FMCR == null || fmcrControl.FMCR.FMCRCamera == null)
|
|
return;
|
|
|
|
if (Event.current.type == EventType.Repaint)
|
|
{
|
|
_previewRenderUtility.BeginPreview(fmcrControl.FMCR.FMCRCamera.pixelRect, background);
|
|
_previewRenderUtility.camera.transform.position = fmcrControl.vCamPosition;
|
|
_previewRenderUtility.camera.transform.rotation = fmcrControl.vCamRotation;
|
|
_previewRenderUtility.camera.fieldOfView = fmcrControl.fieldOfView;
|
|
_previewRenderUtility.camera.nearClipPlane = fmcrControl.nearClipPlane;
|
|
_previewRenderUtility.camera.farClipPlane = fmcrControl.farClipPlane;
|
|
_previewRenderUtility.camera.aspect = fmcrControl.FMCR.FMCRCamera.aspect;
|
|
_previewRenderUtility.camera.Render();
|
|
|
|
Texture resultRender = _previewRenderUtility.EndPreview();
|
|
|
|
Camera cam = _previewRenderUtility.camera;
|
|
|
|
Rect rr = cam.pixelRect.FitIntoRect(r);
|
|
|
|
GUI.DrawTexture(rr, resultRender);
|
|
fmcrControl.DrawComposerGUI(cam, rr);
|
|
}
|
|
if (Event.current.type == EventType.Layout)
|
|
{
|
|
//Debug.Log("Layout");
|
|
}
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
if (_previewRenderUtility != null)
|
|
_previewRenderUtility.Cleanup();
|
|
}
|
|
|
|
[DrawGizmo(GizmoType.Selected | GizmoType.NonSelected)]
|
|
static void DrawGizmo_FMCRControl(FMCRControl scr, GizmoType gizmoType)
|
|
{
|
|
Vector3 position = scr.transform.position;
|
|
|
|
Matrix4x4 m = Gizmos.matrix;
|
|
Gizmos.matrix = Matrix4x4.TRS(scr.vCamPosition, scr.vCamRotation, Vector3.one);
|
|
Color hex_color;
|
|
if (ColorUtility.TryParseHtmlString("#633F5B", out hex_color))
|
|
{
|
|
Gizmos.color = hex_color;
|
|
Gizmos.DrawFrustum(new Vector3(0, 0, scr.nearClipPlane), scr.fieldOfView, scr.farClipPlane, scr.nearClipPlane, scr.CurrentAspect);
|
|
}
|
|
Gizmos.matrix = m;
|
|
}
|
|
|
|
[DrawGizmo(GizmoType.Pickable)]
|
|
static void DrawGizmo_FreeMotionCameraRig(FreeMotionCameraRig scr, GizmoType gizmoType)
|
|
{
|
|
|
|
}
|
|
} |