static public int constructor(IntPtr l) {
		try {
			UnityEngine.UI.ColorBlock o;
			o=new UnityEngine.UI.ColorBlock();
			pushValue(l,true);
			pushValue(l,o);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
Beispiel #2
0
    public void SetupRom(Color color, string consoleKey, string romPath)
    {
        label.color = Color.white;
        //Get the accent color for the console
        Color accentColor   = HubManager.consoleData[consoleKey].accentColor;
        Color darkenedColor = new Color(accentColor.r, accentColor.g, accentColor.b, 0.5f);
        //Create a new color block for the button
        var colorBlock = new UnityEngine.UI.ColorBlock();

        colorBlock.normalColor      = darkenedColor;
        colorBlock.highlightedColor = accentColor;
        colorBlock.selectedColor    = accentColor;
        colorBlock.pressedColor     = darkenedColor;
        colorBlock.disabledColor    = darkenedColor;
        colorBlock.fadeDuration     = 0.1f;
        colorBlock.colorMultiplier  = 1;
        //Set the colors from the color block
        viewButton.colors = colorBlock;

        viewButton.onClick.AddListener(() =>
        {
            if (!UIController.instance.inputEnabled)
            {
                return;
            }
            HubManager.consoleData[consoleKey].LoadROM(romPath);
        });
    }
 static public int constructor(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.UI.ColorBlock o;
         o = new UnityEngine.UI.ColorBlock();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
    static int Equals(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.UI.ColorBlock), typeof(UnityEngine.UI.ColorBlock)))
            {
                UnityEngine.UI.ColorBlock obj  = (UnityEngine.UI.ColorBlock)ToLua.ToObject(L, 1);
                UnityEngine.UI.ColorBlock arg0 = (UnityEngine.UI.ColorBlock)ToLua.ToObject(L, 2);
                bool o = obj.Equals(arg0);
                LuaDLL.lua_pushboolean(L, o);
                ToLua.SetBack(L, 1, obj);
                return(1);
            }
            else if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(UnityEngine.UI.ColorBlock), typeof(object)))
            {
                UnityEngine.UI.ColorBlock obj = (UnityEngine.UI.ColorBlock)ToLua.ToObject(L, 1);
                object arg0 = ToLua.ToVarObject(L, 2);
                bool   o    = obj.Equals(arg0);
                LuaDLL.lua_pushboolean(L, o);
                ToLua.SetBack(L, 1, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.UI.ColorBlock.Equals"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Beispiel #5
0
    // Start is called before the first frame update
    void Start()
    {
        List <int> divisors = new List <int>();

        for (int i = 1; i < 11; i++)
        {
            if (SpriteManager.SPRITE_SIZE % i == 0)
            {
                divisors.Add(i);
            }
        }

        for (int i = 0; i < divisors.Count; i++)
        {
            int                       divisor         = divisors[i];
            GameObject                buttonObject    = new GameObject("Resize Button " + divisor.ToString());
            UnityEngine.UI.Button     buttonComponent = buttonObject.AddComponent <UnityEngine.UI.Button>();
            UnityEngine.UI.ColorBlock colorBlock      = buttonComponent.colors;
            colorBlock.highlightedColor = Color.grey;
            RectTransform rectTransform = buttonObject.AddComponent <RectTransform>();
            buttonObject.transform.SetParent(gameObject.transform);
            buttonObject.AddComponent <PixelSizeButton>().Initiate(divisor);
            TMPro.TextMeshProUGUI text = buttonObject.AddComponent <TMPro.TextMeshProUGUI>();
            text.color = Color.black;
            text.text  = divisor.ToString();
            rectTransform.anchorMin = new Vector2((float)i / divisors.Count, 0);
            rectTransform.anchorMax = new Vector2((float)(i + 1) / divisors.Count, 1);
            rectTransform.offsetMin = Vector2.zero;
            rectTransform.offsetMax = Vector2.zero;
            text.alignment          = TMPro.TextAlignmentOptions.Center;
        }
    }
Beispiel #6
0
 private void AddSceneColor(UnityEngine.UI.Selectable selectable)
 {
     UnityEngine.UI.ColorBlock colorBlock = selectable.colors;
     AddSceneColor(colorBlock.normalColor);
     // Uncomment if you want to include additional colorBlock colors
     //AddSceneColor(colorBlock.highlightedColor);
     //AddSceneColor(colorBlock.pressedColor);
     //AddSceneColor(colorBlock.disabledColor);
 }
 static public int set_disabledColor(IntPtr l)
 {
     UnityEngine.UI.ColorBlock o = (UnityEngine.UI.ColorBlock)checkSelf(l);
     UnityEngine.Color         v;
     checkType(l, 2, out v);
     o.disabledColor = v;
     setBack(l, o);
     return(0);
 }
    static public int set_colorMultiplier(IntPtr l)
    {
        UnityEngine.UI.ColorBlock o = (UnityEngine.UI.ColorBlock)checkSelf(l);
        float v;

        checkType(l, 2, out v);
        o.colorMultiplier = v;
        setBack(l, o);
        return(0);
    }
Beispiel #9
0
 public IEnumerator EnableIndicator()
 {
     for (float f = button.colors.disabledColor.r; f <= 1.0f; f += 0.2f)
     {
         UnityEngine.UI.ColorBlock buttonColors = button.colors;
         buttonColors.disabledColor = new Color(f, f, f, 1.0f);
         button.colors = buttonColors;
         yield return(null);
     }
 }
 void DoSetButtonColor()
 {
     if (_Button != null && enabled.Value)
     {
         // Do the actual action stuff here.
         uUI.ColorBlock _colorBlock = _Button.colors;
         _colorBlock.normalColor = normalColor.Value;
         _Button.colors          = _colorBlock;
     }
 }
    static public int set_fadeDuration(IntPtr l)
    {
        UnityEngine.UI.ColorBlock o = (UnityEngine.UI.ColorBlock)checkSelf(l);
        float v;

        checkType(l, 2, out v);
        o.fadeDuration = v;
        setBack(l, o);
        return(0);
    }
    void Awake()
    {
        // ステージの状態を管理する PlayerPrefs のキーを作成します。
        // 接頭辞にステージのシーン名を足した文字列がキーになります。
        string keyStageStatus = prefixKeyStageStatus + nameStage;

        // ボタンのコンポーネントを取得します。
        UnityEngine.UI.Button coButton = GetComponent <UnityEngine.UI.Button>();

        // ステージの状態の記録がない場合は新規で設定します。
        // インストール直後のゲームの起動の際に行われます。
        if (PlayerPrefs.HasKey(keyStageStatus) == false)
        {
            // 最初のステージだけを「選択可能」にして、他は「選択不可」にします。
            if (flgFirstStage == true)
            {
                PlayerPrefs.SetInt(keyStageStatus, (int)StageStatus.Unlocked);
            }
            else
            {
                PlayerPrefs.SetInt(keyStageStatus, (int)StageStatus.Locked);
            }
        }

        // ステージの状態を取得します
        int stageStatus = PlayerPrefs.GetInt(keyStageStatus);

        // ステージの状態がクリア済みの場合
        if (stageStatus == (int)StageStatus.Cleared)
        {
            // すでにクリアしている場合は色をクリア済みのものに変えます
            UnityEngine.UI.ColorBlock colorBlock = coButton.colors;
            colorBlock.normalColor      = colorOnClear;
            colorBlock.highlightedColor = colorOnClear;
            coButton.colors             = colorBlock;
        }

        // ステージの状態が選択不可の場合
        if (stageStatus == (int)StageStatus.Locked)
        {
            // ロック解除されていない
            if (flgFirstStage == true)
            {
                // ただし、最初のステージのボタンは、強制的にロックを解除する
            }
            else
            {
                // ボタンコンポーネントを押せないように無効にする
                coButton.enabled = false;
                // ロック状態を表す画像のオブジェクトを有効にする
                imageLocked.SetActive(true);
            }
        }
    }
Beispiel #13
0
        private ColorBlock CreateColorBlock(Color normal)
        {
            ColorBlock colors = new ColorBlock();

            colors.normalColor = normal;
            colors.highlightedColor = new Color(1f, 1f, 1f, 1f);
            colors.pressedColor = new Color(200f / 255f, 200f / 255f, 200f / 255f, 255f / 255f);
            colors.disabledColor = new Color(200f / 255f, 200f / 255f, 200f / 255f, 128f / 255f);
            colors.colorMultiplier = 1f;
            colors.fadeDuration = 0.1f;
            return colors;
        }
 void DoSetOldColorValue()
 {
     if (_Button != null && enabled.Value)           // JFF: enabled should be consistent, if enabled is false, it should not do anything at all.
     {
         // reset
         uUI.ColorBlock _colorBlock = _Button.colors;
         _colorBlock.normalColor = _OriginalNormalColor;
         _Button.colors          = _colorBlock;
         // if you reset using the whole Colorblock taken from the start, other actions that may change other properties of the same ColorBlock will be corrupted.
         // that's why I take the latest ColorBlock at the time I need to change the normal Color, and straight away reassign it. nothing else will be affected. Same in DoSetButtonColor()
     }
 }
Beispiel #15
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.UI.ColorBlock o;
         o = new UnityEngine.UI.ColorBlock();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #16
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.UI.ColorBlock o;
         o = new UnityEngine.UI.ColorBlock();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.UI.ColorBlock o;
         o=new UnityEngine.UI.ColorBlock();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
Beispiel #18
0
        void ApplyStyle(Button graphic)
        {
            if (ButtonData != null)
            {
                var colorBlock = new ColorBlock();
                colorBlock.normalColor = ButtonData.Normal.Color;
                colorBlock.highlightedColor = ButtonData.Highlighted.Color;
                colorBlock.pressedColor = ButtonData.Pressed.Color;
                colorBlock.disabledColor = ButtonData.Disabled;
                colorBlock.colorMultiplier = ButtonData.ColorMultiplier;

                graphic.colors = colorBlock;
            }
        }
Beispiel #19
0
    static int QPYX_get_colors_YXQP(IntPtr L_YXQP)
    {
        object QPYX_o_YXQP = null;

        try
        {
            QPYX_o_YXQP = ToLua.ToObject(L_YXQP, 1);                        UnityEngine.UI.Selectable QPYX_obj_YXQP = (UnityEngine.UI.Selectable)QPYX_o_YXQP;
            UnityEngine.UI.ColorBlock QPYX_ret_YXQP = QPYX_obj_YXQP.colors;
            ToLua.PushValue(L_YXQP, QPYX_ret_YXQP);
            return(1);
        }
        catch (Exception QPYX_e_YXQP)            {
            return(LuaDLL.toluaL_exception(L_YXQP, QPYX_e_YXQP, QPYX_o_YXQP, "attempt to index colors on a nil value"));
        }
    }
 public void ApplyStyleToButton(Button button)
 {
     var colorBlock = new ColorBlock();
     colorBlock.highlightedColor = Style.ButtonHighlightedColor;
     colorBlock.pressedColor = Style.ButtonPressedColor;
     colorBlock.disabledColor = Style.ButtonDisabledColor;
     colorBlock.normalColor = Style.ButtonNormalColor;
     colorBlock.colorMultiplier = Style.ButtonColorMultiplier;
     colorBlock.fadeDuration = 0.1f;
     var buttonImage = button.gameObject.GetComponent<Image>();
     buttonImage.color = Style.ButtonImage.color;
     buttonImage.sprite = Style.ButtonImage.sprite;
     buttonImage.material = Style.ButtonImage.material;
     button.colors = colorBlock;
 }
 static int GetHashCode(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         UnityEngine.UI.ColorBlock obj = (UnityEngine.UI.ColorBlock)ToLua.CheckObject(L, 1, typeof(UnityEngine.UI.ColorBlock));
         int o = obj.GetHashCode();
         LuaDLL.lua_pushinteger(L, o);
         ToLua.SetBack(L, 1, obj);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #22
0
    static int QPYX_set_colors_YXQP(IntPtr L_YXQP)
    {
        object QPYX_o_YXQP = null;

        try
        {
            QPYX_o_YXQP = ToLua.ToObject(L_YXQP, 1);                        UnityEngine.UI.Selectable QPYX_obj_YXQP = (UnityEngine.UI.Selectable)QPYX_o_YXQP;
            UnityEngine.UI.ColorBlock QPYX_arg0_YXQP = StackTraits <UnityEngine.UI.ColorBlock> .Check(L_YXQP, 2);

            QPYX_obj_YXQP.colors = QPYX_arg0_YXQP;
            return(0);
        }
        catch (Exception QPYX_e_YXQP)            {
            return(LuaDLL.toluaL_exception(L_YXQP, QPYX_e_YXQP, QPYX_o_YXQP, "attempt to index colors on a nil value"));
        }
    }
 static int op_Equality(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         UnityEngine.UI.ColorBlock arg0 = (UnityEngine.UI.ColorBlock)ToLua.ToObject(L, 1);
         UnityEngine.UI.ColorBlock arg1 = (UnityEngine.UI.ColorBlock)ToLua.ToObject(L, 2);
         bool o = arg0 == arg1;
         LuaDLL.lua_pushboolean(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #24
0
    static int set_colors(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.UI.Selectable obj  = (UnityEngine.UI.Selectable)o;
            UnityEngine.UI.ColorBlock arg0 = (UnityEngine.UI.ColorBlock)ToLua.CheckObject(L, 2, typeof(UnityEngine.UI.ColorBlock));
            obj.colors = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index colors on a nil value" : e.Message));
        }
    }
Beispiel #25
0
    static int get_colors(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.UI.Selectable obj = (UnityEngine.UI.Selectable)o;
            UnityEngine.UI.ColorBlock ret = obj.colors;
            ToLua.PushValue(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index colors on a nil value" : e.Message));
        }
    }
    static int get_fadeDuration(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.UI.ColorBlock obj = (UnityEngine.UI.ColorBlock)o;
            float ret = obj.fadeDuration;
            LuaDLL.lua_pushnumber(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index fadeDuration on a nil value" : e.Message));
        }
    }
    static int get_disabledColor(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.UI.ColorBlock obj = (UnityEngine.UI.ColorBlock)o;
            UnityEngine.Color         ret = obj.disabledColor;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index disabledColor on a nil value" : e.Message));
        }
    }
    public bindingViewChild()
    {
        var colorBlock = new UnityEngine.UI.ColorBlock();

        colorBlock.disabledColor    = Color.gray;
        colorBlock.normalColor      = Color.white;
        colorBlock.highlightedColor = Color.red;
        colorBlock.pressedColor     = Color.yellow;
        colorBlock.colorMultiplier  = 1;
        color = colorBlock;
        value = new string[] {
            "a",
            "b",
            "c"
        };
        ButtonClicked = OnButtonClicked;
    }
Beispiel #29
0
    static int set_colors(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.UI.Selectable obj  = (UnityEngine.UI.Selectable)o;
            UnityEngine.UI.ColorBlock arg0 = StackTraits <UnityEngine.UI.ColorBlock> .Check(L, 2);

            obj.colors = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index colors on a nil value"));
        }
    }
    static int set_fadeDuration(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.UI.ColorBlock obj = (UnityEngine.UI.ColorBlock)o;
            float arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
            obj.fadeDuration = arg0;
            ToLua.SetBack(L, 1, obj);
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index fadeDuration on a nil value" : e.Message));
        }
    }
    public void achieved(UnityEngine.UI.Button input)
    {
        UnityEngine.UI.Button     button     = input.GetComponent("Button") as UnityEngine.UI.Button;
        UnityEngine.UI.ColorBlock colorblock = new UnityEngine.UI.ColorBlock();
        colorblock.normalColor      = new Color(255f, 215f, 0f, 1.0f);
        colorblock.pressedColor     = new Color(255f, 215f, 0f, 1.0f);
        colorblock.disabledColor    = new Color(255f, 215f, 0f, 1.0f);
        colorblock.highlightedColor = new Color(255f, 215f, 0f, 1.0f);
        colorblock.colorMultiplier  = 1f;
        button.colors = colorblock;
        UnityEngine.UI.Image image = input.GetComponent("Image") as UnityEngine.UI.Image;
        image.color = new Color(255f, 215f, 0f, 1.0f);

        UnityEngine.UI.Text text = input.GetComponentInChildren <UnityEngine.UI.Text> ();
        text.color = new Color(0f, 0f, 0f, 1f);

        GetComponent <AudioSource>().Play();
    }
    static int set_disabledColor(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.UI.ColorBlock obj  = (UnityEngine.UI.ColorBlock)o;
            UnityEngine.Color         arg0 = ToLua.ToColor(L, 2);
            obj.disabledColor = arg0;
            ToLua.SetBack(L, 1, obj);
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index disabledColor on a nil value" : e.Message));
        }
    }
    public void Initialize(string displayName, string levelName, bool isUnlocked, bool isCompleted, MainMenuHelper mainMenuHelper)
    {
        levelToLoad = levelName;

        if (displayText != null)
        {
            if (isUnlocked || Debug.isDebugBuild)
            {
                displayText.text    = displayName;
                displayText.enabled = true;
                if (lockIcon != null)
                {
                    lockIcon.enabled = false;
                }
            }
            else
            {
                displayText.enabled = false;
                if (lockIcon != null)
                {
                    lockIcon.enabled = true;
                }
            }
        }

        if (buttonToUse != null)
        {
            buttonToUse.interactable = Debug.isDebugBuild || isUnlocked;

            savedColorBlock = buttonToUse.colors;
            savedColorBlock.disabledColor = lockedColor;
            buttonToUse.colors            = savedColorBlock;

            if (buttonToUse.image != null)
            {
                buttonToUse.image.color = isCompleted ? alreadyCompletedColor : unlockedColor;
            }
        }

        if (mainMenuHelper != null && buttonToUse != null)
        {
            buttonToUse.onClick.AddListener(() => mainMenuHelper.PlayRandomButtonSound(true));
        }
    }
