👨💻个人主页:@元宇宙-秩沅
👨💻 hallo 欢迎 点赞👍 收藏⭐ 留言📝 加关注✅!
👨💻 本文由 秩沅 原创
👨💻 收录于专栏:就业宝典
⭐🅰️推荐专栏⭐
⭐-软件设计师高频考点大全⭐
文章目录
- ⭐前言⭐
- 🎶(==1==) 特效
- 结算特效
- 游戏特效
- 场景特效
- 🎶(==2==) 控制器
- 账户控制器
- 数据控制器
- 音轨控制器
- 面板启动器
- ⭐🅰️⭐
⭐前言⭐
🎶(1) 特效
结算特效
游戏特效
场景特效
🎶(2) 控制器
账户控制器
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//-------------------------------
//-------功能: 账户控制器
//-------创建者: -------
//------------------------------
public class acountContorller : SingleManager<acountContorller>
{
public AcountData foreverAcountData = new AcountData(); //用来存储上一次的账户
/// <summary>
/// 用Json序列化存储数据
/// </summary>
/// <param name="name"></param>
public void SaveData(AcountData acountData, string name)
{
if (acountData == null) //如果为空的话
{
Debug.Log("为空");
foreverAcountData.aount.Add(name); //直接存名字
JsonManager.Instance.SaveData(foreverAcountData, "acountArrary");
}
acountData.aount.Add(name);
JsonManager.Instance.SaveData(acountData, "acountArrary");
}
/// <summary>
/// Json序列化读取数据
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public AcountData ReadData()
{
return JsonManager.Instance.LoadData<AcountData>("acountArrary");
}
}
数据控制器
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//-------------------------------------
//—————————————————————————————————————
//___________项目: ______________
//___________功能: 数据管理
//___________创建者:
//_____________________________________
//-------------------------------------
public class DataContorl : SingleManager<DataContorl>
{
//场景
public bool levelGame; //是否是关卡游戏
public bool livingGame; //是否是生存模式
public bool foreverGame;//是否是无尽模式
public float speed;//中介存储,供外部调用
public AudioClip[] audioClip = new AudioClip[5];
public int index = 0;
//单例模式中单个全局信息不会随着改变
public PlayerData foreverPalyerdata = new PlayerData(); //用来存储上一次选中的item数据
//private List<ServerData> serverLists = new List<ServerData>();
//public List<ServerData> ServerLists => serverLists;
/// <summary>
/// 用Json序列化存储数据
/// </summary>
/// <param name="name"></param>
public void SaveData(string name, PlayerData data)
{
JsonManager.Instance.SaveData(data, name);
}
//更新存储高分信息
public void UpdateHightSocer( int socers , int index)
{
switch (index)
{
case 1:
if (socers > foreverPalyerdata.AllScore) //如果大于关卡模式的最高星星就保留否则不保留
{
foreverPalyerdata.AllScore = socers;
}
break;
case 2:
if (socers > foreverPalyerdata.livingScore) //如果大于生存模式的最高分数就保留否则不保留
{
foreverPalyerdata.livingScore = socers;
}
break;
case 3:
if (socers > foreverPalyerdata.foreverScore) //如果大于无尽模式的最高分数就保留否则不保留
{
foreverPalyerdata.foreverScore = socers;
}
break;
default:
break;
}
SaveData(foreverPalyerdata.userName , foreverPalyerdata);
}
public void CloseALL()
{
levelGame = false;
livingGame = false;
foreverGame = false;
}
/// <summary>
/// Json序列化读取数据
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public PlayerData ReadData(string name)
{
return JsonManager.Instance.LoadData<PlayerData>(name);
}
/// <summary>
/// 供外部调用识别账号密码是否正确
/// </summary>
/// <param name="userName"></param>
/// <param name="password"></param>
/// <returns></returns>
public bool Tip(string userName, string password)
{
try
{
string pass = ReadData(userName).password ;
Debug.Log(pass);
if (userName != null && pass == password)
{
return true;
}
else return false;
}
catch
{ return false; }
}
/// <summary>
/// 供外部调用识别注册时是否有相同的账号
/// </summary>
public bool TipSame(string userName)
{
Debug.Log("该账号已注册");
return false;
}
/// <summary>
/// 全局性玩家数据存盘
/// </summary>
public void UpdataPlayerInfo()
{
SaveData(foreverPalyerdata.userName, foreverPalyerdata);
}
}
音轨控制器
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SonicBloom.Koreo;
public class LaneController : MonoBehaviour {
//-------------------------------
//-------功能: 音轨管理器脚本
//-------创建者:
//------------------------------
RhythmGameController gameController;
[Tooltip("此音轨使用的键盘按键")]
public KeyCode keyboardButton;
[Tooltip("此音轨对应事件的编号")]
public int laneID;
//对“目标”位置的键盘按下的视觉效果
public Transform targetVisuals;
//上下边界
public Transform targetTopTrans;
public Transform targetBottomTrans;
//包含在此音轨中的所有事件列表
List<KoreographyEvent> laneEvents = new List<KoreographyEvent>();
//包含此音轨当前活动的所有音符对象的队列
Queue<NoteObject> trackedNotes = new Queue<NoteObject>();
//检测此音轨中的生成的下一个事件的索引
int pendingEventIdx = 0;
public GameObject downVisual;
//音符移动的目标位置
public Vector3 TargetPosition
{
get
{
return transform.position;
}
}
public bool hasLongNote;
public float timeVal = 0;
public GameObject longNoteHitEffectGo;
// Update is called once per frame
void Update() {
if (gameController.isPauseState)
{
return;
}
//清除无效音符
while (trackedNotes.Count>0&&trackedNotes.Peek().IsNoteMissed())
{
if (trackedNotes.Peek().isLongNoteEnd)
{
hasLongNote = false;
timeVal = 0;
downVisual.SetActive(false);
longNoteHitEffectGo.SetActive(false);
}
gameController.comboNum = 0;
gameController.HideComboNumText();
gameController.ChangeHitLevelSprite(0);
gameController.UpdateHP();
trackedNotes.Dequeue();
}
//检测新音符的产生
CheckSpawnNext();
//检测玩家的输入
if (Input.GetKeyDown(keyboardButton))
{
CheckNoteHit();
downVisual.SetActive(true);
}
else if (Input.GetKey(keyboardButton))
{
//检测长音符
if (hasLongNote)
{
if (timeVal>=0.15f)
{
//显示命中等级(Great Perfect)
if (!longNoteHitEffectGo.activeSelf)
{
gameController.ChangeHitLevelSprite(2);
CreateHitLongEffect();
}
timeVal = 0;
}
else
{
timeVal += Time.deltaTime;
}
}
}
else if (Input.GetKeyUp(keyboardButton))
{
downVisual.SetActive(false);
//检测长音符
if (hasLongNote)
{
longNoteHitEffectGo.SetActive(false);
CheckNoteHit();
}
}
}
//初始化
public void Initialize(RhythmGameController controller)
{
gameController = controller;
}
//检测事件是否匹配当前编号的音轨
public bool DoesMatch(int noteID)
{
return noteID == laneID;
}
//如果匹配,则把当前事件添加进音轨所持有的事件列表
public void AddEventToLane(KoreographyEvent evt)
{
laneEvents.Add(evt);
}
//音符在音谱上产生的位置偏移量
int GetSpawnSampleOffset()
{
//出生位置与目标点的位置
float spawnDistToTarget = targetTopTrans.position.z - transform.position.z;
//到达目标点的时间
float spawnPosToTargetTime = spawnDistToTarget / gameController.noteSpeed;
return (int)spawnPosToTargetTime * gameController.SampleRate;
}
//检测是否生成下一个新音符
void CheckSpawnNext()
{
int samplesToTarget = GetSpawnSampleOffset();
int currentTime = gameController.DelayedSampleTime;
while (pendingEventIdx < laneEvents.Count
&& laneEvents[pendingEventIdx].StartSample < currentTime + samplesToTarget)
{
KoreographyEvent evt = laneEvents[pendingEventIdx];
int noteNum = evt.GetIntValue();
NoteObject newObj = gameController.GetFreshNoteObject();
bool isLongNoteStart = false;
bool isLongNoteEnd = false;
if (noteNum > 6)
{
isLongNoteStart = true;
noteNum = noteNum - 6;
if (noteNum > 6)
{
isLongNoteEnd = true;
isLongNoteStart = false;
noteNum = noteNum - 6;
}
}
newObj.Initialize(evt, noteNum, this, gameController, isLongNoteStart, isLongNoteEnd);
trackedNotes.Enqueue(newObj);
pendingEventIdx++;
}
}
/// <summary>
/// 生成特效的有关方法
/// </summary>
void CreateDownEffect()
{
GameObject downEffectGo = gameController.GetFreshEffectObject(gameController.downEffectObjectPool, gameController.downEffectGo);
downEffectGo.transform.position = targetVisuals.position;
}
void CreateHitEffect()
{
GameObject hitEffectGo = gameController.GetFreshEffectObject(gameController.hitEffectObjectPool, gameController.hitEffectGo);
hitEffectGo.transform.position = targetVisuals.position;
}
void CreateHitLongEffect()
{
longNoteHitEffectGo.SetActive(true);
longNoteHitEffectGo.transform.position = targetVisuals.position;
}
//检测是否有击中音符对象
//如果是,它将执行命中并删除
public void CheckNoteHit()
{
if (!gameController.gameStart)
{
CreateDownEffect();
return;
}
if (trackedNotes.Count>0)
{
NoteObject noteObject = trackedNotes.Peek();
if (noteObject.hitOffset>-6000)
{
trackedNotes.Dequeue();
int hitLevel= noteObject.IsNoteHittable();
gameController.ChangeHitLevelSprite(hitLevel);
if (hitLevel>0)
{
//更新分数
gameController.UpdateScoreText(100 * hitLevel);
if (noteObject.isLongNote)
{
hasLongNote = true;
CreateHitLongEffect();
}
else if (noteObject.isLongNoteEnd)
{
hasLongNote = false;
}
else
{
CreateHitEffect();
}
//增加连接数
gameController.comboNum++;
}
else
{
//未击中
//减少玩家HP
gameController.UpdateHP();
//断掉玩家命中连接数
gameController.HideComboNumText();
gameController.comboNum = 0;
}
noteObject.OnHit();
}
else
{
CreateDownEffect();
}
}
else
{
CreateDownEffect();
}
}
}
面板启动器
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//-------------------------------------
//—————————————————————————————————————
//___________项目:
//___________功能: UI面板启动器
//___________创建者:
//_____________________________________
//-------------------------------------
public class UIContorl : SingletonMono<UIContorl>
{
// Start is called before the first frame update
void Start()
{
UIManager.GetInstance().ShowPanel<BKPanel>("BKPanel"); //先加载背景面板
UIManager.GetInstance().ShowPanel<LoginPanel>("LoginPanel"); //先加载开始登陆面板
// DataContorl.GetInstance().LoadServerData(); //加载所有区服数据到数据管理器中
Debug.Log(Application.persistentDataPath);
}
/// <summary>
/// 提供改变提示面板内容的方法并显示
/// </summary>
/// <param name="component"></param>
public void ChangeTipPanel(string component)
{
UIManager.GetInstance().ShowPanel<TipPanel>("TipPanel", E_UI_Layer.Top, (panel) =>
{
panel.ChangComponent(component);
});
}
}
⭐🅰️⭐
⭐【Unityc#专题篇】之c#进阶篇】
⭐【Unityc#专题篇】之c#核心篇】
⭐【Unityc#专题篇】之c#基础篇】
⭐【Unity-c#专题篇】之c#入门篇】
⭐【Unityc#专题篇】—进阶章题单实践练习
⭐【Unityc#专题篇】—基础章题单实践练习
⭐【Unityc#专题篇】—核心章题单实践练习
你们的点赞👍 收藏⭐ 留言📝 关注✅是我持续创作,输出优质内容的最大动力!、