Пример #1
0
		Control MessageBoxDefaultButtonCombo()
		{
			var control = new EnumDropDown<MessageBoxDefaultButton>();
			var binding = new ControlBinding<MessageBoxSection, MessageBoxDefaultButton>(this, r => r.MessageBoxDefaultButton, (r, val) => r.MessageBoxDefaultButton = val);
			control.SelectedValueBinding.Bind(binding);
			return control;
		}
Пример #2
0
		Control CaptionBox()
		{
			var control = new TextBox { Size = new Size(300, -1) };
			var binding = new ControlBinding<MessageBoxSection, string>(this, r => r.MessageBoxCaption, (r, val) => r.MessageBoxCaption = val);
			control.TextBinding.Bind(binding);
			return control;
		}
Пример #3
0
		Control CaptionBox()
		{
			var control = new TextBox { Size = new Size(300, -1) };
			var binding = new ControlBinding<MessageBoxSection, string>(this, r => r.MessageBoxCaption, (r, val) => r.MessageBoxCaption = val);
			control.TextBinding.Bind(binding);
			return control;
		}
Пример #4
0
		Control TitleBox()
		{
			var control = new TextArea { Size = new Size(300, -1) };
			var binding = new ControlBinding<MessageBoxSection, string>(this, r => r.MessageBoxText, (r, val) => r.MessageBoxText = val);
			control.TextBinding.Bind(binding);
			return control;
		}
Пример #5
0
 void DrawSources(ControlBinding binding)
 {
     for (int i = 0; i < binding.sources.Count; i++)
     {
         DrawSourceSummary(binding.sources[i]);
     }
 }
Пример #6
0
		Control AttachToParentCheckBox()
		{
			var control = new CheckBox { Text = "Attach to Parent Window" };
			var binding = new ControlBinding<MessageBoxSection, bool?>(this, r => r.AttachToParent, (r, val) => r.AttachToParent = val ?? false);
			control.CheckedBinding.Bind(binding);
			return control;
		}
Пример #7
0
 void DrawButtonAxisSources(ControlBinding binding)
 {
     for (int i = 0; i < binding.buttonAxisSources.Count; i++)
     {
         DrawButtonAxisSourceSummary(binding.buttonAxisSources[i]);
     }
 }
    private static ControlBinding CreateButtonAxisBinding(System.Type deviceType, params int[] controlIndices)
    {
        if (controlIndices.Length % 2 != 0)
        {
            throw new System.Exception("Number of indices must be even.");
        }
        var binding = new ControlBinding();

        binding.primaryIsButtonAxis = true;
        binding.buttonAxisSources   = new List <ButtonAxisSource>();
        for (int i = 0; i < controlIndices.Length; i += 2)
        {
            binding.buttonAxisSources.Add(
                new ButtonAxisSource(
                    new InputControlDescriptor
            {
                deviceType   = deviceType,
                controlIndex = controlIndices[i]
            },
                    new InputControlDescriptor
            {
                deviceType   = deviceType,
                controlIndex = controlIndices[i + 1]
            }
                    )
                );
        }
        return(binding);
    }
    void DisplayControlBinding(InputAction action, ControlBinding controlBinding)
    {
        if (controlBinding.sources.Count > 0)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(action.name, GUILayout.Width(k_NameWidth));
            for (int i = 0; i < controlBinding.sources.Count; i++)
            {
                DisplaySource(controlBinding.sources[i]);
            }
            GUILayout.EndHorizontal();
        }

        if (controlBinding.buttonAxisSources.Count > 0)
        {
            GUILayout.BeginHorizontal();
            // Use unicode minus sign that has same width as plus sign.
            GUILayout.Label(action.name + " (\u2212)", GUILayout.Width(k_NameWidth));
            for (int i = 0; i < controlBinding.buttonAxisSources.Count; i++)
            {
                DisplayButtonAxisSource(controlBinding.buttonAxisSources[i], false);
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label(action.name + " (+)", GUILayout.Width(k_NameWidth));
            for (int i = 0; i < controlBinding.buttonAxisSources.Count; i++)
            {
                DisplayButtonAxisSource(controlBinding.buttonAxisSources[i], true);
            }
            GUILayout.EndHorizontal();
        }
    }
