Skip to content

Commit

Permalink
refactor: removing convert code from NetworkInspectorCallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Mar 25, 2024
1 parent dd2d8a3 commit 66c9f71
Showing 1 changed file with 0 additions and 52 deletions.
52 changes: 0 additions & 52 deletions Assets/Mirage/Runtime/NetworkIdentityInspectorCallbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,57 +26,5 @@ private void Awake()
Identity.OnStopClient.AddListener(_onStopClient.Invoke);
Identity.OnStopServer.AddListener(_onStopServer.Invoke);
}


#if UNITY_EDITOR
public void Convert()
{
_onStartServer = GetAndClear<AddLateEventUnity>(nameof(_onStartServer));
_onStartClient = GetAndClear<AddLateEventUnity>(nameof(_onStartClient));
_onStartLocalPlayer = GetAndClear<AddLateEventUnity>(nameof(_onStartLocalPlayer));
_onAuthorityChanged = GetAndClear<BoolAddLateEvent>(nameof(_onAuthorityChanged));
_onOwnerChanged = GetAndClear<NetworkPlayerAddLateEvent>(nameof(_onOwnerChanged));
_onStopClient = GetAndClear<AddLateEventUnity>(nameof(_onStopClient));
_onStopServer = GetAndClear<AddLateEventUnity>(nameof(_onStopServer));

UnityEditor.EditorUtility.SetDirty(this);
UnityEditor.EditorUtility.SetDirty(Identity);

if (Identity.gameObject.scene.IsValid())
{
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(Identity.gameObject.scene);
}
}

private T GetAndClear<T>(string field) where T : new()
{
var type = typeof(NetworkIdentity);
var flags = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic;
var info = type.GetField(field, flags);
var value = (T)info.GetValue(Identity);
info.SetValue(Identity, new T());
return value;
}
#endif
}
}

#if UNITY_EDITOR
namespace Mirage.EditorScripts
{
[UnityEditor.CustomEditor(typeof(NetworkInspectorCallbacks))]
public class NetworkInspectorCallbacksEditor : UnityEditor.Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();

var target = (NetworkInspectorCallbacks)base.target;
if (GUILayout.Button("Move Identity events"))
{
target.Convert();
}
}
}
}
#endif

0 comments on commit 66c9f71

Please sign in to comment.