//---------------------------------------------------- /// <summary> /// Thumb 更新 /// </summary> private void UpdateThumb() { if (scope == null || thumb == null) { return; } if (m_DisplayType == DisplayType.Stretch) { if (m_Value <= 0) { scope.SetActive(false); } else { scope.SetActive(true); scope.SetAnchorToStretch(); scope.SetAnchorMin(0, 0); scope.SetAnchorMax(m_Value, 1); thumb.SetAnchorToStretch(); thumb.SetMargin(0, 0, 0, 0); } } else if (m_DisplayType == DisplayType.Mask) { if (m_Value <= 0) { scope.SetActive(false); } else { scope.SetActive(true); scope.SetAnchorToStretch(); float d = scope._w * (1.0f - m_Value); scope.SetMargin(0, d, 0, 0); thumb.SetAnchorToStretch(); thumb.SetMargin(0, -d, 0, 0); } } }
//----------------------------------------------------------- // 各派生クラスでの初期化処理を行う(メニューまたは AddView から生成される場合のみ実行れる) override protected void OnBuild(string tOption = "") { Scrollbar tScrollbar = _scrollbar; if (tScrollbar == null) { tScrollbar = gameObject.AddComponent <Scrollbar>(); } if (tScrollbar == null) { // 異常 return; } //---------------------------------- Direction tDirection = Direction.Unknown; if (tOption.ToLower() == "h") { tDirection = Direction.Horizontal; } else if (tOption.ToLower() == "v") { tDirection = Direction.Vertical; } Vector2 tSize = GetCanvasSize(); if (tSize.x > 0 && tSize.y > 0) { float s; if (tSize.x <= tSize.y) { s = tSize.x; } else { s = tSize.y; } if (tDirection == Direction.Horizontal) { SetSize(s * 0.4f, s * 0.075f); tScrollbar.direction = Scrollbar.Direction.LeftToRight; } else if (tDirection == Direction.Vertical) { SetSize(s * 0.075f, s * 0.4f); tScrollbar.direction = Scrollbar.Direction.BottomToTop; } } ColorBlock tColorBlock = tScrollbar.colors; tColorBlock.fadeDuration = 0.2f; tScrollbar.colors = tColorBlock; Image tImage = _image; tImage.sprite = Resources.Load <Sprite>("uGUIHelper/Textures/UIDefaultFrame"); tImage.color = Color.white; tImage.type = Image.Type.Sliced; // UIImage tFrame = AddView<UIImage>( "Frame" ) ; // tFrame.SetAnchorToStretch() ; // tFrame.SetMargin( 0, 0, 0, 0 ) ; // tFrame.sprite = Resources.Load<Sprite>( "uGUIHelper/Textures/UIDefaultFrame" ) ; // tFrame.color = Color.white ; // tFrame.type = Image.Type.Sliced ; UIView tSlidingArea = AddView <UIView>("Sliding Area"); tSlidingArea.SetAnchorToStretch(); tSlidingArea.SetMargin(10, 10, 10, 10); UIImage tHandle = tSlidingArea.AddView <UIImage>("Handle"); if (tDirection == Direction.Horizontal) { tHandle.SetAnchorToStretch(); } else if (tDirection == Direction.Vertical) { tHandle.SetAnchorToStretch(); } tHandle.SetMargin(-10, -10, -10, -10); tHandle.sprite = Resources.Load <Sprite>("uGUIHelper/Textures/UIDefaultButton"); tHandle.type = Image.Type.Sliced; tHandle.fillCenter = true; tScrollbar.targetGraphic = tHandle._image; tScrollbar.handleRect = tHandle._rectTransform; ResetRectTransform(); }
//----------------------------------------------------- /// <summary> /// 各派生クラスでの初期化処理を行う(メニューまたは AddView から生成される場合のみ実行れる) /// </summary> /// <param name="tOption"></param> override protected void OnBuild(string tOption = "") { Vector2 tSize = GetCanvasSize(); if (tSize.x > 0 && tSize.y > 0) { float s; if (tSize.x <= tSize.y) { s = tSize.x; } else { s = tSize.y; } SetSize(s * 0.5f, s * 0.05f); } Sprite tDefaultFrameSprite = null; Sprite tDefaultThumbSprite = null; #if UNITY_EDITOR if (Application.isPlaying == false) { // メニューから操作した場合のみ自動設定を行う DefaultSettings tDS = Resources.Load <DefaultSettings>("uGUIHelper/DefaultSettings"); if (tDS != null) { tDefaultFrameSprite = tDS.progressbarFrame; tDefaultThumbSprite = tDS.progressbarThumb; } } #endif UIAtlasSprite tAtlas = UIAtlasSprite.Create("uGUIHelper/Textures/UIProgressbar"); // Frame Image tFrame = _image; if (tDefaultFrameSprite == null) { tFrame.sprite = tAtlas["UIProgressbar_Frame"]; } else { tFrame.sprite = tDefaultFrameSprite; } tFrame.type = Image.Type.Sliced; tFrame.fillCenter = true; if (isCanvasOverlay == true) { tFrame.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default"); } UIView tFillArea = AddView <UIView>("Fill Area"); tFillArea.SetAnchorToStretch(); // Mask scope = tFillArea.AddView <UIImage>("Scope"); scope.SetAnchorToStretch(); scope.SetMargin(0, 0, 0, 0); scope.isMask = true; scope.showMaskGraphic = false; if (isCanvasOverlay == true) { scope.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default"); } // Thumb thumb = scope.AddView <UIImage>("Thumb"); thumb.SetAnchorToStretch(); thumb.SetMargin(0, 0, 0, 0); if (tDefaultThumbSprite == null) { thumb.sprite = tAtlas["UIProgressbar_Thumb"]; } else { thumb.sprite = tDefaultThumbSprite; } thumb.type = Image.Type.Sliced; thumb.fillCenter = true; if (isCanvasOverlay == true) { thumb.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default"); } UpdateThumb(); // Label label = AddView <UINumber>("Label"); label.fontSize = ( int )(_h * 0.6f); label.isOutline = true; label.percent = true; if (isCanvasOverlay == true) { label.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default"); } UpdateLabel(); // DestroyImmediate( tAtlas ) ; }
// 各派生クラスでの初期化処理を行う(メニューまたは AddView から生成される場合のみ実行れる) override protected void OnBuild(string tOption = "") { Slider tSlider = _slider; if (tSlider == null) { tSlider = gameObject.AddComponent <Slider>(); } if (tSlider == null) { // 異常 return; } //--------------------------------- Direction tDirection = Direction.Unknown; if (tOption.ToLower() == "h") { tDirection = Direction.Horizontal; } else if (tOption.ToLower() == "v") { tDirection = Direction.Vertical; } Vector2 tSize = GetCanvasSize(); if (tSize.x > 0 && tSize.y > 0) { float s; if (tSize.x <= tSize.y) { s = tSize.x; } else { s = tSize.y; } if (tDirection == Direction.Horizontal) { SetSize(s * 0.25f, s * 0.05f); tSlider.direction = Slider.Direction.LeftToRight; } else if (tDirection == Direction.Vertical) { SetSize(s * 0.05f, s * 0.25f); tSlider.direction = Slider.Direction.BottomToTop; } } ResetRectTransform(); UIImage tBackground = AddView <UIImage>("Background"); if (tDirection == Direction.Horizontal) { tBackground.SetAnchorMinAndMax(0.00f, 0.25f, 1.00f, 0.75f); } else if (tDirection == Direction.Vertical) { tBackground.SetAnchorMinAndMax(0.25f, 0.00f, 0.75f, 1.00f); } tBackground.SetMargin(0, 0, 0, 0); tBackground.sprite = Resources.Load <Sprite>("uGUIHelper/Textures/UIDefaultFrame"); tBackground.type = Image.Type.Sliced; tBackground.fillCenter = true; tBackground.SetSize(0, 0); UIView tFillArea = AddView <UIView>("Fill Area"); if (tDirection == Direction.Horizontal) { tFillArea.SetAnchorMinAndMax(0.00f, 0.25f, 1.00f, 0.75f); tFillArea.SetMargin(5, 15, 0, 0); } else if (tDirection == Direction.Vertical) { tFillArea.SetAnchorMinAndMax(0.25f, 0.00f, 0.75f, 1.00f); tFillArea.SetMargin(0, 0, 5, 15); } UIImage tFill = tFillArea.AddView <UIImage>("Fill"); tFill.SetAnchorMinAndMax(0.00f, 0.00f, 1.00f, 1.00f); tFill.sprite = Resources.Load <Sprite>("uGUIHelper/Textures/UIDefaultButton"); tFill.type = Image.Type.Sliced; tFill.fillCenter = true; if (tDirection == Direction.Horizontal) { tFill.SetMargin(-5, -5, 0, 0); } else if (tDirection == Direction.Vertical) { tFill.SetMargin(0, 0, -5, -5); } tSlider.fillRect = tFill._rectTransform; UIView tHandleSlideArea = AddView <UIView>("Handle Slide Area"); tHandleSlideArea.SetAnchorToStretch(); if (tDirection == Direction.Horizontal) { tHandleSlideArea.SetMargin(10, 10, 0, 0); } else if (tDirection == Direction.Vertical) { tHandleSlideArea.SetMargin(0, 0, 10, 10); } UIImage tHandle = tHandleSlideArea.AddView <UIImage>("Handle"); if (tDirection == Direction.Horizontal) { tHandle.SetAnchorToRightStretch(); tHandle._x = 0; tHandle._w = _h * 1.0f; tHandle.SetMarginY(0, 0); } else if (tDirection == Direction.Vertical) { tHandle.SetAnchorToStretchTop(); tHandle._y = 0; tHandle._h = _w * 1.0f; tHandle.SetMarginX(0, 0); } tHandle.sprite = Resources.Load <Sprite>("uGUIHelper/Textures/UIDefaultButton"); tSlider.targetGraphic = tHandle._image; tSlider.handleRect = tHandle._rectTransform; }