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


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


在这里插入图片描述


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/592798.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

大语言模型教程与实践(开源)

1.简介 大语言模型&#xff08;Large Language Models, LLMs&#xff09;的兴起确实始于OpenAI在2018年发布的GPT&#xff08;Generative Pre-trained Transformer&#xff09;&#xff0c;这一开创性工作引领了自然语言处理领域的新纪元。随后&#xff0c;2022年底ChatGPT的横…

基于Spring Boot的在线BLOG网设计与实现

基于Spring Boot的在线BLOG网设计与实现 开发语言&#xff1a;Java框架&#xff1a;springbootJDK版本&#xff1a;JDK1.8数据库工具&#xff1a;Navicat11开发软件&#xff1a;eclipse/myeclipse/idea 系统部分展示 前台首页管理界面&#xff0c;用户经过登录前台首页查看通…

SQL Server 存储过程中的字符串本身包含单引号的用法

文章目录 引言I 存储过程中的字符串本身包含单引号的用法1.1 问题1.2解决方法引言 使用场景: 字符串类型字段的值比较 I 存储过程中的字符串本身包含单引号的用法 在SQL Server中,单引号用于表示字符串常量。如果你的存储过程中的字符串本身包含单引号,你需要用两个连续的…

3.2Java全栈开发前端+后端(全栈工程师进阶之路)-前端框架VUE3框架-企业级应用- Vuex

Vuex简介 Vuex概述 Vuex是一个专门为Vue.js应用程序开发的状态管理模式, 它采用集中式存储管理所有组件的公共状态, 并以相应的规 则保证状态以一种可预测的方式发生变化. 试想这样的场景, 比如一个Vue的根实例下面有一个根组件名为App.vue, 它下面有两个子组件A.vue和B.vu…

【C++】文件

目录 文件文件分类文本文件的读写(ASCII文件)的读写打开文件打开文件的方式关闭文件将数据写入ASCII文件从ASCII文件读入数据 二进制存储对比ASCII和二进制存储用成员函数read和write读写二进制文件打开方式文件的读入与读出 文件 所谓文件&#xff0c;一般指存储在外部介质上…

【k8s】利用Kubeadm搭建k8s1.29.x版本+containerd

文章目录 前言1.准备的三台虚拟机2.安装 kubeadm 前的准备工作3.安装containerd1.解压安装包2.生成默认配置文件3.使用systemd托管containerd4.修改默认配置文件 4.安装runc5.安装 CNI plugins6.安装 kubeadm、kubelet 和 kubectl6.1 配置crictl 7.初始化集群1.打印初始化配置到…

DETR类型检测网络---思考和Tricks测试

目录 batch_size的影响辅助损失的作用学习率的影响Decoder层数增多的影响3D检测中, feats位置编码和query位置编码是否共享mpl层背景-关于query的生成方式 利用widthformer类似的方式简化注意力机制 batch_size的影响 batch8: batch20: 由实验结果可知:这里实验有问题,横坐标…

堆栈打印跟踪Activity的启动过程(基于Android10.0.0-r41),framework修改,去除第三方app的倒计时页面

文章目录 堆栈打印跟踪Activity的启动过程(基于Android10.0.0-r41)&#xff0c;framework修改&#xff0c;去除第三方app的倒计时页面1.打印异常堆栈2.去除第三方app的倒计时页面3.模拟点击事件跳过首页进入主页 堆栈打印跟踪Activity的启动过程(基于Android10.0.0-r41)&#x…

C语言 | Leetcode C语言题解之第67题二进制求和

题目&#xff1a; 题解&#xff1a; void reserve(char* s) {int len strlen(s);for (int i 0; i < len / 2; i) {char t s[i];s[i] s[len - i - 1], s[len - i - 1] t;} }char* addBinary(char* a, char* b) {reserve(a);reserve(b);int len_a strlen(a), len_b st…

2024全域数字化转型评估模型研究报告

