|
|
|
|
|
|
using System; |
|
|
|
using UnityEngine; |
|
|
|
#if UNITY_EDITOR
|
|
|
|
using UnityEditor; |
|
|
|
using UnityEditor.Experimental.SceneManagement; |
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
protected virtual void OnMeshInstanceCreated() { } |
|
|
|
protected virtual void OnMeshInstanceDeleted() { } |
|
|
|
|
|
|
|
static bool IsMeshInstance(Mesh mesh) |
|
|
|
{ |
|
|
|
#if UNITY_EDITOR
|
|
|
|
return (EditorUtility.IsPersistent(mesh) == false); |
|
|
|
#else
|
|
|
|
return (mesh.GetInstanceID() < 0); |
|
|
|
#endif
|
|
|
|
} |
|
|
|
|
|
|
|
if (smr.sharedMesh == null || (smr.sharedMesh.GetInstanceID() < 0 && smr.sharedMesh != meshInstance)) |
|
|
|
if (smr.sharedMesh == null || (IsMeshInstance(smr.sharedMesh) && smr.sharedMesh != meshInstance)) |
|
|
|
if (smr.sharedMesh != null && smr.sharedMesh.GetInstanceID() >= 0) |
|
|
|
if (smr.sharedMesh != null && !IsMeshInstance(smr.sharedMesh)) |
|
|
|
smr.sharedMesh = EnsureMeshInstanceAux(smr.sharedMesh); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
if (mf != null) |
|
|
|
{ |
|
|
|
if (mf.sharedMesh == null || (mf.sharedMesh.GetInstanceID() < 0 && mf.sharedMesh != meshInstance)) |
|
|
|
if (mf.sharedMesh == null || (IsMeshInstance(mf.sharedMesh) && mf.sharedMesh != meshInstance)) |
|
|
|
if (mf.sharedMesh != null && mf.sharedMesh.GetInstanceID() >= 0) |
|
|
|
if (mf.sharedMesh != null && !IsMeshInstance(mf.sharedMesh)) |
|
|
|
mf.sharedMesh = EnsureMeshInstanceAux(mf.sharedMesh); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
var smr = GetComponent<SkinnedMeshRenderer>(); |
|
|
|
if (smr != null) |
|
|
|
{ |
|
|
|
if (smr.sharedMesh == null || smr.sharedMesh.GetInstanceID() < 0) |
|
|
|
if (smr.sharedMesh == null || IsMeshInstance(smr.sharedMesh)) |
|
|
|
smr.sharedMesh = meshAsset; |
|
|
|
|
|
|
|
RemoveMeshInstanceAux(); |
|
|
|
|
|
|
var mf = GetComponent<MeshFilter>(); |
|
|
|
if (mf != null) |
|
|
|
{ |
|
|
|
if (mf.sharedMesh == null || mf.sharedMesh.GetInstanceID() < 0) |
|
|
|
if (mf.sharedMesh == null || IsMeshInstance(mf.sharedMesh)) |
|
|
|
mf.sharedMesh = meshAsset; |
|
|
|
|
|
|
|
RemoveMeshInstanceAux(); |
|
|
|