Beispiel #34
0
        /// <summary>
        /// 设置颜色切换规则
        /// </summary>
        /// <param name="image"></param>
        /// <param name="button"></param>
        private void SetColorSwipe(Data.ImgNode image, UnityEngine.UI.Button button)
        {
            Color color = image.color;

            if (MatchAddress(image.Name, normalAddress))
            {
                if (image.type == ImgType.Label)
                {
                    (button.targetGraphic as UnityEngine.UI.Text).text = image.text;
                }

                RectTransform rectTransform = button.GetComponent <RectTransform>();
                rectTransform.sizeDelta        = new Vector2(image.rect.width, image.rect.height);
                rectTransform.anchoredPosition = new Vector2(image.rect.x, image.rect.y);

                button.targetGraphic.color = color;
                button.transition          = UnityEngine.UI.Selectable.Transition.ColorTint;
                UnityEngine.UI.ColorBlock state = button.colors;
                state.normalColor = color;
                button.colors     = state;
            }
            else if (MatchAddress(image.Name, pressedAddress))
            {
                button.transition = UnityEngine.UI.Selectable.Transition.ColorTint;
                UnityEngine.UI.ColorBlock state = button.colors;
                state.pressedColor = color;
                button.colors      = state;
            }
            else if (MatchAddress(image.Name, disableAddress))
            {
                button.transition = UnityEngine.UI.Selectable.Transition.ColorTint;
                UnityEngine.UI.ColorBlock state = button.colors;
                state.disabledColor = color;
                button.colors       = state;
            }
            else if (MatchAddress(image.Name, highlightedAddress))
            {
                button.transition = UnityEngine.UI.Selectable.Transition.ColorTint;
                UnityEngine.UI.ColorBlock state = button.colors;
                state.highlightedColor = color;
                button.colors          = state;
            }
        }
    public bindingViewChild()
    {
        var colorBlock = new UnityEngine.UI.ColorBlock();

        colorBlock.disabledColor    = Color.gray;
        colorBlock.normalColor      = Color.white;
        colorBlock.highlightedColor = Color.red;
        colorBlock.pressedColor     = Color.yellow;
        colorBlock.colorMultiplier  = 1;
        color = colorBlock;
        value = new string[] {
            "a",
            "b",
            "c"
        };
        inputfield    = "输入框内容";
        ButtonClicked = OnButtonClicked;
        GetBindableProperty <string>(keyword_inputfield).RegistValueChanged(OnInputFieldChanged);
    }