来源&#xff1a;伏羲智库&腾讯智慧零售 智慧零售逐渐成为发展趋势 随着技术突破、商业创新和监管制度的发展演进,零售业数字化转型的内涵随实践延展而不断丰富,智慧零售逐渐成为零售业数字化转型的新趋势。 在技术层面,零售业数字化转型呈现出三大变化与趋势: 一是数字技…

能将图片转为WebP格式的WebP Server Go

本文完成于 2023 年 11 月 之前老苏介绍过 webp2jpg-online&#xff0c;可以将 webp 格式的图片&#xff0c;转为 jpg 等&#xff0c;今天介绍的 WebP Server Go 是将 jpg 等转为 webp 格式 文章传送门&#xff1a;多功能图片转换器webp2jpg-online 什么是 WebP ? WebP 它是由…

多多搜索在哪里找到

拼多多推广可以使用3an推客。3an推客&#xff08;CPS模式&#xff09;给商家提供的营销工具&#xff0c;由商家自主设置佣金比例&#xff0c;激励推广者去帮助商家推广商品链接&#xff0c;按最终有效交易金额支付佣金&#xff0c;不成交不扣费。是商家破零、积累基础销量的重要…

OpenHarmony实战开发-使用通用事件、焦点事件

基本概念 焦点 指向当前应用界面上唯一的一个可交互元素&#xff0c;当用户使用键盘、电视遥控器、车机摇杆/旋钮等非指向性输入设备与应用程序进行间接交互时&#xff0c;基于焦点的导航和交互是重要的输入手段。 默认焦点 应用打开或切换页面后&#xff0c;若当前页上存在…

缤纷成长:儿童换牙顺序解析与注意事项

引言&#xff1a; 儿童的换牙过程是成长中的一个重要阶段&#xff0c;但每个孩子的换牙顺序可能会有所不同。本文将详细解析儿童换牙的顺序&#xff0c;并提供换牙期间的注意事项&#xff0c;助您更好地理解孩子的口腔健康&#xff0c;并为他们提供正确的护理与关爱。 1. 换牙顺…

【开发记录】青龙面板设置飞书机器人

接上篇文章&#xff0c;笔者在写上篇文章时对青龙面板的消息通知功能感兴趣&#xff0c;遂实验之&#xff0c;于是有了这篇文章。 首先参考这篇文章在群聊中引入一个机器人&#xff0c;此时可以获得该机器人的webhook。在青龙面板的通知设置中有larkKey一项&#xff0c;填入web…

【idea-sprongboot项目】在linux服务器上纯远程开发方式

继上一篇博客【idea-sprongboot项目】SSH连接云服务器进行远程开发-CSDN博客 目录 五、远程开发方式 2&#xff09;纯远程开发方式 步骤 五、远程开发方式 2&#xff09;纯远程开发方式 实现原理&#xff0c; 步骤 &#xff08;1&#xff09;首先&#xff0c;关闭当前正在…

Java17 --- SpringCloud之Zipkin链路追踪

目录 一、下载zipkin及运行 二、在父工程中引入pom依赖 三、在子工程8001引入相关pom依赖 3.1、修改yml配置文件 3.2、测试代码 四、在子工程80引入相关pom依赖 4.1、修改yml配置文件 4.2、测试代码 五、测试结果 一、下载zipkin及运行 运行控制台访问地址&#xff1…

Java之LinkedHashMap

系列文章目录 文章目录 系列文章目录前言前言 前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到网站,这篇文章男女通用,看懂了就去分享给你的码吧。 LinkedHashMap是Map接口的哈希表和链接列表实现,具有可预知的迭代顺序。…

「C++ STL篇 1-0」string类的使用

目录 〇、概念 一、string类的构造函数 二、赋值运算符重载 三、有关容量的操作 四、string对象的访问 五、遍历string对象的字符数组 六、string对象的修改 七、string对象的常用操作 八、字符串和数字间的转换 拓展】 练习】 源代码】 〇、概念 1. string类是什么&#xff1…
最新文章