static bool IsNativeObjectAlive(UnityEngine.Object o) { if (o.GetCachedPtr() != IntPtr.Zero) { return(true); } //Ressurection of assets is complicated. //For almost all cases, if you have a c# wrapper for an asset like a material, //if the material gets moved, or deleted, and later placed back, the persistentmanager //will ensure it will come back with the same instanceid. //in this case, we want the old c# wrapper to still "work". //we only support this behaviour in the editor, even though there //are some cases in the player where this could happen too. (when unloading things from assetbundles) //supporting this makes all operator== slow though, so we decided to not support it in the player. // //we have an exception for assets that "are" a c# object, like a MonoBehaviour in a prefab, and a ScriptableObject. //in this case, the asset "is" the c# object, and you cannot actually pretend //the old wrapper points to the new c# object. this is why we make an exception in the operator== //for this case. If we had a c# wrapper to a persistent monobehaviour, and that one gets //destroyed, and placed back with the same instanceID, we still will say that the old //c# object is null. if (o is MonoBehaviour || o is ScriptableObject) { return(false); } return(DoesObjectWithInstanceIDExist(o.GetInstanceID())); }
private static bool IsNativeObjectAlive(UnityEngine.Object o) { if (o.GetCachedPtr() != IntPtr.Zero) { return(true); } if ((o is MonoBehaviour) || (o is ScriptableObject)) { return(false); } return(DoesObjectWithInstanceIDExist(o.GetInstanceID())); }
private static bool IsNativeObjectAlive(UnityEngine.Object o) { return((o.GetCachedPtr() != IntPtr.Zero) || ((!(o is MonoBehaviour) && !(o is ScriptableObject)) && DoesObjectWithInstanceIDExist(o.GetInstanceID()))); }