Пример #10
0
		Control MessageBoxTypeCombo()
		{
			var control = new EnumDropDown<MessageBoxType>();
			var binding = new ControlBinding<MessageBoxSection, MessageBoxType>(this, r => r.MessageBoxType, (r, val) => r.MessageBoxType = val);
			control.SelectedValueBinding.Bind(binding);
			return control;
		}
Пример #11
0
		Control TitleBox()
		{
			var control = new TextArea { Size = new Size(300, -1) };
			var binding = new ControlBinding<MessageBoxSection, string>(this, r => r.MessageBoxText, (r, val) => r.MessageBoxText = val);
			control.TextBinding.Bind(binding);
			return control;
		}
Пример #12
0
 void DrawButtonAxisSources(ref Rect rect, ControlBinding binding)
 {
     for (int i = 0; i < binding.buttonAxisSources.Count; i++)
     {
         DrawButtonAxisSourceSummary(rect, binding.buttonAxisSources[i]);
         rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
     }
 }
Пример #13
0
 public void borrowBindings(ControlManager controlManager)
 {
     for (int i = 0; i < controlManager.controlBindings.Count; i++)
     {
         ControlBinding binding = controlManager.controlBindings[i];
         setControlBinding(binding.inputItem, binding.control);
     }
 }
Пример #14
0
    void ShowAddOptions(Rect rect, ControlBinding binding)
    {
        GenericMenu menu = new GenericMenu();

        menu.AddItem(new GUIContent("Regular Source"), false, AddSource, binding);
        menu.AddItem(new GUIContent("Button Axis Source"), false, AddButtonAxisSource, binding);
        menu.DropDown(rect);
    }
Пример #15
0
        Control MessageBoxButtonsCombo()
        {
            var control = new EnumDropDown <MessageBoxButtons>();
            var binding = new ControlBinding <MessageBoxSection, MessageBoxButtons>(this, r => r.MessageBoxButtons, (r, val) => r.MessageBoxButtons = val);

            control.SelectedValueBinding.Bind(binding);
            return(control);
        }
Пример #16
0
        public void BindAction(PlayerAction action, KeyCode code)
        {
            MapDisplay(action, code);

            _controlBindings[action] = new ControlBinding {
                key = code
            };

            onActionChosen.Invoke(action.ToString());
        }
Пример #17
0
        public void BindAction(PlayerAction action, Axis axis)
        {
            MapDisplay(action, axis);

            _controlBindings[action] = new ControlBinding {
                axis = axis
            };

            onActionChosen.Invoke(action.ToString());
        }
Пример #18
0
    void AddButtonAxisSource(object data)
    {
        ControlBinding binding = (ControlBinding)data;
        var            source  = new ButtonAxisSource(new InputControlDescriptor(), new InputControlDescriptor());

        binding.buttonAxisSources.Add(source);

        m_SelectedSource           = null;
        m_SelectedButtonAxisSource = source;
    }
Пример #19
0
    public void setControlBinding(InputItem inputItem, Control control)
    {
        ControlBinding controlJobItem = getControlBinding(control);

        if (controlJobItem != null)
        {
            controlJobItem.inputItem = inputItem;
            return;
        }
        controlBindings.Add(new ControlBinding(inputItem, control));
    }
Пример #20
0
    // Check if any control has a certain hardware input bound to it, and remove it
    public static void RemoveAllHardwareBind(string hardwareName)
    {
        ControlBinding removeMe = new ControlBinding(hardwareName);

        foreach (string key in bindings.Keys)
        {
            if (bindings[key].Contains(removeMe))
            {
                bindings[key].Remove(removeMe);
            }
        }
    }
