Created
April 13, 2025 13:03
-
-
Save TakaakiIchijo/7dae5c3f2f071405338f5b8f114e9fb2 to your computer and use it in GitHub Desktop.
Detect this player is vitual player or not in Unity Multiplayer Play Mode package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Reflection; | |
using UnityEditor; | |
using UnityEngine; | |
namespace NetcodeExtension | |
{ | |
[InitializeOnLoad] | |
public static class MultiPlayerPlayModeExtensions | |
{ | |
private static Type _targetType; | |
private static PropertyInfo _targetPropertyInfo; | |
public static readonly bool IsClone = false; | |
static MultiPlayerPlayModeExtensions() | |
{ | |
_targetType = Type.GetType("Unity.Multiplayer.Playmode.VirtualProjects.Editor.VirtualProjectsEditor,Unity.Multiplayer.Playmode.VirtualProjects.Editor"); | |
if (_targetType == null) | |
{ | |
Debug.LogError("Type VirtualProjectsEditor not found."); | |
} | |
_targetPropertyInfo = _targetType?.GetProperty("IsClone", BindingFlags.Public | BindingFlags.Static); | |
if (_targetPropertyInfo == null) | |
{ | |
Debug.LogError("Event IsClone not found."); | |
} | |
IsClone = (bool)_targetPropertyInfo.GetValue(null); | |
Debug.Log("VirtualPlayer.IsClone "+IsClone); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment