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

news2024/10/5 17:24:52

在这里插入图片描述


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

👨‍💻 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.coloradmin.cn/o/1643651.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

jvm 马士兵 01 JVM简介,class文件结构

01.JVM是什么 JVM是一个跨平台的标准 JVM只识别class文件&#xff0c;符合JVM规范的class文件都可以被识别 u1 是一个字节 u2是两个字节

正则表达式_字符匹配/可选字符集

正则表达式&#xff08;Regular Expression&#xff09;也叫匹配模式(Pattern)&#xff0c;用来检验字符串是否满足特 定规则&#xff0c;或从字符串中捕获满足特定规则的子串。 字符匹配 最简单的正则表达式由“普通字符”和“通配符”组成。比如“Room\d\d\d”就这样 的正则…

1.pytorch加载收数据(B站小土堆)

数据的加载主要有两个函数&#xff1a; 1.dataset整体收集数据&#xff1a;提供一种方法去获取数据及其label&#xff0c;告诉我们一共有多少数据&#xff08;就是自开始把要的数据和标签都收进来&#xff09; 2.dataloader&#xff0c;后面传入模型时候&#xff0c;每次录入数…

C++类定义时成员变量初始化

在C11中允许在类定义时对成员变量初始化。 class A { public:A() { }void show(){cout << "m_a " << m_a << endl;cout << "m_b " << m_b << endl;} private:int m_a 10;//类定义时初始化int m_b; //没有初始化…

2024阿里云ctf-web-chain17学习

agent jdk17依赖有h2思路清晰打jdbc attack <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/com.aliba…

踏春正当时!VELO Prevail Ride带你探索多元骑行潮流体验~

嘿&#xff0c;朋友&#xff01;踏春正当时嘞&#xff01;在这个追求个性化与多元化的新时代&#xff0c;骑行爱好者们也开始寻找能适应各种骑行场景的理想坐垫。从悠闲自在的日常通勤&#xff0c;到热血沸腾的公路竞速&#xff0c;再到勇攀高峰的山地探险&#xff0c;维乐VELO…

更深层次理解传输层两协议【UDP | TCP】【UDP 缓冲区 | TCP 8种策略 | 三次握手四次挥手】

博客主页&#xff1a;花果山~程序猿-CSDN博客 文章分栏&#xff1a;Linux_花果山~程序猿的博客-CSDN博客 关注我一起学习&#xff0c;一起进步&#xff0c;一起探索编程的无限可能吧&#xff01;让我们一起努力&#xff0c;一起成长&#xff01; 目录 再谈端口号 端口号的返回…

C语言-整体内容简单的认识

目录 一、数据类型的介绍二、数据的变量和常量三、变量的作用域和生命周期四、字符串五、转义字符六、操作符六、常见的关键字6.1 关键字static 七、内存分配八、结构体九、指针 一、数据类型的介绍 sizeof是一个操作符&#xff0c;是计算机类型/变量所占内存空间的大小   sc…

AEC Capital Limited:开启可持续金融新纪元

在当今社会&#xff0c;环保和可持续发展已成为全球关注的焦点。在这个背景下&#xff0c;AEC Capital Limited作为香港的一家金融服务公司&#xff0c;以其专业、高端的服务和创新的理念&#xff0c;成为可持续金融领域的引领者。我们致力于将环境保护与金融服务相结合&#x…

设计模式之拦截过滤器模式

想象一下&#xff0c;在你的Java应用里&#xff0c;每个请求就像一场冒险旅程&#xff0c;途中需要经过层层安检和特殊处理。这时候&#xff0c;拦截过滤器模式就化身为你最可靠的特工团队&#xff0c;悄无声息地为每一个请求保驾护航&#xff0c;确保它们安全、高效地到达目的…

触动精灵纯本地离线文字识别插件

目的 触动精灵是一款可以模拟鼠标和键盘操作的自动化工具。它可以帮助用户自动完成一些重复的、繁琐的任务&#xff0c;节省大量人工操作的时间。但触动精灵的图色功能比较单一&#xff0c;无法识别屏幕上的图像&#xff0c;根据图像的变化自动执行相应的操作。本篇文章主要讲解…

C语言二分查找的区间问题

概念 什么是二分查找呢&#xff1f; 二分查找&#xff1a;在有序数组中查找某一特定元素的搜索算法。 二分查找又称折半查找&#xff0c;通过将数组折半&#xff0c;用中间值和查找值作比较&#xff0c;多次使用&#xff0c;直到找到要查找的值。 注意:二分查找的前提是&#…

内核workqueue框架

workqueue驱动的底半部实现方式之一就是工作队列&#xff0c;作为内核的标准模块&#xff0c;它的使用接口也非常简单&#xff0c;schedule_work或者指定派生到哪个cpu的schedule_work_on。 还有部分场景会使用自定义的workqueue&#xff0c;这种情况会直接调用queue_work和qu…

JavaScript的操作符运算符

前言&#xff1a; JavaScript的运算符与C/C一致 算数运算符&#xff1a; 算数运算符说明加-减*乘%除/取余 递增递减运算符&#xff1a; 运算符说明递增1-- 递减1 补充&#xff1a; 令a1&#xff0c;b1 运算a b ab12ab22ab--10a--b00 比较(关系)运算符&#xff1a; 运算…

服务器端集群优化-集群还是主从

7、服务器端集群优化-集群还是主从 集群虽然具备高可用特性&#xff0c;能实现自动故障恢复&#xff0c;但是如果使用不当&#xff0c;也会存在一些问题&#xff1a; 集群完整性问题集群带宽问题数据倾斜问题客户端性能问题命令的集群兼容性问题lua和事务问题 问题1、在Redi…

[Spring Cloud] (6)gateway整体加解密

文章目录 简述整体效果后端增加配置nacos增加配置GlobalConfig 添加请求整体解密拦截器DecryptionFilter添加响应整体解密拦截器EncryptionFilter 前端请求拦截器添加整体加密逻辑请求头中添加sessionId 响应拦截器添加整体解密逻辑 简述 本文网关gateway&#xff0c;微服务&a…

VsCode插件 -- Power Mode

一、安装插件 1. 首先在扩展市场里搜索 Power Mode 插件&#xff0c;如下图 二、配置插件 设置 点击小齿轮 打上勾 就可以了 第二种设置方法 1. 安装完成之后&#xff0c;使用快捷键 Ctrl Shift P 打开命令面板&#xff0c;在命令行中输入 settings.json &#xff0c; 选择首…

扩展学习|结合故事的力量和数字的力量:混合方法研究和混合研究综述

文献来源&#xff1a;Pluye, Pierre, and Quan Nha Hong. "Combining the power of stories and the power of numbers: mixed methods research and mixed studies reviews." Annual review of public health 35 (2014): 29-45. 文献获取&#xff1a;链接&#xff1…

【机器视觉】yolo-world-opencvsharp-.net4.8 C# 窗体应用程序

这段代码是基于 OpenCvSharp, OpenVinoSharp 和 .NET Framework 4.8 的 Windows Forms 应用程序。其主要目的是加载和编译机器学习模型&#xff0c;对输入数据进行推理&#xff0c;并显示结果。 下面是该程序的主要功能和方法的详细总结&#xff1a; 初始化 OpenVINO 运行时核心…

【微服务】配置管理

Nacos配置管理 配置管理配置共享配置热更新 配置管理 将微服务集群中常用&#xff0c;经常变化的配置都写到一个独立的配置文件微服务中进行统一管理 配置共享 在Nacos的界面当中进行配置管理&#xff0c;在配置列表中添加配置 比如各个服务中的jdbc的连接配置&#xff1a; …