Пример #21
0
    // Attempts to detect input on any axis or button.
    // Returns true if input was captured. False otherwise.
    // Only creates the binding if captured input wasn't escape key/back button.
    // Binds it to the specified binding slot for the specified control
    public static bool CaptureInput(string inputFor, int slot, bool mouseMovement = true)
    {
        string axis = GetPressedAxis(mouseMovement);

        if (axis != null)
        {
            bool positive = (axis[axis.Length - 1] == '+');
            if (bindings[inputFor].Count - 1 < slot)
            {
                bindings[inputFor].Add(new ControlBinding(axis.Substring(0, axis.Length - 1), positive));
            }
            else
            {
                bindings[inputFor][slot] = new ControlBinding(axis.Substring(0, axis.Length - 1), positive);
            }
            bindings.Save(inputFor);
            return(true);
        }
        else
        {
            KeyCode kcode = InputWrapper.GetPressedKey();
            if (kcode != KeyCode.None)
            {
                if (kcode != KeyCode.Escape)
                {
                    if (bindings[inputFor].Count - 1 < slot)
                    {
                        bindings[inputFor].Add(new ControlBinding(kcode));
                    }
                    else
                    {
                        bindings[inputFor][slot] = new ControlBinding(kcode);
                    }
                    bindings.Save(inputFor);
                }
                else
                {
                    if (bindings[inputFor].Count > slot)
                    {
                        bindings[inputFor].RemoveAt(slot);
                    }
                }
                return(true);
            }
        }
        return(false);
    }
Пример #22
0
        protected override void ParseLine(string line)
        {
            string[] keyValuePair = line.Split(KeyValueSeperator, 2);

            if (keyValuePair.Length < 2)
            {
                return;
            }

            string keyString = keyValuePair[0].Trim();

            string[] valueStrings = keyValuePair[1].Split(ValueSeperator).Select(s => s = s.Trim()).ToArray();

            if (accessorDictionary.TryGetValue(keyString, out var accessor))
            {
                if (ControlBinding.TryParse(valueStrings, out ControlBinding binding))
                {
                    accessor.Setter?.Invoke(binding);
                }
            }
        }
Пример #23
0
    public bool CheckControlBinding(ControlBinding binding, KeyState keystate = KeyState.Down)
    {
        switch (keystate)
        {
        case KeyState.Down:
            foreach (KeyCode key in binding)
            {
                if (Input.GetKeyDown(key))
                {
                    return(true);
                }
            }
            break;

        case KeyState.Up:
            foreach (KeyCode key in binding)
            {
                if (Input.GetKeyUp(key))
                {
                    return(true);
                }
            }
            break;

        case KeyState.Held:
            foreach (KeyCode key in binding)
            {
                if (Input.GetKey(key))
                {
                    return(true);
                }
            }
            break;
        }


        return(false);
    }
Пример #24
0
    void DrawBinding(ControlBinding binding)
    {
        if (binding.primaryIsButtonAxis)
        {
            DrawButtonAxisSources(binding);
            DrawSources(binding);
        }
        else
        {
            DrawSources(binding);
            DrawButtonAxisSources(binding);
        }

        // Remove and add buttons
        EditorGUILayout.BeginHorizontal();
        GUILayout.Space(15 * EditorGUI.indentLevel);
        if (GUILayout.Button(Styles.iconToolbarMinus, GUIStyle.none))
        {
            if (m_SelectedSource != null)
            {
                binding.sources.Remove(m_SelectedSource);
            }
            if (m_SelectedButtonAxisSource != null)
            {
                binding.buttonAxisSources.Remove(m_SelectedButtonAxisSource);
            }
        }
        Rect r = GUILayoutUtility.GetRect(Styles.iconToolbarPlusMore, GUIStyle.none);

        if (GUI.Button(r, Styles.iconToolbarPlusMore, GUIStyle.none))
        {
            ShowAddOptions(r, binding);
        }
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();
    }
