示例#1
0
        protected virtual void OnDestroy()
        {
            if (meshes != null)
            {
                for (var i = meshes.Count - 1; i >= 0; i--)
                {
                    var mesh = meshes[i];

                    if (mesh != null)
                    {
                        mesh.Clear(false);

                        SgtObjectPool <Mesh> .Add(meshes[i]);
                    }
                }
            }

            if (models != null)
            {
                for (var i = models.Count - 1; i >= 0; i--)
                {
                    SgtAuroraModel.MarkForDestruction(models[i]);
                }
            }

            SgtHelper.Destroy(material);
        }
        public static void MarkForDestruction(SgtAuroraModel model)
        {
            if (model != null)
            {
                model.Aurora = null;

                model.gameObject.SetActive(true);
            }
        }
        public static void Pool(SgtAuroraModel model)
        {
            if (model != null)
            {
                model.Aurora = null;

                SgtComponentPool <SgtAuroraModel> .Add(model);
            }
        }
示例#4
0
        public void UpdateMeshesAndModels()
        {
            if (meshes == null)
            {
                meshes = new List <Mesh>();
            }

            if (PathDetail > 0 && PathLengthMin > 0.0f && PathLengthMax > 0.0f)
            {
                var meshCount   = 1;
                var mesh        = GetMesh(0);
                var vertexCount = 0;

                SgtHelper.BeginRandomSeed(Seed);
                {
                    for (var i = 0; i < PathCount; i++)
                    {
                        AddPath(ref mesh, ref meshCount, ref vertexCount);
                    }
                }
                SgtHelper.EndRandomSeed();

                BakeMesh(mesh);

                for (var i = meshes.Count - 1; i >= meshCount; i--)
                {
                    var extraMesh = meshes[i];

                    if (extraMesh != null)
                    {
                        extraMesh.Clear(false);

                        SgtObjectPool <Mesh> .Add(extraMesh);
                    }

                    meshes.RemoveAt(i);
                }
            }

            for (var i = 0; i < meshes.Count; i++)
            {
                var model = SgtHelper.GetIndex(ref models, i);

                if (model == null)
                {
                    model = models[i] = SgtAuroraModel.Create(this);
                }

                model.SetMesh(meshes[i]);
                model.SetMaterial(material);
            }

            // Remove any excess
            if (models != null)
            {
                var min = Mathf.Max(0, meshes.Count);

                for (var i = models.Count - 1; i >= min; i--)
                {
                    SgtAuroraModel.Pool(models[i]);

                    models.RemoveAt(i);
                }
            }
        }