public void Update(Vector2D pos) { float scroll = Input.GetAxis("Mouse ScrollWheel"); float newCutSize = cutSize + scroll; if (newCutSize > 0.05f) { cutSize = newCutSize; } if (Input.GetMouseButtonDown(0)) { linearPair.A.Set(pos); } if (Input.GetMouseButton(0)) { linearPair.B.Set(pos); mouseDown = true; } if (mouseDown == true && Input.GetMouseButton(0) == false) { mouseDown = false; Destruction2D.DestroyByLinearCutAll(linearCutLine, destructionLayer); } }
void Start() { bool addEvents = false; foreach (Collider2D collider in anchorColliders) { addEvents = true; } if (addEvents == false) { return; } Destruction2D destruction = GetComponent <Destruction2D>(); foreach (Collider2D collider in anchorColliders) { if (collider == null) { continue; } destruction.anchorPolygons.Add(Polygon2DList.CreateFromGameObject(collider.gameObject)[0]); destruction.anchorColliders.Add(collider); } Destruction2D destructionEvent = GetComponent <Destruction2D>(); destructionEvent.AddAnchorEvent(AnchorEvent); }
public bool Update(Vector2D pos) { float scroll = Input.GetAxis("Mouse ScrollWheel"); float newPolygonSize = polygonSize + scroll; if (newPolygonSize > 0.05f) { polygonSize = newPolygonSize; } mouseDown = true; if (Input.GetMouseButtonDown(0)) { Polygon2D.defaultCircleVerticesCount = polygonEdgeCount; slicePolygon = Polygon2D.Create(polygonType, polygonSize); Polygon2D polygon = new Polygon2D(); polygon.pointsList = new List <Vector2D>(slicePolygon.pointsList); polygon.ToOffsetItself(pos); EraseBrush EraseBrush = new EraseBrush(null, polygon); Destruction2D.DestroyByPolygonAll(EraseBrush, destructionLayer); return(true); } else { return(false); } }
public void SetDestructible(Destruction2D d) { destructible = d; spriteBufferObject.destructible = destructible; meshBufferObject.destructible = destructible; spriteShapeBufferObject.destructible = destructible; tilemapBufferObject.destructible = destructible; }
public void OnRenderObject() { if (Camera.current != renderCamera) { return; } Destruction2DManager.DestructionDebug.bufferUpdates++; Destruction2D destruction; switch (destructible.textureType) { case Destruction2D.TextureType.Sprite: spriteBufferObject.OnRenderObject(); break; case Destruction2D.TextureType.Mesh: meshBufferObject.OnRenderObject(); break; case Destruction2D.TextureType.SpriteShape: spriteShapeBufferObject.OnRenderObject(); Destroy(destructible); Destroy(gameObject); destruction = destructible.gameObject.AddComponent <Destruction2D>(); destruction.split = destructible.split; destruction.filterMode = destructible.filterMode; break; case Destruction2D.TextureType.Tilemap: tilemapBufferObject.OnRenderObject(); Destroy(destructible); Destroy(gameObject); destruction = destructible.gameObject.AddComponent <Destruction2D>(); destruction.split = destructible.split; break; } renderCamera.enabled = false; if (destructible.textureType != Destruction2D.TextureType.SpriteShape && destructible.textureType != Destruction2D.TextureType.Tilemap) { destructible = null; timer.Reset(); renderCamera.targetTexture = null; renderCamera.orthographicSize = 1f; } }
public void Update(Vector2D pos) { if (Input.GetMouseButton(0)) { eraseBrush.SetPosition(pos); Destruction2D.DestroyByPolygonAll(eraseBrush, destructionLayer); } }
public void Set(Destruction2D destructibleObject) { SetDestructible(destructibleObject); //Sprite Shape renderCamera.enabled = true; renderCamera.targetTexture = destructible.renderTexture; renderCamera.orthographicSize = (float)destructible.originalSprite.texture.height / (destructible.originalSprite.pixelsPerUnit * 2) * destructible.transform.localScale.x; }
void Update() { isSlicing = false; if (GameManager.GameIsPaused) { return; } if (!SlicesManager.allowToSlice) { skipedFrame = false; return; } Vector2 pos = GetMousePosition(); if (Input.GetMouseButtonDown(0)) { oldPosition = new Vector2D(pos); } bool slicingDetected = false; if (Input.GetMouseButton(0)) { eraseBrushStart.SetPosition(new Vector2D(pos)); if (Destruction2D.DestroyByPolygonAll(eraseBrushStart)) { slicingDetected = true; } if (oldPosition != null) { if (UpdateMiddleEraseMesh()) { if (Destruction2D.DestroyByPolygonAll(eraseBrushMiddle)) { slicingDetected = true; } oldPosition = new Vector2D(pos); } } } else { oldPosition = new Vector2D(pos); } isSlicing = slicingDetected; Draw(transform, pos); }
public void Spawn(Vector2D pos) { if (modifierTextures.Length > 0) { Destruction2D.AddModifierAll(modifierTextures[modifierID], pos.ToVector2(), modifierSize, modifierRotation, destructionLayer); if (randomRotation) { modifierRotation = Random.Range(0, 360); } if (randomModifierID) { modifierID = Random.Range(0, modifierTextures.Length - 1); } } }
public void OnCollisionEnter2D(Collision2D col) { Polygon2D polygon = Polygon2DList.CreateFromGameObject(gameObject)[0]; // or //Polygon2D.Create(Polygon2D.PolygonType.Pentagon, 1); polygon = polygon.ToScale(new Vector2(5, 5)); polygon = polygon.ToWorldSpace(transform); EraseBrush EraseBrush = new EraseBrush(null, polygon); Destruction2D.DestroyByPolygonAll(EraseBrush, Destruction2DLayer.Create()); Destruction2D.AddModifierAll(modifierTexture, gameObject.transform.position, new Vector2(5, 5), 0, Destruction2DLayer.Create()); Destroy(gameObject); }
static public void CopyComponents(Destruction2D slicer, GameObject gObject) { Component[] scriptList = slicer.gameObject.GetComponents <Component>(); foreach (Component script in scriptList) { if (script.GetType().ToString() == "UnityEngine.PolygonCollider2D" || script.GetType().ToString() == "UnityEngine.BoxCollider2D" || script.GetType().ToString() == "UnityEngine.CircleCollider2D" || script.GetType().ToString() == "UnityEngine.CapsuleCollider2D") { continue; } if (script.GetType().ToString() == "Destruction2D") { continue; } CopyComponent(script, gObject, slicer.gameObject); } }
public void Update(Vector2D pos) { float scroll = Input.GetAxis("Mouse ScrollWheel"); float newCutSize = cutSize + scroll; if (newCutSize > 0.05f) { cutSize = newCutSize; } if (Input.GetMouseButtonDown(0)) { complexSlicerPointsList.Clear(); complexSlicerPointsList.Add(pos); mouseDown = true; } if (complexSlicerPointsList.Count < 1) { return; } if (Input.GetMouseButton(0)) { Vector2D posMove = new Vector2D(complexSlicerPointsList.Last()); while ((Vector2D.Distance(posMove, pos) > visuals.minVertexDistance * visuals.visualScale)) { float direction = (float)Vector2D.Atan2(pos, posMove); posMove.Push(direction, visuals.minVertexDistance * visuals.visualScale); complexSlicerPointsList.Add(new Vector2D(posMove)); } } if (mouseDown == true && Input.GetMouseButton(0) == false) { mouseDown = false; Destruction2D.DestroyByComplexCutAll(complexCutLine, destructionLayer); complexSlicerPointsList.Clear(); } }
static public Destruction2DBuffer GetBuffer(Destruction2D destructible) { foreach (Destruction2DBuffer buffer in Destruction2DBuffer.GetList()) { if (buffer.destructible == destructible) { return(buffer); } } foreach (Destruction2DBuffer buffer in Destruction2DBuffer.GetList()) { if (buffer.destructible == null) { return(buffer); } } return(CreateBuffer()); }
public void Update(Destruction2D source) { Transform transform = source.transform; if (updatePosition != transform.position) { updatePosition = transform.position; update = true; } if (updateRotation != transform.rotation.eulerAngles.z) { updateRotation = transform.rotation.eulerAngles.z; update = true; } /* * if (source.spriteRenderer != null) { * if (sprite != source.spriteRenderer.sprite) { * sprite = source.spriteRenderer.sprite; * * update = true; * } * * if (spriteflipX != source.spriteRenderer.flipX) { * spriteflipX = source.spriteRenderer.flipX; * * update = true; * } * * if (spriteflipY != source.spriteRenderer.flipY) { * spriteflipY = source.spriteRenderer.flipY; * * update = true; * } * } */ }
void Start() { sateliteParent = new GameObject(); sateliteParent.name = "Satelites"; sateliteParent.transform.parent = transform; sateliteParent.transform.position = transform.position; for (int i = 0; i < sprites.Length; i++) { GameObject satelite = new GameObject(); satelite.name = "Satelite " + (i + 1); satelite.transform.position = sateliteParent.transform.position; satelite.transform.parent = sateliteParent.transform; SpriteRenderer spriteRenderer = satelite.AddComponent <SpriteRenderer>(); spriteRenderer.sprite = sprites[i]; Cloud cloudScript = satelite.AddComponent <Cloud>(); cloudScript.distance = sateliteDistance; cloudScript.rotation = ((float)i / sprites.Length) * 360f; cloudScript.parent = sateliteParent.transform; cloudScript.zOffset = -5; cloudScript.speed = sateliteSpeed; Destruction2D destruction2D = satelite.AddComponent <Destruction2D>(); if (i == 0) { destruction2D.destructionLayer = DestructionLayer.Layer2; } else { destruction2D.destructionLayer = DestructionLayer.Layer3; } cloudScript.transform.localScale = new Vector3(1, 1, 1); } }
public void Update(Vector2D pos) { float scroll = Input.GetAxis("Mouse ScrollWheel"); float newCutSize = cutSize + scroll; if (newCutSize > 0.05f) { cutSize = newCutSize; } if (Input.GetMouseButtonDown(0)) { linearPair.A = pos; } if (Input.GetMouseButton(0)) { mouseDown = true; Vector2D posMove = linearPair.A; linearPair.B = pos; if ((Vector2D.Distance(posMove, pos) > visuals.minVertexDistance * visuals.visualScale)) { linearCutLine = LinearCut.Create(linearPair, cutSize); Destruction2D.DestroyByLinearCutAll(linearCutLine, destructionLayer); linearPair.A = pos; } } else { mouseDown = false; } }
void StartTilemap() { if (init == true) { return; } Tilemap tilemap = GetComponent <Tilemap>(); TilemapRenderer renderer = GetComponent <TilemapRenderer>(); BoundsInt bounds = tilemap.cellBounds; Rect rect = new Rect(); rect.x = bounds.x * gridSize.x; rect.y = bounds.y * gridSize.y; rect.width = bounds.size.x * gridSize.x; rect.height = bounds.size.y * gridSize.y; GameObject newGamObject = new GameObject(); newGamObject.name = gameObject.name; newGamObject.transform.position = transform.position; newGamObject.transform.rotation = transform.rotation; newGamObject.transform.localScale = transform.localScale; newGamObject.transform.parent = transform.parent; foreach (Component c in gameObject.GetComponents <Component>()) { if (c.GetType().ToString() == "UnityEngine.PolygonCollider2D") { continue; } if (c.GetType().ToString() == "UnityEngine.EdgeCollider2D") { continue; } if (c.GetType().ToString() != "UnityEngine.Tilemaps.Tilemap" && c.GetType().ToString() != "UnityEngine.Tilemaps.TilemapRenderer") { if (CopyComponent(c, newGamObject, gameObject) == true) { Destroy(c); } } } Destruction2D destructible = newGamObject.GetComponent <Destruction2D>(); destructible.init = true; newGamObject.AddComponent <PolygonCollider2D>(); //PolygonCollider2D collider = gameObject.GetComponent<PolygonCollider2D>(); //if (collider != null) { // newGamObject.AddComponent<PolygonCollider2D>(); // Destroy(collider); //} GameObject newGridObject = new GameObject(); newGridObject.name = "Buffer: " + gameObject.name; Grid grid = newGridObject.AddComponent <Grid>(); grid.cellSize = new Vector3(gridSize.x, gridSize.y, 0); newGridObject.transform.parent = Destruction2DManager.instance.transform; gameObject.transform.parent = newGridObject.transform; gameObject.name = "Tilemap"; gameObject.transform.rotation = Quaternion.Euler(0, 0, 0); gameObject.transform.localScale = new Vector3(1, 1, 1); gameObject.transform.position = new Vector3(0, 0, 0); destructible.buffer = Destruction2DManager.CreateCustomBuffer(newGridObject); destructible.pixelsPerUnit = scaledPixelsPerUnit; int textureWidth = (int)(rect.width * destructible.pixelsPerUnit); int textureHeight = (int)(rect.height * destructible.pixelsPerUnit); destructible.renderTexture = new RenderTexture(textureWidth, textureHeight, 32); destructible.outputTexture = new Texture2D(textureWidth, textureHeight); // Filter Mode??? destructible.filterMode = filterMode; // destructible.outputTexture.filterMode = filterMode; destructible.buffer.renderCamera.orthographicSize = (rect.height) / 2; destructible.buffer.renderCamera.transform.Translate(rect.center.x, rect.center.y, -1f); destructible.buffer.renderCamera.farClipPlane = 5; destructible.buffer.renderCamera.targetTexture = destructible.renderTexture; newGamObject.transform.Translate(rect.center.x, rect.center.y, -1f); destructible.spriteRenderer = newGamObject.AddComponent <SpriteRenderer>(); // Set Up Destructible destructible.buffer.SetDestructible(destructible); destructible.buffer.renderCamera.enabled = true; destructible.originalSprite = Sprite.Create(destructible.outputTexture, new Rect(0.0f, 0.0f, destructible.renderTexture.width, destructible.renderTexture.height), new Vector2(0.5f, 0.5f), pixelsPerUnit, 2, SpriteMeshType.FullRect); //Destroy(gameObject.GetComponent<EdgeCollider2D>()); }
void StartChunks() { Sprite sprite = spriteRenderer.sprite; pixelsPerUnit = sprite.pixelsPerUnit; GameObject parentGameObject = new GameObject(); int rowSize = sprite.texture.height / chunks.chunksRows; int columnSize = sprite.texture.width / chunks.chunksColumns; for (int column = 0; column < chunks.chunksColumns; column++) { for (int row = 0; row < chunks.chunksRows; row++) { GameObject newGameObject = new GameObject(); newGameObject.transform.parent = parentGameObject.transform; newGameObject.name = "Chunk (" + column + ", " + row + ")"; // Pivot or Transform offset float positionX; float positionY; Vector2 pivot = new Vector2(0.5f, 0.5f); switch (chunks.chunkOffset) { case Destruction2DChunks.Offset.Transform: positionX = (((float)column - ((float)chunks.chunksColumns - 1) / 2) * (float)sprite.texture.width / chunks.chunksColumns) / pixelsPerUnit; positionY = (((float)row - ((float)chunks.chunksRows - 1) / 2) * (float)sprite.texture.height / chunks.chunksRows) / pixelsPerUnit; newGameObject.transform.position = new Vector3(positionX, positionY, 0); break; case Destruction2DChunks.Offset.SpritePivot: positionX = (((float)column - ((float)chunks.chunksColumns - 1) / 2) * (float)sprite.texture.width) / pixelsPerUnit; positionY = (((float)row - ((float)chunks.chunksRows - 1) / 2) * (float)sprite.texture.height) / pixelsPerUnit; float pivotX = -positionX / 6; float pivotY = -positionY / 6; pivot = new Vector2(0.5f, 0.5f) + new Vector2(pivotX, pivotY); break; } SpriteRenderer srenderer = newGameObject.AddComponent <SpriteRenderer>(); Sprite output = Sprite.Create(GetComponent <SpriteRenderer>().sprite.texture, new Rect(column * columnSize, row * rowSize, columnSize, rowSize), pivot, pixelsPerUnit, 2, SpriteMeshType.FullRect); srenderer.sprite = output; if (gameObject.GetComponent <PolygonCollider2D>()) { PolygonCollider2D collider = newGameObject.AddComponent <PolygonCollider2D>(); if (collider.pathCount == 1) { Vector2[] standardPentagon = collider.GetPath(0); Vector2 v0 = standardPentagon[0] / (3f / chunks.chunksColumns); // + Rows (Y) Vector2 v1 = new Vector2(0, 1); Vector2 v2 = standardPentagon[1] / (3f / chunks.chunksColumns); // + Rows (Y) Vector2 v3 = new Vector2(-0.9510565f, 0.309017f); switch (chunks.chunkOffset) { case Destruction2DChunks.Offset.SpritePivot: v0.x -= (1 - chunks.chunksColumns + column * 2); v0.y -= (1 - chunks.chunksRows + row * 2); v2.x -= (1 - chunks.chunksColumns + column * 2); v2.y -= (1 - chunks.chunksRows + row * 2); break; } if (v0 == v1 && v2 == v3) { Destroy(newGameObject); newGameObject = null; } //Debug.Log(newGameObject.name + " " + ((1-chunksColumns + column * 2)) + " " +((1-chunksRows + row * 2)) + " (" + v0.x + ", " + v0.y + ") - (" + v1.x + ", " + v1.y + ")"); } } if (newGameObject != null) { Destruction2D destructible = newGameObject.AddComponent <Destruction2D>(); destructible.originalSprite = sprite; //destructible.replaceSprite = true; } } } parentGameObject.name = gameObject.name; parentGameObject.transform.parent = gameObject.transform.parent; parentGameObject.transform.localScale = gameObject.transform.localScale; parentGameObject.transform.rotation = gameObject.transform.rotation; parentGameObject.transform.position = gameObject.transform.position; Destroy(gameObject); }
public void UpdateCollider() { PolygonCollider2D polygonCollider2D = GetComponent <PolygonCollider2D>(); if (polygonCollider2D != null) { Destroy(polygonCollider2D); PolygonCollider2D collider = gameObject.AddComponent <PolygonCollider2D>(); float scale = (float)originalSprite.texture.width / (originalSprite.pixelsPerUnit * 2); // Y? // Check If There Is No Proper Collide Generated () if (collider.pathCount == 1) { Vector2[] standardPentagon = collider.GetPath(0); Vector2 v0 = standardPentagon[0] / scale; Vector2 v1 = new Vector2(0, 1); Vector2 v2 = standardPentagon[1] / scale; Vector2 v3 = new Vector2(-0.9510565f, 0.309017f); if (v0 == v1 && v2 == v3) { Destroy(gameObject); } } if (textureType == TextureType.Sprite) { if (split.enabled == true && (split.splitLimit == false || split.splitCount <= split.maxSplits)) { List <Polygon2D> polys = Polygon2DList.CreateFromPolygonColliderToLocalSpace(collider); List <GameObject> disattachedObjects = new List <GameObject>(); if (polys.Count > 1) { int id = 1; Rigidbody2D originalRigidBody = GetComponent <Rigidbody2D>(); foreach (Polygon2D poly in polys) { GameObject gObject = new GameObject(); gObject.name = gameObject.name + " (" + id + ")"; gObject.transform.parent = transform.parent; Polygon2D polygon = poly; polygon.CreatePolygonCollider(gObject); gObject.transform.position = transform.position; gObject.transform.rotation = transform.rotation; gObject.transform.localScale = transform.localScale; Destruction2D.CopyComponents(this, gObject); gObject.GetComponent <SpriteRenderer>().sprite = spriteRenderer.sprite; Destruction2D destructible = gObject.AddComponent <Destruction2D>(); destructible.replaceSprite = true; destructible.originalSprite = originalSprite; destructible.originalSpriteMaterial = originalSpriteMaterial; destructible.customPolygon = poly; destructible.modifiers = new List <DestructionModifier>(modifiers); destructible.EraseBrushes = new List <EraseMesh>(EraseBrushes); destructible.split.enabled = true; destructible.split.splitLimit = split.splitLimit; destructible.split.maxSplits = split.maxSplits; destructible.split.splitCount = split.splitCount + 1; destructible.centerOfMass = centerOfMass; if (anchorColliders.Count > 0) { if (destructible.Detach(collider) == true) { disattachedObjects.Add(gameObject); } } foreach (Polygon2D p in polys) { if (p != poly) { destructible.erasePolygons.Add(p); } } // CopyRigidbody if (originalRigidBody) { Rigidbody2D newRigidBody = gObject.GetComponent <Rigidbody2D> (); newRigidBody.isKinematic = originalRigidBody.isKinematic; newRigidBody.velocity = originalRigidBody.velocity; newRigidBody.drag = originalRigidBody.drag; newRigidBody.angularVelocity = originalRigidBody.angularVelocity; newRigidBody.angularDrag = originalRigidBody.angularDrag; newRigidBody.constraints = originalRigidBody.constraints; newRigidBody.gravityScale = originalRigidBody.gravityScale; newRigidBody.collisionDetectionMode = originalRigidBody.collisionDetectionMode; //newRigidBody.sleepMode = originalRigidBody.sleepMode; //newRigidBody.inertia = originalRigidBody.inertia; // Center of Mass : Auto / Center if (centerOfMass == CenterOfMass.RigidbodyOnly) { newRigidBody.centerOfMass = Vector2.zero; } } id++; } Destroy(gameObject); } else { if (anchorColliders.Count > 0) { if (Detach(collider) == true) { disattachedObjects.Add(gameObject); } } } if (disattachedObjects.Count > 0) { if ((destructionAnchorEvent != null)) { Destruction2DEvent destruction = new Destruction2DEvent(); destruction.gameObjects = disattachedObjects; destructionAnchorEvent(destruction); } } } } } }
void Start() { Destruction2D destruction = GetComponent <Destruction2D>(); destruction.AddAnchorEvent(AnchorEvent); }
public void SetOrigin(Destruction2D slicerPass) { destructible = slicerPass; }
override public void OnInspectorGUI() { Destruction2D script = target as Destruction2D; script.textureType = (Destruction2D.TextureType)EditorGUILayout.EnumPopup("Texture Type", script.textureType); if (script.textureType == Destruction2D.TextureType.SpriteShape) { // Only Sprite Shape? script.spriteShapeBounds = (Destruction2D.SpriteShapeBounds)EditorGUILayout.EnumPopup("Bounds", script.spriteShapeBounds); script.scaledPixelsPerUnit = EditorGUILayout.FloatField("Scaled Pixels Per Unit", script.scaledPixelsPerUnit); } if (script.textureType == Destruction2D.TextureType.Tilemap) { // Only Tile Map script.scaledPixelsPerUnit = EditorGUILayout.FloatField("Scaled Pixels Per Unit", script.scaledPixelsPerUnit); } // DEBUG //script.buffer = (Destruction2DBuffer)EditorGUILayout.ObjectField(script.buffer, typeof(Destruction2DBuffer)); script.filterMode = (FilterMode)EditorGUILayout.EnumPopup("Filter Mode", script.filterMode); script.destructionLayer = (DestructionLayer)EditorGUILayout.EnumPopup("Destruction Layer", script.destructionLayer); EditorGUI.BeginDisabledGroup(script.chunks.enabled == true); script.centerOfMass = (Destruction2D.CenterOfMass)EditorGUILayout.EnumPopup("Center of Mass", script.centerOfMass); EditorGUI.EndDisabledGroup(); script.gridSize = EditorGUILayout.Vector2IntField("Grid Size", script.gridSize); EditorGUI.BeginDisabledGroup(script.split.enabled == true); script.chunks.enabled = EditorGUILayout.Toggle("Chunks", script.chunks.enabled); if (script.chunks.enabled) { script.centerOfMass = Destruction2D.CenterOfMass.Default; EditorGUI.indentLevel = EditorGUI.indentLevel + 1; script.split.enabled = false; script.chunks.chunkOffset = (Destruction2DChunks.Offset)EditorGUILayout.EnumPopup("Offsets", script.chunks.chunkOffset); script.chunks.chunksRows = EditorGUILayout.IntSlider("Rows", script.chunks.chunksRows, 1, 20); script.chunks.chunksColumns = EditorGUILayout.IntSlider("Columns", script.chunks.chunksColumns, 1, 20); EditorGUI.indentLevel = EditorGUI.indentLevel - 1; } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(script.chunks.enabled == true); script.split.enabled = EditorGUILayout.Toggle("Split", script.split.enabled); if (script.split.enabled) { EditorGUI.indentLevel = EditorGUI.indentLevel + 1; script.chunks.enabled = false; script.split.splitLimit = GUILayout.Toggle(script.split.splitLimit, "Split Limit"); if (script.split.splitLimit) { script.split.maxSplits = EditorGUILayout.IntSlider("Max Splits", script.split.maxSplits, 1, 10); } EditorGUI.indentLevel = EditorGUI.indentLevel - 1; } EditorGUI.EndDisabledGroup(); //script.createChunks = EditorGUILayout.Toggle("Create Chunks", script.createChunks); //script.recalculateCenterPivot = EditorGUILayout.Toggle("Recalculate Pivot", script.recalculateCenterPivot); }
static public void RequestBufferEvent(Destruction2D destructible) { Destruction2DBuffer buffer = GetBuffer(destructible); buffer.Set(destructible); }
void StartSpriteShape() { if (init == true) { return; } Rect rect = new Rect(); switch (spriteShapeBounds) { case SpriteShapeBounds.Renderer: Bounds bounds = new Bounds(); bool found = false; foreach (Component c in gameObject.GetComponents <Component>()) { if (c.GetType().ToString() == "UnityEngine.U2D.SpriteShapeRenderer") { UnityEngine.U2D.SpriteShapeRenderer ssr = (UnityEngine.U2D.SpriteShapeRenderer)c; bounds = ssr.bounds; found = true; break; } } if (found) { rect = new Rect(bounds.center.x - bounds.extents.x - transform.position.x, bounds.center.y - bounds.extents.y - transform.position.y, bounds.extents.x * 2, bounds.extents.y * 2); } else { Debug.LogWarning("Destruction2D: SpriteShape game object is missing SpriteShapeRenderer"); } break; case SpriteShapeBounds.Collider: List <Polygon2D> polygons = Polygon2DList.CreateFromGameObject(gameObject); if (polygons.Count < 1) { Debug.LogError("Destruction2D: SpriteShape game object is missing collider"); return; } rect = polygons[0].GetBounds(); break; } GameObject newGamObject = new GameObject(); newGamObject.name = gameObject.name; newGamObject.transform.position = transform.position; newGamObject.transform.rotation = transform.rotation; newGamObject.transform.localScale = transform.localScale; newGamObject.transform.parent = transform.parent; foreach (Component c in gameObject.GetComponents <Component>()) { if (c.GetType().ToString() == "UnityEngine.PolygonCollider2D") { continue; } if (c.GetType().ToString() == "UnityEngine.EdgeCollider2D") { continue; } if (c.GetType().ToString() != "UnityEngine.U2D.SpriteShapeController" && c.GetType().ToString() != "UnityEngine.U2D.SpriteShapeRenderer") { if (CopyComponent(c, newGamObject, gameObject) == true) { Destroy(c); } } } Destruction2D destructible = newGamObject.GetComponent <Destruction2D>(); destructible.init = true; Destroy(gameObject.GetComponent <EdgeCollider2D>()); PolygonCollider2D collider = gameObject.GetComponent <PolygonCollider2D>(); if (collider != null) { newGamObject.AddComponent <PolygonCollider2D>(); Destroy(collider); } gameObject.transform.parent = Destruction2DManager.instance.transform; gameObject.name = "Buffer: " + gameObject.name; gameObject.transform.rotation = Quaternion.Euler(0, 0, 0); gameObject.transform.localScale = new Vector3(1, 1, 1); destructible.buffer = Destruction2DManager.CreateCustomBuffer(gameObject); destructible.pixelsPerUnit = scaledPixelsPerUnit; destructible.filterMode = filterMode; int textureWidth = (int)(rect.width * destructible.pixelsPerUnit); int textureHeight = (int)(rect.height * destructible.pixelsPerUnit); destructible.renderTexture = new RenderTexture(textureWidth, textureHeight, 32); destructible.outputTexture = new Texture2D(textureWidth, textureHeight); destructible.buffer.renderCamera.orthographicSize = (rect.height) / 2; destructible.buffer.renderCamera.transform.Translate(rect.center.x, rect.center.y, -1f); destructible.buffer.renderCamera.farClipPlane = 5; destructible.buffer.renderCamera.targetTexture = destructible.renderTexture; newGamObject.transform.Translate(rect.center.x, rect.center.y, -1f); destructible.spriteRenderer = newGamObject.AddComponent <SpriteRenderer>(); // Set Up Destructible destructible.buffer.SetDestructible(destructible); destructible.buffer.renderCamera.enabled = true; destructible.originalSprite = Sprite.Create(destructible.outputTexture, new Rect(0.0f, 0.0f, destructible.renderTexture.width, destructible.renderTexture.height), new Vector2(0.5f, 0.5f), pixelsPerUnit, 2, SpriteMeshType.FullRect); }