Пример #25
0
        private Dictionary <string, ControlBindingAccessor> GetAccessorDictionary()
        {
            return(new Dictionary <string, ControlBindingAccessor>()
            {
                {
                    "SKIP_NETWORK_CHECKS", new ControlBindingAccessor(() => SkipNetworkBinding, (v) => SkipNetworkBinding = v)
                },
                {
                    "INSERT_COIN", new ControlBindingAccessor(() => InsertCoinBinding, (v) => InsertCoinBinding = v)
                },

                {
                    JvsButtons.JVS_TEST.ToString(), new ControlBindingAccessor(() => TestButtonBinding, (v) => TestButtonBinding = v)
                },
                {
                    JvsButtons.JVS_SERVICE.ToString(), new ControlBindingAccessor(() => ServiceButtonBinding, (v) => ServiceButtonBinding = v)
                },
                {
                    JvsButtons.JVS_START.ToString(), new ControlBindingAccessor(() => StartButtonBinding, (v) => StartButtonBinding = v)
                },

                {
                    JvsButtons.JVS_TRIANGLE.ToString(), new ControlBindingAccessor(() => TriangleButtonBinding, (v) => TriangleButtonBinding = v)
                },
                {
                    JvsButtons.JVS_SQUARE.ToString(), new ControlBindingAccessor(() => SquareButtonBinding, (v) => SquareButtonBinding = v)
                },
                {
                    JvsButtons.JVS_CROSS.ToString(), new ControlBindingAccessor(() => CrossButtonBinding, (v) => CrossButtonBinding = v)
                },
                {
                    JvsButtons.JVS_CIRCLE.ToString(), new ControlBindingAccessor(() => CircleButtonBinding, (v) => CircleButtonBinding = v)
                },

                {
                    "LEFT_SIDE_SLIDE_LEFT", new ControlBindingAccessor(() => LeftSideSlideLeftBinding, (v) => LeftSideSlideLeftBinding = v)
                },
                {
                    "LEFT_SIDE_SLIDE_RIGHT", new ControlBindingAccessor(() => LeftSideSlideRightBinding, (v) => LeftSideSlideRightBinding = v)
                },
                {
                    "RIGHT_SIDE_SLIDE_LEFT", new ControlBindingAccessor(() => RightSideSlideLeftBinding, (v) => RightSideSlideLeftBinding = v)
                },
                {
                    "RIGHT_SIDE_SLIDE_RIGHT", new ControlBindingAccessor(() => RightSideSlideRightBinding, (v) => RightSideSlideRightBinding = v)
                },
                {
                    "GAME_MODE_ADVERTISE", new ControlBindingAccessor(() => ToggleGsAdvertise, (v) => ToggleGsAdvertise = v)
                },
                {
                    "GAME_MODE_GAMEPLAY", new ControlBindingAccessor(() => ToggleGsGameplay, (v) => ToggleGsGameplay = v)
                },
                {
                    "GAME_MODE_DATA_TEST", new ControlBindingAccessor(() => ToggleGsDataTest, (v) => ToggleGsDataTest = v)
                },
                {
                    "GAME_MODE_APP_ERROR", new ControlBindingAccessor(() => ToggleGsAppError, (v) => ToggleGsAppError = v)
                },
                {
                    "TOGGLE_CAMERA_CONTROL", new ControlBindingAccessor(() => ToggleCameraControl, (v) => ToggleCameraControl = v)
                },
                {
                    "FAST_CAMERA_SPEED", new ControlBindingAccessor(() => FastCameraSpeedBinding, (v) => FastCameraSpeedBinding = v)
                },
                {
                    "MOVE_CAMERA_FORWARD", new ControlBindingAccessor(() => MoveCameraForwardBinding, (v) => MoveCameraForwardBinding = v)
                },
                {
                    "MOVE_CAMERA_BACKWARD", new ControlBindingAccessor(() => MoveCameraBackwardBinding, (v) => MoveCameraBackwardBinding = v)
                },
                {
                    "MOVE_CAMERA_LEFT", new ControlBindingAccessor(() => MoveCameraLeftBinding, (v) => MoveCameraLeftBinding = v)
                },
                {
                    "MOVE_CAMERA_RIGHT", new ControlBindingAccessor(() => MoveCameraRightBinding, (v) => MoveCameraRightBinding = v)
                },
                {
                    "MOVE_CAMERA_UP", new ControlBindingAccessor(() => MoveCameraUpBinding, (v) => MoveCameraUpBinding = v)
                },
                {
                    "MOVE_CAMERA_DOWN", new ControlBindingAccessor(() => MoveCameraDownBinding, (v) => MoveCameraDownBinding = v)
                },
                {
                    "INCREASE_CAMERA_FOV", new ControlBindingAccessor(() => IncreaseCameraFovBinding, (v) => IncreaseCameraFovBinding = v)
                },
                {
                    "DECREASE_CAMERA_FOV", new ControlBindingAccessor(() => DecreaseCameraFovBinding, (v) => DecreaseCameraFovBinding = v)
                },
                {
                    "RESET_CAMERA_FOV", new ControlBindingAccessor(() => ResetCameraFovBinding, (v) => ResetCameraFovBinding = v)
                },
            });
        }
        private ControlBinding GetThisControlBinding()
        {
            var controlName        = ControlBindings[CpdInputControl].ControlName;
            var thisControlBinding = new ControlBinding {
                CpdInputControl = CpdInputControl, ControlName = controlName
            };

            if (rdoJoystick.Checked)
            {
                var device  = (DIPhysicalDeviceInfo)cbJoysticks.SelectedItem;
                var control = (DIPhysicalControlInfo)cboJoystickControl.SelectedItem;
                switch (control.ControlType)
                {
                case ControlType.Axis:
                    thisControlBinding.BindingType = BindingType.DirectInputAxisBinding;
                    break;

                case ControlType.Button:
                    thisControlBinding.BindingType = BindingType.DirectInputButtonBinding;
                    break;

                case ControlType.Pov:
                    thisControlBinding.BindingType = BindingType.DirectInputPovBinding;
                    if (rdoPovUp.Checked)
                    {
                        thisControlBinding.PovDirection = PovDirections.Up;
                    }
                    else if (rdoPovUpLeft.Checked)
                    {
                        thisControlBinding.PovDirection = PovDirections.UpLeft;
                    }
                    else if (rdoPovUpRight.Checked)
                    {
                        thisControlBinding.PovDirection = PovDirections.UpRight;
                    }
                    else if (rdoPovRight.Checked)
                    {
                        thisControlBinding.PovDirection = PovDirections.Right;
                    }
                    else if (rdoPovLeft.Checked)
                    {
                        thisControlBinding.PovDirection = PovDirections.Left;
                    }
                    else if (rdoPovDownLeft.Checked)
                    {
                        thisControlBinding.PovDirection = PovDirections.DownLeft;
                    }
                    else if (rdoPovDownRight.Checked)
                    {
                        thisControlBinding.PovDirection = PovDirections.DownRight;
                    }
                    else if (rdoPovDown.Checked)
                    {
                        thisControlBinding.PovDirection = PovDirections.Down;
                    }
                    break;

                default:
                    break;
                }
                thisControlBinding.DirectInputDevice  = device;
                thisControlBinding.DirectInputControl = control;
            }
            else if (rdoKeystroke.Checked)
            {
                thisControlBinding.BindingType = BindingType.Keybinding;
                thisControlBinding.Keys        = (Keys)Enum.Parse(typeof(Keys), txtKeystroke.Text);
            }
            return(thisControlBinding);
        }
