Skip to content

Commit

Permalink
#3 コメントを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
miyaji255 committed Apr 16, 2023
1 parent 23d832f commit 19dae9b
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 12 deletions.
37 changes: 27 additions & 10 deletions Assets/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ public class GameManager : MonoBehaviour

private NoteObject[] _noteObjects;

/// <summary>
/// 1秒あたりに進む速度
/// </summary>
private float _speed = 2f;

private void Start()
{
_playerInput = GetComponent<PlayerInput>();
Expand All @@ -52,9 +47,12 @@ private void OnDestroy()
}
}

/// <summary>
/// ノーツを取得し、配置します
/// </summary>
public void LoadNotes()
{
NoteOrigin.GetComponent<NoteContoroler>().NoteVelocity = _speed;
NoteOrigin.GetComponent<NoteContoroler>().NoteVelocity = ConfigManager.Instance.Speed;

var notes = ScoreManager.Instance.Initialize();

Expand All @@ -67,6 +65,9 @@ public void LoadNotes()
}
}

/// <summary>
/// 失敗したeventを受け取ります
/// </summary>
private void ControllerNoteMiss(int noteId)
{
ScoreManager.Instance.OnMiss(noteId);
Expand All @@ -76,6 +77,9 @@ private void ControllerNoteMiss(int noteId)
controller.NoteDestroy();
}

/// <summary>
/// レーンの位置を取得します
/// </summary>
private Vector3 CalculateNotePosition(NoteEntity note)
{
switch (note.Type)
Expand All @@ -89,21 +93,27 @@ private Vector3 CalculateNotePosition(NoteEntity note)
LanePosition.MidRight => _lanePoint.NoteLanePoint[3],
LanePosition.Right2 => _lanePoint.NoteLanePoint[4],
LanePosition.Right1 => _lanePoint.NoteLanePoint[5],
_ => throw new NotImplementedException(),
_ => throw new NotSupportedException(),
};
lane.z += _speed * 1000 * note.StartTime;
lane.z += ConfigManager.Instance.Speed * 1000 * note.StartTime;
return lane;
default:
throw new NotSupportedException();
}
}

/// <summary>
/// スコテキストとコンボテキストを更新します
/// </summary>
public void UpdateText()
{
_scoreText.text = ScoreManager.Instance.CurrentScore.ToString().PadLeft(8, ' ');
_comboText.text = $"{ScoreManager.Instance.CurrentComboCount} Combo";
_comboText.text = ScoreManager.Instance.CurrentComboCount.ToString();
}

/// <summary>
/// 評価を表示します
/// </summary>
public void UpdateGradeText(Grade grade)
{
switch (grade)
Expand All @@ -129,11 +139,18 @@ public void UpdateGradeText(Grade grade)
}
}

/// <summary>
/// 再生を開始します
/// </summary>
public void StartPlay()
{

// 音楽がそもそもないので未実装
throw new NotSupportedException();
}

/// <summary>
/// キーインプットを受け取ります
/// </summary>
private void OnMainInput(InputAction.CallbackContext context)
{
LanePosition lanePosition;
Expand Down
21 changes: 21 additions & 0 deletions Assets/Scripts/Manager/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,26 @@

namespace OUCC.MusicGame.Manager
{
/// <summary>
/// 現在の設定を示します
/// </summary>
public class ConfigManager
{
public static readonly ConfigManager Instance = new();

/// <summary>
/// 現在選択されている音楽
/// </summary>
public MusicEntity CurrentMusic { get; private set; }

/// <summary>
/// 1秒あたりに進む速度
/// </summary>
public float Speed { get; set; }

/// <summary>
/// ゲーム全体の情報
/// </summary>
public GameConfig GameConfig { get; private set; }

public ConfigManager()
Expand Down Expand Up @@ -41,6 +55,10 @@ public ConfigManager()
}
}

/// <summary>
/// 音楽IDをセットしようとします
/// </summary>
/// <returns>該当する音楽がないときfalse</returns>
public bool TrySetMusic(int id)
{
var music = GameConfig.Musics.FirstOrDefault(m => m.Id == id);
Expand All @@ -51,6 +69,9 @@ public bool TrySetMusic(int id)
return true;
}

/// <summary>
/// データを保存する
/// </summary>
public void Save(bool prettyPrint = false)
{
#if UNITY_EDITOR
Expand Down
3 changes: 3 additions & 0 deletions Assets/Scripts/Manager/GameConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace OUCC.MusicGame.Manager
[Serializable]
public class GameConfig
{
/// <summary>
/// 用意している音楽
/// </summary>
public MusicEntity[] Musics = Array.Empty<MusicEntity>();
}
}
7 changes: 6 additions & 1 deletion Assets/Scripts/Manager/MusicNotesContainer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using log4net.Util;

namespace OUCC.MusicGame.Manager
{
Expand All @@ -12,8 +11,14 @@ public class MusicNotesContainer
Notes = Array.Empty<NoteEntity>()
};

/// <summary>
/// 現在選択している音楽の情報
/// </summary>
public MusicEntity Info;

/// <summary>
/// 現在選択している音楽のノーツ
/// </summary>
public NoteEntity[] Notes;
}
}
16 changes: 15 additions & 1 deletion Assets/Scripts/Manager/ScoreManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,26 @@ public class ScoreManager
{
public static ScoreManager Instance = new();


private MusicNotesContainer _container;

/// <summary>
/// スコアの最大値
/// </summary>
public int TotalScore { get; private set; }

/// <summary>
/// 最大コンボ数
/// </summary>
public int MaxCombo { get; private set; }

/// <summary>
/// 現在のスコア
/// </summary>
public int CurrentScore { get; private set; }

/// <summary>
/// 現在のコンボ数
/// </summary>
public int CurrentComboCount
{
get => _currentComboCount;
Expand All @@ -31,6 +42,9 @@ private set
}
private int _currentComboCount;

/// <summary>
/// ノーツを保存しているJSONを読み込んで初期化します
/// </summary>
public NoteEntity[] Initialize()
{
var music = ConfigManager.Instance.CurrentMusic;
Expand Down
9 changes: 9 additions & 0 deletions Assets/Scripts/NoteObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ public NoteObject(int id, GameObject note)
Controller = note.GetComponent<NoteContoroler>();
}

/// <summary>
/// ノーツID
/// </summary>
public readonly int NoteId;

/// <summary>
/// ノーツのオブジェクト
/// </summary>
public readonly GameObject Object;

/// <summary>
/// ノーツのコントローラー
/// </summary>
public readonly NoteContoroler Controller;
}
}

0 comments on commit 19dae9b

Please sign in to comment.