void OnDestroy() // Destroy in VFTerrain { Mc.sharedMesh = null; _bPrimal = false; Data = null; TransvoxelGo = null; Destroy(Mf.sharedMesh); }
public void OnRecycle() { gameObject.SetActive(false); if (IsOriginalGo) { Mr.enabled = true; } else if (_bPrimal) { if (Mc.sharedMesh != null) { OnColliderDestroy(); } } //Note: Directly mesh.Clear() will cause rebuilding MeshCollider which cause spike; // Destroy do not destroy it until the end of this frame, which cause FillMesh may fill the willDestroy mesh // So use DestroyImmediate instead. //DestroyImmediate(_mf.sharedMesh, true); Mc.sharedMesh = null; Mf.sharedMesh.Clear(); _terType = int.MinValue; _bPrimal = false; Data = null; if (OriginalChunkGo != null) { Debug.LogError("[VFChunkGo]Free original chunk go" + OriginalChunkGo.name); VFGoPool <VFVoxelChunkGo> .FreeGo(OriginalChunkGo); OriginalChunkGo = null; } if (TransvoxelGo != null) { VFGoPool <VFTransVoxelGo> .FreeGo(TransvoxelGo); TransvoxelGo = null; } // Reset to default Mr.sharedMaterial = DefMat; gameObject.layer = DefLayer; transform.parent = DefParent; for (int i = transform.childCount - 1; i >= 0; i--) { Transform child = transform.GetChild(i); VFGoPool <VFVoxelChunkGo> .FreeGo(child.GetComponent <VFVoxelChunkGo>()); } }
public void SetTransGo(IVxSurfExtractReq req, int faceMask) { if (TransvoxelGo != null) { VFGoPool <VFTransVoxelGo> .FreeGo(TransvoxelGo); TransvoxelGo = null; } if (faceMask != 0) { VFTransVoxelGo go = VFGoPool <VFTransVoxelGo> .GetGo(); req.FillMesh(go._mf.sharedMesh); go._faceMask = faceMask; go.transform.parent = transform; //go.transform.localScale = Vector3.one; go.transform.localPosition = Vector3.zero; go.gameObject.SetActive(true); TransvoxelGo = go; } }