/// <summary> /// 各派生クラスでの初期化処理を行う(メニューまたは AddView から生成される場合のみ実行れる) /// </summary> /// <param name="tOption"></param> override protected void OnBuild(string tOption = "") { ImageNumber tImageNumber = _imageNumber; if (tImageNumber == null) { tImageNumber = gameObject.AddComponent <ImageNumber>(); } if (tImageNumber == null) { // 異常 return; } //---------------------------- // Default tImageNumber.color = Color.white; tImageNumber.atlasSprite = UIAtlasSprite.Create("uGUIHelper/Textures/UIDefaultImageNumber"); if (isCanvasOverlay == true) { tImageNumber.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default"); } ResetRectTransform(); }
// AtlasSprite の項目を描画する private void DrawAtlas(ImageNumber tTarget) { UIAtlasSprite tAtlasSprite; Texture tAtlasTextureBase = null; if (tTarget.atlasSprite != null) { tAtlasTextureBase = tTarget.atlasSprite.texture; } Texture tAtlasTexture = EditorGUILayout.ObjectField("Atlas Texture", tAtlasTextureBase, typeof(Texture), false) as Texture; if (tAtlasTexture != tAtlasTextureBase) { Undo.RecordObject(tTarget, "UIAtlasSprite Texture : Change"); // アンドウバッファに登録 List <Sprite> tList = new List <Sprite>(); if (tAtlasTexture != null) { string tPath = AssetDatabase.GetAssetPath(tAtlasTexture.GetInstanceID()); // テクスチャからパスを取得してマルチタイプスプライトとしてロードする UnityEngine.Object[] tSpriteAll = AssetDatabase.LoadAllAssetsAtPath(tPath); if (tSpriteAll != null) { int i, l = tSpriteAll.Length; for (i = 0; i < l; i++) { if (tSpriteAll[i] is UnityEngine.Sprite) { tList.Add(tSpriteAll[i] as UnityEngine.Sprite); } } } } if (tList.Count > 0) { // 存在するので更新する tAtlasSprite = UIAtlasSprite.Create(); tAtlasSprite.Set(tList.ToArray()); /* tAtlasSprite.name = tAtlasTexture.name + "(Instance Only)" ;*/ tTarget.atlasSprite = tAtlasSprite; } else { // 存在しないのでクリアする tTarget.atlasSprite = null; } EditorUtility.SetDirty(tTarget); } }
/// <summary> /// アトラスタイプのスプライトを生成する /// </summary> /// <param name="tPath"></param> /// <returns></returns> public static UIAtlasSprite Create(string tPath = null) { // UIAtlasSprite tAtlasSprite = ScriptableObject.CreateInstance<UIAtlasSprite>() ; UIAtlasSprite tAtlasSprite = new UIAtlasSprite(); if (string.IsNullOrEmpty(tPath) == false) { if (tAtlasSprite.Load(tPath) == false) { // DestroyImmediate( tAtlasSprite ) ; return(null); } } return(tAtlasSprite); }
//----------------------------------------------------------- /// <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 ) ; }
//----------------------------------------------------- /// <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 ) ; }