public virtual void RecalcForcesAndClearBody(bool p_forceRecalc = false, bool p_ropesMassOnly = false) { if (_needRecalcAndClear || p_forceRecalc) { RecalcForces(true, p_ropesMassOnly); _needRecalcAndClear = false; RopeInternalUtils.TryClearRigidBody2D(RigidBody2DComponent); ResetTimeToLerp(); } }
public float GetSumOfIndirectObjectsMass(bool p_includeOtherPluggedObjects = true, bool p_includeChildrens = true, bool p_multiplyByGravityScale = true) { List <GameObject> v_indirectOtherObjectsList = GetAllIndirectObjects(p_includeOtherPluggedObjects); float v_massSum = 0; foreach (GameObject v_object in v_indirectOtherObjectsList) { v_massSum += RopeInternalUtils.GetObjectMass(v_object, p_includeChildrens, p_multiplyByGravityScale); } return(v_massSum); }
public virtual float GetSumOfOtherObjectsMass(bool p_includeChildrens = true, bool p_multiplyByGravityScale = true) { float v_sumOfOtherObjectsMass = 0; List <GameObject> v_otherObjects = GetAllOtherAttachedObjectsInPluggedRopes(); foreach (GameObject v_object in v_otherObjects) { v_sumOfOtherObjectsMass += RopeInternalUtils.GetObjectMass(v_object, p_includeChildrens, p_multiplyByGravityScale); } return(v_sumOfOtherObjectsMass); }
public void CloneModelForceBallonComponents() { if (Application.isPlaying && !RopeInternalUtils.IsPrefab(this.gameObject)) { BallonObjectToCloneByMass v_structToCheck = null; //Find Correct Struct foreach (BallonObjectToCloneByMass v_struct in SpriteChangerModel) { if (v_struct != null && v_struct.ObjectContainer != null && (_sumOfOtherObjectsMass * BallonForceScale) + ExtraThrust >= v_struct.MassToAcceptClone) { if (v_structToCheck == null) { v_structToCheck = v_struct; } else { if (v_struct.MassToAcceptClone > v_structToCheck.MassToAcceptClone) { v_structToCheck = v_struct; } } } } //Copy Components if (v_structToCheck != null && v_structToCheck.ObjectContainer != null) { MonoBehaviour[] v_componentsArray = v_structToCheck.ObjectContainer.GetComponents <MonoBehaviour>(); foreach (MonoBehaviour v_component in v_componentsArray) { if (v_component != null) { RopeInternalUtils.CopyComponent <MonoBehaviour>(this.gameObject, v_component); } } //Copy Sprite Renderer SpriteRenderer v_otherSpriteRenderer = v_structToCheck.ObjectContainer.GetComponent <SpriteRenderer>(); SpriteRenderer v_myRenderer = this.gameObject.GetComponent <SpriteRenderer>(); if (v_myRenderer != null && v_otherSpriteRenderer != null) { v_myRenderer.sprite = v_otherSpriteRenderer.sprite; //v_myRenderer.material = v_otherSpriteRenderer.material; } } } }
protected virtual GameObject FindCloseObjectInRange(Vector2 p_globalPoint, float p_radius) { GameObject v_returnObject = null; if (PressRadius > 0) { float v_currentDistance = 9999999f; float v_angleStep = 10f; for (float j = 0; j < 360.0f; j += v_angleStep) { Vector3 v_rotatedVector = RopeInternalUtils.RotateZ(new Vector2(1, 0), j); RaycastHit2D v_hit = Physics2D.Raycast(p_globalPoint, v_rotatedVector, p_radius); if (v_hit.transform != null && v_hit.transform.gameObject != null) { if (v_hit.distance < v_currentDistance) { v_returnObject = v_hit.transform.gameObject; v_currentDistance = v_hit.distance; } } } } return(v_returnObject); }
protected virtual void Update() { if (o != null) { o.transform.position = Vector3.zero; o.layer = this.gameObject.layer; } if (emit && emitTime != 0) { emitTime -= GetDeltaTime(); if (emitTime == 0) { emitTime = -1; } if (emitTime < 0) { emit = false; } } if (!emit && points.Count == 0 && autoDestruct) { Destroy(o); Destroy(gameObject); } // early out if there is no camera Camera v_camera = RopeInternalUtils.GetCameraThatDrawLayer(this.gameObject.layer); if (v_camera == null) { return; } bool re = false; // if we have moved enough, create a new vertex and make sure we rebuild the mesh float theDistance = (lastPosition - transform.position).magnitude; if (emit) { if (theDistance > minVertexDistance) { bool make = false; if (points.Count < 3) { make = true; } else { Vector3 l1 = ((Point)points[points.Count - 2]).position - ((Point)points[points.Count - 3]).position; Vector3 l2 = ((Point)points[points.Count - 1]).position - ((Point)points[points.Count - 2]).position; if (Vector3.Angle(l1, l2) > maxAngle || theDistance > maxVertexDistance) { make = true; } } if (make) { Point p = new Point(); p.position = transform.position; p.timeCreated = GetTime(); points.Add(p); lastPosition = transform.position; } else { ((Point)points[points.Count - 1]).position = transform.position; ((Point)points[points.Count - 1]).timeCreated = GetTime(); } } else if (points.Count > 0) { ((Point)points[points.Count - 1]).position = transform.position; ((Point)points[points.Count - 1]).timeCreated = GetTime(); } } if (!emit && lastFrameEmit && points.Count > 0) { ((Point)points[points.Count - 1]).lineBreak = true; } lastFrameEmit = emit; // approximate if we should rebuild the mesh or not if (points.Count > 1) { Vector3 cur1 = v_camera.WorldToScreenPoint(((Point)points[0]).position); lastCameraPosition1.z = 0; Vector3 cur2 = v_camera.WorldToScreenPoint(((Point)points[points.Count - 1]).position); lastCameraPosition2.z = 0; float distance = (lastCameraPosition1 - cur1).magnitude; distance += (lastCameraPosition2 - cur2).magnitude; if (distance > movePixelsForRebuild || GetTime() - lastRebuildTime > maxRebuildTime) { re = true; lastCameraPosition1 = cur1; lastCameraPosition2 = cur2; } } else { re = true; } if (re) { lastRebuildTime = GetTime(); int i = 0; ArrayList v_newList = new ArrayList(); foreach (Point p in points) { // cull old points first if (GetTime() - p.timeCreated <= lifeTime) { v_newList.Add(p); } i++; } points.Clear(); points = v_newList; if (points.Count > 1) { Vector3[] newVertices = new Vector3[points.Count * 2]; Vector2[] newUV = new Vector2[points.Count * 2]; int[] newTriangles = new int[(points.Count - 1) * 6]; Color[] newColors = new Color[points.Count * 2]; i = 0; float curDistance = 0.00f; foreach (Point p in points) { float time = (GetTime() - p.timeCreated) / lifeTime; Color color = Color.Lerp(Color.white, Color.clear, time); if (colors != null && colors.Length > 0) { float colorTime = time * (colors.Length - 1); float min = Mathf.Floor(colorTime); float max = Mathf.Clamp(Mathf.Ceil(colorTime), 1, colors.Length - 1); float lerp = Mathf.InverseLerp(min, max, colorTime); if (min >= colors.Length) { min = colors.Length - 1; } if (min < 0) { min = 0; } if (max >= colors.Length) { max = colors.Length - 1; } if (max < 0) { max = 0; } if (colors.Length > min && min >= 0 && colors.Length > max && max >= 0) { color = Color.Lerp(colors[(int)min], colors[(int)max], lerp); } } float size = 1f; if (sizes != null && sizes.Length > 0) { float sizeTime = time * (sizes.Length - 1); float min = Mathf.Floor(sizeTime); float max = Mathf.Clamp(Mathf.Ceil(sizeTime), 1, sizes.Length - 1); float lerp = Mathf.InverseLerp(min, max, sizeTime); if (min >= sizes.Length) { min = sizes.Length - 1; } if (min < 0) { min = 0; } if (max >= sizes.Length) { max = sizes.Length - 1; } if (max < 0) { max = 0; } if (sizes.Length > min && min >= 0 && sizes.Length > max && max >= 0) { size = Mathf.Lerp(sizes[(int)min], sizes[(int)max], lerp); } } Vector3 lineDirection = Vector3.zero; if (i == 0) { lineDirection = p.position - ((Point)points[i + 1]).position; } else { lineDirection = ((Point)points[i - 1]).position - p.position; } Vector3 vectorToCamera = v_camera.transform.position - p.position; Vector3 perpendicular = Vector3.Cross(lineDirection, vectorToCamera).normalized; newVertices[i * 2] = p.position + (perpendicular * (size * 0.5f)); newVertices[(i * 2) + 1] = p.position + (-perpendicular * (size * 0.5f)); newColors[i * 2] = newColors[(i * 2) + 1] = color; newUV[i * 2] = new Vector2(curDistance * uvLengthScale, 0); newUV[(i * 2) + 1] = new Vector2(curDistance * uvLengthScale, 1); if (i > 0 && !((Point)points[i - 1]).lineBreak) { if (higherQualityUVs) { curDistance += (p.position - ((Point)points[i - 1]).position).magnitude; } else { curDistance += (p.position - ((Point)points[i - 1]).position).sqrMagnitude; } newTriangles[(i - 1) * 6] = (i * 2) - 2; newTriangles[((i - 1) * 6) + 1] = (i * 2) - 1; newTriangles[((i - 1) * 6) + 2] = i * 2; newTriangles[((i - 1) * 6) + 3] = (i * 2) + 1; newTriangles[((i - 1) * 6) + 4] = i * 2; newTriangles[((i - 1) * 6) + 5] = (i * 2) - 1; } i++; } if (o != null) { Mesh mesh = (o.GetComponent(typeof(MeshFilter)) as MeshFilter).mesh; mesh.Clear(); mesh.vertices = newVertices; mesh.colors = newColors; mesh.uv = newUV; mesh.triangles = newTriangles; } } else { if (o != null) { Mesh mesh = (o.GetComponent(typeof(MeshFilter)) as MeshFilter).mesh; mesh.Clear(); } } } }
public float GetSelfMass(bool p_includeChildrens = true, bool p_multiplyByGravityScale = true) { return(RopeInternalUtils.GetObjectMass(this.gameObject, p_includeChildrens, p_multiplyByGravityScale)); }