Пример #27
0
    void DrawActionRow(InputAction action, int selectedScheme)
    {
        int actionIndex = m_ActionMapEditCopy.actions.IndexOf(action);

        int sourceCount = 0;

        for (int i = 0; i < m_ActionMapEditCopy.controlSchemes.Count; i++)
        {
            ControlBinding schemeBinding = m_ActionMapEditCopy.controlSchemes[i].bindings[actionIndex];
            int            count         = schemeBinding.sources.Count + schemeBinding.buttonAxisSources.Count;
            sourceCount = Mathf.Max(sourceCount, count);
        }
        int lines = Mathf.Max(1, sourceCount);

        float height    = EditorGUIUtility.singleLineHeight * lines + EditorGUIUtility.standardVerticalSpacing * (lines - 1) + 8;
        Rect  totalRect = GUILayoutUtility.GetRect(1, height);

        Rect baseRect = totalRect;

        baseRect.yMin += 4;
        baseRect.yMax -= 4;

        if (selectedAction == action)
        {
            GUI.DrawTexture(totalRect, EditorGUIUtility.whiteTexture);
        }

        // Show control fields

        Rect rect = baseRect;

        rect.height = EditorGUIUtility.singleLineHeight;
        rect.width  = EditorGUIUtility.labelWidth - 4;

        EditorGUI.LabelField(rect, action.controlData.name);

        // Show binding fields

        ControlBinding binding = m_ActionMapEditCopy.controlSchemes[selectedScheme].bindings[actionIndex];

        if (binding != null)
        {
            rect        = baseRect;
            rect.height = EditorGUIUtility.singleLineHeight;
            rect.xMin  += EditorGUIUtility.labelWidth;

            if (binding.primaryIsButtonAxis)
            {
                DrawButtonAxisSources(ref rect, binding);
                DrawSources(ref rect, binding);
            }
            else
            {
                DrawSources(ref rect, binding);
                DrawButtonAxisSources(ref rect, binding);
            }
        }

        if (Event.current.type == EventType.MouseDown && totalRect.Contains(Event.current.mousePosition))
        {
            EditorGUIUtility.keyboardControl = 0;
            selectedAction = action;
            Event.current.Use();
        }
    }
