| | 1 | | using DCL.Controllers; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using DCL.Models; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace DCL.Components |
| | 7 | | { |
| | 8 | | public class SphereShape : ParametrizedShape<SphereShape.Model> |
| | 9 | | { |
| | 10 | | [System.Serializable] |
| | 11 | | new public class Model : BaseShape.Model |
| | 12 | | { |
| 19 | 13 | | public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); } |
| | 14 | | } |
| | 15 | |
|
| 33 | 16 | | public SphereShape() { model = new Model(); } |
| | 17 | |
|
| 0 | 18 | | public override int GetClassId() { return (int) CLASS_ID.SPHERE_SHAPE; } |
| | 19 | |
|
| | 20 | | public static Mesh mesh = null; |
| | 21 | | private static int meshUses = 0; |
| | 22 | |
|
| | 23 | | public override Mesh GenerateGeometry() |
| | 24 | | { |
| 9 | 25 | | if (mesh == null) |
| | 26 | | { |
| 1 | 27 | | mesh = PrimitiveMeshBuilder.BuildSphere(1f); |
| | 28 | | } |
| | 29 | |
|
| 9 | 30 | | meshUses++; |
| | 31 | |
|
| 9 | 32 | | return mesh; |
| | 33 | | } |
| | 34 | |
|
| | 35 | | protected override void DestroyGeometry() |
| | 36 | | { |
| 4 | 37 | | meshUses--; |
| 4 | 38 | | if (meshUses == 0) |
| | 39 | | { |
| 0 | 40 | | GameObject.Destroy(mesh); |
| | 41 | | } |
| 4 | 42 | | } |
| | 43 | |
|
| 19 | 44 | | protected override bool ShouldGenerateNewMesh(BaseShape.Model newModel) { return currentMesh == null; } |
| | 45 | | } |
| | 46 | | } |