Example #1
0
        void assignComponents()
        {
            thisRect             = gameObject.GetComponent <RectTransform> ();
            thisImage            = gameObject.GetComponent <Image>();
            listCanvasGroup      = listLayer.GetComponent <CanvasGroup> ();
            scrollbarCanvasGroup = scrollbar.GetComponent <CanvasGroup> ();
            shadowConfig         = gameObject.GetComponent <ShadowConfig>();

            listItemPrefab = Resources.Load("SelectionListItem", typeof(GameObject)) as GameObject;
        }
        public void ExpandList()
        {
            originalPos = thisRect.anchoredPosition.y;

            if (gameObject.GetComponent <ShadowConfig>())
            {
                hasShadows = true;
                if (!shadowConfig)
                {
                    shadowConfig = gameObject.GetComponent <ShadowConfig>();
                }
            }
            else
            {
                hasShadows = false;
            }

            contractedShadowLevel = shadowConfig.shadowNormalSize;

            if (!rippleConfig)
            {
                rippleConfig = gameObject.GetComponent <RippleConfig> ();
            }
            if (!thisButton)
            {
                thisButton = gameObject.GetComponent <Button> ();
            }

            shadowConfig.shadowNormalSize = expandedListShadowLevel;
            shadowConfig.shadowActiveSize = expandedListShadowLevel;

            rippleConfig.enabled    = false;
            thisButton.interactable = false;

            icon.enabled         = false;
            selectedText.enabled = false;

            currentColor = thisImage.color;

            if (autoMaxItemHeight)
            {
                float tempFloat = (Screen.height / 100f * percentageOfScreenHeight / 36f);


                if (tempFloat >= listItems.Length)
                {
                    listheight = (listItems.Length * 36f) + 16f;
                }
                else
                {
                    listheight        = (tempFloat * 36f) - 8f;
                    scrollbarEnabled  = true;
                    scrollbar.enabled = true;
                    scrollbarCanvasGroup.interactable   = true;
                    scrollbarCanvasGroup.blocksRaycasts = true;
                }
            }
            else if (manualMaxItemHeight > 0)
            {
                listheight        = (manualMaxItemHeight * 36f) - 8f;
                scrollbarEnabled  = true;
                scrollbar.enabled = true;
                scrollbarCanvasGroup.interactable   = true;
                scrollbarCanvasGroup.blocksRaycasts = true;
            }
            else
            {
                listheight = (listItems.Length * 36f) + 16f;
            }

            listLayerHeight = (listItems.Length * 36f) + 16f;

            if (expandDirection == PopDirection.Popup)
            {
                expandedPos = originalPos + (listheight / 2f) - 24f;
            }
            else if (expandDirection == PopDirection.Popdown)
            {
                expandedPos = originalPos - (listheight / 2f) + 24f;
            }
            else
            {
                expandedPos = originalPos;
            }

            listLayer.SetActive(true);
            listCanvasGroup.interactable   = true;
            listCanvasGroup.blocksRaycasts = true;
            cancelLayer.enabled            = true;
            icon.enabled         = false;
            selectedText.enabled = true;

            listCanvasAlpha = listCanvasGroup.alpha;

            animStartTime = Time.realtimeSinceStartup;
            state         = 1;
        }
        void Start()
        {
            thisRect = gameObject.GetComponent<RectTransform> ();
            thisImage = gameObject.GetComponent<Image>();
            listCanvasGroup = listLayer.GetComponent<CanvasGroup> ();
            scrollbarCanvasGroup = scrollbar.GetComponent<CanvasGroup> ();
            shadowConfig = gameObject.GetComponent<ShadowConfig>();

            listItemPrefab = Resources.Load ("SelectionListItem", typeof(GameObject)) as GameObject;
            Setup ();
        }
        public void ExpandList()
        {
            originalPos = thisRect.anchoredPosition.y;

            if (gameObject.GetComponent<ShadowConfig>())
            {
                hasShadows = true;
                if (!shadowConfig)
                    shadowConfig = gameObject.GetComponent<ShadowConfig>();
            }
            else
            {
                hasShadows = false;
            }

            contractedShadowLevel = shadowConfig.shadowNormalSize;

            if (!rippleConfig)
                rippleConfig = gameObject.GetComponent<RippleConfig> ();
            if (!thisButton)
                thisButton = gameObject.GetComponent<Button> ();

            shadowConfig.shadowNormalSize = expandedListShadowLevel;
            shadowConfig.shadowActiveSize = expandedListShadowLevel;

            rippleConfig.enabled = false;
            thisButton.interactable = false;

            icon.enabled = false;
            selectedText.enabled = false;

            currentColor = thisImage.color;

            if (autoMaxItemHeight)
            {
                float tempFloat = (Screen.height / 100f * percentageOfScreenHeight / 36f);

                if (tempFloat >= listItems.Length)
                {
                    listheight = (listItems.Length * 36f) + 16f;
                }
                else
                {
                    listheight = (tempFloat * 36f) - 8f;
                    scrollbarEnabled = true;
                    scrollbar.enabled = true;
                    scrollbarCanvasGroup.interactable = true;
                    scrollbarCanvasGroup.blocksRaycasts = true;
                }
            }
            else if (manualMaxItemHeight > 0)
            {

                listheight = (manualMaxItemHeight * 36f) - 8f;
                scrollbarEnabled = true;
                scrollbar.enabled = true;
                scrollbarCanvasGroup.interactable = true;
                scrollbarCanvasGroup.blocksRaycasts = true;
            }
            else
            {
                listheight = (listItems.Length * 36f) + 16f;
            }

            listLayerHeight = (listItems.Length * 36f) + 16f;

            if (expandDirection == PopDirection.Popup)
                expandedPos = originalPos + (listheight / 2f) - 24f;
            else if (expandDirection == PopDirection.Popdown)
                expandedPos = originalPos - (listheight / 2f) + 24f;
            else
                expandedPos = originalPos;

            listLayer.SetActive (true);
            listCanvasGroup.interactable = true;
            listCanvasGroup.blocksRaycasts = true;
            cancelLayer.enabled = true;
            icon.enabled = false;
            selectedText.enabled = true;

            listCanvasAlpha = listCanvasGroup.alpha;

            animStartTime = Time.realtimeSinceStartup;
            state = 1;
        }
