public void UpdateModels() { var angleStep = SgtHelper.Divide(360.0f, Segments); for (var i = 0; i < Segments; i++) { var model = SgtHelper.GetIndex(ref models, i); var angle = angleStep * i; var rotation = Quaternion.Euler(0.0f, angle, 0.0f); if (model == null) { model = models[i] = SgtAccretionModel.Create(this); } model.SetMesh(Mesh); model.SetMaterial(material); model.SetRotation(rotation); } // Remove any excess if (models != null) { var min = Mathf.Max(0, Segments); for (var i = models.Count - 1; i >= min; i--) { SgtAccretionModel.Pool(models[i]); models.RemoveAt(i); } } }
public static void Pool(SgtAccretionModel model) { if (model != null) { model.Accretion = null; SgtComponentPool <SgtAccretionModel> .Add(model); } }
public static void MarkForDestruction(SgtAccretionModel model) { if (model != null) { model.Accretion = null; model.gameObject.SetActive(true); } }
protected virtual void OnDestroy() { if (models != null) { for (var i = models.Count - 1; i >= 0; i--) { SgtAccretionModel.MarkForDestruction(models[i]); } } SgtHelper.Destroy(material); }