Guest User

Untitled

a guest
May 24th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. using System.Text.RegularExpressions;
  2. using UnityEngine;
  3.  
  4. /// <summary>
  5. /// ステージデータを管理するクラス
  6. /// </summary>
  7. public sealed class StageData : ScriptableObject
  8. {
  9. //====================================================================================
  10. // 定数
  11. //====================================================================================
  12. private static readonly Regex m_regex = new Regex( "^[\r\n]+" );
  13.  
  14. //====================================================================================
  15. // 変数(SerializeField)
  16. //====================================================================================
  17. [SerializeField] private int m_width = 0 ;
  18. [SerializeField] private int m_height = 0 ;
  19. [SerializeField] private int[] m_cellList = null ;
  20.  
  21. //====================================================================================
  22. // プロパティ
  23. //====================================================================================
  24. public int Width { get { return m_width ; } }
  25. public int Height { get { return m_height ; } }
  26.  
  27. //====================================================================================
  28. // 関数
  29. //====================================================================================
  30. /// <summary>
  31. /// 初期化します
  32. /// </summary>
  33. public void Init( string text, int width, int height )
  34. {
  35. m_width = width;
  36. m_height = height;
  37.  
  38. text = m_regex.Replace( text, string.Empty );
  39.  
  40. m_cellList = new int[ width * height ];
  41.  
  42. var rows = text.Split( '\n' );
  43.  
  44. for ( int y = 0; y < height; y++ )
  45. {
  46. var row = rows[ y ];
  47. var columns = row.Split( ',' );
  48.  
  49. for ( int x = 0; x < width; x++ )
  50. {
  51. var column = columns[ x ];
  52. var cell = int.Parse( column );
  53.  
  54. m_cellList[ x + y * width ] = cell;
  55. }
  56. }
  57. }
  58.  
  59. /// <summary>
  60. /// セルを返します
  61. /// </summary>
  62. public int GetCell( int x,int y )
  63. {
  64. return m_cellList[ x + y * m_width ];
  65. }
  66. }
Add Comment
Please, Sign In to add comment