// // /*=============================================================================== // // Copyright (C) 2024 PhantomsXR Ltd. All Rights Reserved. // // // // This file is part of the Phantom.XRMOD.UnityFusion.Runtime.Core. // // // // The AVPPlatform cannot be copied, distributed, or made available to // // third-parties for commercial purposes without written permission of PhantomsXR Ltd. // // // // Contact info@phantomsxr.com for licensing requests. // // ===============================================================================*/ using UnityEngine; using UnityFusion.Runtime.Intepreter; namespace UnityFusion.Runtime { public class Utility { /// /// find ilrt gameObject /// /// /// GameObject public static GameObject FindGameFromILTypeInstance(ILTypeInstance _instance) { var tmp_ReturnType = _instance.Type; if (tmp_ReturnType.ReflectionType == typeof(MonoBehaviour)) { var tmp_PropertyInfo = tmp_ReturnType.ReflectionType.GetProperty("gameObject"); if (tmp_PropertyInfo != null) return tmp_PropertyInfo.GetValue((_instance as ILTypeInstance).CLRInstance) as GameObject; } else if (tmp_ReturnType.ReflectionType.IsSubclassOf(typeof(MonoBehaviour))) { if (tmp_ReturnType.ReflectionType.BaseType == null) return null; var tmp_PropertyInfo = tmp_ReturnType.ReflectionType.BaseType.GetProperty("gameObject"); if (tmp_PropertyInfo != null) return tmp_PropertyInfo.GetValue((_instance as ILTypeInstance).CLRInstance) as GameObject; } return null; } } }