Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions Source/Editor/ClientSimEditorRuntimeLinker.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using UnityEditor;
using UnityEngine;
using VRC.SDKBase;

namespace VRC.SDK3.ClientSim.Editor
{
Expand All @@ -12,25 +13,38 @@ public static class ClientSimEditorRuntimeLinker
{
private static void ModeStateChanged(PlayModeStateChange state)
{

if(state == PlayModeStateChange.EnteredPlayMode)
{
ClientSimMenu.openSettingsHook += ClientSimSettingsWindow.Init;
ClientSimMenu.checkValidSettingsHook += ClientSimProjectSettingsSetup.IsUsingCorrectSettings;
}

// On exiting playmode, remove the Editor method hooks.
if (state == PlayModeStateChange.ExitingPlayMode)
{
ClientSimMenu.openSettingsHook -= ClientSimSettingsWindow.Init;
ClientSimMenu.checkValidSettingsHook -= ClientSimProjectSettingsSetup.IsUsingCorrectSettings;

EditorApplication.playModeStateChanged -= ModeStateChanged;
}

if (state == PlayModeStateChange.ExitingEditMode)
{
InitializeScene();
}
}

// When entering playmode, set Editor method hooks.
// Using this runtime initialized method due to timing issues with with Domain Reloading on and off.
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
private static void OnPlaymodeStart()
[InitializeOnLoadMethod]
private static void OnProjectLoadedInEditor()
{
ClientSimMenu.openSettingsHook += ClientSimSettingsWindow.Init;
ClientSimMenu.checkValidSettingsHook += ClientSimProjectSettingsSetup.IsUsingCorrectSettings;

EditorApplication.playModeStateChanged += ModeStateChanged;
}


private static void InitializeScene()
{
ClientSimNetworkingUtilities.DoSceneSetup();
}
}
}
72 changes: 72 additions & 0 deletions Source/Editor/Editors/ClientSimNetworkIdHolderEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using VRC.SDK3.ClientSim.Editor.VisualElements;

namespace VRC.SDK3.ClientSim.Editor
{
#if VRC_ENABLE_PLAYER_PERSISTENCE
[UnityEditor.CustomEditor(typeof(ClientSimNetworkIdHolder))]
public class ClientSimNetworkIdHolderEditor : UnityEditor.Editor
{
private VisualElement _List;
private IClientSimEventDispatcher _eventDispatcher;

public void OnEnable()
{
_eventDispatcher = ClientSimMain.GetInstance().GetEventDispatcher();
_eventDispatcher.Subscribe<ClientSimOnPlayerObjectUpdatedEvent>(OnPlayerObjectUpdated);
}

public override VisualElement CreateInspectorGUI()
{
VisualElement root = new VisualElement();
ClientSimNetworkIdHolder networkIdHolder = (ClientSimNetworkIdHolder) target;

if (networkIdHolder._components != null)
{
root.Add(new Label("Network Id: " + networkIdHolder._networkId.GetNetworkId()));
root.Add(new Label("Network Components"));
_List = new VisualElement();
for (int i = 0; i < networkIdHolder._components.Count; i++)
{
if (ClientSimNetworkHolderInstanceElement.encodeDecoders.TryGetValue(networkIdHolder._components[i].GetType().FullName, out var encodeDecoder))
{
MonoBehaviour component = networkIdHolder._components[i];
if(networkIdHolder._data.Count > i)
_List.Add(encodeDecoder.GenerateFields(component,networkIdHolder._data[i].DataDictionary));
}
}
root.Add(_List);
}

return root;
}

private void OnPlayerObjectUpdated(ClientSimOnPlayerObjectUpdatedEvent e)
{
ClientSimNetworkIdHolder networkIdHolder = (ClientSimNetworkIdHolder) target;
if ((ClientSimNetworkIdHolder)e.Data != networkIdHolder) return;

if (networkIdHolder._components != null)
{
for (int i = 0; i < networkIdHolder._components.Count; i++)
{
if (ClientSimNetworkHolderInstanceElement.encodeDecoders.TryGetValue(networkIdHolder._components[i].GetType().FullName, out var encodeDecoder))
{
MonoBehaviour component = networkIdHolder._components[i];
if(networkIdHolder._data.Count > i)
encodeDecoder.UpdateFields(component,_List[i],networkIdHolder._data[i].DataDictionary);
}
}
}
}

public void OnDisable()
{
_eventDispatcher?.Unsubscribe<ClientSimOnPlayerObjectUpdatedEvent>(OnPlayerObjectUpdated);
}
}
#endif
}
3 changes: 3 additions & 0 deletions Source/Editor/Editors/ClientSimNetworkIdHolderEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading