Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何直接访问自定义类中的二维数组_C# - Fatal编程技术网

C# 如何直接访问自定义类中的二维数组

C# 如何直接访问自定义类中的二维数组,c#,C#,我有一个类ShapeMap,它包含2D int数组ShapeMap。 在我的主脚本中,我将我的类引用为ShapeMap-map,是否有一种方法可以使用int-value=map[x,y]获取值 我的ShapeMap类是 using UnityEngine; using System.Collections; using System; public class ShapeMap { private int[,] shapeMap; public ShapeMap(int width, in

我有一个类
ShapeMap
,它包含2D int数组
ShapeMap
。 在我的主脚本中,我将我的类引用为
ShapeMap-map
,是否有一种方法可以使用
int-value=map[x,y]
获取值

我的
ShapeMap
类是

using UnityEngine;
using System.Collections;
using System;

public class ShapeMap {

private int[,] shapeMap;

public ShapeMap(int width, int height, string seed, int randomFillPercent, int smoothAmount) {

    shapeMap = new int[width, height];

    RandomFillMap (randomFillPercent, seed);

    for (int i = 0; i < smoothAmount; i++) {

        Smooth ();

    }

}

private void RandomFillMap() {

}

private void Smooth() {

}

}
使用UnityEngine;
使用系统集合;
使用制度;
公共类形状映射{
私有int[,]形状映射;
公共形状映射(整数宽度、整数高度、字符串种子、整数随机填充百分比、整数平滑量){
shapeMap=新整数[宽度、高度];
随机填充图(随机填充百分比,种子);
对于(int i=0;i
我的主要剧本是

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MapGenerator : MonoBehaviour {

ShapeMap map;

public int width, height, fillPercent, smoothAmount;
public string seed;
public bool useRandomSeed;

private void Awake() {

    if (useRandomSeed) {

        seed = Time.time.ToString ();

    }

    map = new ShapeMap (width, height, seed, fillPercent, smoothAmount);

    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            int value = map [x, y];

            if (value == 1) {

                // Do This

            } else {

                // Do That

            }

        }

    }

}
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共类映射生成器:MonoBehavior{
形状映射图;
公共整型宽度、高度、填充百分比、平滑量;
公共串种子;
公共bool用户和omseed;
私人空间{
if(useRandomSeed){
seed=Time.Time.ToString();
}
贴图=新的形状贴图(宽度、高度、种子、填充百分比、平滑量);
对于(int x=0;x
您只需修改
形状映射
添加索引器:

public int this[int x, int y]
{
    get { return shapeMap[x, y]; }
    set { shapeMap[x, y] = value; }
}



有关索引器的更多信息,您可以找到

您需要做的就是修改
形状映射
添加索引器:

public int this[int x, int y]
{
    get { return shapeMap[x, y]; }
    set { shapeMap[x, y] = value; }
}



你可以找到更多关于索引器的信息

你能显示你的代码吗?
map.shapeMap[x,y]
上有什么问题吗?它可能是重复的,没有技术问题,但是它很凌乱。你能显示你的代码吗?
map.shapeMap[x,y]上有什么问题吗
?可能重复的没有任何技术问题,但它是Messytank you,我想知道如何做,不知道从哪里开始寻找或如何称呼它,这正是我想要的。谢谢,我想知道如何做,不知道从哪里开始寻找或如何称呼它,这正是我想要的。