Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Text.RegularExpressions;
- using UnityEngine;
- /// <summary>
- /// ステージデータを管理するクラス
- /// </summary>
- public sealed class StageData : ScriptableObject
- {
- //====================================================================================
- // 定数
- //====================================================================================
- private static readonly Regex m_regex = new Regex( "^[\r\n]+" );
- //====================================================================================
- // 変数(SerializeField)
- //====================================================================================
- [SerializeField] private int m_width = 0 ;
- [SerializeField] private int m_height = 0 ;
- [SerializeField] private int[] m_cellList = null ;
- //====================================================================================
- // プロパティ
- //====================================================================================
- public int Width { get { return m_width ; } }
- public int Height { get { return m_height ; } }
- //====================================================================================
- // 関数
- //====================================================================================
- /// <summary>
- /// 初期化します
- /// </summary>
- public void Init( string text, int width, int height )
- {
- m_width = width;
- m_height = height;
- text = m_regex.Replace( text, string.Empty );
- m_cellList = new int[ width * height ];
- var rows = text.Split( '\n' );
- for ( int y = 0; y < height; y++ )
- {
- var row = rows[ y ];
- var columns = row.Split( ',' );
- for ( int x = 0; x < width; x++ )
- {
- var column = columns[ x ];
- var cell = int.Parse( column );
- m_cellList[ x + y * width ] = cell;
- }
- }
- }
- /// <summary>
- /// セルを返します
- /// </summary>
- public int GetCell( int x,int y )
- {
- return m_cellList[ x + y * m_width ];
- }
- }
Add Comment
Please, Sign In to add comment