Skip to content

Commit

Permalink
Fix player layers, pickup buttons, duplicated debuggers and missing d…
Browse files Browse the repository at this point in the history
…ebuggers on disabled objects
  • Loading branch information
GotoFinal committed Apr 14, 2020
1 parent ae5683e commit e07aaca
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
7 changes: 4 additions & 3 deletions Assets/GotoUdon/Editor/GotoUdonEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[InitializeOnLoad]
public class GotoUdonEditor : EditorWindow
{
private const string VERSION = "v1.0.1";
private const string VERSION = "v1.0.2";

// register an event handler when the class is initialized
static GotoUdonEditor()
Expand All @@ -38,11 +38,12 @@ private static void OnModeChange(PlayModeStateChange state)
}

Instance.OnPlay();
foreach (UdonBehaviour udonBehaviour in Object.FindObjectsOfType<UdonBehaviour>())
foreach (UdonBehaviour udonBehaviour in Resources.FindObjectsOfTypeAll<UdonBehaviour>())
{
GameObject gameObject = udonBehaviour.gameObject;
if (gameObject == null) return;
gameObject.AddComponent<UdonDebugger>();
if (gameObject.GetComponent<UdonDebugger>() == null)
gameObject.AddComponent<UdonDebugger>();
}
}

Expand Down
6 changes: 3 additions & 3 deletions Assets/GotoUdon/Editor/UdonDebuggerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public override void OnInspectorGUI()
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
ActionButton("OnPickup", behaviour => behaviour.OnDestroy());
ActionButton("OnPickupUseDown", behaviour => behaviour.OnSpawn());
ActionButton("OnPickupUseUp", behaviour => behaviour.OnDrop());
ActionButton("OnPickup", behaviour => behaviour.OnPickup());
ActionButton("OnPickupUseDown", behaviour => behaviour.OnPickupUseDown());
ActionButton("OnPickupUseUp", behaviour => behaviour.OnPickupUseUp());
GUILayout.EndHorizontal();

// TODO: more interactions
Expand Down
23 changes: 23 additions & 0 deletions Assets/GotoUdon/VRC/SimulatedVRCPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,29 @@ private void Start()
}
}

public void OnBecameLocal()
{
// local player layer
SetLayerRecursively(gameObject, 10);
}

public void OnBecameRemote()
{
// players layer
SetLayerRecursively(gameObject, 9);
}

private void SetLayerRecursively(GameObject obj, int newLayer)
{
if (obj == null) return;
obj.layer = newLayer;
foreach (Transform child in obj.transform)
{
if (child == null) continue;
SetLayerRecursively(child.gameObject, newLayer);
}
}

public T SetMetadata<T>(string key, Func<T, T> newValueFunc)
{
T newValue = newValueFunc(GetMetadata<T>(key));
Expand Down
3 changes: 3 additions & 0 deletions Assets/GotoUdon/VRC/VRCEmulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ public void MakeLocal(SimulatedVRCPlayer player)
if (localPlayer != null)
{
localPlayer.isLocal = false;
localPlayer.SimulatedVrcPlayer.OnBecameRemote();
}

localPlayer = player.VRCPlayer;
localPlayer.isLocal = true;
player.OnBecameLocal();
}

private bool _hasStarted = false;
Expand All @@ -84,6 +86,7 @@ public void AddPlayer(SimulatedVRCPlayer player)
{
MakeLocal(player);
}
else player.OnBecameRemote();

// if its first play on startup we delay firing on OnJoin events as this seems to fire before all components are ready in code and might cause weird issues.
if (_hasStarted)
Expand Down

0 comments on commit e07aaca

Please sign in to comment.