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

embedded/2024/9/23 6:24:09/

在这里插入图片描述


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

👨‍💻 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#专题篇】—核心章题单实践练习


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


在这里插入图片描述



http://www.ppmy.cn/embedded/32695.html

相关文章

netbeans中add server instance界面为什么让创建一个user

在NetBeans中&#xff0c;“Add Server Instance”&#xff08;添加服务器实例&#xff09;界面要求创建一个用户&#xff0c;是为了配置服务器实例的运行环境和访问权限。 创建一个用户是为了确保服务器实例能够以安全的方式运行&#xff0c;并限制对服务器的访问。通过创建一…

redis保存数据的结构-redisobject结构体

在redis中&#xff0c;所有键值对的保存&#xff0c;都是机遇redisboject的一个结构体&#xff0c;如下 typedef struct redisObject {unsigned type:4; unsigned encoding:4; unsigned lru:LRU_BITS; int refcount; void *ptr; …

spring boot “error“: “Not Found“

标题spring boot “error”: “Not Found” {"timestamp": "2024-05-04T07:26:21.15000:00","status": 404,"error": "Not Found","path": "/user/register" }出现以上这个提示可能是如下原因 查看在…

【已解决】VSCode 连接远程 Ubuntu :检测到 #include 错误。请更新 includePath。

文章目录 1. 环境声明2. 解决过程 1. 环境声明 即使是同一个报错&#xff0c;在不同的环境中&#xff0c;报错原因、解决方法都是不同的&#xff0c;本文只能解决跟我类似的问题&#xff0c;如果你发现你跟我遇到的问题不太一样&#xff0c;建议寻找其他解法。 必须要吐槽的是…

微软如何打造数字零售力航母系列科普09 - 什么是Dynamics 365 Customer Insight 以及如何使用它?

什么是Dynamics 365 Customer Insight(客户见解)以及如何使用它? 新的Dynamics 365 Customer Insights平台在Microsoft Inspire 2023上推出&#xff0c;为CX创新者提供了对组合客户数据平台&#xff08;CDP&#xff09;和旅程编排工具的访问。 更新后的解决方案于2023年9月首…

JVM笔记2--垃圾收集算法

1、如何确认哪些对象“已死” 在上一篇文章中介绍到Java内存运行时的各个区域。其中程序计数器、虚拟机栈、本地方法栈3个区域随着线程而生&#xff0c;随线程而灭&#xff0c;栈中的栈帧随着方法的进入和退出而有条不紊的执行着入栈和出栈操作。每个栈帧中分配多少内存基本上…

微博一级评论爬虫

cookies需要替换成自己的 import requests import requests from lxml import etree import openpyxl from concurrent.futures.thread import ThreadPoolExecutor import re from datetime import datetime, timedelta from urllib import parse from jsonpath import jsonpa…

01-MySQL 基础篇笔记

一、MySQL 概述 1.1 数据库相关概念 数据库&#xff1a;&#xff08;DB&#xff1a;DataBase&#xff09; 存储数据的仓库&#xff0c;数据是有组织的进行存储 数据库管理系统&#xff1a;&#xff08;DBMS&#xff1a;DataBase Management System&#xff09; 操作和管理数…