示例#1
0
    public void fieldValueChange(int idx)
    {
        double val;
        string text = inputFields[idx].text;

        if (text == "")
        {
            val = 0;
        }
        else if (!double.TryParse(text, out val))
        {
            return;
        }

        if (idx == 0)
        {
            (float, float)bounds = (0.01f, 1000f);
            float value = (float)val;
            value       = Mathf.Clamp(value, bounds.Item1, bounds.Item2);
            rbcurr.mass = value;
            sliders[idx].SetValueWithoutNotify((value - bounds.Item1) / bounds.Item2);
            if ((text[text.Length - 1] != '.' && text[text.Length - 1] != '0') || (text[text.Length - 1] == '0' && !text.Contains(".")))
            {
                inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(value * 100f) / 100f);
            }
        }
        else if (idx == 1)
        {
            (float, float)bounds = (0.01f, 1000f);
            float value = (float)val;
            value = Mathf.Clamp(value, bounds.Item1, bounds.Item2);
            float length = value;
            if (namecurr == "FixedRectangle")
            {
                transcurr.localScale = new v2(length / Util.FixedRectWidthMultiplier, transcurr.localScale.y);
            }
            else if (namecurr == "MoveableRectangle")
            {
                transcurr.localScale = new v2(length / Util.MoveableRectWidthMultiplier, transcurr.localScale.y);
            }
            sliders[idx].SetValueWithoutNotify((length - bounds.Item1) / bounds.Item2);
            if ((text[text.Length - 1] != '.' && text[text.Length - 1] != '0') || (text[text.Length - 1] == '0' && !text.Contains(".")))
            {
                inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(length * 100f) / 100f);
            }
        }
        else if (idx == 2)
        {
            (float, float)bounds = (0.01f, 1000f);
            float value = (float)val;
            value = Mathf.Clamp(value, bounds.Item1, bounds.Item2);
            float width = value;
            if (namecurr == "FixedRectangle")
            {
                transcurr.localScale = new v2(transcurr.localScale.x, width / Util.FixedRectHeightMultiplier);
            }
            else if (namecurr == "MoveableRectangle")
            {
                transcurr.localScale = new v2(transcurr.localScale.x, width / Util.MoveableRectHeightMultiplier);
            }
            sliders[idx].SetValueWithoutNotify((width - bounds.Item1) / bounds.Item2);
            if ((text[text.Length - 1] != '.' && text[text.Length - 1] != '0') || (text[text.Length - 1] == '0' && !text.Contains(".")))
            {
                inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(width * 100f) / 100f);
            }
        }
        else if (idx == 3) //circle
        {
            (float, float)bounds = (0.01f, 100f);
            float value = (float)val;
            value = Mathf.Clamp(value, bounds.Item1, bounds.Item2);
            transcurr.localScale = new v2(value, value);
            sliders[idx].SetValueWithoutNotify((value - bounds.Item1) / bounds.Item2);
            if ((text[text.Length - 1] != '.' && text[text.Length - 1] != '0') || (text[text.Length - 1] == '0' && !text.Contains(".")))
            {
                inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(value * 100f) / 100f);
            }
        }
        else if (idx == 4)
        {
            (float, float)bounds = (0.01f, 1000f);
            float value = (float)val;
            value = Mathf.Clamp(value, bounds.Item1, bounds.Item2);
            SpringControl spring = focused.GetComponent <SpringControl>();
            spring.setSpringConstant(value);
            sliders[idx].SetValueWithoutNotify((value - bounds.Item1) / bounds.Item2);
            if ((text[text.Length - 1] != '.' && text[text.Length - 1] != '0') || (text[text.Length - 1] == '0' && !text.Contains(".")))
            {
                inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(value * 100f) / 100f);
            }
        }
        else if (idx == 5)
        {
            (float, float)bounds = (0.01f, 1000f);
            float value = (float)val;
            value = Mathf.Clamp(value, bounds.Item1, bounds.Item2);
            ForceControl force = focused.GetComponent <ForceControl>();
            if ((text[text.Length - 1] != '.' && text[text.Length - 1] != '0') || (text[text.Length - 1] == '0' && !text.Contains(".")))
            {
                inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(value * 100f) / 100f);
            }
            force.setForce(value);
            //sliders[idx].SetValueWithoutNotify((value - bounds.Item1) / bounds.Item2);
            //inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(value * 100f) / 100f);
        }
        else if (idx == 6)
        {
            (float, float)bounds = (0.01f, 100f);
            float value = (float)val;
            value = Mathf.Clamp(value, bounds.Item1, bounds.Item2);
            VelocityControl velocity = focused.GetComponent <VelocityControl>();
            if ((text[text.Length - 1] != '.' && text[text.Length - 1] != '0') || (text[text.Length - 1] == '0' && !text.Contains(".")))
            {
                inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(value * 100f) / 100f);
            }
            velocity.setSpeed(value);
        }
        else if (idx == 7)
        {
            (float, float)bounds = (0f, 360f);
            float value = (float)val;
            value = Mathf.Clamp(value, bounds.Item1, bounds.Item2);
            if (namecurr == "Force")
            {
                if ((text[text.Length - 1] != '.' && text[text.Length - 1] != '0') || (text[text.Length - 1] == '0' && !text.Contains(".")))
                {
                    inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(value * 100f) / 100f);
                }
                this.focused.GetComponent <ForceControl>().setAngle(value);
            }
            else if (namecurr == "Velocity")
            {
                if ((text[text.Length - 1] != '.' && text[text.Length - 1] != '0') || (text[text.Length - 1] == '0' && !text.Contains(".")))
                {
                    inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(value * 100f) / 100f);
                }
                this.focused.GetComponent <VelocityControl>().setAngle(value);
            }
            else
            {
                transcurr.localEulerAngles = new v3(0, 0, value);
                sliders[idx].SetValueWithoutNotify((value - bounds.Item1) / bounds.Item2);
                if ((text[text.Length - 1] != '.' && text[text.Length - 1] != '0') || (text[text.Length - 1] == '0' && !text.Contains(".")))
                {
                    inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(value * 100f) / 100f);
                }
            }
        }
        else if (idx == 8) //equilibrium length
        {
            (float, float)bounds = (0.01f, 100f);
            float value = (float)val;
            value = Mathf.Clamp(value, bounds.Item1, bounds.Item2);
            SpringControl spring = focused.GetComponent <SpringControl>();
            spring.setElength(value);
            sliders[idx].SetValueWithoutNotify((value - bounds.Item1) / bounds.Item2);
            if ((text[text.Length - 1] != '.' && text[text.Length - 1] != '0') || (text[text.Length - 1] == '0' && !text.Contains(".")))
            {
                inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(value * 100f) / 100f);
            }
        }
        else if (idx == 9) //break force (N)
        {
            (double, double)bounds = (0.01, 999999999);
            SpringControl spring     = focused.GetComponent <SpringControl>();
            double        breakforce = Math.Max(Math.Min(val, bounds.Item2), bounds.Item1);
            spring.setBreakForce(breakforce);
            sliders[idx].SetValueWithoutNotify((float)((breakforce - bounds.Item1) / bounds.Item2));
            if ((text[text.Length - 1] != '.' && text[text.Length - 1] != '0') || (text[text.Length - 1] == '0' && !text.Contains(".")))
            {
                inputFields[idx].SetTextWithoutNotify("" + Math.Round(breakforce * 100f) / 100f);
            }
        }
        else if (idx == 10)
        {
            (float, float)bounds = (0f, 1f);
            Collider2D col   = focused.GetComponent <Collider2D>();
            float      value = (float)val;
            value = Mathf.Clamp(value, bounds.Item1, bounds.Item2);
            col.sharedMaterial.friction = value;
            Attachable.ResetAllColliders();
            sliders[idx].SetValueWithoutNotify((value - bounds.Item1) / bounds.Item2);
            if ((text[text.Length - 1] != '.' && text[text.Length - 1] != '0') || (text[text.Length - 1] == '0' && !text.Contains(".")))
            {
                inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(value * 100f) / 100f);
            }
        }
        //else if (idx == 10)
        //{
        //    (float, float) bounds = (0f, 1f);
        //    Collider2D col = focused.GetComponent<Collider2D>();
        //    float value = (float)val;
        //    value = Mathf.Clamp(value, bounds.Item1, bounds.Item2);
        //    col.sharedMaterial.bounciness = value;
        //    sliders[idx].SetValueWithoutNotify((value - bounds.Item1) / bounds.Item2);
        //    if ((text[text.Length - 1] != '.' && text[text.Length - 1] != '0') || (text[text.Length - 1] == '0' && !text.Contains("."))) inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(value * 100f) / 100f);
        //}
        //else if (idx == 11)
        //{

        //}
    }
