简体   繁体   English

我如何通过unity3d中的C#脚本关联不同的网格?

[英]How can i relate different meshes through c# script in unity3d?

I am a unity newb creating a board game. 我是一个创建棋盘游戏的统一新手。 The board will consist of isles divided in territories, much like continents are in Risk. 董事会将由按地区划分的小岛组成,就像各大洲处于风险之中。 I have divised the following setup but i have no clue if its the best approach, please point me in the right direction if its not. 我对以下设置进行了划分,但是我不知道它是否是最好的方法,如果不是最好的方法,请指出正确的方向。

I followed this tutorial : http://games.ucla.edu/resource/unity-3-importing-assets-board-making/ and created 3 isle meshes : 我遵循了本教程: http : //games.ucla.edu/resource/unity-3-importing-assets-board-making/并创建了3个岛网格:

在此处输入图片说明

Now i want to obtain the adjacent tiles to each tile. 现在我想获取每个图块的相邻图块。 For example in the image, the tiles next to tile1 (including the corner tile). 例如,在图像中,tile1旁边的图块(包括边角图块)。 I will need this info to tell a player which territories he is capable of invading. 我将需要此信息来告诉玩家他可以入侵哪个地区。 Creating a List for each tile containing the adjacent tiles crossed my mind, but i find it a poor and sub-optimal solution. 我为每个包含相邻图块的图块创建一个列表,这使我不禁思索,但是我发现这是一个糟糕且次优的解决方案。

Is there a better way to achieve this? 有没有更好的方法来实现这一目标?

What I did for a similar problem was on the same track as you suggested in your question. 我针对类似问题所做的工作与您在问题中所建议的一样。 However, instead of just mindlessly assigning lists in the inspector, I wrote an editor script that will automatically find and assign the lists based on how far apart tiles are. 但是,我不仅仅是在检查器中随意分配列表,还编写了一个编辑器脚本,该脚本将根据图块之间的距离自动查找和分配列表。 Then if there were any discrepancies I would just change those by hand. 然后,如果有任何差异,我将手动更改。

In the end i did what Agumander suggested in his comment: 最后,我做了Agumander在他的评论中建议的内容:

If the tiles are strictly a rectangular grid on each island, then you can make a 2D array to store references to the tiles, and also store the grid coordinates in each tile for fast neighbor lookup. 如果图块严格来说是每个岛上的矩形网格,则可以制作2D数组以存储对图块的引用,还可以将网格坐标存储在每个图块中以快速查找邻居。

I used an array structure to for each Island in which each Tile would have its neighbor tile's assigned. 我为每个孤岛使用了一个数组结构,在每个孤岛中为其分配了相邻的瓦片。

Thanks to both of you. 感谢你们俩。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM