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

news2024/10/6 21:26:28

在这里插入图片描述


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

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

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

🅰️推荐专栏

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



文章目录

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


前言

请添加图片描述


🎶( 玩法相关


在这里插入图片描述


1 面板显隐命令


  • PUREMVC框架
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/1660252.html

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

相关文章

【基础算法总结】滑动窗口二

滑动窗口二 1.水果成篮2.找到字符串中所有字母异位词3.串联所有单词的子串4.最小覆盖子串 点赞&#x1f44d;&#x1f44d;收藏&#x1f31f;&#x1f31f;关注&#x1f496;&#x1f496; 你的支持是对我最大的鼓励&#xff0c;我们一起努力吧!&#x1f603;&#x1f603; 1.水…

Dbeaver network unavailable due to certificate issue

场景&#xff1a;出现在DBeaver连接数据库下载驱动的时候 解决&#xff1a; 别勾选就可以了

Java的基本语法

文章目录 Java语言的一些基本语法要点&#xff1a;Java语言的一些进阶概念和特性&#xff1a;Java代码示例基础示例1. Hello World2. 计算两个数的和 进阶示例1. 使用Lambda表达式过滤列表2. 实现一个简单的泛型类3. 使用多线程打印数字 异常处理示例捕获并处理异常 接口使用示…

【前端】HTML实现个人简历信息填写页面

文章目录 前言一、综合案例&#xff1a;个人简历信息填写页面 前言 这篇博客仅仅是对HTML的基本结构进行了一些说明&#xff0c;关于HTML的更多讲解以及CSS、Javascript部分的讲解可以关注一下下面的专栏&#xff0c;会持续更新的。 链接&#xff1a; Web前端学习专栏 下面我对…

Python专题:六、循环语句(2)

for循环语句 列表可以简单的理解为&#xff1a; 顺序保存的若干元素 注释&#xff1a;变量largest&#xff0c;循环语句for&#xff0c;还有二层缩进八个空格 依次取出counts&#xff08;列表&#xff09;里的数字&#xff0c;并赋予给x&#xff0c;判断x和largest数值大小。…

深度学习之视觉特征提取器——AlexNet

AlexNet 参考资料&#xff1a; &#xff08;1&#xff09;ImageNet十年历任霸主之AlexNet - 知乎 (zhihu.com) &#xff08;2&#xff09;AlexNet - Wikipedia 引入 AlexNet在2012年以第一名在Top-1分类精度霸榜ImageNet&#xff0c;并超过第二名近10个百分点&#xff0c;…

OpenCV-基于累计直方图的中值滤波算法

作者&#xff1a;翟天保Steven 版权声明&#xff1a;著作权归作者所有&#xff0c;商业转载请联系作者获得授权&#xff0c;非商业转载请注明出处 实现原理 基于累计直方图的中值滤波算法是一种图像处理技术&#xff0c;用于去除图像中的噪声。它利用了像素值的频数分布&#…

图片过大怎么处理变小?在线编辑图片工具推荐

在各种平台进行图片上传时&#xff0c;经常会遇到由于图片过大而无法成功上传的问题&#xff0c;为了顺利进行下一步操作&#xff0c;我们需要将图片进行缩小处理&#xff0c;通常情况下&#xff0c;我们可以使用各种软件工具来对图片进行缩小&#xff0c;如何快速有效地调整图…

自动驾驶系统中的端到端学习

资料下载-《自动驾驶系统中的端到端学习&#xff08;2020&#xff09;》https://mp.weixin.qq.com/s/ttNpsn7qyVWvDMZzluU_pA 近年来&#xff0c;卷积神经网络显著提高了视觉感知能力。实现这一成功的两个主要因素是将简单的模块组合成复杂的网络和端到端的优化。然而&#xf…

源代码防泄密-文档加密与沙盒加密的区别

研发人员比普通办公人员要精通电脑&#xff0c;除了常见的网络&#xff0c;邮件&#xff0c;U盘&#xff0c;QQ等数据扩散方法外&#xff0c;外设中转对研发人员来说轻而易举&#xff1a; — 对于嵌入式开发场景&#xff0c;可以通过串口&#xff0c;U口&#xff0c;网口把代码…

美团二面:SpringBoot读取配置优先级顺序是什么?

引言 Spring Boot作为一种轻量级的Java应用程序框架&#xff0c;以其开箱即用、快速搭建新项目的特性赢得了广大开发者的青睐。其核心理念之一就是简化配置过程&#xff0c;使开发者能够快速响应复杂多变的生产环境需求。为了实现这一点&#xff0c;Spring Boot支持丰富的外部…

OpenVoiceV2本地部署教程,苹果MacOs部署流程,声音响度统一,文字转语音,TTS

最近OpenVoice项目更新了V2版本&#xff0c;新的模型对于中文推理更加友好&#xff0c;音色也得到了一定的提升&#xff0c;本次分享一下如何在苹果的MacOs系统中本地部署OpenVoice的V2版本。 首先下载OpenVoiceV2的压缩包&#xff1a; OpenVoiceV2-for-mac代码和模型 https:…

Minio(官方docker版)容器部署时区问题研究记录

文章目录 感慨&概述补充&#xff1a;MINIO_REGION和容器时间的关系 问题一&#xff1a;minio容器和本地容器时间不一致问题说明原因探究解决方法结果验证 问题二&#xff1a;minio修改时间和本地查询结果不一致具体问题原因探究解决办法时间转化工具类调用测试和验证上传文…

4. 从感知机到神经网络

目录 1. 从感知机到神经网络 2. 最简单的神经网络 3. 激活函数的引入 1. 从感知机到神经网络 之前章节我们了解了感知机&#xff0c;感知机可以处理与门、非与门、或门、异或门等逻辑运算&#xff1b;不过在感知机中设定权重的工作是由人工来做的&#xff0c;而设定合适的&a…

障碍物识别软件的优缺点

在这个科技与人文关怀交织的时代&#xff0c;一款基于激光雷达技术的障碍物识别软件正悄然为视障人士的日常生活带来一场革命性的改变。这一款叫做“蝙蝠避障”的软件利用先进科技的力量&#xff0c;为盲人出行铺设了一条更加安全、独立的道路。今天&#xff0c;让我们从资深记…

智能呼叫中心客服系统:企业客户服务的新引擎

在如今商业竞争激烈的大环境下&#xff0c;企业的客户服务需求已不仅仅局限于简单的沟通。随着科技的进步&#xff0c;客户对于高效、智能的交互体验有着更高的期待。为了满足这些需求&#xff0c;智能呼叫中心客服系统应运而生&#xff0c;成为企业提升客户服务质量、优化客户…

vs Code配置python环境

vs Code 作为一款轻量级的源代码编辑IDE,其以轻量级和易用性著称&#xff0c;笔者今天记录分享下在其上面配置python环境&#xff0c;因为 笔者最近在学习了解Python&#xff0c;其实关于python的IDE有 pyCharm,但后期还需要进行其他语言的开发&#xff0c;索性就弄个集成度比较…

Python专题:十、字典(1)

数据类型:字典,是一个集合性质的数据类型 字典的初始化 字典{关键字:数值} 新增元素 修改元素 字典元素访问 字典[关键字} in 操作符 字典关键字检测 字典元素遍历 ①遍历关键字

每日OJ题_记忆化搜索②_力扣62. 不同路径(三种解法)

目录 力扣62. 不同路径 解析代码1_暴搜递归&#xff08;超时&#xff09; 解析代码2_记忆化搜索 解析代码3_动态规划 力扣62. 不同路径 62. 不同路径 难度 中等 一个机器人位于一个 m x n 网格的左上角 &#xff08;起始点在下图中标记为 “Start” &#xff09;。 机器…

【算法基础实验】排序-最小优先队列MinPQ

优先队列 理论知识 MinPQ&#xff08;最小优先队列&#xff09;是一种常见的数据结构&#xff0c;用于有效管理一组元素&#xff0c;其中最小元素可以快速被检索和删除。这种数据结构广泛应用于各种算法中&#xff0c;包括图算法&#xff08;如 Dijkstra 的最短路径算法和 Pr…