加入测试样例,初步完善队列信息——视图转换
This commit is contained in:
@@ -6,22 +6,22 @@ using UnityEngine.UI;
|
||||
public class BeatmapManager : MonoBehaviour
|
||||
|
||||
{
|
||||
public Beatmap beatmap; // 当前谱面数据
|
||||
public Beatmap beatmap; // 当前谱面数据
|
||||
|
||||
// 音符生成器引用
|
||||
// 音符生成器引用
|
||||
public NoteSpawner noteSpawner;
|
||||
|
||||
|
||||
|
||||
// 保存谱面数据到 JSON 文件
|
||||
// 保存谱面数据到 JSON 文件
|
||||
//public void SaveBeatmap(string fileName)
|
||||
//{
|
||||
// string json = JsonUtility.ToJson(beatmap, true); // 格式化 JSON 输出
|
||||
// string json = JsonUtility.ToJson(beatmap, true); // 格式化 JSON 输出
|
||||
// File.WriteAllText(Application.dataPath + "/" + fileName, json);
|
||||
// Debug.Log("谱面已保存:" + Application.dataPath + "/" + fileName);
|
||||
// Debug.Log("谱面已保存:" + Application.dataPath + "/" + fileName);
|
||||
//}
|
||||
|
||||
// 从 JSON 文件加载谱面数据
|
||||
// 从 JSON 文件加载谱面数据
|
||||
public void LoadBeatmap(string fileName)
|
||||
{
|
||||
string path = Application.streamingAssetsPath + "/" + fileName;
|
||||
@@ -29,23 +29,23 @@ public class BeatmapManager : MonoBehaviour
|
||||
{
|
||||
string json = File.ReadAllText(path);
|
||||
beatmap = JsonUtility.FromJson<Beatmap>(json);
|
||||
Debug.Log("谱面已加载:" + json);
|
||||
Debug.Log("谱面已加载:" + json);
|
||||
|
||||
// 在加载后立即调用音符生成
|
||||
// 在加载后立即调用音符生成
|
||||
noteSpawner.LoadBeatmap(beatmap);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("文件不存在:" + path);
|
||||
Debug.LogError("文件不存在:" + path);
|
||||
}
|
||||
}
|
||||
public void LoadBeatmap(Beatmap loadedBeatmap)
|
||||
{
|
||||
beatmap = loadedBeatmap;
|
||||
Debug.Log("谱面已加载:" + beatmap.title);
|
||||
Debug.Log("谱面已加载:" + beatmap.title);
|
||||
|
||||
// 在加载后立即调用音符生成
|
||||
// 在加载后立即调用音符生成
|
||||
noteSpawner.LoadBeatmap(beatmap);
|
||||
}
|
||||
|
||||
@@ -56,15 +56,15 @@ public class BeatmapManager : MonoBehaviour
|
||||
// {
|
||||
// string json = File.ReadAllText(path);
|
||||
// Beatmap beatmap = JsonUtility.FromJson<Beatmap>(json);
|
||||
// beatmapManager.LoadBeatmap(beatmap); // 使用 LoadBeatmap 方法传递 Beatmap 对象
|
||||
// beatmapManager.LoadBeatmap(beatmap); // 使用 LoadBeatmap 方法传递 Beatmap 对象
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Debug.LogError("文件不存在:" + path);
|
||||
// Debug.LogError("文件不存在:" + path);
|
||||
// }
|
||||
//}
|
||||
|
||||
// 创建一个示例谱面并保存
|
||||
// 创建一个示例谱面并保存
|
||||
//public void CreateSampleBeatmap()
|
||||
//{
|
||||
// beatmap = new Beatmap
|
||||
@@ -105,7 +105,7 @@ public class BeatmapManager : MonoBehaviour
|
||||
// SaveBeatmap("test_beatmap.json");
|
||||
//}
|
||||
|
||||
// 读取并加载当前谱面到音符生成器
|
||||
// 读取并加载当前谱面到音符生成器
|
||||
public void LoadBeatmapFromFile()
|
||||
{
|
||||
string path = Application.streamingAssetsPath + "/Emilia_demo.json";
|
||||
@@ -117,15 +117,15 @@ public class BeatmapManager : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("谱面文件未找到!");
|
||||
Debug.LogError("谱面文件未找到!");
|
||||
}
|
||||
}
|
||||
|
||||
// 在 Start() 方法中初始化
|
||||
// 在 Start() 方法中初始化
|
||||
void Start()
|
||||
{
|
||||
// 这里可以选择在启动时创建一个示例谱面并加载
|
||||
//CreateSampleBeatmap(); // 创建并保存一个示例谱面
|
||||
LoadBeatmap("Emilia_demo.json"); // 加载并实例化音符
|
||||
// 这里可以选择在启动时创建一个示例谱面并加载
|
||||
//CreateSampleBeatmap(); // 创建并保存一个示例谱面
|
||||
LoadBeatmap("Emilia_demo.json"); // 加载并实例化音符
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ public class JudgeManager : MonoBehaviour
|
||||
private Dictionary<KeyCode, Queue<Note>> judgeQueues = new Dictionary<KeyCode, Queue<Note>>();
|
||||
private Dictionary<string, bool> startJudgedNotes = new Dictionary<string, bool>();
|
||||
private Dictionary<string, bool> releasedNotes = new Dictionary<string, bool>();
|
||||
// 记录 End 段的 scheduledEndTime(防止 End 被回收后仍然能判定)
|
||||
// 记录 End 段的 scheduledEndTime(防止 End 被回收后仍然能判定)
|
||||
private Dictionary<string, float> noteEndTimes = new Dictionary<string, float>();
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class JudgeManager : MonoBehaviour
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录某个颜色的长音符 End 段的 scheduledEndTime
|
||||
/// 记录某个颜色的长音符 End 段的 scheduledEndTime
|
||||
/// </summary>
|
||||
public void RegisterScheduledEndTime(string noteColor, float endTime)
|
||||
{
|
||||
@@ -34,7 +34,7 @@ public class JudgeManager : MonoBehaviour
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取某个颜色的 End 段的 scheduledEndTime
|
||||
/// 获取某个颜色的 End 段的 scheduledEndTime
|
||||
/// </summary>
|
||||
public float GetScheduledEndTime(string noteColor)
|
||||
{
|
||||
@@ -63,7 +63,7 @@ public class JudgeManager : MonoBehaviour
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当音符进入判定区域时调用
|
||||
/// 当音符进入判定区域时调用
|
||||
/// </summary>
|
||||
public void RegisterNote(KeyCode key, Note note)
|
||||
{
|
||||
@@ -77,7 +77,7 @@ public class JudgeManager : MonoBehaviour
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当音符离开判定区域时调用
|
||||
/// 当音符离开判定区域时调用
|
||||
/// </summary>
|
||||
public void UnregisterNote(KeyCode key, Note note)
|
||||
{
|
||||
@@ -93,7 +93,7 @@ public class JudgeManager : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
// **如果音符未被判定,则触发 Miss**
|
||||
// **如果音符未被判定,则触发 Miss**
|
||||
if (!n.IsJudged())
|
||||
{
|
||||
n.JudgeMiss();
|
||||
@@ -104,13 +104,13 @@ public class JudgeManager : MonoBehaviour
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按键按下时,判定队列中最早进入的音符
|
||||
/// 按键按下时,判定队列中最早进入的音符
|
||||
/// </summary>
|
||||
public void JudgeEarliestNote(KeyCode key)
|
||||
{
|
||||
if (judgeQueues.ContainsKey(key) && judgeQueues[key].Count > 0)
|
||||
{
|
||||
Note note = judgeQueues[key].Dequeue(); // 只取最早的音符
|
||||
Note note = judgeQueues[key].Dequeue(); // 只取最早的音符
|
||||
if (note != null && !note.IsJudged())
|
||||
{
|
||||
note.Judge();
|
||||
|
||||
@@ -7,7 +7,7 @@ public class KeyBindingManager : MonoBehaviour
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Debug.Log("KeyBindingManager Awake() 被调用,开始加载按键映射...");
|
||||
Debug.Log("KeyBindingManager Awake() 被调用,开始加载按键映射...");
|
||||
|
||||
if (keyBindings.Count == 0)
|
||||
{
|
||||
@@ -15,18 +15,18 @@ public class KeyBindingManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> 获取颜色对应的按键 </summary>
|
||||
/// <summary> 获取颜色对应的按键 </summary>
|
||||
public static KeyCode GetKeyForColor(string color)
|
||||
{
|
||||
if (keyBindings.TryGetValue(color.ToLower(), out KeyCode key))
|
||||
{
|
||||
return key;
|
||||
}
|
||||
Debug.LogError($"未找到颜色 {color} 对应的按键!请检查 KeyBindingManager 是否正确初始化。");
|
||||
Debug.LogError($"未找到颜色 {color} 对应的按键!请检查 KeyBindingManager 是否正确初始化。");
|
||||
return KeyCode.None;
|
||||
}
|
||||
|
||||
/// <summary> 修改按键绑定 </summary>
|
||||
/// <summary> 修改按键绑定 </summary>
|
||||
public static void ChangeKeyBinding(string color, KeyCode newKey)
|
||||
{
|
||||
if (keyBindings.ContainsKey(color.ToLower()))
|
||||
@@ -41,7 +41,7 @@ public class KeyBindingManager : MonoBehaviour
|
||||
SaveKeyBindings();
|
||||
}
|
||||
|
||||
/// <summary> 存储按键绑定到 `PlayerPrefs` </summary>
|
||||
/// <summary> 存储按键绑定到 `PlayerPrefs` </summary>
|
||||
private static void SaveKeyBindings()
|
||||
{
|
||||
foreach (var kvp in keyBindings)
|
||||
@@ -51,7 +51,7 @@ public class KeyBindingManager : MonoBehaviour
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
/// <summary> 从 `PlayerPrefs` 加载按键绑定 </summary>
|
||||
/// <summary> 从 `PlayerPrefs` 加载按键绑定 </summary>
|
||||
private static void LoadKeyBindings()
|
||||
{
|
||||
string[] colors = { "red", "green", "yellow", "purple", "blue" };
|
||||
@@ -69,6 +69,6 @@ public class KeyBindingManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log("KeyBindings 初始化成功:" + string.Join(", ", keyBindings));
|
||||
Debug.Log("KeyBindings 初始化成功:" + string.Join(", ", keyBindings));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ public class NoteController : MonoBehaviour
|
||||
{
|
||||
private float speed;
|
||||
private bool isMoving = true;
|
||||
private bool isInJudgeZone = false; // 判定区域标记
|
||||
private bool isInJudgeZone = false; // 判定区域标记
|
||||
|
||||
private ParticleSystem hitEffect;
|
||||
private Note linkedNote;
|
||||
@@ -59,7 +59,7 @@ public class NoteController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// 将 OnTriggerEnter2D 和 OnTriggerExit2D 挂载在 Controller 上
|
||||
// 将 OnTriggerEnter2D 和 OnTriggerExit2D 挂载在 Controller 上
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
@@ -92,7 +92,7 @@ public class NoteController : MonoBehaviour
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 供 Note 查询是否处于判定区域
|
||||
/// 供 Note 查询是否处于判定区域
|
||||
/// </summary>
|
||||
public bool IsInJudgeZone()
|
||||
{
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34e2f32e0653f2e45b65f7266beb8ec4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,27 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Character
|
||||
{
|
||||
/// <summary>
|
||||
/// 角色名称
|
||||
/// </summary>
|
||||
public string name{get; set;}
|
||||
/// <summary>
|
||||
/// 职业
|
||||
/// </summary>
|
||||
public string occupation{get; set;}
|
||||
/// <summary>
|
||||
/// 突破等级
|
||||
/// </summary>
|
||||
public int boundaryLevel{get; set;}
|
||||
/// <summary>
|
||||
/// 技能名称
|
||||
/// </summary>
|
||||
public string SkillName{get; set;}
|
||||
/// <summary>
|
||||
/// 是否为队长
|
||||
/// </summary>
|
||||
public bool isLeader{get; set;}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bae42af9bcfec5f46a3025f40ce5bd7b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,94 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class TeamManager : MonoBehaviour
|
||||
{
|
||||
public static TeamManager Instance {get; private set;}
|
||||
|
||||
public teamSettingPanel teamSettingPanelInstance;
|
||||
//当前玩家存档下的所有编队配置
|
||||
public Dictionary<int, List<Character>> currentTeamSettings = new Dictionary<int, List<Character>>();
|
||||
/// <summary>
|
||||
/// 根据此字段来在编队信息页显示已有编队
|
||||
/// </summary>
|
||||
public int currentSelectedTeam = 0;
|
||||
/// <summary>
|
||||
/// 记录被选中的编队中角色的索引,用于处理队列位置交换的逻辑。-1表示无角色被选中
|
||||
/// </summary>
|
||||
public int currentSelectedCharacter = -1;
|
||||
/// <summary>
|
||||
/// 在修改被选中的编队中角色的索引时触发
|
||||
/// </summary>
|
||||
public event Action OnSelectedCharacterChanged;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if(teamSettingPanelInstance == null)
|
||||
{
|
||||
teamSettingPanelInstance = teamSettingPanel.Instance;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 读取玩家存档信息后可直接在此写入编队信息
|
||||
/// </summary>
|
||||
/// <param name="playerTeamSettings"></param>
|
||||
public void setcurrentTeamSettings(Dictionary<int,List<Character>> playerTeamSettings)
|
||||
{
|
||||
currentTeamSettings = playerTeamSettings;
|
||||
}
|
||||
/// <summary>
|
||||
/// 依据选定的队伍预设索引来获得队伍信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<Character> getCurrentSelectedTeam()
|
||||
{
|
||||
return currentTeamSettings[currentSelectedTeam];
|
||||
}
|
||||
|
||||
public void setCurrentSelectedTeam(List<Character> newTeamData, int teamIndex)
|
||||
{
|
||||
currentTeamSettings[teamIndex] = newTeamData;
|
||||
}
|
||||
public void setCurrentSelectedCharacterInTeam(int characterIndex)
|
||||
{
|
||||
if (characterIndex != currentSelectedCharacter)
|
||||
{
|
||||
currentSelectedCharacter = characterIndex;
|
||||
OnSelectedCharacterChanged?.Invoke(); // 触发事件
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 交换指定索引中的两个队伍中元素的位置
|
||||
/// </summary>
|
||||
/// <param name="firstIndex"></param>
|
||||
/// <param name="secondIndex"></param>
|
||||
public void swapTeamElements(int firstIndex, int secondIndex)
|
||||
{
|
||||
List<Character> newCurrentTeam = getCurrentSelectedTeam();
|
||||
Character temp = newCurrentTeam[firstIndex];
|
||||
newCurrentTeam[firstIndex] = newCurrentTeam[secondIndex];
|
||||
newCurrentTeam[secondIndex] = temp;
|
||||
currentTeamSettings[currentSelectedTeam] = newCurrentTeam;
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: debeba9c3c2f7334ab04c769534a1f85
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -20,7 +20,7 @@ public class TrackKeyManager : MonoBehaviour
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当音符进入判定区域时,添加按键映射
|
||||
/// 当音符进入判定区域时,添加按键映射
|
||||
/// </summary>
|
||||
public void RegisterKey(int trackIndex, KeyCode key)
|
||||
{
|
||||
@@ -31,7 +31,7 @@ public class TrackKeyManager : MonoBehaviour
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当音符离开判定区域时,移除按键映射
|
||||
/// 当音符离开判定区域时,移除按键映射
|
||||
/// </summary>
|
||||
public void UnregisterKey(int trackIndex, KeyCode key)
|
||||
{
|
||||
@@ -45,7 +45,7 @@ public class TrackKeyManager : MonoBehaviour
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取轨道当前的按键(队列头)
|
||||
/// 获取轨道当前的按键(队列头)
|
||||
/// </summary>
|
||||
public KeyCode GetCurrentKey(int trackIndex)
|
||||
{
|
||||
@@ -53,6 +53,6 @@ public class TrackKeyManager : MonoBehaviour
|
||||
{
|
||||
return trackKeyMappings[trackIndex].Peek();
|
||||
}
|
||||
return KeyCode.None; // 无按键
|
||||
return KeyCode.None; // 无按键
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user