/// <summary> /// Initializes non-serialized internal cache in the component. /// Should be called after instantiation. /// Use <see cref="isInitialized"/> to check if it has already been initialized. /// </summary> internal void Initialize() { if (isInitialized) { return; } if (!m_ComponentsCache.IsValid()) { m_ComponentsCache = new MeshComponentsCache(gameObject); } if (m_PolyMesh == null) { m_PolyMesh = new PolyMesh(); } Mesh mesh = null; if (m_ComponentsCache.MeshFilter != null) { mesh = m_ComponentsCache.MeshFilter.sharedMesh; } else if (m_ComponentsCache.SkinnedMeshRenderer != null) { mesh = m_ComponentsCache.SkinnedMeshRenderer.sharedMesh; } if (!polyMesh.IsValid() && mesh) { SetMesh(mesh); } m_Initialized = true; }
/// <summary> /// Initializes non-serialized internal cache in the component. /// Should be called after instantiation. /// Use <see cref="isInitialized"/> to check if it has already been initialized. /// </summary> internal void Initialize() { if (isInitialized) { return; } if (!m_ComponentsCache.IsValid()) { m_ComponentsCache = new MeshComponentsCache(gameObject); } if (m_PolyMesh == null) { m_PolyMesh = new PolyMesh(); } Mesh mesh = null; if (m_ComponentsCache.MeshFilter != null) { mesh = m_ComponentsCache.MeshFilter.sharedMesh; if (m_OriginalMeshObject == null) { m_OriginalMeshObject = mesh; } } else if (m_ComponentsCache.SkinnedMeshRenderer != null) { mesh = m_ComponentsCache.SkinnedMeshRenderer.sharedMesh; } if (!polyMesh.IsValid() && mesh) { SetMesh(mesh); } else if (polyMesh.IsValid() && (mesh == null || mesh.vertexCount != polyMesh.vertexCount)) { SetMesh(polyMesh.ToUnityMesh()); } m_Initialized = true; }