Beispiel #36
0
	// Use this for initialization
	void Start () {
		original = leftButton.colors;
	}
Beispiel #37
0
        public void CreateControl()
        {
            rectTransform = GetComponent<RectTransform>();

            var buttonGO = new GameObject("Button");
            buttonGO.transform.SetParent(transform, false);
            buttonRectTransform = buttonGO.AddComponent<RectTransform>();
            buttonRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, rectTransform.sizeDelta.x);
            buttonRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, rectTransform.sizeDelta.y);
            buttonRectTransform.anchoredPosition = Vector2.zero;

            var comboButtonGO = new GameObject("ComboButton");
            comboButtonGO.transform.SetParent(buttonRectTransform, false);
            comboButtonRectTransform = comboButtonGO.AddComponent<RectTransform>();
            comboButtonRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, buttonRectTransform.sizeDelta.x);
            comboButtonRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, buttonRectTransform.sizeDelta.y);
            comboButtonRectTransform.anchoredPosition = Vector2.zero;

            var comboButtonImage = comboButtonGO.AddComponent<Image>();
            comboButtonImage.sprite = Sprite_UISprite;
            comboButtonImage.type = Image.Type.Sliced;
            var comboButtonButton = comboButtonGO.AddComponent<Button>();
            comboButtonButton.targetGraphic = comboButtonImage;
            var comboButtonColors = new ColorBlock();
            comboButtonColors.normalColor = new Color32(255, 255, 255, 255);
            comboButtonColors.highlightedColor = new Color32(245, 245, 245, 255);
            comboButtonColors.pressedColor = new Color32(200, 200, 200, 255);
            comboButtonColors.disabledColor = new Color32(200, 200, 200, 128);
            comboButtonColors.colorMultiplier = 1.0f;
            comboButtonColors.fadeDuration = 0.1f;
            comboButtonButton.colors = comboButtonColors;

            var comboArrowGO = new GameObject("Arrow");
            comboArrowGO.transform.SetParent(buttonRectTransform, false);
            var comboArrowText = comboArrowGO.AddComponent<Text>();
            comboArrowText.color = new Color32(0, 0, 0, 255);
            comboArrowText.alignment = TextAnchor.MiddleCenter;
            comboArrowText.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
            comboArrowText.text = "▼";
            comboArrowRectTransform.localScale = new Vector3(1.0f, 0.5f, 1.0f);
            comboArrowRectTransform.pivot = new Vector2(1.0f, 0.5f);
            comboArrowRectTransform.anchorMin = Vector2.right;
            comboArrowRectTransform.anchorMax = Vector2.one;
            comboArrowRectTransform.anchoredPosition = Vector2.zero;
            comboArrowRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, comboButtonRectTransform.sizeDelta.y);
            comboArrowRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, comboButtonRectTransform.sizeDelta.y);
            var comboArrowCanvasGroup = comboArrowGO.AddComponent<CanvasGroup>();
            comboArrowCanvasGroup.interactable = false;
            comboArrowCanvasGroup.blocksRaycasts = false;

            var comboImageGO = new GameObject("Image");
            comboImageGO.transform.SetParent(comboButtonRectTransform, false);
            var comboImageImage = comboImageGO.AddComponent<Image>();
            comboImageImage.color = new Color32(255, 255, 255, 0);
            comboImageRectTransform.pivot = Vector2.up;
            comboImageRectTransform.anchorMin = Vector2.zero;
            comboImageRectTransform.anchorMax = Vector2.up;
            comboImageRectTransform.anchoredPosition = new Vector2(4.0f, -4.0f);
            comboImageRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, comboButtonRectTransform.sizeDelta.y - 8.0f);
            comboImageRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, comboButtonRectTransform.sizeDelta.y - 8.0f);

            var comboTextGO = new GameObject("Text");
            comboTextGO.transform.SetParent(comboButtonRectTransform, false);
            var comboTextText = comboTextGO.AddComponent<Text>();
            comboTextText.color = new Color32(0, 0, 0, 255);
            comboTextText.alignment = TextAnchor.MiddleLeft;
            comboTextText.lineSpacing = 1.2f;
            comboTextText.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
            comboTextRectTransform.pivot = Vector2.up;
            comboTextRectTransform.anchorMin = Vector2.zero;
            comboTextRectTransform.anchorMax = Vector2.one;
            comboTextRectTransform.anchoredPosition = new Vector2(10.0f, 0.0f);
            comboTextRectTransform.offsetMax = new Vector2(4.0f, 0.0f);
            comboTextRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, comboButtonRectTransform.sizeDelta.y);
        }
