private void ClearShells() { for (var i = shells.Count - 1; i >= 0; i--) { SgtClassPool <Shell> .Add(shells[i]); } shells.Clear(); }
protected override void OnDestroy() { base.OnDestroy(); if (Asteroids != null) { for (var i = Asteroids.Count - 1; i >= 0; i--) { SgtClassPool <SgtBeltAsteroid> .Add(Asteroids[i]); } } }
protected override void OnDestroy() { base.OnDestroy(); if (Stars != null) { for (var i = Stars.Count - 1; i >= 0; i--) { SgtClassPool <SgtPointStar> .Add(Stars[i]); } } }
public static void Clear <T>(List <T> cameraStates) where T : SgtCameraState { if (cameraStates != null) { for (var i = cameraStates.Count - 1; i >= 0; i--) { SgtClassPool <T> .Add(cameraStates[i]); } cameraStates.Clear(); } }
public static T Save <T>(ref List <T> cameraStates, Camera camera) where T : SgtCameraState, new() { if (cameraStates == null) { cameraStates = new List <T>(); } for (var i = cameraStates.Count - 1; i >= 0; i--) { var cameraState = cameraStates[i]; if (cameraState == null) { cameraStates.RemoveAt(i); continue; } if (cameraState.Camera == null) { SgtClassPool <T> .Add(cameraState); cameraStates.RemoveAt(i); continue; } if (cameraState.Camera == camera) { return(cameraState); } } var newCameraState = SgtClassPool <T> .Pop() ?? new T(); newCameraState.Camera = camera; cameraStates.Add(newCameraState); return(newCameraState); }
protected override void RegenerateMeshes() { var stars = default(List <SgtStarfieldStar>); var pool = default(bool); CalculateStars(out stars, out pool); if (stars != null) { // Sort stars into groups for (var i = stars.Count - 1; i >= 0; i--) { var star = stars[i]; if (star != null) { var group = GetGroup(star.Sprite); group.Stars.Add(star); } } // Pool stars? if (pool == true) { SgtClassPool <SgtStarfieldStar> .Add(stars); } // Build groups for (var i = groups.Count - 1; i >= 0; i--) { var group = groups[i]; if (group.Stars.Count > 0) { var groupStars = group.Stars; var minMaxSet = false; var min = default(Vector3); var max = default(Vector3); SgtProceduralMesh.Clear(); for (var j = groupStars.Count - 1; j >= 0; j--) { var star = groupStars[j]; var position = star.Position; var radius = star.Radius; var uv = SgtHelper.CalculateSpriteUV(star.Sprite); var rotation = Quaternion.FromToRotation(Vector3.back, position.normalized) * Quaternion.Euler(0.0f, 0.0f, star.Angle); var up = rotation * Vector3.up * radius; var right = rotation * Vector3.right * radius; ExpandBounds(ref minMaxSet, ref min, ref max, position, radius); SgtProceduralMesh.PushPosition(position - up - right); SgtProceduralMesh.PushPosition(position - up + right); SgtProceduralMesh.PushPosition(position + up - right); SgtProceduralMesh.PushPosition(position + up + right); SgtProceduralMesh.PushColor(star.Color, 4); SgtProceduralMesh.PushCoord1(uv.x, uv.y); SgtProceduralMesh.PushCoord1(uv.z, uv.y); SgtProceduralMesh.PushCoord1(uv.x, uv.w); SgtProceduralMesh.PushCoord1(uv.z, uv.w); } var bounds = SgtHelper.NewBoundsFromMinMax(min, max); SgtProceduralMesh.SplitQuads(HideFlags.DontSave); var meshCount = SgtProceduralMesh.Count; // Copy meshes for (var j = 0; j < meshCount; j++) { var mesh = SgtProceduralMesh.Pop(); var model = group.Models.Count > j ? group.Models[j] : SgtStarfieldModel.Create(group); mesh.bounds = bounds; model.Mesh = mesh; } } } } }
protected virtual void RegenerateMeshes() { var stars = default(List <SgtStarfieldStar>); var pool = default(bool); CalculateStars(out stars, out pool); if (stars != null) { // Sort stars into groups for (var i = stars.Count - 1; i >= 0; i--) { var star = stars[i]; if (star != null) { var group = GetGroup(star.Sprite); group.Stars.Add(star); } } // Pool stars? if (pool == true) { SgtClassPool <SgtStarfieldStar> .Add(stars); } // Build groups for (var i = groups.Count - 1; i >= 0; i--) { var group = groups[i]; if (group.Stars.Count > 0) { var groupStars = group.Stars; var minMaxSet = false; var min = default(Vector3); var max = default(Vector3); SgtProceduralMesh.Clear(); for (var j = groupStars.Count - 1; j >= 0; j--) { var star = groupStars[j]; var position = star.Position; var radius = star.Radius; var uv = SgtHelper.CalculateSpriteUV(star.Sprite); var angle = star.Angle / Mathf.PI; ExpandBounds(ref minMaxSet, ref min, ref max, position, radius); SgtProceduralMesh.PushPosition(position, 4); SgtProceduralMesh.PushColor(star.Color, 4); SgtProceduralMesh.PushNormal(-1.0f, 1.0f, angle); SgtProceduralMesh.PushNormal(1.0f, 1.0f, angle); SgtProceduralMesh.PushNormal(-1.0f, -1.0f, angle); SgtProceduralMesh.PushNormal(1.0f, -1.0f, angle); SgtProceduralMesh.PushTangent(star.PulseOffset, star.PulseSpeed, star.PulseRange, 0.0f, 4); SgtProceduralMesh.PushCoord1(uv.x, uv.y); SgtProceduralMesh.PushCoord1(uv.z, uv.y); SgtProceduralMesh.PushCoord1(uv.x, uv.w); SgtProceduralMesh.PushCoord1(uv.z, uv.w); SgtProceduralMesh.PushCoord2(radius, 0.5f); SgtProceduralMesh.PushCoord2(radius, -0.5f); SgtProceduralMesh.PushCoord2(radius, 0.5f); SgtProceduralMesh.PushCoord2(radius, -0.5f); } var bounds = SgtHelper.NewBoundsFromMinMax(min, max); SgtProceduralMesh.SplitQuads(HideFlags.DontSave); var meshCount = SgtProceduralMesh.Count; // Copy meshes for (var j = 0; j < meshCount; j++) { var mesh = SgtProceduralMesh.Pop(); var model = group.Models.Count > j ? group.Models[j] : SgtStarfieldModel.Create(group); mesh.bounds = bounds; model.Mesh = mesh; } } } } }
private void RegenerateMeshes() { var asteroids = default(List <SgtBeltAsteroid>); var pool = default(bool); CalculateAsteroids(out asteroids, out pool); if (asteroids != null) { // Sort asteroids into groups for (var i = asteroids.Count - 1; i >= 0; i--) { var asteroid = asteroids[i]; if (asteroid != null) { var group = GetGroup(asteroid.MainTex, asteroid.HeightTex); group.Asteroids.Add(asteroid); } } // Pool asteroids? if (pool == true) { SgtClassPool <SgtBeltAsteroid> .Add(asteroids); } // Build groups for (var i = groups.Count - 1; i >= 0; i--) { var group = groups[i]; var groupAsteroids = group.Asteroids; var maxWidth = 0.0f; var maxHeight = 0.0f; SgtProceduralMesh.Clear(); for (var j = groupAsteroids.Count - 1; j >= 0; j--) { var asteroid = groupAsteroids[j]; var radius = asteroid.Radius; var distance = asteroid.OrbitDistance; var height = asteroid.Height; var uv = SgtHelper.CalculateSpriteUV(asteroid.MainTex); maxWidth = Mathf.Max(maxWidth, distance + radius); maxHeight = Mathf.Max(maxHeight, height + radius); SgtProceduralMesh.PushPosition(asteroid.OrbitAngle, distance, asteroid.OrbitSpeed, 4); SgtProceduralMesh.PushColor(asteroid.Color, 4); SgtProceduralMesh.PushNormal(-1.0f, 1.0f, 0.0f); SgtProceduralMesh.PushNormal(1.0f, 1.0f, 0.0f); SgtProceduralMesh.PushNormal(-1.0f, -1.0f, 0.0f); SgtProceduralMesh.PushNormal(1.0f, -1.0f, 0.0f); SgtProceduralMesh.PushTangent(asteroid.Angle / Mathf.PI, asteroid.Spin / Mathf.PI, 0.0f, 0.0f, 4); SgtProceduralMesh.PushCoord1(uv.x, uv.y); SgtProceduralMesh.PushCoord1(uv.z, uv.y); SgtProceduralMesh.PushCoord1(uv.x, uv.w); SgtProceduralMesh.PushCoord1(uv.z, uv.w); SgtProceduralMesh.PushCoord2(radius, height, 4); } var bounds = new Bounds(Vector3.zero, new Vector3(maxWidth * 2.0f, maxHeight * 2.0f, maxWidth * 2.0f)); SgtProceduralMesh.SplitQuads(HideFlags.DontSave); var meshCount = SgtProceduralMesh.Count; // Copy meshes for (var j = 0; j < meshCount; j++) { var mesh = SgtProceduralMesh.Pop(); var model = group.Models.Count > j ? group.Models[j] : SgtBeltModel.Create(group); mesh.bounds = bounds; model.Mesh = mesh; } } } }