/// <summary> /// 全ての状態で表示する画像を設定する /// </summary> /// <param name="tName"></param> public bool ReplaceImage(string tName) { UIImage tImage = GetComponent <UIImage>(); if (tImage == null || tImage.atlasSprite == null) { return(false); } Sprite tSprite = tImage.GetSpriteInAtlas(tName); if (tSprite == null) { return(false); } int i, l = transition.Count; for (i = 0; i < l; i++) { if (transition[i] != null) { transition[i].sprite = tSprite; } } tImage.SetSpriteInAtlas(tName); return(true); }
/// <summary> /// 指定の状態で表示する画像を設定する /// </summary> /// <param name="tState"></param> /// <param name="tName"></param> /// <returns></returns> public bool ReplaceImage(State tState, string tName) { UIImage tImage = GetComponent <UIImage>(); if (tImage == null || tImage.atlasSprite == null) { return(false); } Sprite tSprite = tImage.GetSpriteInAtlas(tName); if (tSprite == null) { return(false); } int i = ( int )tState; if (transition[i] != null) { transition[i].sprite = tSprite; } if (m_State == tState) { tImage.SetSpriteInAtlas(tName); } return(true); }
//------------------------------------------------------------------- // トランジジョンの状態を変える private bool ChangeTransitionState(State tState, State tEaseState) { if (m_State == tState) { // 状態が同じなので処理しない return(true); } // 現在の RectTransform の状態を退避する if (m_RectTransform == null) { m_RectTransform = GetComponent <RectTransform>(); } if (m_RectTransform == null) { // RectTransform がアタッチされていない return(false); } // 現在変化中の状態を変化前の状態とする // m_BasePosition = m_MovePosition ; m_BaseRotation = m_MoveRotation; m_BaseScale = m_MoveScale; m_State = tState; m_EaseState = tEaseState; m_BaseTime = Time.realtimeSinceStartup; m_Processing = true; if (spriteOverwriteEnabled == true) { UIImage tImage = GetComponent <UIImage>(); if (tImage != null && tImage.atlasSprite != null) { // 画像を変更する Transition tData = transition[( int )m_State]; if (tData.sprite != null) { tImage.SetSpriteInAtlas(tData.sprite.name); } } } if (m_State == State.Clicked) { UIEventSystem.Disable(31); } return(true); }
// AtlasSprite の項目を描画する protected void DrawAtlas(UIView tView) { UIImage tTarget = null; if (tView is UIImage) { tTarget = tView as UIImage; } else { return; } Texture tAtlasTextureBase = null; if (tTarget.atlasSprite != null) { tAtlasTextureBase = tTarget.atlasSprite.texture; } bool tAtlasTextureRefresh = false; Texture tAtlasTexture = EditorGUILayout.ObjectField("Atlas Texture", tAtlasTextureBase, typeof(Texture), false) as Texture; if (tAtlasTexture != tAtlasTextureBase) { Undo.RecordObject(tTarget, "UIAtlasSprite Texture : Change"); // アンドウバッファに登録 RefreshAtlasSprite(tTarget, tAtlasTexture); EditorUtility.SetDirty(tTarget); tAtlasTextureRefresh = true; } GUILayout.Label("Atlas Path"); GUILayout.BeginHorizontal(); { GUI.color = Color.cyan; GUILayout.Label("Resources/"); GUI.color = Color.white; string tAtlasPath = EditorGUILayout.TextField("", tTarget.atlasSprite.path); if (tAtlasPath != tTarget.atlasSprite.path) { Undo.RecordObject(tTarget, "UIAtlasSprite Path : Change"); // アンドウバッファに登録 tTarget.atlasSprite.path = tAtlasPath; EditorUtility.SetDirty(tTarget); } tAtlasPath = ""; if (tTarget.atlasSprite.texture != null) { string tPath = AssetDatabase.GetAssetPath(tTarget.atlasSprite.texture.GetInstanceID()); if (System.IO.File.Exists(tPath) == true) { string c = "/Resources/"; int p = tPath.IndexOf(c); if (p >= 0) { // 有効なパス tAtlasPath = tPath.Substring(p + c.Length, tPath.Length - (p + c.Length)); p = tAtlasPath.IndexOf("."); if (p >= 0) { tAtlasPath = tAtlasPath.Substring(0, p); } } } } if (string.IsNullOrEmpty(tAtlasPath) == false) { if (tAtlasPath != tTarget.atlasSprite.path) { GUI.backgroundColor = Color.yellow; } else { GUI.backgroundColor = Color.white; } if (GUILayout.Button("Set", GUILayout.Width(50f)) == true || tAtlasTextureRefresh == true) { Undo.RecordObject(tTarget, "UIAtlasSprite Path : Change"); // アンドウバッファに登録 tTarget.atlasSprite.path = tAtlasPath; EditorUtility.SetDirty(tTarget); } GUI.backgroundColor = Color.white; } } GUILayout.EndHorizontal(); //----------------------------------------------------- // 一覧から選択出来るようにする // if( tTarget.atlasSprite != null && tTarget.atlasSprite.texture != null ) // { // GUI.backgroundColor = Color.yellow ; // if( GUILayout.Button( "Refresh", GUILayout.Width( 140f ) ) == true ) // { // Undo.RecordObject( tTarget, "UIAtlasSprite Texture : Change" ) ; // アンドウバッファに登録 // RefreshAtlasSprite( tTarget, tTarget.atlasSprite.texture ) ; // EditorUtility.SetDirty( tTarget ) ; // } // GUI.backgroundColor = Color.white ; // } if (tTarget.atlasSprite != null) { EditorGUILayout.Separator(); // 少し区切りスペース if (GUILayout.Button("Reload", GUILayout.Width(50f)) == true || (tTarget.atlasSprite.isAvailable == false && tTarget.atlasSprite.texture != null && Application.isPlaying == false)) { // データに異常が発生しているので自動的に更新する Debug.LogWarning("Atlas を自動的に更新:" + tTarget.atlasSprite.texture.name); RefreshAtlasSprite(tTarget, tTarget.atlasSprite.texture); EditorUtility.SetDirty(tTarget); UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene()); } string[] tName = tTarget.atlasSprite.GetNameList(); if (tName != null && tName.Length > 0) { // ソートする List <string> tSortName = new List <string>(); int i, l = tName.Length; for (i = 0; i < l; i++) { tSortName.Add(tName[i]); } tSortName.Sort(); tName = tSortName.ToArray(); string tCurrentName = null; if (tTarget.sprite != null) { tCurrentName = tTarget.sprite.name; } int tIndexBase = -1; for (i = 0; i < l; i++) { if (tName[i] == tCurrentName) { tIndexBase = i; break; } } if (tIndexBase < 0) { List <string> tList = new List <string>(); tList.Add("Unknown"); for (i = 0; i < l; i++) { tList.Add(tName[i]); } tName = tList.ToArray(); tIndexBase = 0; } // フレーム番号 int tIndex = EditorGUILayout.Popup("Selected Sprite", tIndexBase, tName); if (tIndex != tIndexBase) { Undo.RecordObject(tTarget, "UIImage Sprite : Change"); // アンドウバッファに登録 tTarget.SetSpriteInAtlas(tName[tIndex]); EditorUtility.SetDirty(tTarget); } // 確認用 Sprite tSprite = EditorGUILayout.ObjectField("", tTarget.sprite, typeof(Sprite), false, GUILayout.Width(60f), GUILayout.Height(60f)) as Sprite; if (tSprite != tTarget.sprite) { } } } }
// トランジジョンの状態を変える private bool ChangeTransitionState(State tState, State tEaseState) { if (m_State == tState) { // 状態が同じなので処理しない return(true); } if (m_Button != null && m_UIButton != null) { if (colorTransmission == true) { ColorBlock tCB = m_Button.colors; if (tState == State.Normal) { m_UIButton.SetColorOfChildren(tCB.normalColor); } else if (tState == State.Highlighted) { m_UIButton.SetColorOfChildren(tCB.highlightedColor); } else if (tState == State.Pressed) { m_UIButton.SetColorOfChildren(tCB.pressedColor); } else if (tState == State.Disabled) { m_UIButton.SetColorOfChildren(tCB.disabledColor); } else { m_UIButton.SetColorOfChildren(tCB.normalColor); } } } // 現在の RectTransform の状態を退避する if (m_RectTransform == null) { m_RectTransform = GetComponent <RectTransform>(); } if (m_RectTransform == null) { // RectTransform がアタッチされていない return(false); } // 現在変化中の状態を変化前の状態とする // m_BasePosition = m_MovePosition ; m_BaseRotation = m_MoveRotation; m_BaseScale = m_MoveScale; m_State = tState; m_EaseState = tEaseState; m_BaseTime = Time.realtimeSinceStartup; m_Processing = true; // 処理する if (spriteOverwriteEnabled == true) { UIImage tImage = GetComponent <UIImage>(); if (tImage != null && tImage.atlasSprite != null) { // 画像を変更する Transition tData = transition[( int )m_State]; if (tData.sprite != null) { tImage.SetSpriteInAtlas(tData.sprite.name); } } } return(true); }