首页 > 其他分享 >Unity3D 自定义类的数组初始化

Unity3D 自定义类的数组初始化

时间:2023-07-23 11:12:44浏览次数:38  
标签:Unity3D 自定义 初始化 int tree elem length public size

实现功能:

1. 自定义类,用于保存数据等

2. 初始化数组

代码:

public class tree_elem
{
    // 位置
    public int x, y;
    // 大小【相对于原始大小的比例】最后随机分配
    public float size;
    // 树的类型,最后随机分配
    public tree_kind kind;

    public tree_elem(int x, int y)
    {
        this.x = x;
        this.y = y;
        this.size = UnityEngine.Random.Range(0.5f, 2.0f); 
        this.kind = (tree_kind)(UnityEngine.Random.Range(0, 100) % 3);
    }
}

public class MapCreator : MonoBehaviour
{
    [Header("生成的面积尺寸")]
    public Vector2 create_map_size = new Vector2(100, 100);
    private tree_elem[] tree_elements;

    // Start is called before the first frame update
    void Start()
    {
                Debug.Log("生成模式:normal,利用random随机数,纯随机");
                int length = create_map_size.x;
                int heigth = create_map_size.y;
                int max_length = length * heigth;
                tree_elements = new tree_elem[max_length];
                for (int i = 0; i < max_length; i++)
                {
                    // 赋值数据
                    tree_elements[i] = new tree_elem(i / length, i % heigth);
                }
    }
}

 

标签:Unity3D,自定义,初始化,int,tree,elem,length,public,size
From: https://www.cnblogs.com/wayne-tao/p/17574778.html

相关文章

  • spring boot 自定义组件
    SpringBoot自定义组件SpringBoot是一个用于快速构建独立的、生产级别的Spring应用程序的框架。它提供了许多开箱即用的组件,可以简化开发流程并提高开发效率。但是,在某些情况下,我们可能需要自定义一些组件来满足特定的需求。本文将介绍如何在SpringBoot中自定义组件,并提......
  • element ui 分页组件自定义每页条数page-size
       参考代码:<divstyle="display:flex;"><el-pagination:total="total":pager-count="5":page-size="searchForm.pageSize":current-page=&q......
  • 自定义异常类
    1'''21.语法说明3自定义异常类是指在编程中,根据实际需要创建的用于表示特定错误或异常情况的类。4通过自定义异常类,我们可以更好地组织和处理代码中可能出现的异常情况。5classCustomException(Exception):6def__init__(self,message):7......
  • 4.8 数值稳定性和模型初始化
    1.数值稳定性当神经网络的层数变得越来越深时,容易出现梯度消失及梯度爆炸的问题。这是因为,输出对于某一层的一组参数的梯度是多个矩阵的乘积,并且越底部(浅层)的层,相乘的矩阵的数量就越多。梯度消失会导致参数更新过小,甚至梯度为0,网络无法训练。sigmoid函数容易导致梯度消失:  ......
  • WPF .net6 自定义启动入口 、 自定义Main函数、自定义 STAThread 方法
    前言:  为了解决程序开启自启动问题参考资料  CustomEntryPointsinWPFon.NETCore链接https://blog.magnusmontin.net/2020/01/31/custom-entry-point-wpf-net-core/  CreatingacustomMainmethodinaWPFapplication链接https://www.meziantou.net/creat......
  • Unity3D 播放运行时游戏对象往上飞了
    我的原因是不小心给主摄像机(MainCamera)添加了刚体(Rigidbody)组件,导致播放运行时摄像机受重力作用往下掉,造成游戏(Game)视图窗口内看见的游戏对象往上飞了!如下图所示: 把挂在摄像机的上刚体(Rigidbody)组件移除即可!~......
  • matlab 郭彦甫 3 结构化程式与自定义函数
    1.脚本文件  保存文件格式 *.m  文件格式函数部分  fx  包含绝大部分的函数介绍注释为   行前加一个 %    如果为连续多行 需要先选中这些行 右键选择注释两个 %%  将下面的部分分为section   区块 通常用于debug    ......
  • gitlab的CICD中自定义钉钉发送内容(通过sh脚本发送测试结果)
    背景:这里报告是allure,提取数据可以用data/categories.csv这个文件思路跟上一篇的python是一样的,这里就简单贴下代码 这里需要注意的是json的转义,message变量需要用双引号括起来。CICD中配置如下 ......
  • K8S初始化报错:CRI v1 runtime API is not implemented for endpoint \"unix:///var/r
    报错具体内容:[preflight]Somefatalerrorsoccurred:[ERRORCRI]:containerruntimeisnotrunning:output:time="2023-07-21T09:20:07Z"level=fatalmsg="validateserviceconnection:CRIv1runtimeAPIisnotimplementedforendpoint\"un......
  • Hibernate初始化时在OneToOneSecondPass类中出现NullPointerException
    启动项目 Hibernate随即报错Causedby:java.lang.NullPointerException   atorg.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:135)  原因: 主类方,无外键方@OneToOne(mappedBy="carveEReviewproject",targetEntity=CarveEReviewcomment.cla......