public void GenerateFromDynamicMesh(BuildRMesh mesh) { if (_mesh == null) { _mesh = new Mesh(); } if (_meshCollider == null) { _meshCollider = gameObject.AddComponent <MeshCollider>(); } mesh.Build(_mesh); _meshCollider.sharedMesh = _mesh; if (mesh.hasOverflowed) { if (_sibling == null) { _sibling = Create(transform.parent, name); } _sibling.GenerateFromDynamicMesh(mesh.overflow); } else { if (_sibling != null) { _sibling.Deactivate(); } _sibling = null; } }
public void Push(ColliderPartRuntime item) { if (!_initialised) { Init(); } item.transform.parent = transform; _pool.Add(item); }
public void GenerateFromDynamicMesh(BuildRMesh overflow = null) { HUtils.log(); if (_dynamicMesh.vertexCount == 0) { return; } if (_mesh == null) { _mesh = new Mesh(); } if (_filter == null) { _filter = gameObject.AddComponent <MeshFilter>(); } if (_renderer == null) { _renderer = gameObject.AddComponent <MeshRenderer>(); } if (overflow != null) { _dynamicMesh = overflow; } _dynamicMesh.Build(_mesh); _filter.sharedMesh = _mesh; _renderer.sharedMaterials = _dynamicMesh.materials.ToArray(); if (_dynamicMesh.hasOverflowed) { if (_sibling == null) { _sibling = GetPoolItem(); } _sibling.GenerateFromDynamicMesh(_dynamicMesh.overflow); } else { if (_sibling != null) { _sibling.Deactivate(); VisualPartRuntimePool.Instance.Push(_sibling); } _sibling = null; } if (_colliderPart == null) { _colliderPart = ColliderPartRuntime.GetPoolItem(); _colliderPart.GenerateFromColliderMesh(_colliderMesh); } }
public static ColliderPartRuntime Create(Transform parent = null, string name = "visual part") { GameObject go = new GameObject(name); if (parent != null) { go.transform.parent = parent; } ColliderPartRuntime output = go.AddComponent <ColliderPartRuntime>(); return(output); }
private ColliderPartRuntime GetPoolItem() { if (_pool.Count > 0) { ColliderPartRuntime output = _pool[0]; _pool.RemoveAt(0); return(output); } else { return(Instantiate()); //there was nothing suitable in the pool - make a new one! } }
public void Deactivate() { _meshCollider.sharedMesh = null; for (int i = 0; i < _boxColliders.Length; i++) { Destroy(_boxColliders[i]); } _mesh = null; _mesh.Clear(false); if (_sibling != null) { _sibling.Deactivate(); _sibling = null; } ColliderPartRuntimePool.Instance.Push(this); }
public void Clear() { if (_mesh == null) { _mesh = new Mesh(); } _mesh.Clear(); if (_sibling != null) { _sibling.Deactivate(); VisualPartRuntimePool.Instance.Push(_sibling); } _colliderMesh.Clear(); if (_colliderPart == null) { _colliderPart = ColliderPartRuntime.GetPoolItem(); } _colliderPart.Clear(); }
private ColliderPartRuntime Instantiate() { return(ColliderPartRuntime.Create(transform, "New Collider Part")); }