Esempio n. 1
0
        public UISliderControl CreateSlider(GameObject prefab, Sprite icon, float minValue, float maxValue, System.Action <int, float> valueChangedCallback, System.Action <int> cancelCallback)
        {
            GameObject      instance = (GameObject)Object.Instantiate(prefab);
            UISliderControl control  = instance.GetComponent <UISliderControl>();

            if (control == null)
            {
                Object.Destroy(instance);
                Debug.LogError("Prefab missing UISliderControl component!");
                return(null);
            }

            instance.transform.SetParent(this.transform, false);
            if (control.iconImage != null)
            {
                control.iconImage.sprite = icon;
            }
            if (control.slider != null)
            {
                control.slider.minValue = minValue;
                control.slider.maxValue = maxValue;
                if (valueChangedCallback != null)
                {
                    control.slider.onValueChanged.AddListener((float value) => { valueChangedCallback(control.id, value); });
                }
                if (cancelCallback != null)
                {
                    control.SetCancelCallback(() => { cancelCallback(control.id); });
                }
            }
            controls.Add(control.id, control);
            return(control);
        }
Esempio n. 2
0
        public UISliderControl CreateSlider(GameObject prefab, Sprite icon, float minValue, float maxValue, Action <int, float> valueChangedCallback, Action <int> cancelCallback)
        {
            GameObject      gameObject = UnityEngine.Object.Instantiate <GameObject>(prefab);
            UISliderControl control    = gameObject.GetComponent <UISliderControl>();

            if (control == null)
            {
                UnityEngine.Object.Destroy(gameObject);
                Debug.LogError("Prefab missing UISliderControl component!");
                return(null);
            }
            gameObject.transform.SetParent(base.transform, false);
            if (control.iconImage != null)
            {
                control.iconImage.sprite = icon;
            }
            if (control.slider != null)
            {
                control.slider.minValue = minValue;
                control.slider.maxValue = maxValue;
                if (valueChangedCallback != null)
                {
                    control.slider.onValueChanged.AddListener(delegate(float value)
                    {
                        valueChangedCallback(control.id, value);
                    });
                }
                if (cancelCallback != null)
                {
                    control.SetCancelCallback(delegate
                    {
                        cancelCallback(control.id);
                    });
                }
            }
            this.controls.Add(control.id, control);
            return(control);
        }