Example #5
0
        public void ExpandList()
        {
            expanded    = true;
            originalPos = thisRect.anchoredPosition.y;

            if (gameObject.GetComponent <ShadowConfig>())
            {
                hasShadows = true;
                if (!shadowConfig)
                {
                    shadowConfig = gameObject.GetComponent <ShadowConfig>();
                }
            }
            else
            {
                hasShadows = false;
            }

            if (shadowConfig != null)
            {
                contractedShadowLevel = shadowConfig.shadowNormalSize;
            }


            if (!rippleConfig)
            {
                rippleConfig = gameObject.GetComponent <RippleConfig> ();
            }
            if (!thisButton)
            {
                thisButton = gameObject.GetComponent <Button> ();
            }

            if (shadowConfig != null)
            {
                shadowConfig.shadowNormalSize = expandedListShadowLevel;
                shadowConfig.shadowActiveSize = expandedListShadowLevel;
            }

            if (rippleConfig)
            {
                rippleConfig.enabled = false;
            }
            thisButton.interactable = false;

            icon.enabled         = false;
            selectedText.enabled = false;

            currentColor = thisImage.color;

            if (autoMaxItemHeight)
            {
                //var scale = Screen.dpi/82f;
                var canvasScale = AppScript.getSharedInstance().scaleFactorRefCanvas.scaleFactor;

                /*Debug.LogWarning ("Screen height: "+Screen.height);
                 * Debug.LogWarning ("DPI: "+Screen.dpi);
                 * Debug.LogWarning ("DPI scale: "+scale);
                 * Debug.LogWarning ("Canvas scale: "+canvasScale);
                 * Debug.LogWarning ("Item height: "+itemHeight);*/

                float tempFloat = Screen.height / canvasScale / 100f * percentageOfScreenHeight / itemHeight;
                //Debug.LogWarning ("Temp float: "+tempFloat);

                if (tempFloat >= listItems.Length)
                {
                    listheight = (listItems.Length * itemHeight) + 16f;
                }
                else
                {
                    listheight        = (tempFloat * itemHeight) - 8f;
                    scrollbarEnabled  = true;
                    scrollbar.enabled = true;
                    scrollbarCanvasGroup.interactable   = true;
                    scrollbarCanvasGroup.blocksRaycasts = true;
                }

                //Debug.LogWarning ("List height: "+listheight);
            }
            else if (manualMaxItemHeight > 0)
            {
                listheight        = (manualMaxItemHeight * itemHeight) - 8f;
                scrollbarEnabled  = true;
                scrollbar.enabled = true;
                scrollbarCanvasGroup.interactable   = true;
                scrollbarCanvasGroup.blocksRaycasts = true;
            }
            else
            {
                listheight = (listItems.Length * itemHeight) + 16f;
            }

            listLayerHeight = (listItems.Length * itemHeight) + 16f;

            if (expandDirection == PopDirection.Popup)
            {
                expandedPos = originalPos + (listheight / 2f) - 24f;
            }
            else if (expandDirection == PopDirection.Popdown)
            {
                expandedPos = originalPos - (listheight / 2f) + 24f;
            }
            else
            {
                expandedPos = originalPos;
            }

            listLayer.SetActive(true);
            listCanvasGroup.interactable   = true;
            listCanvasGroup.blocksRaycasts = true;
            cancelLayer.enabled            = true;
            icon.enabled         = false;
            selectedText.enabled = true;

            listCanvasAlpha = listCanvasGroup.alpha;

            animStartTime = Time.realtimeSinceStartup;
            state         = 1;
        }