Пример #28
0
    public override void OnInspectorGUI()
    {
        //DrawDefaultInspector();

        if (_script != _lastScript)
        {
            //The script got changed, clean house.
            UpdateBindings();
            _lastScript = _script;
        }

        //Don't allow changing the target script during runtime
        EditorGUI.BeginDisabledGroup(Application.isPlaying);
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Target Monoscript: ", EditorStyles.boldLabel);
        _script = (MonoScript)EditorGUILayout.ObjectField(_script, typeof(MonoScript), false, null);
        EditorGUILayout.EndHorizontal();
        EditorGUI.EndDisabledGroup();

        //Target component
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Runtime Component: ", EditorStyles.boldLabel);
        //_console.RuntimeScript = (Component)EditorGUILayout.ObjectField(_console.RuntimeScript, _scriptType, true, null);
        Component newcomponent = (Component)EditorGUILayout.ObjectField(_console.RuntimeScript, _scriptType, true, null);

        if (newcomponent != _console.RuntimeScript)
        {
            _console.ChangeRuntimeScript(newcomponent);
        }



        //Display bindings
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Display Properties", EditorStyles.boldLabel);

        for (int i = 0; i < _console.DisplayBindingsList.Count; i++)
        {
            DisplayBinding dbind = _console.DisplayBindingsList[i]; //Shorthand

            EditorGUILayout.BeginHorizontal();

            //Figure out the BaseDisplay type
            Type generic     = typeof(BaseDisplay <>);
            Type constructed = generic.MakeGenericType(new Type[1] {
                _scriptType.GetMethod(dbind.MethodName).ReturnType
            });                                                                           //This gets called most every frame, so would be nice to optimize later.

            EditorGUILayout.LabelField(dbind.MethodName + " <" + dbind.TypeString + ">"); //Adding type in label since the object field won't show it properly due to serialization

            BaseDisplay basedisp = (BaseDisplay)EditorGUILayout.ObjectField(dbind.Display, constructed, true, null);

            EditorGUILayout.EndHorizontal();

            //If the bound object has changed, inject this binding in place of the old one.
            if (dbind.Display != basedisp)
            {
                DisplayBinding replacebind = new DisplayBinding
                {
                    MethodName = dbind.MethodName,
                    Display    = basedisp,
                    TypeString = dbind.TypeString
                };
                _console.DisplayBindingsList[i] = replacebind;
                Debug.Log("Replaced");
            }
        }

        //Control bindings
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Control Properties/Methods", EditorStyles.boldLabel);

        for (int i = 0; i < _console.ControlBindingsList.Count; i++)
        {
            ControlBinding cbind = _console.ControlBindingsList[i]; //Shorthand
            EditorGUILayout.BeginHorizontal();

            //Figure out the BaseControl type
            Type            generic    = typeof(BaseControl <>);
            ParameterInfo[] paramsinfo = _scriptType.GetMethod(cbind.MethodName).GetParameters();
            Type            newtype    = (paramsinfo.Length > 0) ? paramsinfo[0].ParameterType : typeof(void);

            Type constructed = generic.MakeGenericType(new Type[1] {
                newtype
            });                                                                            //This gets called most every frame, so would be nice to optimize later. //WRONG fix later

            EditorGUILayout.LabelField(cbind.MethodName + " <" + cbind.ParamString + ">"); //Adding type in label since the object field won't show it properly due to serialization

            BaseControl basecont = (BaseControl)EditorGUILayout.ObjectField(cbind.Control, constructed, true, null);

            EditorGUILayout.EndHorizontal();

            //If the bound object has changed inject this binding in place of old one.
            if (cbind.Control != basecont)
            {
                ControlBinding replacebind = new ControlBinding
                {
                    MethodName  = cbind.MethodName,
                    Control     = basecont,
                    ParamString = cbind.ParamString
                };
                _console.ControlBindingsList[i] = replacebind;
                Debug.Log("Replaced");
            }
        }
    }
