SRPG游戏开发(三十六)第八章 游戏中的数据 - 六 运行时对象(Runtime Object)

Runtime方法的使用—Class篇 二十一世纪最贵的是什么? ————————————— 答案:人才or房子 本篇主要是各种Class相关方法的实现,还有两种运行时调用方法的实现 - (void)viewDidLoad { [super viewDidLoad]; // 调用方法方案1 // objc_msgSend(self,@selector(initial:),@"完成初始化"); // 阅读详情

返回总目录

第八章 游戏中的数据(Data in Game)

在之前的章节中,我们进行地图对象的生成,移动等操作。

这一章本来可以进行战斗的编写,不过数据缺失是一个问题。

所以这一章我们先来建立一些数据,以及如何编辑它们,是否需要生成配置文件等。



六 运行时对象(Runtime Object)

之前建立的数据几乎都是静态数据,而实际在游戏中,我们要创建一些类来使用它们。

在数据上,我们来创建一些类。在之前应该注意:

  • 角色(role)在SRPG中分为独有人物,和一系列的杂兵。当然还包括职业;

  • 物品(item)存在不同分类;

  • 移动消耗(Move Consumption)、人物(character)和职业(class)只是静态数据的代理。


1 移动消耗、人物与职业(Move Consumption, Character and Class)

在实际游戏中,移动消耗、人物与职业数据是不存在变化的,我们只需要读取它(只读属性)。

两种方式(以人物为例):

  • 其一,内部直接使用静态数据

    namespace DR.Book.SRPG_Dev.Models
    {
         
         
        public class Character
        {
         
         
            private CharacterInfo m_Info;
    
            // 类似这样的只读属性
            public int id
            {
         
         
                get {
         
          return m_Info.id; }
            }
    
            // 其它只读属性
    
            public Character(CharacterInfo info)
            {
         
         
                this.m_Info = info;
            }
        }
    }
    
  • 其二,内部不使用静态数据,外部读取静态数据后创建

    namespace DR.Book.SRPG_Dev.Models
    {
         
         
        public class Character
        {
         
         
            // 类似这样的只读属性
            public int id {
         
          get; private set;}
    
            // 其它只读属性
    
            public Character(int id /* 其它读取属性 */)
            {
         
         
                this.id = id;
    
                // 读取其它属性
            }
    
            public Character(CharacterInfo info)
            {
         
         
                this.id = info.id;
    
                // 读取其它属性
            }
        }
    }
    

当然你也可以不在构造函数中进行,而是自己写一个读取函数(例如Load)。

这里我们不再过多的阐述,以下是移动消耗完整的类,人物与职业也可以参考它。

完整的移动消耗的类:

using UnityEngine;

namespace DR.Book.SRPG_Dev.Models
{
   
   
    using DR.Book.SRPG_Dev.Maps;

    public class MoveConsumption
    {
   
   
        private MoveConsumptionInfo m_Info;

        public ClassType classType
        {
   
   
            get {
   
    return m_Info.classType; }
        }

        public float this[TerrainType terrainType]
        {
   
   
            get
            {
   
   
                if (terrainType == TerrainType.MaxLength)
                {
   
   
                    Debug.LogError("MoveConsumption -> TerrainType can not be MaxLength.");
                    return 255f;
                }
                return m_Info.consumptions[terrainType.ToInteger()];
            }
        }

        public MoveConsumption(MoveConsumptionInfo info)
        {
   
   
            this.m_Info = info;
        }
    }
}

2 运行时数据(Runtime Data)

在写其他的类之前,我们都知道一些数据是随着游戏进程而动态变化的(例如经验值,等级等)。

增加保存这些数据的变量是必须的,这里我把这些变量单独建立一个类来存储:

using System;
using System.Reflection;
using UnityEngine;

namespace DR.Book.SRPG_Dev.Models
{
   
   
    [Serializable]
    public abstract class RuntimeData<T> : IRuntimeData<T> where T : RuntimeData<T>, new()
    {
   
   
        public virtual T Clone()
        {
   
   
            T clone = new T();
            CopyTo(clone);
            return clone;
        }

        public virtual void CopyTo(T data)
        {
   
   
            if (data == null)
            {
   
   
                Debug.LogError("RuntimeData -> CopyTo: data is null.")
告别卡顿!OBS Studio最佳录制参数设置指南(适合游戏/网课/会议场景) 本文提供OBS Studio录制参数优化指南,针对游戏、网课及会议三大场景,详细解析帧率、码率与编码器设置。重点推荐利用硬件编码器(如NVENC)实现游戏录制零卡顿,并分享清晰稳定的网课录制与长时间会议录制配置方案,助你告别视频卡顿与音画不同步问题。 阅读详情

相关推荐

Shopee商品详情页反爬实战:手把手逆向x-sap-Ri和x-sap-Sec参数(附完整调试过程)

本文详细解析了Shopee商品详情页反爬机制中的x-sap-Ri和x-sap-Sec参数逆向过程。通过JS逆向技术,从环境数据采集到多层哈希运算,完整拆解了这两个关键参数的生成逻辑,并提供了实战技巧和Node.js实现方案,帮助开发者应对Shopee的动态加密挑战。

weixin_33701251的博客 1615

专治疑难系列 - 解决打印机凭证冲突问题

一、问题描述 二、解决方法 三、问题已解决

Passerby_Wang的博客 2万+

使用 Python 实现无人机避障的人工势场算法

人工势场算法是一种基于力的控制方法,通过将目标位置视为一个吸引力源,而将障碍物视为排斥力源,来引导移动体朝着目标前进,同时避开障碍物。接下来,我们将定义几个类来实现人工势场算法,包括无人机类、障碍物类和势场类。

闲人编程的博客 2593

海康威视iVMS-8700综合安防管理平台 文件读取漏洞复现

HIKVISION iVMS 综合安防管理平台download接口处存在任意文件读取漏洞,攻击者通过构造token绕过身份认证,读取服务器中的目录信息与敏感文件。使系统处于极不安全的状态。

0xSec 3326

图像分割 - 使用Mask R-CNN模型在COCO数据集上进行图像分割任务

图像分割是计算机视觉领域的一个重要任务,它旨在将图像中的每个像素分类为对象或背景。Mask R-CNN是一种基于区域的卷积神经网络,可用于图像分割任务。它是Faster R-CNN的扩展,将目标检测与图像分割结合起来,能够同时检测和分割对象。在本博客中,我们将使用Mask R-CNN模型在COCO数据集上进行图像分割任务。我们将介绍如何下载和准备COCO数据集,以及如何使用Mask R-CNN模型进行训练和推理。

斌擎科技 1196

K8s-K8s部署Zookeeper+Kafka+ELFK+持久化数据

K8s环境下容器化部署`Zookeeper+Kafka+ELFK`日志收集系统

✅ 专注企业级 Linux/DevOps 运维的实战派 ✅ 已输出上百篇可落地方案 ✅ Shell 脚本开箱即用 ✅ K8s/YAML 环境验证 ✅ 故障排查链路完整复现 1921

27、VXLAN BGP EVPN网络的自动化部署与运维管理

本文深入探讨了VXLAN BGP EVPN网络从初始配置到运维管理的全生命周期自动化流程,涵盖Day-0设备自动上线、Day-0.5增量变更与连接验证、Day-1覆盖服务配置与计算集成,以及Day-2监控与故障排查。详细介绍了推送与拉取两种配置模型、主流工具如Cisco VTS、NFM、DCNM的功能特点,以及开源自动化工具的应用。通过流程图和命令示例,系统展示了MAC/IP学习、BGP通告和VXLAN封装的验证方法,为构建高效、可扩展的数据中心网络提供了全面的技术指导。

banana的博客 83

SAP MM ME21N保存前检查增强

想在ME21N保存前做一些数据检查, 可以做一个增强功能,  运行 CMOD 新增,   增强接口 输入 MM06E005  (  EXIT_SAPMM06E_012 ) ,在 NCLUDE ZXM06U43 .  里写代码功能。  例子如下: *&---------------------------------------------------------------------*

heng0757的专栏 1万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

上一篇: SRPG游戏开发(三十五)第八章 游戏中的数据 - 五 测试,导出,导入与编辑器说明(Test, Export, Import and Description)
下一篇: SRPG游戏开发(三十七)第八章 游戏中的数据 - 七 数据的容器(Data Container)
沙沙的兔子
博客等级 码龄17年 360粉丝 135原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值