Skip to content

Commit

Permalink
feat: hiding COM prefab list when it is empty and NetworkPrefab is set
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Feb 2, 2023
1 parent 8c63726 commit 5088d33
Showing 1 changed file with 52 additions and 2 deletions.
54 changes: 52 additions & 2 deletions Assets/Mirage/Editor/ClientObjectManagerInspector.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

Expand All @@ -10,8 +9,59 @@ public class ClientObjectManagerInspector : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
DefaultInspector();

DrawButtons();
}

private void DefaultInspector()
{
serializedObject.UpdateIfRequiredOrScript();
var itt = serializedObject.GetIterator();
//script field
itt.NextVisible(true);
GUI.enabled = false;
EditorGUILayout.PropertyField(itt);
GUI.enabled = true;

// other fields
while (itt.NextVisible(false))
{
if (OverrideProperty(itt))
continue;

EditorGUILayout.PropertyField(itt, true);
}
serializedObject.ApplyModifiedProperties();
}

private bool OverrideProperty(SerializedProperty property)
{
if (property.propertyPath == nameof(ClientObjectManager.spawnPrefabs))
return OverrideSpawnPrefabProperty(property);

return false;
}

private bool OverrideSpawnPrefabProperty(SerializedProperty property)
{
var com = (ClientObjectManager)target;

// if networkPrefab has value and no items in spawnprefabs list,
// then hide the list
var removeField = com.NetworkPrefabs != null && property.arraySize == 0;
if (removeField) ;
{
EditorGUILayout.Space(5);
EditorGUILayout.LabelField("Prefabs", EditorStyles.boldLabel);
EditorGUILayout.Space(3);
}

return removeField;
}

public void DrawButtons()
{
var com = (ClientObjectManager)target;
if (com.NetworkPrefabs != null && com.spawnPrefabs.Count > 0)
{
Expand Down

0 comments on commit 5088d33

Please sign in to comment.