private SgtQuadsModel GetOrNewModel(int index) { var model = default(SgtQuadsModel); if (models == null) { models = new List <SgtQuadsModel>(); } if (index < models.Count) { model = models[index]; } else { models.Add(model); } if (model == null || model.Quads != this) { model = models[index] = SgtQuadsModel.Create(this); model.SetMaterial(material); } return(model); }
public static void MarkForDestruction(SgtQuadsModel model) { if (model != null) { model.Quads = null; model.PoolMeshNow(); model.gameObject.SetActive(true); } }
public static void Pool(SgtQuadsModel model) { if (model != null) { model.Quads = null; model.PoolMeshNow(); SgtComponentPool <SgtQuadsModel> .Add(model); } }
protected virtual void OnDestroy() { if (models != null) { for (var i = models.Count - 1; i >= 0; i--) { SgtQuadsModel.MarkForDestruction(models[i]); } } SgtHelper.Destroy(material); }
private Mesh GetOrNewMesh(SgtQuadsModel model) { var mesh = model.Mesh; if (mesh == null) { mesh = SgtHelper.CreateTempMesh("Quads Mesh (Generated)"); model.SetMesh(mesh); } else { mesh.Clear(false); } return(mesh); }
public void UpdateMeshesAndModels() { updateMeshesAndModelsCalled = true; var starCount = BeginQuads(); var modelCount = 0; // Build meshes and models until starCount reaches 0 if (starCount > 0) { BuildRects(); ConvertRectsToCoords(); while (starCount > 0) { var quadCount = Mathf.Min(starCount, SgtHelper.QuadsPerMesh); var model = GetOrNewModel(modelCount); var mesh = GetOrNewMesh(model); model.SetMaterial(material); BuildMesh(mesh, modelCount * SgtHelper.QuadsPerMesh, quadCount); modelCount += 1; starCount -= quadCount; } } // Remove any excess if (models != null) { for (var i = models.Count - 1; i >= modelCount; i--) { SgtQuadsModel.Pool(models[i]); models.RemoveAt(i); } } EndQuads(); }