예제 #1
0
        } // Update

        public void ChageState(System.IComparable newState)
        {
            if (_currentState != null)
            {
                _currentState.OnDeactivate();
            }

            _currentState = GetState(newState);
            if (_currentState == null)
            {
                Debug.LogError("The state " + newState.ToString() + "doesnt exist in the FSM");
                return;
            }

            _currentStateTran = _currentState.GetTransitions();
            _currentState.OnActivate();
        } // ChageState
        public override void InsertKeyAndValue(System.IComparable key, object value)
        {
            int position     = GetPositionOfKey(key);
            int realPosition = 0;

            if (position >= 0)
            {
                throw new NeoDatis.Btree.Exception.DuplicatedKeyException(key.ToString());
            }
            realPosition = -position - 1;
            // If there is an element at this position, then right shift, size
            // safety is guaranteed by the rightShiftFrom method
            if (realPosition < nbKeys)
            {
                RightShiftFrom(realPosition, true);
            }
            keys[realPosition]   = key;
            values[realPosition] = value;
            nbKeys++;
        }
예제 #3
0
        private static void CreateNumberControl(DisplayNameAttribute control, PropertyInfo prop, Vector2 anchorPosition)
        {
            UIRangeAttribute rangeAttr     = prop.GetCustomAttribute <UIRangeAttribute>();
            bool             sliderControl = rangeAttr != null && rangeAttr.Slider;

            RectTransform element = Object.Instantiate(sliderControl ? sliderTemplate : inputTemplate, multiplayerContent, false);

            SetupUIElement(element, control, prop, anchorPosition);

            bool isFloatingPoint = prop.PropertyType == typeof(float) || prop.PropertyType == typeof(double);

            if (sliderControl)
            {
                Slider slider = element.GetComponentInChildren <Slider>();
                slider.minValue     = rangeAttr.Min;
                slider.maxValue     = rangeAttr.Max;
                slider.wholeNumbers = !isFloatingPoint;
                Text sliderThumbText = slider.GetComponentInChildren <Text>();
                slider.onValueChanged.RemoveAllListeners();
                slider.onValueChanged.AddListener((value) =>
                {
                    prop.SetValue(tempMultiplayerOptions, value, null);
                    sliderThumbText.text = value.ToString("0");
                });

                tempToUICallbacks[prop.Name] = () =>
                {
                    slider.value         = (float)prop.GetValue(tempMultiplayerOptions, null);
                    sliderThumbText.text = slider.value.ToString("0");
                };
            }
            else
            {
                InputField input = element.GetComponentInChildren <InputField>();

                input.onValueChanged.RemoveAllListeners();
                input.onValueChanged.AddListener((str) => {
                    try
                    {
                        var converter            = TypeDescriptor.GetConverter(prop.PropertyType);
                        System.IComparable value = (System.IComparable)converter.ConvertFromString(str);

                        if (rangeAttr != null)
                        {
                            System.IComparable min = (System.IComparable)System.Convert.ChangeType(rangeAttr.Min, prop.PropertyType);
                            System.IComparable max = (System.IComparable)System.Convert.ChangeType(rangeAttr.Max, prop.PropertyType);
                            if (value.CompareTo(min) < 0)
                            {
                                value = min;
                            }
                            if (value.CompareTo(max) > 0)
                            {
                                value = max;
                            }
                            input.text = value.ToString();
                        }

                        prop.SetValue(tempMultiplayerOptions, value, null);
                    }
                    catch
                    {
                        // If the char is not a number, rollback to previous value
                        input.text = prop.GetValue(tempMultiplayerOptions, null).ToString();
                    }
                });

                tempToUICallbacks[prop.Name] = () =>
                {
                    input.text = prop.GetValue(tempMultiplayerOptions, null).ToString();
                };
            }
        }
예제 #4
0
 public override string ToString()
 {
     return(key.ToString());
 }