Пример #1
0
        public void Update()
        {
            if (!IsOnEditor())
            {
                return;
            }

            if (this.isSetting)
            {
                foreach (var key in KRSUtils.BindableKeys)
                {
                    if (Input.GetKey(key))
                    {
                        SetInputFieldValue(this.currentControl.Key, this.currentControl.Value,
                                           KRSInputAttribute.GetInputString(key.ToString(), false, this.currentReversed));
                        this.isSetting = false;
                    }
                }

                for (int i = 0; i < Input.GetJoystickNames().Length; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        var axis = String.Format(KRSUtils.AxisFormat, i, j);
                        if (Math.Abs(Input.GetAxis(axis)) > 0.25f)
                        {
                            SetInputFieldValue(this.currentControl.Key, this.currentControl.Value,
                                               KRSInputAttribute.GetInputString(axis, true, this.currentReversed));
                            this.isSetting = false;
                        }
                    }
                }
            }
            else if (isClearing)
            {
                this.isClearing = false;
                SetInputFieldValue(this.currentControl.Key, this.currentControl.Value, "");
            }
            else if (this.isReversing)
            {
                this.isReversing = false;
                var    v = GetInputFieldValue(this.currentControl.Key, this.currentControl.Value);
                string inputName;
                bool   inputIsAxis, inputIsReversed;
                if (KRSInputAttribute.GetInputDef(v, out inputName, out inputIsAxis, out inputIsReversed))
                {
                    SetInputFieldValue(this.currentControl.Key, this.currentControl.Value,
                                       KRSInputAttribute.GetInputString(inputName, inputIsAxis, this.currentReversed));
                }
            }
        }
Пример #2
0
 public void WindowGUI(int id)
 {
     GUI.DragWindow(new Rect(0f, 0f, 1000f, 50f));
     GUILayout.BeginVertical("box");
     scrollPos = GUILayout.BeginScrollView(scrollPos, false, true);
     foreach (var c in (KRSHinge[])UnityEngine.Object.FindObjectsOfType(typeof(KRSHinge)))
     {
         GUILayout.BeginVertical("box");
         GUILayout.Label("<b>" + c.part.partInfo.title + "</b>");
         foreach (var f in GetInputFieldsAttributes(c))
         {
             string inputName;
             bool   inputIsAxis, inputIsReversed;
             var    fieldValue       = GetInputFieldValue(c, f.Key);
             var    active           = KRSInputAttribute.GetInputDef(fieldValue, out inputName, out inputIsAxis, out inputIsReversed);
             var    isSettingCurrent = isSetting && this.currentControl.Value == f.Key;
             GUILayout.BeginHorizontal("box");
             GUILayout.Label(f.Value.guiName + ": ");
             GUILayout.Label(!isSettingCurrent ? (active ? inputName : "<i><none></i>") : "<i><press key / axis></i>");
             GUILayout.EndHorizontal();
             GUILayout.BeginHorizontal("box");
             GUI.enabled = !(isSetting || active);
             if (GUILayout.Button("Set"))
             {
                 this.currentControl = new KeyValuePair <KRSHinge, string>(c, f.Key);
                 this.isSetting      = true;
             }
             GUI.enabled = isSettingCurrent || active;
             if (GUILayout.Button("Clear"))
             {
                 this.currentControl = new KeyValuePair <KRSHinge, string>(c, f.Key);
                 this.isClearing     = true;
             }
             var r = GUILayout.Toggle(inputIsReversed, "Reversed");
             if (r != inputIsReversed)
             {
                 this.currentControl  = new KeyValuePair <KRSHinge, string>(c, f.Key);
                 this.currentReversed = r;
                 this.isReversing     = true;
             }
             GUI.enabled = true;
             GUILayout.EndHorizontal();
             GUILayout.Space(5);
         }
         GUILayout.EndVertical();
         GUILayout.Space(5);
     }
     GUILayout.EndScrollView();
     GUILayout.EndVertical();
 }
Пример #3
0
        public override void OnUpdate()
        {
            if ((this.vessel == null) || (this.vessel != FlightGlobals.ActiveVessel))
            {
                return;
            }

            float dir = Mathf.Clamp(KRSInputAttribute.GetInputValue(inputRotateAnalog) +
                                    KRSInputAttribute.GetInputValue(inputRotateCW) -
                                    KRSInputAttribute.GetInputValue(inputRotateCCW), -1f, 1f);

            if (Math.Abs(dir) > 0.001f)
            {
                Rotate(dir);
            }
            else if (Math.Abs(this.currentAngularVelocity) > 0.001f)
            {
                Rotate(0f);
            }
        }