【UnityRPG游戏制作】Unity_RPG项目_玩法相关

2024-05-05 22:44

本文主要是介绍【UnityRPG游戏制作】Unity_RPG项目_玩法相关,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在这里插入图片描述


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

👨‍💻 hallo 欢迎 点赞👍 收藏⭐ 留言📝 加关注✅!

👨‍💻 本文由 秩沅 原创
👨‍💻 收录于专栏:就业宝典

🅰️推荐专栏

⭐-软件设计师高频考点大全



文章目录

    • 前言
    • 🎶(==四==) 玩法相关
    • (==1==) 面板显隐命令
    • (==2==) 玩家升级命令
    • (==3==) 玩家受伤命令
    • (==4==) 经验升级命令
    • (==5==) 武器和伤害命令
    • 🅰️


前言

请添加图片描述


🎶( 玩法相关


在这里插入图片描述


1 面板显隐命令


using PureMVC.Interfaces;
using PureMVC.Patterns.Command;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;//-------------------------------
//-------功能:  面板隐藏命令
//-------创建者:         
//------------------------------public class HidePanelCommand : SimpleCommand
{public override void Execute(INotification notification){base.Execute(notification);Debug.Log("隐藏面板的命令开始执行");string panelName = notification.Body.ToString();//Debug.Log(panelName);SelectPanel(panelName);}/// <summary>/// 封装选择需要执行的面板/// </summary>/// <param name="panelName"></param>private void SelectPanel(string panelName){//面板命令的选择switch (panelName){case "BackpackPanel":Debug.Log("命令为BackpackPanel");if (!Facade.HasMediator(BackpackViewMediator.NAME))  //首先判断是否有该中介,没有就new一个{Facade.RegisterMediator(new BackpackViewMediator()); //注册该视图中介}//获取视图对应的中介BackpackViewMediator bm = Facade.RetrieveMediator(BackpackViewMediator.NAME) as BackpackViewMediator;if (bm.ViewComponent != null) //当对应的视图中介有关联界面面板时 {//通过UI管理器隐藏面板UIManager.GetInstance().HidePanel("BackpackPanel");}break;case "DefeatPanel":Debug.Log("命令为DefeatPanel");if (!Facade.HasMediator(DefeatViewMediator.NAME))  //首先判断是否有该中介,没有就new一个{Facade.RegisterMediator(new DefeatViewMediator()); //注册该视图中介}//获取视图对应的中介DefeatViewMediator dm = Facade.RetrieveMediator(DefeatViewMediator.NAME) as DefeatViewMediator;if (dm.ViewComponent != null) //当对应的视图中介有关联界面面板时 {          //通过UI管理器隐藏面板UIManager.GetInstance().HidePanel("DefeatPanel");          }break;case "GamePanel":Debug.Log("GamePanel");if (!Facade.HasMediator(GameViewMediator.NAME))  //首先判断是否有该中介,没有就new一个{Facade.RegisterMediator(new GameViewMediator()); //注册该视图中介}//获取视图对应的中介GameViewMediator gm = Facade.RetrieveMediator(GameViewMediator.NAME) as GameViewMediator;if (gm.ViewComponent != null) //当对应的视图中介有关联界面面板时 {//通过UI管理器隐藏面板UIManager.GetInstance().HidePanel("GamePanel");}break;case "NPCTipPanel":Debug.Log("NPCTipPanel");if (!Facade.HasMediator(NPCTipViewMediator.NAME))  //首先判断是否有该中介,没有就new一个{Facade.RegisterMediator(new NPCTipViewMediator()); //注册该视图中介}//获取视图对应的中介NPCTipViewMediator nm = Facade.RetrieveMediator(NPCTipViewMediator.NAME) as NPCTipViewMediator;if (nm.ViewComponent != null) //当对应的视图中介有关联界面面板时 {//通过UI管理器隐藏面板UIManager.GetInstance().HidePanel("NPCTipPanel");}break;case "RolePanel":Debug.Log("命令为RolePanel");if (!Facade.HasMediator(RoleViewMediator.NAME))  //首先判断是否有该中介,没有就new一个{Facade.RegisterMediator(new RoleViewMediator()); //注册该视图中介}//获取视图对应的中介RoleViewMediator rm = Facade.RetrieveMediator(RoleViewMediator.NAME) as RoleViewMediator;if (rm.ViewComponent != null) //当对应的视图中介有关联界面面板时 {//通过UI管理器隐藏面板UIManager.GetInstance().HidePanel("RolePanel");}break;case "StartPanel":Debug.Log("StartPanel");if (!Facade.HasMediator(StartViewMediator.NAME))  //首先判断是否有该中介,没有就new一个{Facade.RegisterMediator(new StartViewMediator()); //注册该视图中介}//获取视图对应的中介StartViewMediator sm = Facade.RetrieveMediator(StartViewMediator.NAME) as StartViewMediator;if (sm.ViewComponent != null) //当对应的视图中介有关联界面面板时 {//通过UI管理器隐藏面板UIManager.GetInstance().HidePanel("StartPanel");}break;case "StartTipPanel":Debug.Log("StartTipPanel");if (!Facade.HasMediator(StartTipViewMediator.NAME))  //首先判断是否有该中介,没有就new一个{Facade.RegisterMediator(new StartTipViewMediator()); //注册该视图中介}//获取视图对应的中介StartTipViewMediator stm = Facade.RetrieveMediator(StartTipViewMediator.NAME) as StartTipViewMediator;if (stm.ViewComponent != null) //当对应的视图中介有关联界面面板时 {//通过UI管理器隐藏面板UIManager.GetInstance().HidePanel("StartTipPanel");}break;case "StatePanel":Debug.Log("命令为StatePanel");if (!Facade.HasMediator(StateViewMediator.NAME))  //首先判断是否有该中介,没有就new一个{Facade.RegisterMediator(new StateViewMediator()); //注册该视图中介}//获取视图对应的中介StateViewMediator mm = Facade.RetrieveMediator(StateViewMediator.NAME) as StateViewMediator;if (mm.ViewComponent != null) //当对应的视图中介有关联界面面板时 {//通过UI管理器隐藏面板UIManager.GetInstance().HidePanel("StatePanel");}break;}}
}

2 玩家升级命令


请添加图片描述

using PureMVC.Interfaces;
using PureMVC.Patterns.Command;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;//-------------------------------
//-------功能:  玩家升级通知
//-------创建者:         
//------------------------------public class LevelUpCommand : SimpleCommand
{public override void Execute(INotification notification){base.Execute(notification);PlayerProxy playerProxy =  Facade.RetrieveProxy(PlayerProxy.NAME) as PlayerProxy ;if (playerProxy != null){playerProxy.LevUp (); //自己将数据升级playerProxy.SavaUp(); //数据保存SendNotification(PureNotification.UPDATA_ROLE_INFO, playerProxy.Data as PlayerDataObj) ; //发送角色信息更新通知}}
}

3 玩家受伤命令


  • 血条减少,玩家数据更新
  • 观察者模式
    请添加图片描述

请添加图片描述

using PureMVC.Interfaces;
using PureMVC.Patterns.Command;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;//-------------------------------
//-------功能: 受伤命令
//-------创建者:         -------
//------------------------------public class HurtCommand : SimpleCommand
{public override void Execute(INotification notification){base.Execute(notification);Debug.Log("玩家受伤的命令开始执行");PlayerProxy playerProxy = Facade.RetrieveProxy(PlayerProxy.NAME) as PlayerProxy;if (playerProxy != null){playerProxy.LevUp(); //自己将数据升级playerProxy.SavaUp(); //数据保存SendNotification(PureNotification.UPDATA_ROLE_INFO, playerProxy.Data as PlayerDataObj); //发送角色信息更新通知SendNotification(PureNotification.PLAYER_INJURY, notification.Body);}}
}
using PureMVC.Interfaces;
using PureMVC.Patterns.Mediator;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;//-------------------------------
//-------功能:  角色面板视图中介
//-------创建者:         -------
//------------------------------/// <summary>
/// 角色面板视图中介
/// 固定:
/// 1.继承PureMVC的Mediator脚本
/// 2.写构造函数
/// 3.重写监听通知的方法
/// 4.重写处理通知的方法
/// 5.可选:重写注册时的方法
/// </summary>
public class RoleViewMediator : Mediator
{//铭牌名public static string NAME = "RoleViewMediator";/// <summary>/// 构造函数/// </summary>public RoleViewMediator( ) : base(NAME){//可以去写创捷面板预设体的逻辑等}/// <summary>/// 重写监听通知的方法,返回需要的监听(通知)/// </summary>/// <returns>返回你需要监听的通知的名字数组</returns>public  override string[] ListNotificationInterests(){return new string[] { PureNotification.UPDATA_ROLE_INFO};}public void SetView(RoleView roleView){Debug.Log(roleView + "执行SetView");ViewComponent = roleView;//开始按钮逻辑监听roleView.back.onClick.AddListener(() =>{SendNotification(PureNotification.HIDE_PANEL, "RolePanel");});}/// <summary>/// 重写处理通知的方法,处理通知/// </summary>/// <param name="notification">通知</param>public override void HandleNotification(INotification notification){switch (notification.Name){case  PureNotification.UPDATA_ROLE_INFO:if (ViewComponent != null)          (ViewComponent as RoleView).UpdateView(notification.Body as PlayerDataObj);else   {Debug.Log("为空");  }break;}}/// <summary>/// 可选:重写注册方法(他们需要到Facde中注册)/// </summary>public override void OnRegister(){base.OnRegister();}}

4 经验升级命令


using PureMVC.Interfaces;
using PureMVC.Patterns.Command;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;//-------------------------------
//-------功能:  經驗更新命令-------
//-------创建者:         -------
//------------------------------public class EXPUpCommand : SimpleCommand
{public override void Execute(INotification notification){base.Execute(notification);SendNotification(PureNotification.UPDATA_EXP ,notification .Body);  //发送更新经验血条的通知}
}
using PureMVC.Interfaces;
using PureMVC.Patterns.Command;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;//-------------------------------
//-------功能:玩家升级通知
//-------创建者:         
//------------------------------public class LevelUpCommand : SimpleCommand
{public override void Execute(INotification notification){base.Execute(notification);PlayerProxy playerProxy =  Facade.RetrieveProxy(PlayerProxy.NAME) as PlayerProxy ;if (playerProxy != null){playerProxy.LevUp (); //自己将数据升级playerProxy.SavaUp(); //数据保存SendNotification(PureNotification.UPDATA_ROLE_INFO, playerProxy.Data as PlayerDataObj) ; //发送角色信息更新通知}     }
}

5 武器和伤害命令


using PureMVC.Interfaces;
using PureMVC.Patterns.Command;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;//-------------------------------
//-------功能:更换武器图标的命令
//-------创建者:         -------
//------------------------------public class WeaponUpCommand : SimpleCommand
{public override void Execute(INotification notification){base.Execute(notification);//先将玩家数据中更新武器信息PlayerDataObj playerProxy = Facade.RetrieveProxy(PlayerProxy.NAME).Data  as PlayerDataObj ;playerProxy.nowItem = notification.Body as Sprite;//playerProxy.item[playerProxy.index] = notification.Body as Sprite;//到时打开role面板时会自动更新数据//  (playerProxy.Data as PlayerDataObj).nowItem = notification.Body as Sprite;//而后发送武器更新的通知——目的是更新State面板中的武器信息SendNotification(PureNotification.UPDATA_WEAPON_INFO2, notification.Body );}
}
using PureMVC.Interfaces;
using PureMVC.Patterns.Command;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;//-------------------------------
//-------功能: 受伤命令
//-------创建者:         -------
//------------------------------public class HurtCommand : SimpleCommand
{public override void Execute(INotification notification){base.Execute(notification);Debug.Log("玩家受伤的命令开始执行");PlayerProxy playerProxy = Facade.RetrieveProxy(PlayerProxy.NAME) as PlayerProxy;if (playerProxy != null){//playerProxy.LevUp(); //自己将数据升级// playerProxy.SavaUp(); //数据保存SendNotification(PureNotification.UPDATA_ROLE_INFO, playerProxy.Data as PlayerDataObj); //发送角色信息更新通知SendNotification(PureNotification.PLAYER_INJURY, notification.Body);}}
}

🅰️


⭐【Unityc#专题篇】之c#进阶篇】

⭐【Unityc#专题篇】之c#核心篇】

⭐【Unityc#专题篇】之c#基础篇】

⭐【Unity-c#专题篇】之c#入门篇】

【Unityc#专题篇】—进阶章题单实践练习

⭐【Unityc#专题篇】—基础章题单实践练习

【Unityc#专题篇】—核心章题单实践练习


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


在这里插入图片描述


这篇关于【UnityRPG游戏制作】Unity_RPG项目_玩法相关的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/962860

相关文章

SpringBoot项目启动错误:找不到或无法加载主类的几种解决方法

《SpringBoot项目启动错误:找不到或无法加载主类的几种解决方法》本文主要介绍了SpringBoot项目启动错误:找不到或无法加载主类的几种解决方法,具有一定的参考价值,感兴趣的可以了解一下... 目录方法1:更改IDE配置方法2:在Eclipse中清理项目方法3:使用Maven命令行在开发Sprin

Nginx实现高并发的项目实践

《Nginx实现高并发的项目实践》本文主要介绍了Nginx实现高并发的项目实践,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录使用最新稳定版本的Nginx合理配置工作进程(workers)配置工作进程连接数(worker_co

Vue项目的甘特图组件之dhtmlx-gantt使用教程和实现效果展示(推荐)

《Vue项目的甘特图组件之dhtmlx-gantt使用教程和实现效果展示(推荐)》文章介绍了如何使用dhtmlx-gantt组件来实现公司的甘特图需求,并提供了一个简单的Vue组件示例,文章还分享了一... 目录一、首先 npm 安装插件二、创建一个vue组件三、业务页面内 引用自定义组件:四、dhtmlx

SpringBoot项目注入 traceId 追踪整个请求的日志链路(过程详解)

《SpringBoot项目注入traceId追踪整个请求的日志链路(过程详解)》本文介绍了如何在单体SpringBoot项目中通过手动实现过滤器或拦截器来注入traceId,以追踪整个请求的日志链... SpringBoot项目注入 traceId 来追踪整个请求的日志链路,有了 traceId, 我们在排

部署Vue项目到服务器后404错误的原因及解决方案

《部署Vue项目到服务器后404错误的原因及解决方案》文章介绍了Vue项目部署步骤以及404错误的解决方案,部署步骤包括构建项目、上传文件、配置Web服务器、重启Nginx和访问域名,404错误通常是... 目录一、vue项目部署步骤二、404错误原因及解决方案错误场景原因分析解决方案一、Vue项目部署步骤

golang内存对齐的项目实践

《golang内存对齐的项目实践》本文主要介绍了golang内存对齐的项目实践,内存对齐不仅有助于提高内存访问效率,还确保了与硬件接口的兼容性,是Go语言编程中不可忽视的重要优化手段,下面就来介绍一下... 目录一、结构体中的字段顺序与内存对齐二、内存对齐的原理与规则三、调整结构体字段顺序优化内存对齐四、内

配置springboot项目动静分离打包分离lib方式

《配置springboot项目动静分离打包分离lib方式》本文介绍了如何将SpringBoot工程中的静态资源和配置文件分离出来,以减少jar包大小,方便修改配置文件,通过在jar包同级目录创建co... 目录前言1、分离配置文件原理2、pom文件配置3、使用package命令打包4、总结前言默认情况下,

python实现简易SSL的项目实践

《python实现简易SSL的项目实践》本文主要介绍了python实现简易SSL的项目实践,包括CA.py、server.py和client.py三个模块,文中通过示例代码介绍的非常详细,对大家的学习... 目录运行环境运行前准备程序实现与流程说明运行截图代码CA.pyclient.pyserver.py参

IDEA运行spring项目时,控制台未出现的解决方案

《IDEA运行spring项目时,控制台未出现的解决方案》文章总结了在使用IDEA运行代码时,控制台未出现的问题和解决方案,问题可能是由于点击图标或重启IDEA后控制台仍未显示,解决方案提供了解决方法... 目录问题分析解决方案总结问题js使用IDEA,点击运行按钮,运行结束,但控制台未出现http://

解决IDEA使用springBoot创建项目,lombok标注实体类后编译无报错,但是运行时报错问题

《解决IDEA使用springBoot创建项目,lombok标注实体类后编译无报错,但是运行时报错问题》文章详细描述了在使用lombok的@Data注解标注实体类时遇到编译无误但运行时报错的问题,分析... 目录问题分析问题解决方案步骤一步骤二步骤三总结问题使用lombok注解@Data标注实体类,编译时