Beispiel #38
0
        private void InitControl()
        {
            var cbi = transform.Find("Button/ComboButton/Image");
            var cbt = transform.Find("Button/ComboButton/Text");
            var cba = transform.Find("Button/Arrow");
            if (cbi == null || cbt == null || cba == null)
            {
                foreach (Transform child in transform)
                    Destroy(child);
                CreateControl();
            }

            comboButtonRectTransform.GetComponent<Button>().onClick.AddListener(() => {
                ToggleComboBox(false); });
            var dropdownHeight = comboButtonRectTransform.sizeDelta.y * Mathf.Min(ItemsToDisplay, Items.Length - (HideFirstItem ? 1 : 0));

            overlayGO = new GameObject("CBOverlay");
            overlayGO.SetActive(false);
            var overlayImage = overlayGO.AddComponent<Image>();
            overlayImage.color = new Color32(0, 0, 0, 0);
            overlayGO.transform.SetParent(canvasTransform, false);
            var overlayRectTransform = overlayGO.GetComponent<RectTransform>();
            overlayRectTransform.anchorMin = Vector2.zero;
            overlayRectTransform.anchorMax = Vector2.one;
            overlayRectTransform.offsetMin = Vector2.zero;
            overlayRectTransform.offsetMax = Vector2.zero;
            var overlayButton = overlayGO.AddComponent<Button>();
            overlayButton.targetGraphic = overlayImage;
            overlayButton.onClick.AddListener(() => {
                ToggleComboBox(false); });

            scrollPanelGO = new GameObject("ScrollPanel");
            var scrollPanelImage = scrollPanelGO.AddComponent<Image>();
            scrollPanelImage.sprite = Sprite_UISprite;
            scrollPanelImage.type = Image.Type.Sliced;
            scrollPanelGO.transform.SetParent(overlayGO.transform, false);
            scrollPanelRectTransfrom.pivot = Vector2.zero;
            scrollPanelRectTransfrom.anchorMin = Vector2.zero;
            scrollPanelRectTransfrom.anchorMax = Vector2.one;
            scrollPanelGO.transform.SetParent(transform, false);
            scrollPanelRectTransfrom.anchoredPosition = new Vector2(0.0f, -rectTransform.sizeDelta.y * _itemsToDisplay);

            scrollPanelRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, comboButtonRectTransform.sizeDelta.x);
            scrollPanelRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
            var scrollPanelScrollRect = scrollPanelGO.AddComponent<ScrollRect>();
            scrollPanelScrollRect.horizontal = false;
            scrollPanelScrollRect.elasticity = 0.0f;
            scrollPanelScrollRect.movementType = ScrollRect.MovementType.Clamped;
            scrollPanelScrollRect.inertia = false;
            scrollPanelScrollRect.scrollSensitivity = comboButtonRectTransform.sizeDelta.y;
            scrollPanelGO.AddComponent<Mask>();

            var scrollbarWidth = Items.Length - (HideFirstItem ? 1 : 0) > _itemsToDisplay ? _scrollbarWidth : 0.0f;

            var itemsGO = new GameObject("Items");
            itemsGO.transform.SetParent(scrollPanelGO.transform, false);
            itemsRectTransfrom = itemsGO.AddComponent<RectTransform>();
            itemsRectTransfrom.pivot = Vector2.up;
            itemsRectTransfrom.anchorMin = Vector2.up;
            itemsRectTransfrom.anchorMax = Vector2.one;
            itemsRectTransfrom.anchoredPosition = Vector2.right;
            itemsRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollPanelRectTransfrom.sizeDelta.x - scrollbarWidth);
            var itemsContentSizeFitter = itemsGO.AddComponent<ContentSizeFitter>();
            itemsContentSizeFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
            itemsContentSizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
            var itemsGridLayoutGroup = itemsGO.AddComponent<GridLayoutGroup>();
            itemsGridLayoutGroup.cellSize = new Vector2(comboButtonRectTransform.sizeDelta.x - scrollbarWidth, comboButtonRectTransform.sizeDelta.y);
            itemsGridLayoutGroup.constraint = GridLayoutGroup.Constraint.FixedColumnCount;
            itemsGridLayoutGroup.constraintCount = 1;
            scrollPanelScrollRect.content = itemsRectTransfrom;

            var scrollbarGO = new GameObject("Scrollbar");
            scrollbarGO.transform.SetParent(scrollPanelGO.transform, false);
            var scrollbarImage = scrollbarGO.AddComponent<Image>();
            scrollbarImage.sprite = Sprite_Background;
            scrollbarImage.type = Image.Type.Sliced;
            var scrollbarScrollbar = scrollbarGO.AddComponent<Scrollbar>();
            var scrollbarColors = new ColorBlock();
            scrollbarColors.normalColor = new Color32(128, 128, 128, 128);
            scrollbarColors.highlightedColor = new Color32(128, 128, 128, 178);
            scrollbarColors.pressedColor = new Color32(88, 88, 88, 178);
            scrollbarColors.disabledColor = new Color32(64, 64, 64, 128);
            scrollbarColors.colorMultiplier = 2.0f;
            scrollbarColors.fadeDuration = 0.1f;
            scrollbarScrollbar.colors = scrollbarColors;
            scrollPanelScrollRect.verticalScrollbar = scrollbarScrollbar;
            scrollbarScrollbar.direction = Scrollbar.Direction.BottomToTop;
            scrollbarRectTransfrom.pivot = Vector2.one;
            scrollbarRectTransfrom.anchorMin = Vector2.one;
            scrollbarRectTransfrom.anchorMax = Vector2.one;
            scrollbarRectTransfrom.anchoredPosition = Vector2.zero;
            scrollbarRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
            scrollbarRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);

            var slidingAreaGO = new GameObject("SlidingArea");
            slidingAreaGO.transform.SetParent(scrollbarGO.transform, false);
            slidingAreaRectTransform = slidingAreaGO.AddComponent<RectTransform>();
            slidingAreaRectTransform.anchoredPosition = Vector2.zero;
            slidingAreaRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
            slidingAreaRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - scrollbarRectTransfrom.sizeDelta.x);

            var handleGO = new GameObject("Handle");
            handleGO.transform.SetParent(slidingAreaGO.transform, false);
            var handleImage = handleGO.AddComponent<Image>();
            handleImage.sprite = Sprite_UISprite;
            handleImage.type = Image.Type.Sliced;
            handleImage.color = new Color32(255, 255, 255, 150);
            scrollbarScrollbar.targetGraphic = handleImage;
            scrollbarScrollbar.handleRect = handleRectTransfrom;
            handleRectTransfrom.pivot = new Vector2(0.5f, 0.5f);
            handleRectTransfrom.anchorMin = new Vector2(0.5f, 0.5f);
            handleRectTransfrom.anchorMax = new Vector2(0.5f, 0.5f);
            handleRectTransfrom.anchoredPosition = Vector2.zero;
            handleRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
            handleRectTransfrom.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, scrollbarWidth);

            Interactable = Interactable;

            if (Items.Length < 1)
                return;
            Refresh();
        }
Beispiel #39
0
	// Update is called once per frame
	void Update () {
		this.GetComponent<UnityEngine.UI.Button>().interactable = NetworkManager.GetInstance().goOn;
		if(NetworkManager.GetInstance().goOn)
			this.GetComponent<UnityEngine.UI.Button> ().colors = colors;
	}
Beispiel #40
0
	// Use this for initialization
	void Start () {
		NetworkManager.GetInstance ().goOn = false;
		colors = this.GetComponent<UnityEngine.UI.Button> ().colors ;
	
	}