private void ComplexSlice(List <Vector2f> slice) { List <Slice2D> results = Slicer2D.ComplexSliceAll(slice, sliceLayer); if (addForce == true) { foreach (Slice2D id in results) { foreach (GameObject gameObject in id.gameObjects) { Rigidbody2D rigidBody2D = gameObject.GetComponent <Rigidbody2D> (); if (rigidBody2D) { List <Pair2f> list = Pair2f.GetList(id.collisions); float forceVal = 1.0f / list.Count; foreach (Pair2f p in list) { float sliceRotation = -Vector2f.Atan2(p.B, p.A); Vector2 force = new Vector2(Mathf.Cos(sliceRotation) * addForceAmount, Mathf.Sin(sliceRotation) * addForceAmount); rigidBody2D.AddForceAtPosition(forceVal * force, (p.A.Get() + p.B.Get()) / 2f); } } } } } }
private bool ComplexSlice(List <Vector2D> slice) { if (sliceJoints) { ComplexSliceJoints(slice); } List <Slice2D> results = Slicer2D.ComplexSliceAll(slice, sliceLayer); bool result = false; foreach (Slice2D id in results) { if (id.gameObjects.Count > 0) { result = true; } if (sliceResultEvent != null) { sliceResultEvent(id); } } if (addForce == true) { foreach (Slice2D id in results) { AddForce.ComplexSlice(id, addForceAmount); } } return(result); }
bool ComplexSlice(List <Vector2D> slice) { if (sliceJoints) { Slicer2DJoints.ComplexSliceJoints(slice); } List <Slice2D> results = Slicer2D.ComplexSliceAll(slice, sliceLayer); bool result = false; foreach (Slice2D id in results) { if (id.GetGameObjects().Count > 0) { result = true; } eventHandler.Perform(id); } if (addForce == true) { foreach (Slice2D id in results) { Slicer2DAddForce.ComplexSlice(id, addForceAmount); } } return(result); }
void Update() { if (Input.GetKeyDown(KeyCode.Space)) { float timer = Time.realtimeSinceStartup; Polygon2D poly = Polygon2D.CreateFromCollider(gameObject).ToWorldSpace(transform); Slicer2D.ComplexSliceAll(poly.pointsList, Slice2DLayer.Create()); Destroy(gameObject); Slicer2D.Debug.Log(name + " in " + (Time.realtimeSinceStartup - timer) * 1000 + "ms"); } }
private void ComplexSlice(List <Vector2D> slice) { List <Slice2D> results = Slicer2D.ComplexSliceAll(slice, null); if (addForce == false) { return; } foreach (Slice2D id in results) { Slicer2DAddForce.ComplexSlice(id, addForceAmount); } }
private bool ComplexSlice(List <Vector2D> slice) { if (sliceJoints) { ComplexSliceJoints(slice); } List <Slice2D> results = Slicer2D.ComplexSliceAll(slice, sliceLayer); bool result = false; foreach (Slice2D id in results) { if (id.gameObjects.Count > 0) { result = true; } } if (addForce == true) { foreach (Slice2D id in results) { foreach (GameObject gameObject in id.gameObjects) { Rigidbody2D rigidBody2D = gameObject.GetComponent <Rigidbody2D> (); if (rigidBody2D) { List <Pair2D> list = Pair2D.GetList(id.collisions); float forceVal = 1.0f / list.Count; foreach (Pair2D p in list) { float sliceRotation = -Vector2D.Atan2(p.B, p.A); Vector2 force = new Vector2(Mathf.Cos(sliceRotation) * addForceAmount, Mathf.Sin(sliceRotation) * addForceAmount); Physics2DHelper.AddForceAtPosition(rigidBody2D, forceVal * force, (p.A.vector + p.B.vector) / 2f); } } } if (sliceResultEvent != null) { sliceResultEvent(id); } } } return(result); }
private void ComplexSlice(List <Vector2D> slice) { List <Slice2D> results = Slicer2D.ComplexSliceAll(slice, null); if (addForce == true) { foreach (Slice2D id in results) { foreach (GameObject gameObject in id.gameObjects) { Rigidbody2D rigidBody2D = gameObject.GetComponent <Rigidbody2D> (); if (rigidBody2D) { foreach (Pair2D p in Pair2D.GetList(id.collisions)) { float sliceRotation = Vector2D.Atan2(p.B, p.A); Physics2DHelper.AddForceAtPosition(rigidBody2D, new Vector2(Mathf.Cos(sliceRotation) * addForceAmount, Mathf.Sin(sliceRotation) * addForceAmount), (p.A.vector + p.B.vector) / 2f); } } } } } }