public void CoerceAdjustValues(int i) { if (i == 5) { (float, float)bounds = (0.01f, 1000f); ForceControl force = focused.GetComponent <ForceControl>(); if (force == null) { return; } float newtons = Mathf.Clamp(force.getForce(), bounds.Item1, bounds.Item2); sliders[i].SetValueWithoutNotify((newtons - bounds.Item1) / bounds.Item2); inputFields[i].SetTextWithoutNotify("" + Mathf.Round(newtons * 100f) / 100f); // Debug.Log(sliders[i].value); } else if (i == 6) { (float, float)bounds = (0.01f, 100f); VelocityControl velocity = focused.GetComponent <VelocityControl>(); if (velocity == null) { return; } float speed = Mathf.Clamp(velocity.getSpeed(), bounds.Item1, bounds.Item2); sliders[i].SetValueWithoutNotify((speed - bounds.Item1) / bounds.Item2); inputFields[i].SetTextWithoutNotify("" + Mathf.Round(speed * 100f) / 100f); } else if (i == 7) { (float, float)bounds = (0f, 360f); float angle; if (namecurr == "Force") { ForceControl force = focused.GetComponent <ForceControl>(); if (force == null) { return; } angle = Mathf.Clamp(force.getAngle(), bounds.Item1, bounds.Item2); } else if (namecurr == "Velocity") { VelocityControl velocity = focused.GetComponent <VelocityControl>(); if (velocity == null) { return; } angle = Mathf.Clamp(velocity.getAngle(), bounds.Item1, bounds.Item2); } else { angle = Mathf.Clamp(transcurr.localEulerAngles.z, bounds.Item1, bounds.Item2); } sliders[i].SetValueWithoutNotify((angle - bounds.Item1) / bounds.Item2); inputFields[i].SetTextWithoutNotify("" + Mathf.Round(angle * 100f) / 100f); } else if (i == 8) //spring equilibrium length { } }
void updateVelocity() { dashhorizontal.gameObject.SetActive(true); dashmoving.gameObject.SetActive(false); label.gameObject.SetActive(true); VelocityControl velocity = this.gameObject.GetComponent <VelocityControl>(); v3 pos = velocity.attachPoint2; pos.z = 0; v3 localpos = Camera.main.WorldToScreenPoint(pos) / this.canvas.localScale.x; localpos.z = 0; //set position and angle dashhorizontal.anchoredPosition = localpos; dashhorizontal.eulerAngles = v3.zero; float length = trans.localScale.y * Util.VelocityHeightMultiplier * Util.WorldToScreenMultiplier / 2f; dashhorizontal.sizeDelta = new v2(length, 3f); Text t = label.GetComponent <Text>(); float angle = velocity.getAngle(); t.text = Mathf.Round(angle * 100f) / 100f + "°"; if (angle < 40f) { angle += 15; } else { angle /= 2f; } v3 direction = new v3(Mathf.Cos(Mathf.Deg2Rad * angle), Mathf.Sin(Mathf.Deg2Rad * angle)).normalized; length = 90f; label.anchoredPosition = localpos + direction * length; }
private void AdjustValues() { for (int i = 0, tempmask = currmask; tempmask != 0; i++, tempmask >>= 1) { if ((tempmask & 1) != 1) { continue; } if (i == 0) { (float, float)bounds = (0.01f, 1000f); sliders[i].SetValueWithoutNotify((rbcurr.mass - bounds.Item1) / bounds.Item2); inputFields[i].SetTextWithoutNotify("" + Mathf.Round(rbcurr.mass * 100f) / 100f); } else if (i == 1) { (float, float)bounds = (0.01f, 1000f); float length = 0f; if (namecurr == "FixedRectangle") { length = transcurr.localScale.x * Util.FixedRectWidthMultiplier; } else if (namecurr == "MoveableRectangle") { length = transcurr.localScale.x * Util.MoveableRectWidthMultiplier; } sliders[i].SetValueWithoutNotify((length - bounds.Item1) / bounds.Item2); inputFields[i].SetTextWithoutNotify("" + Mathf.Round(length * 100f) / 100f); } else if (i == 2) { (float, float)bounds = (0.01f, 1000f); float width = 0f; if (namecurr == "FixedRectangle") { width = transcurr.localScale.y * Util.FixedRectHeightMultiplier; } else if (namecurr == "MoveableRectangle") { width = transcurr.localScale.y * Util.MoveableRectHeightMultiplier; } sliders[i].SetValueWithoutNotify((width - bounds.Item1) / bounds.Item2); inputFields[i].SetTextWithoutNotify("" + Mathf.Round(width * 100f) / 100f); } else if (i == 3) //circle { (float, float)bounds = (0.01f, 100f); float diameter = transcurr.localScale.x; sliders[i].SetValueWithoutNotify((diameter - bounds.Item1) / bounds.Item2); inputFields[i].SetTextWithoutNotify("" + Mathf.Round(diameter * 100f) / 100f); } else if (i == 4) //spring constant (N/m) { (float, float)bounds = (0.01f, 1000f); SpringControl spring = focused.GetComponent <SpringControl>(); float constant = Mathf.Clamp(spring.getSpringConstant(), bounds.Item1, bounds.Item2); sliders[i].SetValueWithoutNotify((constant - bounds.Item1) / bounds.Item2); inputFields[i].SetTextWithoutNotify("" + Mathf.Round(constant * 100f) / 100f); } else if (i == 5) //force { (float, float)bounds = (0.01f, 1000f); ForceControl force = focused.GetComponent <ForceControl>(); float newtons = Mathf.Clamp(force.getForce(), bounds.Item1, bounds.Item2); sliders[i].SetValueWithoutNotify((newtons - bounds.Item1) / bounds.Item2); inputFields[i].SetTextWithoutNotify("" + Mathf.Round(newtons * 100f) / 100f); } else if (i == 6) //velocity { (float, float)bounds = (0.01f, 100f); VelocityControl velocity = focused.GetComponent <VelocityControl>(); float speed = Mathf.Clamp(velocity.getSpeed(), bounds.Item1, bounds.Item2); sliders[i].SetValueWithoutNotify((speed - bounds.Item1) / bounds.Item2); inputFields[i].SetTextWithoutNotify("" + Mathf.Round(speed * 100f) / 100f); } else if (i == 7) { (float, float)bounds = (0f, 360f); float angle = transcurr.localEulerAngles.z; if (namecurr == "Force") { ForceControl force = focused.GetComponent <ForceControl>(); if (force == null) { return; } angle = Mathf.Clamp(force.getAngle(), bounds.Item1, bounds.Item2); } else if (namecurr == "Velocity") { VelocityControl velocity = focused.GetComponent <VelocityControl>(); if (velocity == null) { return; } angle = Mathf.Clamp(velocity.getAngle(), bounds.Item1, bounds.Item2); } else { angle = Mathf.Clamp(transcurr.localEulerAngles.z, bounds.Item1, bounds.Item2); } sliders[i].SetValueWithoutNotify((angle - bounds.Item1) / bounds.Item2); inputFields[i].SetTextWithoutNotify("" + Mathf.Round(angle * 100f) / 100f); } else if (i == 8) //equilibrium length { //cannot set this property when spring is attached SpringControl spring = focused.GetComponent <SpringControl>(); //if (!spring.available()) { this.CoerceAdjustValues(8); return; } (float, float)bounds = (0.01f, 100f); float elength = Mathf.Clamp(spring.getElength(), bounds.Item1, bounds.Item2); sliders[i].SetValueWithoutNotify((elength - bounds.Item1) / bounds.Item2); inputFields[i].SetTextWithoutNotify("" + Mathf.Round(elength * 100f) / 100f); } else if (i == 9) //break force (N) { (double, double)bounds = (0.01, 999999999); SpringControl spring = focused.GetComponent <SpringControl>(); double breakforce = Math.Max(Math.Min(spring.getBreakForce(), bounds.Item2), bounds.Item1); sliders[i].SetValueWithoutNotify((float)((breakforce - bounds.Item1) / bounds.Item2)); inputFields[i].SetTextWithoutNotify("" + Math.Round(breakforce * 100f) / 100f); } else if (i == 10) { (float, float)bounds = (0f, 1f); Collider2D col = focused.GetComponent <Collider2D>(); sliders[i].SetValueWithoutNotify((col.sharedMaterial.friction - bounds.Item1) / bounds.Item2); inputFields[i].SetTextWithoutNotify("" + Mathf.Round(col.sharedMaterial.friction * 100f) / 100f); } //else if (i == 10) //{ // (float, float) bounds = (0f, 1f); // Collider2D col = focused.GetComponent<Collider2D>(); // sliders[i].SetValueWithoutNotify((col.bounciness - bounds.Item1) / bounds.Item2); // inputFields[i].SetTextWithoutNotify("" + Mathf.Round(col.bounciness * 100f) / 100f); //} //else if (i == 11) //{ // (float, float) bounds = (0f, 1f); // Collider2D col = focused.GetComponent<Collider2D>(); // sliders[i].SetValueWithoutNotify((col.friction - bounds.Item1) / bounds.Item2); // inputFields[i].SetTextWithoutNotify("" + Mathf.Round(col.friction * 100f) / 100f); //} } }