// 各派生クラスでの初期化処理を行う(メニューまたは 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; }