【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

相关文章

深度解析Java项目中包和包之间的联系

《深度解析Java项目中包和包之间的联系》文章浏览阅读850次,点赞13次,收藏8次。本文详细介绍了Java分层架构中的几个关键包:DTO、Controller、Service和Mapper。_jav... 目录前言一、各大包1.DTO1.1、DTO的核心用途1.2. DTO与实体类(Entity)的区别1

如何在Spring Boot项目中集成MQTT协议

《如何在SpringBoot项目中集成MQTT协议》本文介绍在SpringBoot中集成MQTT的步骤,包括安装Broker、添加EclipsePaho依赖、配置连接参数、实现消息发布订阅、测试接口... 目录1. 准备工作2. 引入依赖3. 配置MQTT连接4. 创建MQTT配置类5. 实现消息发布与订阅

springboot项目打jar制作成镜像并指定配置文件位置方式

《springboot项目打jar制作成镜像并指定配置文件位置方式》:本文主要介绍springboot项目打jar制作成镜像并指定配置文件位置方式,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录一、上传jar到服务器二、编写dockerfile三、新建对应配置文件所存放的数据卷目录四、将配置文

怎么用idea创建一个SpringBoot项目

《怎么用idea创建一个SpringBoot项目》本文介绍了在IDEA中创建SpringBoot项目的步骤,包括环境准备(JDK1.8+、Maven3.2.5+)、使用SpringInitializr... 目录如何在idea中创建一个SpringBoot项目环境准备1.1打开IDEA,点击New新建一个项

springboot项目中整合高德地图的实践

《springboot项目中整合高德地图的实践》:本文主要介绍springboot项目中整合高德地图的实践,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一:高德开放平台的使用二:创建数据库(我是用的是mysql)三:Springboot所需的依赖(根据你的需求再

一文详解如何在idea中快速搭建一个Spring Boot项目

《一文详解如何在idea中快速搭建一个SpringBoot项目》IntelliJIDEA作为Java开发者的‌首选IDE‌,深度集成SpringBoot支持,可一键生成项目骨架、智能配置依赖,这篇文... 目录前言1、创建项目名称2、勾选需要的依赖3、在setting中检查maven4、编写数据源5、开启热

Python实例题之pygame开发打飞机游戏实例代码

《Python实例题之pygame开发打飞机游戏实例代码》对于python的学习者,能够写出一个飞机大战的程序代码,是不是感觉到非常的开心,:本文主要介绍Python实例题之pygame开发打飞机... 目录题目pygame-aircraft-game使用 Pygame 开发的打飞机游戏脚本代码解释初始化部

SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志

《SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志》在SpringBoot项目中,使用logback-spring.xml配置屏蔽特定路径的日志有两种常用方式,文中的... 目录方案一:基础配置(直接关闭目标路径日志)方案二:结合 Spring Profile 按环境屏蔽关

CSS3中的字体及相关属性详解

《CSS3中的字体及相关属性详解》:本文主要介绍了CSS3中的字体及相关属性,详细内容请阅读本文,希望能对你有所帮助... 字体网页字体的三个来源:用户机器上安装的字体,放心使用。保存在第三方网站上的字体,例如Typekit和Google,可以link标签链接到你的页面上。保存在你自己Web服务器上的字

MySQL版本问题导致项目无法启动问题的解决方案

《MySQL版本问题导致项目无法启动问题的解决方案》本文记录了一次因MySQL版本不一致导致项目启动失败的经历,详细解析了连接错误的原因,并提供了两种解决方案:调整连接字符串禁用SSL或统一MySQL... 目录本地项目启动报错报错原因:解决方案第一个:第二种:容器启动mysql的坑两种修改时区的方法:本地