Skip to content

Instantly share code, notes, and snippets.

@TakaakiIchijo
Created April 13, 2025 13:03
Show Gist options
  • Save TakaakiIchijo/7dae5c3f2f071405338f5b8f114e9fb2 to your computer and use it in GitHub Desktop.
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
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