示例#1
0
        //-----------------------------------------------------------

        /// <summary>
        /// 各派生クラスでの初期化処理を行う(メニューまたは AddView から生成される場合のみ実行れる)
        /// </summary>
        /// <param name="tOption"></param>
        override protected void OnBuild(string tOption = "")
        {
            SetAnchorToLeftStretch();
            Vector2 tSize = GetCanvasSize();

            if (tSize.x > 0 && tSize.y > 0)
            {
                _w = tSize.x * 0.5f;
            }
            SetPivot(0, 0);

            Image tImage = _image;

            tImage.color = new Color32(255, 255, 255, 32);

            isCanvasGroup  = true;
            isEventTrigger = true;

            UIAtlasSprite tAtlas = UIAtlasSprite.Create("uGUIHelper/Textures/UISimpleJoystick");

            UIImage tFrame = AddView <UIImage>("Frame");

            tFrame.SetAnchorToLeftBottom();
            tFrame.sprite = tAtlas["UISimpleJoystick_Frame_Type_0"];
            tFrame.SetSize(frameWidth, frameWidth);
            frame = tFrame;

            float thumbWidth = frameWidth * thumbScale;

            UIImage tThumb = tFrame.AddView <UIImage>("Thumb");

            tThumb.SetAnchorToCenter();
            tThumb.sprite = tAtlas["UISimpleJoystick_Thumb_Type_0"];
            tThumb.SetSize(thumbWidth, thumbWidth);
            thumb = tThumb;

//			DestroyImmediate( tAtlas ) ;
        }
示例#2
0
        //---------------------------------------------

        // 各派生クラスでの初期化処理を行う(メニューまたは AddView から生成される場合のみ実行れる)
        override protected void OnBuild(string option = "")
        {
            Toggle toggle = _toggle;

            if (toggle == null)
            {
                toggle = gameObject.AddComponent <Toggle>();
            }
            if (toggle == null)
            {
                // 異常
                return;
            }

            //-------------------------

            Vector2 tSize = GetCanvasSize();

            if (tSize.x > 0 && tSize.y > 0)
            {
                SetSize(tSize.y * 0.25f, tSize.y * 0.05f);
            }

            // Background
            background = AddView <UIImage>("Background");
            background.SetAnchorToLeftMiddle();
            background.SetPosition(_h * 0.5f, 0);
            background.SetSize(_h, _h);
            background.sprite     = Resources.Load <Sprite>("uGUIHelper/Textures/UIDefaultFrame");
            background.type       = Image.Type.Sliced;
            background.fillCenter = true;

            background.raycastTarget = true;                    // 必須

            if (isCanvasOverlay == true)
            {
                background.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default");
            }

            toggle.targetGraphic = background._image;

            // Checkmark
            checkmark = background.AddView <UIImage>("Checkmark");
            checkmark.SetAnchorToCenter();
            checkmark.SetSize(_h, _h);
            checkmark.sprite = Resources.Load <Sprite>("uGUIHelper/Textures/UIDefaultCheck");

            if (isCanvasOverlay == true)
            {
                checkmark.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default");
            }

            toggle.graphic = checkmark._image;

            // Label
            label = AddView <UIText>("Label");
            label.SetAnchorToLeftMiddle();
            label.SetPosition(_h * 1.2f, 0);
            label.SetPivot(0, 0.5f);
            //		label.text = "Toggle" ;
            label.fontSize = ( int )(_h * 0.75f);

            if (isCanvasOverlay == true)
            {
                label.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default");
            }

            //----------------------------------------

            // 親にグループがアタッチされていればグループとみなす
            ToggleGroup toggleGroup = GetComponentInParent <ToggleGroup>();

            if (toggleGroup != null)
            {
                toggle.group = toggleGroup;
            }

            //----------------------------------------

            ResetRectTransform();
        }