Пример #29
0
    private void UpdateBindings()
    {
        List <MethodInfo> dispmethods = new List <MethodInfo>();
        List <MethodInfo> contmethods = new List <MethodInfo>();

        //We'll make custom bindings for each - except if the current bindings list already has a binding that matches the name and type.
        List <DisplayBinding> finaldispbinds = new List <DisplayBinding>();
        List <ControlBinding> finalcontbinds = new List <ControlBinding>();

        //Stop if we don't have a script
        if (_script != null)
        {
            //Iterate through methods and assign relevant ones to bindings list
            MethodInfo[] methods = _scriptType.GetMethods(BindingFlags.Instance | BindingFlags.Public);
            for (int i = 0; i < methods.Length; i++)
            {
                //Don't do anything if it's part of MonoBehaviour, because the developer didn't add that.
                if (methods[i].DeclaringType.IsAssignableFrom(typeof(MonoBehaviour)))
                {
                    continue;
                }

                //Assign everything into a relevant list, if there is one.
                if (methods[i].ReturnType == typeof(void))
                {
                    //No return type. It can fit a control.
                    contmethods.Add(methods[i]);
                }
                else if (methods[i].GetParameters().Length == 0)
                {
                    //It has a return, but takes no parameters. It's either a getter or a method made to act like one.
                    dispmethods.Add(methods[i]);
                }
            }

            //Now we've got all the methods that need bindings.


            //Display first.
            foreach (MethodInfo info in dispmethods)
            {
                bool foundoldmatch = false;
                //Check existing bindings for both names and return types.
                foreach (DisplayBinding oldbinding in _console.DisplayBindingsList)
                {
                    if (oldbinding.MethodName == info.Name && _scriptType.GetMethod(oldbinding.MethodName).ReturnType == info.ReturnType)
                    {
                        //It's a match. Pass in the old one.
                        finaldispbinds.Add(oldbinding);
                        foundoldmatch = true;
                        break;
                    }
                }

                if (foundoldmatch == false)
                {
                    DisplayBinding newdisp = new DisplayBinding
                    {
                        MethodName = info.Name,
                        TypeString = info.ReturnType.Name
                    };

                    finaldispbinds.Add(newdisp);
                }
            }

            //Now Control.
            foreach (MethodInfo info in contmethods)
            {
                bool            foundoldmatch = false;
                ParameterInfo[] newparams     = info.GetParameters(); // Caching because we'll compare a lot.
                                                                      //Check existing bindings for both names and parameters.
                foreach (ControlBinding oldbinding in _console.ControlBindingsList)
                {
                    //if (oldbinding.MethodName == info.Name && _scriptType.GetMethod(oldbinding.MethodName).GetParameters() == newparams)
                    if (oldbinding.MethodName == info.Name)
                    {
                        //The names match. Make sure the parameter types match.
                        ParameterInfo[] oldparams = _scriptType.GetMethod(oldbinding.MethodName).GetParameters();

                        if (newparams.Length != oldparams.Length)
                        {
                            continue;
                        }

                        bool foundbadparam = false;
                        for (int i = 0; i < newparams.Length; i++)
                        {
                            if (newparams[i].ParameterType != oldparams[i].ParameterType)
                            {
                                foundbadparam = true;
                            }
                        }
                        if (foundbadparam)
                        {
                            continue;
                        }


                        //It's a match. Pass in the old one.
                        finalcontbinds.Add(oldbinding);
                        foundoldmatch = true;
                        break;
                    }
                }

                if (foundoldmatch == false)
                {
                    //Make a string that lists the parameters for easy display
                    string paramstring = "";
                    for (int i = 0; i < newparams.Length; i++)
                    {
                        paramstring += newparams[i].ParameterType.Name;
                        if (i < newparams.Length - 1)
                        {
                            paramstring += ", ";
                        }
                    }
                    ControlBinding newcont = new ControlBinding
                    {
                        MethodName  = info.Name,
                        ParamString = paramstring
                    };

                    finalcontbinds.Add(newcont);
                }
            }
        }
        //Replace the console's list with ours.
        _console.DisplayBindingsList = finaldispbinds;
        _console.ControlBindingsList = finalcontbinds;
    }
Пример #30
0
		Control AttachToParentCheckBox()
		{
			var control = new CheckBox { Text = "Attach to Parent Window" };
			var binding = new ControlBinding<MessageBoxSection, bool?>(this, r => r.AttachToParent, (r, val) => r.AttachToParent = val ?? false);
			control.CheckedBinding.Bind(binding);
			return control;
		}