Skip to content

Commit

Permalink
Fix quick layer changing on mirrors
Browse files Browse the repository at this point in the history
  • Loading branch information
oneVR committed Jun 9, 2020
1 parent 53ed07f commit f09d6c7
Showing 1 changed file with 24 additions and 31 deletions.
55 changes: 24 additions & 31 deletions Scripts/Editor/CustomEditors.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
#if VRC_SDK_VRCSDK3
#if VRC_SDK_VRCSDK3
using VRC.SDKBase;
#endif
#if VRC_SDK_VRCSDK2
using VRCSDK2;
#endif
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;

#if VRC_SDK_VRCSDK2 || VRC_SDK_VRCSDK3
namespace VRWorldToolkit
Expand All @@ -18,7 +19,7 @@ public class CustomEditors : MonoBehaviour
[CanEditMultipleObjects]
public class CustomMirrorInspector : Editor
{
private bool _showExplanations = false;
private bool _showExplanations;

public override void OnInspectorGUI()
{
Expand All @@ -32,43 +33,21 @@ public override void OnInspectorGUI()

EditorGUILayout.BeginHorizontal();

if (GUILayout.Button("Show only players"))
{
foreach (var o in Selection.objects)
{
var mirror = (GameObject) o;
mirror.GetComponent<VRC_MirrorReflection>().m_ReflectLayers.value = 262656;
}

EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
}
if (GUILayout.Button("Show only players")) MirrorLayerChange(262656);

if (GUILayout.Button("Show players/world"))
{
foreach (var o in Selection.objects)
{
var mirror = (GameObject) o;
mirror.GetComponent<VRC_MirrorReflection>().m_ReflectLayers.value = 262657;
}

EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
}
if (GUILayout.Button("Show players/world")) MirrorLayerChange(262657);

EditorGUILayout.EndHorizontal();

if (Selection.gameObjects.Length == 1)
{
VRC_MirrorReflection currentMirror = (VRC_MirrorReflection)target;
var currentMirror = (VRC_MirrorReflection) target;

if (currentMirror.m_ReflectLayers == -1025)
{
EditorGUILayout.HelpBox("Avoid using default layers on mirrors to save on frames, you should disable all layers that aren't needed in this mirror.", MessageType.Info);
}

if (Helper.LayerIncludedInMask(LayerMask.NameToLayer("UiMenu"), currentMirror.m_ReflectLayers))
{
EditorGUILayout.HelpBox("Having UiMenu enabled on mirrors causes VRChat UI elements to render twice which can cause noticable performance drop in populated instances", MessageType.Warning);
}
EditorGUILayout.HelpBox("Having UiMenu enabled on mirrors causes VRChat UI elements to render twice which can cause noticeable performance drop in populated instances", MessageType.Warning);
}

_showExplanations = EditorGUILayout.Foldout(_showExplanations, "VRChat specific layer explanations");
Expand All @@ -86,6 +65,20 @@ public override void OnInspectorGUI()
GUILayout.Label("<b>MirrorReflection:</b>\nThis layer is used for your own mirror version", style);
}
}

private static void MirrorLayerChange(int layerMask)
{
foreach (GameObject gameObject in Selection.objects)
{
var mirror = gameObject.GetComponent<VRC_MirrorReflection>();

mirror.m_ReflectLayers.value = layerMask;

PrefabUtility.RecordPrefabInstancePropertyModifications(mirror);
}

EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
}
}
}
}
Expand Down

0 comments on commit f09d6c7

Please sign in to comment.