示例#2
0
    public void sliderValueChange(int idx)
    {
        if (sliders[idx].gameObject != EventSystem.current.currentSelectedGameObject)
        {
            return;
        }
        // Debug.Log(idx);
        float value = sliders[idx].value;

        if (idx == 0)
        {
            (float, float)bounds = (0.01f, 1000f);
            float mass = bounds.Item1 + value / 1f * (bounds.Item2 - bounds.Item1);
            rbcurr.mass = mass;
            inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(mass * 100f) / 100f);
        }
        else if (idx == 1)
        {
            (float, float)bounds = (0.01f, 1000f);
            float length = bounds.Item1 + value / 1f * (bounds.Item2 - bounds.Item1);
            if (namecurr == "FixedRectangle")
            {
                transcurr.localScale = new v2(length / Util.FixedRectWidthMultiplier, transcurr.localScale.y);
            }
            else if (namecurr == "MoveableRectangle")
            {
                transcurr.localScale = new v2(length / Util.MoveableRectWidthMultiplier, transcurr.localScale.y);
            }
            inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(length * 100f) / 100f);
        }
        else if (idx == 2)
        {
            (float, float)bounds = (0.01f, 1000f);
            float width = bounds.Item1 + value / 1f * (bounds.Item2 - bounds.Item1);
            if (namecurr == "FixedRectangle")
            {
                transcurr.localScale = new v2(transcurr.localScale.x, width / Util.FixedRectHeightMultiplier);
            }
            else if (namecurr == "MoveableRectangle")
            {
                transcurr.localScale = new v2(transcurr.localScale.x, width / Util.MoveableRectHeightMultiplier);
            }
            inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(width * 100f) / 100f);
        }
        else if (idx == 3) //circle
        {
            (float, float)bounds = (0.01f, 100f);
            float diameter = bounds.Item1 + value / 1f * (bounds.Item2 - bounds.Item1);
            transcurr.localScale = new v2(diameter, diameter);
            inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(diameter * 100f) / 100f);
        }
        else if (idx == 4) //spring constant (N/m)
        {
            (float, float)bounds = (0.01f, 1000f);
            SpringControl spring   = focused.GetComponent <SpringControl>();
            float         constant = bounds.Item1 + value / 1f * (bounds.Item2 - bounds.Item1);
            spring.setSpringConstant(constant);
            inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(constant * 100f) / 100f);
        }
        else if (idx == 5) //force
        {
            (float, float)bounds = (0.01f, 1000f);
            float        newtons = bounds.Item1 + value / 1f * (bounds.Item2 - bounds.Item1);
            ForceControl force   = focused.GetComponent <ForceControl>();
            force.setForce(newtons);
            //inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(newtons * 100f) / 100f);
        }
        else if (idx == 6) //velocity
        {
            (float, float)bounds = (0.01f, 100f);
            float           speed    = bounds.Item1 + value / 1f * (bounds.Item2 - bounds.Item1);
            VelocityControl velocity = focused.GetComponent <VelocityControl>();
            velocity.setSpeed(speed);
        }
        else if (idx == 7)
        {
            (float, float)bounds = (0f, 360f);
            float angle = bounds.Item1 + value / 1f * (bounds.Item2 - bounds.Item1);
            if (namecurr == "Force")
            {
                this.focused.GetComponent <ForceControl>().setAngle(angle);
            }
            else if (namecurr == "Velocity")
            {
                this.focused.GetComponent <VelocityControl>().setAngle(angle);
            }
            else
            {
                transcurr.localEulerAngles = new v3(0, 0, angle);
                inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(angle * 100f) / 100f);
            }
        }
        else if (idx == 8) //equilibrium length
        {
            (float, float)bounds = (0.01f, 100f);
            SpringControl spring  = focused.GetComponent <SpringControl>();
            float         elength = bounds.Item1 + value / 1f * (bounds.Item2 - bounds.Item1);
            spring.setElength(elength);
            inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(elength * 100f) / 100f);
        }
        else if (idx == 9) //break force (N)
        {
            (double, double)bounds = (0.01, 999999999);
            SpringControl spring     = focused.GetComponent <SpringControl>();
            double        breakforce = bounds.Item1 + value * (bounds.Item2 - bounds.Item1);
            spring.setBreakForce(breakforce);
            inputFields[idx].SetTextWithoutNotify("" + Math.Round(breakforce * 100f) / 100f);
        }
        else if (idx == 10)
        {
            (float, float)bounds = (0f, 1f);
            Collider2D col      = focused.GetComponent <Collider2D>();
            float      friction = bounds.Item1 + value * (bounds.Item2 - bounds.Item1);
            col.sharedMaterial.friction = friction;
            Attachable.ResetAllColliders();
            inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(friction * 100f) / 100f);
        }
        //else if (idx == 10)
        //{
        //    (float, float) bounds = (0f, 1f);
        //    Collider2D col = focused.GetComponent<Collider2D>();
        //    float bounciness = bounds.Item1 + value * (bounds.Item2 - bounds.Item1);
        //    col.sharedMaterial.bounciness = bounciness;
        //    inputFields[idx].SetTextWithoutNotify("" + Mathf.Round(bounciness * 100f) / 100f);
        //}
        //else if (idx == 11)
        //{

        //}
    }