public void Draw(int x, int y, int width, int height, int column) { int remain = tileList.Count % column; int rowCount = tileList.Count + (remain > 0 ? 1 : 0); // GUIContent는 렌더링할 대상을 정의하고, (시각적인 매체를 추가하는 개념인듯) // GUIStyle은 렌더링하는 방법을 정의한다. (양식, 수치 조절 등) GUIStyle guiStyle = new GUIStyle(GUI.skin.button); guiStyle.imagePosition = ImagePosition.ImageAbove; GUILayout.BeginArea(new Rect(x, y, width, height), EditorStyles.textField); scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(width - 5), GUILayout.Height(height)); for (int i = 0; i < rowCount; i++) { GUILayout.BeginHorizontal(); for (int j = 0; j < column; j++) { int index = i * column + j; if (index < tileList.Count) { GUIContent guiContent = new GUIContent(tileList[index].texture.name, tileList[index].texture); bool state = GUILayout.Button(guiContent, guiStyle, GUILayout.Width(100), GUILayout.Height(100)); if (state) { selTile = tileList[index]; } } else { break; } } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.EndArea(); }
public void Load(string path) { Sprite[] sprites = Resources.LoadAll <Sprite>(path); // 리소스로부터 복사본을 생성하여 새 클래스 객체(리스트)에 저장하는 과정 foreach (Sprite s in sprites) { TileImg tile = new TileImg(); Texture2D texture = new Texture2D((int)s.textureRect.width, (int)s.textureRect.height); var pixels = s.texture.GetPixels((int)s.textureRect.x, (int)s.textureRect.y, (int)s.textureRect.width, (int)s.textureRect.height); texture.SetPixels(pixels); texture.name = s.name; tile.texture = texture; tile.sprite = s; texture.Apply(); tileImg.Add(tile); //Debug.Log(tile.sprite); } }
public void Draw(int x, int y, int width, int height, TileImg tileImg) { int layer = 0; this.width = 0; this.height = 0; string imageName = null; Texture2D texture = null; Color color = Color.white; ColliderType colliderType = ColliderType.None; TileType tileType = TileType.None; // 타일 이미지의 정보를 받아옴 if (tileImg != null && tileImg.texture != null) { tileType = tileImg.tileType; colliderType = tileImg.colliderType; color = tileImg.color; this.width = (int)tileImg.sprite.textureRect.width; this.height = (int)tileImg.sprite.textureRect.height; imageName = tileImg.sprite.name; texture = tileImg.texture; } GUILayout.BeginArea(new Rect(x, y, width, height), EditorStyles.textField); #region 이미지의 사이즈 출력 GUILayout.BeginHorizontal(); GUILayout.Box("Width: " + this.width); //EditorGUILayout.IntField("", this.width, EditorStyles.numberField, // GUILayout.MinWidth(30), GUILayout.MaxWidth(40), GUILayout.MinHeight(22)); GUILayout.Box("Height: " + this.height); //EditorGUILayout.IntField("", this.height, EditorStyles.numberField, // GUILayout.MinWidth(30), GUILayout.MaxWidth(40), GUILayout.MinHeight(22)); GUILayout.EndHorizontal(); #endregion #region 이미지 출력 GUILayout.BeginHorizontal(); GUILayout.Label("Image :"); GUILayout.Button(texture, GUILayout.Width(100), GUILayout.Height(100)); GUILayout.EndHorizontal(); #endregion GUILayout.Label("Image Name: " + imageName); layer = tileImg != null ? tileImg.layerOrder : 0; GUILayout.Label("Layer Order: " + layer); GUILayout.BeginHorizontal(); if (GUILayout.Button("<", GUILayout.Width(93))) { if (tileImg != null) { tileImg.layerOrder--; } } if (GUILayout.Button(">", GUILayout.Width(93))) { if (tileImg != null) { tileImg.layerOrder++; } } GUILayout.EndHorizontal(); color = EditorGUILayout.ColorField(color); GUILayout.Label("Collider Type"); colliderType = (ColliderType)EditorGUILayout.EnumPopup(colliderType); GUILayout.Label("Tile Type"); tileType = (TileType)EditorGUILayout.EnumPopup(tileType); if (tileImg != null) { tileImg.color = color; tileImg.colliderType = colliderType; tileImg.tileType = tileType; } GUILayout.EndArea(); }