Search Unity

Modify gameObject in PreviewGUI

Discussion in 'Immediate Mode GUI (IMGUI)' started by NDSno1, Sep 17, 2018.

  1. NDSno1

    NDSno1

    Joined:
    Dec 20, 2014
    Posts:
    223
    Hi,
    I'm writing a custom Editor Window that has a PreviewGUI that preview a gameObject from the ObjectField. I would like to be able to actually modify the gameObject being previewed, ie: moving position of child objects within the previewing object.
    What I'm trying to do is to modify the position of the child object by using value from the sliders (as shown in picture below).
    I was able to get the child object and modify the position, but the actual gameObject in the scene is modified, not the one in the preview. What I need is the model in the preview.
    Is something like that possible?
    Thanks in advance.

    2018-09-17.png
     
  2. BinaryCats

    BinaryCats

    Joined:
    Feb 8, 2016
    Posts:
    317
    IIRC, This is a problem with the stock OnPreviewGUI (or what ever) you cant get a reference to previewed object in the preview scene.

    This caused me to rip out the Object Preview from unity (using unity cs reference from git hub)
    And here is the code, hopefully its self explanatory:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEditor;
    4. using UnityEngine;
    5. using UnityEngine.Rendering;
    6.  
    7. public class window : EditorWindow
    8. {
    9.     Preview p;
    10.  
    11.     // Add menu named "My Window" to the Window menu
    12.     [MenuItem("Window/My Window")]
    13.     static void Init()
    14.     {
    15.         // Get existing open window or if none, make a new one:
    16.         var window = (window)EditorWindow.GetWindow(typeof(window));
    17.         window.Show();
    18.  
    19.     }
    20.     private void OnSelectionChange()
    21.     {
    22.         p.InitInstance(Selection.activeGameObject);
    23.  
    24.     }
    25.     Rect prect = new Rect();
    26.     void OnGUI()
    27.     {
    28.         if (p == null)
    29.         {
    30.             p = new Preview();
    31.  
    32.         }
    33.         prect.height = position.height;
    34.         prect.width = position.width;
    35.         p.OnPreviewGUI(prect, null);
    36.     }
    37. }
    38.  
    39.  
    40. public class Preview : Editor
    41. {
    42.     public override bool HasPreviewGUI()
    43.     {
    44.         return true;
    45.     }
    46.  
    47.     PreviewRenderUtility m_PreviewUtility;
    48.     private GameObject m_PreviewInstance;
    49.     private float m_BoundingVolumeScale;
    50.     private float m_AvatarScale;
    51.     private float m_ZoomFactor;
    52.     private Vector2 m_PreviewDir = new Vector2(120, -20);
    53.     private Vector3 m_PivotPositionOffset = Vector3.zero;
    54.     protected ViewTool m_ViewTool = ViewTool.None;
    55.     private PreviewRenderUtility previewUtility
    56.     {
    57.         get
    58.         {
    59.             if (m_PreviewUtility == null)
    60.             {
    61.                 m_PreviewUtility = new PreviewRenderUtility();
    62.                 m_PreviewUtility.camera.fieldOfView = 30.0f;
    63.                 m_PreviewUtility.camera.allowHDR = false;
    64.                 m_PreviewUtility.camera.allowMSAA = false;
    65.                 m_PreviewUtility.ambientColor = new Color(.1f, .1f, .1f, 0);
    66.                 m_PreviewUtility.lights[0].intensity = 1.4f;
    67.                 m_PreviewUtility.lights[0].transform.rotation = Quaternion.Euler(40f, 40f, 0);
    68.                 m_PreviewUtility.lights[1].intensity = 1.4f;
    69.                 m_PreviewUtility.camera.transform.position = new Vector3(1, 1f, -6);
    70.  
    71.             }
    72.  
    73.             return m_PreviewUtility;
    74.  
    75.         }
    76.     }
    77.     protected ViewTool viewTool
    78.     {
    79.         get
    80.         {
    81.             Event evt = Event.current;
    82.             if (m_ViewTool == ViewTool.None)
    83.             {
    84.                 bool controlKeyOnMac = (evt.control && Application.platform == RuntimePlatform.OSXEditor);
    85.                 // actionKey could be command key on mac or ctrl on windows
    86.                 bool actionKey = EditorGUI.actionKey;
    87.                 bool noModifiers = (!actionKey && !controlKeyOnMac && !evt.alt);
    88.                 if ((evt.button <= 0 && noModifiers) || (evt.button <= 0 && actionKey) || evt.button == 2)
    89.                     m_ViewTool = ViewTool.Pan;
    90.                 else if ((evt.button <= 0 && controlKeyOnMac) || (evt.button == 1 && evt.alt))
    91.                     m_ViewTool = ViewTool.Zoom;
    92.                 else if (evt.button <= 0 && evt.alt || evt.button == 1)
    93.                     m_ViewTool = ViewTool.Orbit;
    94.  
    95.             }
    96.  
    97.             return m_ViewTool;
    98.  
    99.         }
    100.  
    101.     }
    102.  
    103.     public Vector3 bodyPosition
    104.     {
    105.         get
    106.         {
    107.             if (m_PreviewInstance != null)
    108.                 return GetRenderableCenterRecurse(m_PreviewInstance, 1, 8);
    109.  
    110.             return Vector3.zero;
    111.  
    112.         }
    113.  
    114.     }
    115.  
    116.     public void InitInstance(GameObject go)
    117.     {
    118.         SetupBounds(go);
    119.         m_PivotPositionOffset = Vector3.zero;
    120.     }
    121.  
    122.     void SetupBounds(GameObject go)
    123.     {
    124.         if (go != null)
    125.         {
    126.             m_PreviewInstance = AddObjectToPreview(go);
    127.  
    128.             Bounds bounds = new Bounds(m_PreviewInstance.transform.position, Vector3.zero);
    129.             GetRenderableBoundsRecurse(ref bounds, m_PreviewInstance);
    130.             m_BoundingVolumeScale = Mathf.Max(bounds.size.x, Mathf.Max(bounds.size.y, bounds.size.z));
    131.             m_AvatarScale = m_ZoomFactor = m_BoundingVolumeScale / 2;
    132.  
    133.         }
    134.  
    135.     }
    136.     public static void GetRenderableBoundsRecurse(ref Bounds bounds, GameObject go)
    137.  
    138.     {
    139.         // Do we have a mesh?
    140.         MeshRenderer renderer = go.GetComponent(typeof(MeshRenderer)) as MeshRenderer;
    141.         MeshFilter filter = go.GetComponent(typeof(MeshFilter)) as MeshFilter;
    142.         if (renderer && filter && filter.sharedMesh)
    143.         {
    144.             // To prevent origo from always being included in bounds we initialize it
    145.             // with renderer.bounds. This ensures correct bounds for meshes with origo outside the mesh.
    146.             if (bounds.extents == Vector3.zero)
    147.                 bounds = renderer.bounds;
    148.             else
    149.                 bounds.Encapsulate(renderer.bounds);
    150.         }
    151.         // Do we have a skinned mesh?
    152.         SkinnedMeshRenderer skin = go.GetComponent(typeof(SkinnedMeshRenderer)) as SkinnedMeshRenderer;
    153.         if (skin && skin.sharedMesh)
    154.         {
    155.             if (bounds.extents == Vector3.zero)
    156.                 bounds = skin.bounds;
    157.             else
    158.                 bounds.Encapsulate(skin.bounds);
    159.         }
    160.         // Do we have a Sprite?
    161.         SpriteRenderer sprite = go.GetComponent(typeof(SpriteRenderer)) as SpriteRenderer;
    162.         if (sprite && sprite.sprite)
    163.         {
    164.             if (bounds.extents == Vector3.zero)
    165.                 bounds = sprite.bounds;
    166.             else
    167.                 bounds.Encapsulate(sprite.bounds);
    168.         }
    169.         // Recurse into children
    170.         foreach (Transform t in go.transform)
    171.         {
    172.             GetRenderableBoundsRecurse(ref bounds, t.gameObject);
    173.         }
    174.     }
    175.  
    176.  
    177.     public static Vector3 GetRenderableCenterRecurse(GameObject go, int minDepth, int maxDepth)
    178.     {
    179.         Vector3 center = Vector3.zero;
    180.  
    181.         float sum = GetRenderableCenterRecurse(ref center, go, 0, minDepth, maxDepth);
    182.  
    183.  
    184.  
    185.         if (sum > 0)
    186.  
    187.         {
    188.  
    189.             center = center / sum;
    190.  
    191.         }
    192.  
    193.         else
    194.  
    195.         {
    196.  
    197.             center = go.transform.position;
    198.  
    199.         }
    200.  
    201.  
    202.  
    203.         return center;
    204.  
    205.     }
    206.     private static float GetRenderableCenterRecurse(ref Vector3 center, GameObject go, int depth, int minDepth, int maxDepth)
    207.  
    208.     {
    209.  
    210.         if (depth > maxDepth)
    211.  
    212.             return 0;
    213.  
    214.  
    215.  
    216.         float ret = 0;
    217.  
    218.  
    219.  
    220.         if (depth > minDepth)
    221.  
    222.         {
    223.  
    224.             // Do we have a mesh?
    225.  
    226.             MeshRenderer renderer = go.GetComponent(typeof(MeshRenderer)) as MeshRenderer;
    227.  
    228.             MeshFilter filter = go.GetComponent(typeof(MeshFilter)) as MeshFilter;
    229.  
    230.             SkinnedMeshRenderer skin = go.GetComponent(typeof(SkinnedMeshRenderer)) as SkinnedMeshRenderer;
    231.  
    232.             SpriteRenderer sprite = go.GetComponent(typeof(SpriteRenderer)) as SpriteRenderer;
    233.  
    234.  
    235.  
    236.             if (renderer == null && filter == null && skin == null && sprite == null)
    237.  
    238.             {
    239.  
    240.                 ret = 1;
    241.  
    242.                 center = center + go.transform.position;
    243.  
    244.             }
    245.  
    246.             else if (renderer != null && filter != null)
    247.  
    248.             {
    249.  
    250.                 // case 542145, epsilon is too small. Accept up to 1 centimeter before discarding this model.
    251.  
    252.                 if (Vector3.Distance(renderer.bounds.center, go.transform.position) < 0.01F)
    253.  
    254.                 {
    255.  
    256.                     ret = 1;
    257.  
    258.                     center = center + go.transform.position;
    259.  
    260.                 }
    261.  
    262.             }
    263.  
    264.             else if (skin != null)
    265.  
    266.             {
    267.  
    268.                 // case 542145, epsilon is too small. Accept up to 1 centimeter before discarding this model.
    269.  
    270.                 if (Vector3.Distance(skin.bounds.center, go.transform.position) < 0.01F)
    271.  
    272.                 {
    273.  
    274.                     ret = 1;
    275.  
    276.                     center = center + go.transform.position;
    277.  
    278.                 }
    279.  
    280.             }
    281.  
    282.             else if (sprite != null)
    283.  
    284.             {
    285.  
    286.                 if (Vector3.Distance(sprite.bounds.center, go.transform.position) < 0.01F)
    287.  
    288.                 {
    289.  
    290.                     ret = 1;
    291.  
    292.                     center = center + go.transform.position;
    293.  
    294.                 }
    295.  
    296.             }
    297.  
    298.         }
    299.  
    300.  
    301.  
    302.         depth++;
    303.  
    304.         // Recurse into children
    305.  
    306.         foreach (Transform t in go.transform)
    307.  
    308.         {
    309.  
    310.             ret += GetRenderableCenterRecurse(ref center, t.gameObject, depth, minDepth, maxDepth);
    311.  
    312.         }
    313.  
    314.  
    315.  
    316.         return ret;
    317.  
    318.     }
    319.  
    320.  
    321.  
    322.     protected MouseCursor currentCursor
    323.  
    324.     {
    325.  
    326.         get
    327.  
    328.         {
    329.  
    330.             switch (m_ViewTool)
    331.  
    332.             {
    333.  
    334.                 case ViewTool.Orbit: return MouseCursor.Orbit;
    335.  
    336.                 case ViewTool.Pan: return MouseCursor.Pan;
    337.  
    338.                 case ViewTool.Zoom: return MouseCursor.Zoom;
    339.  
    340.                 default: return MouseCursor.Arrow;
    341.  
    342.             }
    343.  
    344.         }
    345.  
    346.     }
    347.  
    348.  
    349.  
    350.  
    351.  
    352.     protected void HandleMouseDown(Event evt, int id, Rect previewRect)
    353.  
    354.     {
    355.  
    356.         if (viewTool != ViewTool.None && previewRect.Contains(evt.mousePosition))
    357.  
    358.         {
    359.  
    360.             EditorGUIUtility.SetWantsMouseJumping(1);
    361.  
    362.             evt.Use();
    363.  
    364.             GUIUtility.hotControl = id;
    365.  
    366.         }
    367.  
    368.     }
    369.  
    370.  
    371.  
    372.     protected void HandleMouseUp(Event evt, int id)
    373.  
    374.     {
    375.  
    376.         if (GUIUtility.hotControl == id)
    377.  
    378.         {
    379.  
    380.             m_ViewTool = ViewTool.None;
    381.  
    382.  
    383.  
    384.             GUIUtility.hotControl = 0;
    385.  
    386.             EditorGUIUtility.SetWantsMouseJumping(0);
    387.  
    388.             evt.Use();
    389.  
    390.         }
    391.  
    392.     }
    393.  
    394.  
    395.  
    396.     protected void HandleMouseDrag(Event evt, int id, Rect previewRect)
    397.     {
    398.         if (m_PreviewInstance == null)
    399.             return;
    400.         if (GUIUtility.hotControl == id)
    401.         {
    402.             switch (m_ViewTool)
    403.             {
    404.                 case ViewTool.Orbit: DoAvatarPreviewOrbit(evt, previewRect); break;
    405.                 case ViewTool.Pan: DoAvatarPreviewPan(evt); break;
    406.  
    407.                 // case 605415 invert zoom delta to match scene view zooming
    408.                 case ViewTool.Zoom: DoAvatarPreviewZoom(evt, -HandleUtility.niceMouseDeltaZoom * (evt.shift ? 2.0f : 0.5f)); break;
    409.                 default: Debug.Log("Enum value not handled"); break;
    410.             }
    411.         }
    412.     }
    413.  
    414.  
    415.  
    416.     protected void HandleViewTool(Event evt, EventType eventType, int id, Rect previewRect)
    417.  
    418.     {
    419.  
    420.         switch (eventType)
    421.  
    422.         {
    423.  
    424.             case EventType.ScrollWheel: DoAvatarPreviewZoom(evt, HandleUtility.niceMouseDeltaZoom * (evt.shift ? 2.0f : 0.5f)); break;
    425.  
    426.             case EventType.MouseDown: HandleMouseDown(evt, id, previewRect); break;
    427.  
    428.             case EventType.MouseUp: HandleMouseUp(evt, id); break;
    429.  
    430.             case EventType.MouseDrag: HandleMouseDrag(evt, id, previewRect); break;
    431.  
    432.         }
    433.  
    434.     }
    435.     public void DoAvatarPreviewOrbit(Event evt, Rect previewRect)
    436.     {
    437.         m_PreviewDir -= evt.delta * (evt.shift ? 3 : 1) / Mathf.Min(previewRect.width, previewRect.height) * 140.0f;
    438.         m_PreviewDir.y = Mathf.Clamp(m_PreviewDir.y, -90, 90);
    439.         evt.Use();
    440.  
    441.     }
    442.  
    443.     public void DoAvatarPreviewPan(Event evt)
    444.     {
    445.         Camera cam = previewUtility.camera;
    446.         Vector3 screenPos = cam.WorldToScreenPoint(bodyPosition + m_PivotPositionOffset);
    447.         Vector3 delta = new Vector3(-evt.delta.x, evt.delta.y, 0);
    448.         // delta panning is scale with the zoom factor to allow fine tuning when user is zooming closely.
    449.         screenPos += delta * Mathf.Lerp(0.25f, 2.0f, m_ZoomFactor * 0.5f);
    450.         Vector3 worldDelta = cam.ScreenToWorldPoint(screenPos) - (bodyPosition + m_PivotPositionOffset);
    451.         m_PivotPositionOffset += worldDelta;
    452.  
    453.         evt.Use();
    454.  
    455.     }
    456.  
    457.     public void DoAvatarPreviewZoom(Event evt, float delta)
    458.     {
    459.         float zoomDelta = -delta * 0.05f;
    460.         m_ZoomFactor += m_ZoomFactor * zoomDelta;
    461.         // zoom is clamp too 10 time closer than the original zoom
    462.         m_ZoomFactor = Mathf.Max(m_ZoomFactor, m_AvatarScale / 10.0f);
    463.         evt.Use();
    464.     }
    465.     public void DoAvatarPreviewDrag(EventType type)
    466.  
    467.     {
    468.         //if (type == EventType.DragUpdated)
    469.         //{
    470.         //    DragAndDrop.visualMode = DragAndDropVisualMode.Link;
    471.         //}
    472.         //else if (type == EventType.DragPerform)
    473.         //{
    474.         //    DragAndDrop.visualMode = DragAndDropVisualMode.Link;
    475.         //    GameObject newPreviewObject = DragAndDrop.objectReferences[0] as GameObject;
    476.         //    if (newPreviewObject)
    477.         //    {
    478.         //        DragAndDrop.AcceptDrag();
    479.         //        SetPreview(newPreviewObject);
    480.         //    }
    481.  
    482.         //}
    483.  
    484.     }
    485.     public void DoAvatarPreviewFrame(Event evt, EventType type, Rect previewRect)
    486.     {
    487.         if (type == EventType.KeyDown && evt.keyCode == KeyCode.F)
    488.         {
    489.             ResetPreviewFocus();
    490.             m_ZoomFactor = m_AvatarScale;
    491.             evt.Use();
    492.         }
    493.  
    494.         if (type == EventType.KeyDown && Event.current.keyCode == KeyCode.G)
    495.         {
    496.             m_PivotPositionOffset = GetCurrentMouseWorldPosition(evt, previewRect) - bodyPosition;
    497.             evt.Use();
    498.  
    499.         }
    500.  
    501.     }
    502.  
    503.     protected Vector3 GetCurrentMouseWorldPosition(Event evt, Rect previewRect)
    504.     {
    505.         Camera cam = previewUtility.camera;
    506.  
    507.         float scaleFactor = previewUtility.GetScaleFactor(previewRect.width, previewRect.height);
    508.  
    509.         Vector3 mouseLocal = new Vector3((evt.mousePosition.x - previewRect.x) * scaleFactor, (previewRect.height - (evt.mousePosition.y - previewRect.y)) * scaleFactor, 0);
    510.  
    511.         mouseLocal.z = Vector3.Distance(bodyPosition, cam.transform.position);
    512.  
    513.         return cam.ScreenToWorldPoint(mouseLocal);
    514.  
    515.     }
    516.  
    517.     public void ResetPreviewFocus()
    518.     {
    519.         m_PivotPositionOffset = bodyPosition - m_PreviewInstance.transform.position;
    520.     }
    521.     public GameObject AddObjectToPreview(GameObject obj)
    522.     {
    523.         var instance = Instantiate(obj);
    524.         //TODO: Remove unnessersary components
    525.         m_PreviewUtility.AddSingleGO(instance);
    526.         return instance;
    527.     }
    528.  
    529.     public override void OnPreviewGUI(Rect r, GUIStyle background)
    530.     {
    531.             DoAvatarPreview(r, background);
    532.     }
    533.  
    534.  
    535.  
    536.     const string s_PreviewStr = "Preview";
    537.  
    538.     int m_PreviewHint = s_PreviewStr.GetHashCode();
    539.  
    540.     const string s_PreviewSceneStr = "PreviewSene";
    541.  
    542.     int m_PreviewSceneHint = s_PreviewSceneStr.GetHashCode();
    543.  
    544.     public void DoAvatarPreview(Rect rect, GUIStyle background)
    545.     {
    546.       //  Init();
    547.  
    548.  
    549.         Rect previewRect = rect;
    550.  
    551.  
    552.         int previewID = GUIUtility.GetControlID(m_PreviewHint, FocusType.Passive, previewRect);
    553.  
    554.         Event evt = Event.current;
    555.  
    556.         EventType type = evt.GetTypeForControl(previewID);
    557.  
    558.  
    559.  
    560.         if (type == EventType.Repaint)
    561.  
    562.         {
    563.  
    564.             DoRenderPreview(previewRect, background);
    565.  
    566.             previewUtility.EndAndDrawPreview(previewRect);
    567.  
    568.         }
    569.  
    570.  
    571.  
    572.  
    573.         int previewSceneID = GUIUtility.GetControlID(m_PreviewSceneHint, FocusType.Passive);
    574.  
    575.         type = evt.GetTypeForControl(previewSceneID);
    576.  
    577.  
    578.  
    579.         DoAvatarPreviewDrag(type);
    580.  
    581.         HandleViewTool(evt, type, previewSceneID, previewRect);
    582.  
    583.         DoAvatarPreviewFrame(evt, type, previewRect);
    584.  
    585.  
    586.  
    587.  
    588.         // Check for model selected from ObjectSelector
    589.  
    590.         //if (evt.type == EventType.ExecuteCommand)
    591.  
    592.         //{
    593.  
    594.         //    string commandName = evt.commandName;
    595.  
    596.         //    if (commandName == ObjectSelector.ObjectSelectorUpdatedCommand && ObjectSelector.get.objectSelectorID == m_ModelSelectorId)
    597.  
    598.         //    {
    599.  
    600.         //        SetPreview(ObjectSelector.GetCurrentObject() as GameObject);
    601.  
    602.         //        evt.Use();
    603.  
    604.         //    }
    605.  
    606.         //}
    607.  
    608.  
    609.  
    610.         // Apply the current cursor
    611.  
    612.         if (evt.type == EventType.Repaint)
    613.  
    614.             EditorGUIUtility.AddCursorRect(previewRect, currentCursor);
    615.  
    616.     }
    617.  
    618.     public void DoRenderPreview(Rect previewRect, GUIStyle background)
    619.     {
    620.         var probe = RenderSettings.ambientProbe;
    621.         previewUtility.BeginPreview(previewRect, background);
    622.  
    623.         Quaternion bodyRot;
    624.  
    625.         Quaternion rootRot;
    626.  
    627.         Vector3 rootPos;
    628.  
    629.         Vector3 bodyPos = m_PreviewInstance.transform.position;
    630.  
    631.         Vector3 pivotPos;
    632.  
    633.  
    634.  
    635.         rootRot = Quaternion.identity;
    636.  
    637.         rootPos = Vector3.zero;
    638.  
    639.  
    640.  
    641.         bodyRot = Quaternion.identity;
    642.  
    643.  
    644.  
    645.         pivotPos = Vector3.zero;
    646.  
    647.  
    648.         SetupPreviewLightingAndFx(probe);
    649.  
    650.  
    651.  
    652.         Vector3 direction = bodyRot * Vector3.forward;
    653.  
    654.         direction[1] = 0;
    655.  
    656.         Quaternion directionRot = Quaternion.LookRotation(direction);
    657.  
    658.         Vector3 directionPos = rootPos;
    659.  
    660.  
    661.  
    662.         Quaternion pivotRot = rootRot;
    663.  
    664.  
    665.  
    666.         // Scale all Preview Objects to fit avatar size.
    667.  
    668.        // PositionPreviewObjects(pivotRot, pivotPos, bodyRot, bodyPosition, directionRot, rootRot, rootPos, directionPos, m_AvatarScale);
    669.  
    670.  
    671.  
    672.         previewUtility.camera.nearClipPlane = 0.5f * m_ZoomFactor;
    673.  
    674.         previewUtility.camera.farClipPlane = 100.0f * m_AvatarScale;
    675.  
    676.         Quaternion camRot = Quaternion.Euler(-m_PreviewDir.y, -m_PreviewDir.x, 0);
    677.  
    678.  
    679.  
    680.         // Add panning offset
    681.  
    682.         Vector3 camPos = camRot * (Vector3.forward * -5.5f * m_ZoomFactor) + bodyPos + m_PivotPositionOffset;
    683.  
    684.         previewUtility.camera.transform.position = camPos;
    685.  
    686.         previewUtility.camera.transform.rotation = camRot;
    687.  
    688.  
    689.         previewUtility.Render(false);
    690.  
    691.  
    692.  
    693.     }
    694.     private void SetupPreviewLightingAndFx(SphericalHarmonicsL2 probe)
    695.     {
    696.         previewUtility.lights[0].intensity = 1.4f;
    697.         previewUtility.lights[0].transform.rotation = Quaternion.Euler(40f, 40f, 0);
    698.         previewUtility.lights[1].intensity = 1.4f;
    699.         RenderSettings.ambientMode = AmbientMode.Custom;
    700.         RenderSettings.ambientLight = new Color(0.1f, 0.1f, 0.1f, 1.0f);
    701.         RenderSettings.ambientProbe = probe;
    702.  
    703.     }
    704.  
    705.     public void OnDisable()
    706.     {
    707.         if (m_PreviewUtility != null)
    708.         {
    709.             m_PreviewUtility.Cleanup();
    710.             m_PreviewUtility = null;
    711.         }
    712.     }
    713. }
    714.  
     
    PiezPiedPy and NDSno1 like this.
  3. NDSno1

    NDSno1

    Joined:
    Dec 20, 2014
    Posts:
    223
    Thank you very much. This saved me from a lot of headache
     
    BinaryCats likes this.
  4. PiezPiedPy

    PiezPiedPy

    Joined:
    Mar 22, 2019
    Posts:
    14
    Cheers BinaryCats
     
    BinaryCats likes this.