Ejemplo n.º 1
0
 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
     {
     }
 }
Ejemplo n.º 2
0
 void Start()
 {
     map_creator  = GameObject.Find("GameRoot").GetComponent <MapCreator>();
     player       = GameObject.Find("Player");
     gameManager  = GameObject.Find("GameManager").GetComponent <GameManager>();
     forceControl = player.GetComponent <ForceControl>();
 }
Ejemplo n.º 3
0
    void updateForce()
    {
        dashhorizontal.gameObject.SetActive(true);
        dashmoving.gameObject.SetActive(false);
        label.gameObject.SetActive(true);

        ForceControl force = this.gameObject.GetComponent <ForceControl>();
        v3           pos   = force.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.ForceHeightMultiplier * Util.WorldToScreenMultiplier;

        dashhorizontal.sizeDelta = new v2(length, 3f);

        Text  t     = label.GetComponent <Text>();
        float angle = force.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;
    }
Ejemplo n.º 4
0
 // Use this for initialization
 void Start()
 {
     player          = GameObject.Find("Player");
     forceController = player.GetComponent <ForceControl>();
     forceController.AddObject(this);
 }
Ejemplo n.º 5
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)
        //{

        //}
    }
Ejemplo n.º 6
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)
        //{

        //}
    }
Ejemplo n.º 7
0
 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);
         //}
     }
 }
Ejemplo n.º 8
0
    public void OnDrop(PointerEventData eventData)
    {
        if (eventData.pointerDrag == null)
        {
            return;
        }
        Vector3 pos = eventData.position;

        //check if pos is inside of scrollViewRect
        if (Util.OnCanvas(pos))
        {
            //this is the object being dropped
            //instantiate a new object in the canvass
            GameObject        ui          = eventData.pointerDrag;
            ObjectDragHandler draghandler = ui.GetComponent <ObjectDragHandler>();
            if (draghandler == null)
            {
                return;
            }
            GameObject reference = draghandler.spritePreFab;
            GameObject newObj    = Instantiate(reference) as GameObject;
            newObj.SetActive(true);
            Vector3 worldPos = Camera.main.ScreenToWorldPoint(eventData.position);
            worldPos.z = 0;
            newObj.transform.position = worldPos;

            //Check for spring
            SpringControl      spring   = newObj.GetComponent <SpringControl>();
            ForceControl       force    = newObj.GetComponent <ForceControl>();
            VelocityControl    velocity = newObj.GetComponent <VelocityControl>();
            PropertiesEditable edit     = newObj.GetComponent <PropertiesEditable>();
            ReplayControl      replay   = newObj.GetComponent <ReplayControl>();
            Name name = newObj.GetComponent <Name>();
            if (spring != null) //if this is a spring
            {
                spring.attachPoint1 = worldPos + new Vector3(0, SpringControl.defaultHeight / 2f, 0);
                spring.attachPoint2 = worldPos - new Vector3(0, SpringControl.defaultHeight / 2f, 0);
            }
            if (force != null) //if this is a force arrow
            {
                force.attachPoint1 = worldPos + new Vector3(0, ForceControl.defaultHeight / 2f, 0);
                force.attachPoint2 = worldPos - new Vector3(0, ForceControl.defaultHeight / 2f, 0);
            }
            if (velocity != null)
            {
                velocity.attachPoint1 = worldPos + new Vector3(0, VelocityControl.defaultHeight / 2f, 0);
                velocity.attachPoint2 = worldPos - new Vector3(0, VelocityControl.defaultHeight / 2f, 0);
            }
            if (replay != null)
            {
                ReplayControl.focusedObject = newObj;
            }
            if (edit != null)
            {
                PropertiesEditable.focusedObject = newObj;
            }
            //if (name.objectname == "FixedRectangle" || name.objectname == "MoveableRectangle" || name.objectname == "Circle")
            //{
            //    Collider2D col = newObj.GetComponent<Collider2D>();
            //    PhysicsMaterial2D material = new PhysicsMaterial2D();
            //    material.friction = 0.4f;
            //    material.bounciness = 0.4f;
            //    col.sharedMaterial = material;
            //}
        }
        //otherwise do nothing;
    }
Ejemplo n.º 9
0
 // Use this for initialization
 void Start()
 {
     forceControl = GameObject.Find("Player").GetComponent <ForceControl>();
     forceControl.onChangeForceCountEvent += new ForceControl.OnChangeForceCount(ChangeValue);
     forceText = GetComponent <Text>();
 }