当前位置: 首页 > news >正文

【Unitydemo制作】音游制作—控制器与特效

在这里插入图片描述


👨‍💻个人主页:@元宇宙-秩沅

👨‍💻 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 framevoid 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{//未击中//减少玩家HPgameController.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 updatevoid 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#专题篇】—核心章题单实践练习


你们的点赞👍 收藏⭐ 留言📝 关注✅是我持续创作,输出优质内容的最大动力!


在这里插入图片描述


http://www.lryc.cn/news/351781.html

相关文章:

  • [程序员] 最近的感悟,错误处理占大头?
  • vue3(一) - 结构认识
  • 数据库迁移——kettle开发01
  • Netty: Netty中的组件
  • Julia编程01:Julia语言介绍
  • 二叉树顺序结构及链式结构
  • 【Python】pandas连续变量分箱
  • Qt 打卡小程序总结
  • 【qt】标准项模型
  • 一文深度剖析 ColBERT
  • css左右滚动互不影响
  • 【linux-uboot移植-mmc及tftp启动-IMX6ULL】
  • Python-温故知新
  • 绿联NAS DXP系列发布:内网穿透技术在私有云的应用分析
  • 力扣:242. 有效的字母异位词
  • 设计模式14——组合模式
  • MyBatis面试题(Mybaits的优点、缺点、适用场合、与Hibernate有哪些不同)
  • python写接口性能测试
  • 《暮色将尽》跨越世纪的历程,慢慢走向并完善自我
  • python-鸡兔同笼问题:已知鸡和兔的总头数与总脚数。求笼中鸡和兔各几只?
  • 【NumPy】关于numpy.transpose()函数,看这一篇文章就够了
  • 什么是住宅IP代理?为什么需要家庭 IP 代理
  • Java方法的重载
  • RabbitMQ 消息队列安装及入门
  • K8S认证|CKA题库+答案| 14. 排查故障节点
  • Linux:网络管理命令之ss
  • 数据结构-队列(带图详解)
  • python文件名通常以什么结尾
  • 前端javascript 中 JSON.parse() 的作用
  • 【Linux学习】进程基础API