예제 #1
0
        /// <inheritdoc />
        public void CopyFrom(IPatchPart part)
        {
            if (part is Partial p)
            {
                Basic.CopyFrom(p.Basic);
                Assign.CopyFrom(p.Assign);
                Amplifier.CopyFrom(p.Amplifier);
                Output.CopyFrom(p.Output);
                Expression.CopyFrom(p.Expression);
                VelocityControl.CopyFrom(p.VelocityControl);

                for (var i = 0; i < p.Wmts.Length; i++)
                {
                    Wmts[i].CopyFrom(p.Wmts[i]);
                }

                Pitch.CopyFrom(p.Pitch);
                Tvf.CopyFrom(p.Tvf);
                Tva.CopyFrom(p.Tva);
                Other.CopyFrom(p.Other);
            }
            else
            {
                throw new NotSupportedException("Copying from that type is not supported");
            }
        }
예제 #2
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
     {
     }
 }
예제 #3
0
        /// <inheritdoc />
        public Partial(DrumKey key)
        {
            Key = key;

            Basic           = new Basic();
            Assign          = new Assign();
            Amplifier       = new Amplifier();
            Output          = new Output();
            Expression      = new Expression();
            VelocityControl = new VelocityControl();
            Wmts            = new[] { new Wmt.Wmt(), new Wmt.Wmt(), new Wmt.Wmt(), new Wmt.Wmt() };
            Pitch           = new Pitch();
            Tvf             = new Tvf();
            Tva             = new Tva();
            Other           = new Other();

            Basic.PropertyChanged           += (sender, args) => NotifyOfPropertyChange(nameof(Basic));
            Assign.PropertyChanged          += (sender, args) => NotifyOfPropertyChange(nameof(Assign));
            Amplifier.PropertyChanged       += (sender, args) => NotifyOfPropertyChange(nameof(Amplifier));
            Output.PropertyChanged          += (sender, args) => NotifyOfPropertyChange(nameof(Output));
            Expression.PropertyChanged      += (sender, args) => NotifyOfPropertyChange(nameof(Expression));
            VelocityControl.PropertyChanged += (sender, args) => NotifyOfPropertyChange(nameof(VelocityControl));
            Wmt1.PropertyChanged            += (sender, args) => NotifyOfPropertyChange(nameof(Wmt1));
            Wmt2.PropertyChanged            += (sender, args) => NotifyOfPropertyChange(nameof(Wmt2));
            Wmt3.PropertyChanged            += (sender, args) => NotifyOfPropertyChange(nameof(Wmt3));
            Wmt4.PropertyChanged            += (sender, args) => NotifyOfPropertyChange(nameof(Wmt4));
            Pitch.PropertyChanged           += (sender, args) => NotifyOfPropertyChange(nameof(Pitch));
            Tvf.PropertyChanged             += (sender, args) => NotifyOfPropertyChange(nameof(Tvf));
            Tva.PropertyChanged             += (sender, args) => NotifyOfPropertyChange(nameof(Tva));
            Other.PropertyChanged           += (sender, args) => NotifyOfPropertyChange(nameof(Other));
        }
예제 #4
0
        /// <inheritdoc />
        public void Reset()
        {
            Basic.Reset();
            Assign.Reset();
            Amplifier.Reset();
            Output.Reset();
            Expression.Reset();
            VelocityControl.Reset();

            foreach (var wmt in Wmts)
            {
                wmt.Reset();
            }

            Pitch.Reset();
            Tvf.Reset();
            Tva.Reset();
            Other.Reset();
        }
예제 #5
0
    void Start()
    {
        dronePositionControl = GetComponent <PositionControl>();
        droneVelocityControl = GetComponent <VelocityControl>();

        dronePositionControl.controlYaw = false;

        // This one is optional, thus cameraPosition can be null
        cameraPosition     = GetComponent <DroneCamera>();
        cameraViewRotation = 0.0f;
        if (cameraPosition != null)
        {
            cameraViewRotation    = cameraPosition.transform.eulerAngles.y;
            oldCameraViewRotation = cameraViewRotation;
        }

        // Instantiate hand target
        handTarget = new GameObject("Hand Target");
        handTarget.transform.localScale = 2.0f * SimulationData.DroneSize * Vector3.one;
        handTarget.transform.position   = dronePositionControl.transform.position;
    }
예제 #6
0
    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;
    }
예제 #7
0
        /// <inheritdoc />
        public byte[] GetBytes()
        {
            var bytes = new List <byte>();

            bytes.AddRange(Basic.GetBytes());               //  12 bytes
            bytes.AddRange(Assign.GetBytes());              //   2 bytes
            bytes.AddRange(Amplifier.GetBytes());           //   8 bytes
            bytes.AddRange(Output.GetBytes());              //   6 bytes
            bytes.AddRange(Expression.GetBytes());          //   4 bytes (3 + 1 reserve)
            bytes.AddRange(VelocityControl.GetBytes());     //   1 byte

            foreach (var wmt in Wmts)
            {
                bytes.AddRange(wmt.GetBytes());             // 116 bytes (29 bytes each)
            }
            bytes.AddRange(Pitch.GetBytes());               //  13 bytes
            bytes.AddRange(Tvf.GetBytes());                 //  20 bytes
            bytes.AddRange(Tva.GetBytes());                 //  11 bytes
            bytes.AddRange(Other.GetBytes());               //   2 bytes

            return(bytes.ToArray());
        }
예제 #8
0
        /// <inheritdoc />
        public void CopyFrom(byte[] data)
        {
            if (data.Length != DumpLength)
            {
                throw new InvalidDumpSizeException(DumpLength, data.Length);
            }

            Basic.CopyFrom(data.Take(12).ToArray());
            Assign.CopyFrom(data.Skip(12).Take(2).ToArray());
            Amplifier.CopyFrom(data.Skip(14).Take(8).ToArray());
            Output.CopyFrom(data.Skip(22).Take(6).ToArray());
            Expression.CopyFrom(data.Skip(28).Take(4).ToArray());
            VelocityControl.CopyFrom(data.Skip(32).Take(1).ToArray());

            for (var i = 0; i < Wmts.Length; i++)
            {
                Wmts[i].CopyFrom(data.Skip(33 + i * 29).Take(29).ToArray());
            }

            Pitch.CopyFrom(data.Skip(149).Take(13).ToArray());
            Tvf.CopyFrom(data.Skip(162).Take(20).ToArray());
            Tva.CopyFrom(data.Skip(182).Take(11).ToArray());
            Other.CopyFrom(data.Skip(193).Take(2).ToArray());
        }
예제 #9
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)
        //{

        //}
    }
예제 #10
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)
        //{

        //}
    }
예제 #11
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);
         //}
     }
 }
 void Start()
 {
     vc          = GetComponent <VelocityControl>();
     vcTranform  = vc.transform;
     vcRigidbody = vc.GetComponent <Rigidbody>();
 }
예제 #13
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;
    }
예제 #14
0
 // Use this for initialization
 void Start()
 {
     vc = GetComponent <VelocityControl>();
 }