using UnityEngine;using System.Collections.Generic;using System;using 的中文翻譯

using UnityEngine;using System.Coll

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

public enum AntState
{
LOOKING_FOR_FOOD,
RETURNING_FOOD_TO_NEST,
/* To be Implmented
ATTACKING_ENEMY,
WARNING_ALLIES
*/
};

public class Ant : MonoBehaviour
{
//an ants actions depend on his current state
public AntState state { get; private set; }
public Vector3 position { get { return transform.position; } set { transform.position = value; } }
//a reference to the last pheromone. Used to set the direction of the next pheromone
public Pheromone last_placed_pheromone { get; set; }

//the final velocity of an ant is based on a random direction and influences from pheromones.
private Vector3 _velocity_random, _velocity_pheromone, _velocity_opposing;
//this is the actual velocity that the ant will use to move
public Vector3 velocity_final;

public NodeManager node_manager { private get; set; }
public Vector3 nest_position { private get; set; }
//random interval, so not all ants are updated at the same time.
private float _speed_random;
//the final speed the ant will use to move
private float _speed_final;
private bool _can_walk = true;

///
///the start function is a coroutine and functions as the update function.
///
IEnumerator Start( )
{
state = AntState.LOOKING_FOR_FOOD;
//all ants start at the nest.
position = nest_position.clone( );
//give a random element to the update time, so update times are spread
_speed_random = UnityEngine.Random.value * 2;

//set timers that will fire every so many seconds
float t_a = 7 / _speed_final, t_b = 51;
while ( true )
{
t_a += Time.deltaTime;

//the timer fires at different intervals, depending on the ant speed.
//this way, the rate of pheromone drops is equal, regardless of speed
if ( t_a >= 7 / _speed_final )
{
_speed_final = _speed_random + node_manager.gui_editor.get_ant_speed( );
node_manager.drop_pheromone( this );
//reset the pheromone drop timer
t_a = 0;
t_b++;
}
//if we are getting or delivering food we dont do anything this update
if ( !_can_walk )
{
//first, we are no longer unable to walk
_can_walk = true;
//wait for 2 seconds before going back to work.
yield return new WaitForSeconds( 2 );
}
//after 7 pheromones were dropped, move the ant in another direction.
if ( t_b >= node_manager.gui_editor.get_change_direction_rate( ) )
{
set_random_direction( );
//get a direction that is influenced by the pheromones in the vicinity
set_influence_from_pheromones( );
//Finally, set the velocity of the ant and make it move
StartCoroutine( calculate_velocity( ) );
//reset the counter so that the
t_b = 0;
}
//if we are at the edge of the grid (we have a collision with the 'walls' of the grid
if ( is_at_border( ) )
{
//reset the counter, so the ant doesnt change direction.
t_b = 0;
}
yield return null;
}
}

///
/// makes sure the ant doesn't walk out of the grid
///
bool is_at_border( )
{
foreach ( Plain p in node_manager.borders )
{
Vector3 ray;
if ( p.will_collide( this, NodeManager.node_size, out ray ) )
{
//make the ant walk in the opposite direction.
p.reflect_velocity( ref velocity_final, ray );
//make the ant move to the new location
StartCoroutine( move_to_new_location( position + velocity_final, 4 ) );
return true;
}
}
return false;
}

///
/// calculates the final velocity and then makes the ant move in that direction.
///
private IEnumerator calculate_velocity( )
{
update_velocity_smoothly( );
//then, we are moving towards that velocity over a period of 4 seconds
yield return StartCoroutine( move_to_new_location( position + velocity_final, 4 ) );
}

void OnTriggerEnter( Collider other )
{
switch( other.gameObject.tag )
{
//if we collided with the nest
case "nest":
// and we were looking for it
if ( state == AntState.RETURNING_FOOD_TO_NEST )
{
state = AntState.LOOKING_FOR_FOOD;
//we cannot walk for a short period of time (we are returning food)
_can_walk = false;
}
break;
//if we collided with food
case "food":
//and we are looking for food
if ( state == AntState.LOOKING_FOR_FOOD )
{
//since food can disappear after we ate it all, return if it is null
if ( other.gameObject == null ) return;
//otherwise, get the food component and tell it we are eating it
( other.gameObject.GetComponent( typeof( Food ) ) as Food ).on_ant_took_food( );
state = AntState.RETURNING_FOOD_TO_NEST;
_can_walk = false;
}
break;
}
}

void update_velocity_smoothly( )
{
//add the three components to summon to_velocity, master of direction! Vector3 to_velocity = ( _velocity_random + _velocity_pheromone + _velocity_opposing ).normalized * _speed_final; //get a mor
0/5000
原始語言: -
目標語言: -
結果 (中文) 1: [復制]
復制成功!
使用 UnityEngine;使用 System.Collections.Generic;使用系统;使用 System.Collections;公共枚举 AntState{LOOKING_FOR_FOOD,RETURNING_FOOD_TO_NEST,/ * 要同时应用ATTACKING_ENEMY,WARNING_ALLIES */};公共类蚂蚁︰ MonoBehaviour{蚂蚁的操作取决于他的当前状态AntState 公立 {get; 私人集;}公共 Vector3 位置 {{返回 transform.position;} 得到设置 {transform.position = 值;}}对信息素的最后一个引用。用于设置下一个信息素的方向公共信息素 last_placed_pheromone {get; 套;} 一只蚂蚁的最终速度基于随机方向和信息素的影响。私人 Vector3 _velocity_random、 _velocity_pheromone、 _velocity_opposing;这是蚂蚁会使用移动的实际速度公共 Vector3 velocity_final; 公共 NodeManager node_manager {私人得到; 套;}公共 Vector3 nest_position {私人得到; 套;}随机时间间隔,所以并不是所有的蚂蚁都在同一时间更新。私人浮 _speed_random;蚂蚁会使用移动的最终速度私人浮 _speed_final;私人 bool _can_walk = true; ///启动功能是协同和功能作为更新功能。 /// IEnumerator 开始 () {状态 = AntState.LOOKING_FOR_FOOD;所有的蚂蚁都开始在窝里。位置 = nest_position.clone ();一个随机元素给更新时间,所以传播更新时间_speed_random = UnityEngine.Random.value * 2; 设置将火每隔这么多秒的计时器浮 t_a = 7 / _speed_final,t_b = 51;同时 (true) {t_a + = Time.deltaTime; 计时器触发间隔不同,具体取决于蚂蚁速度。这种方式,信息素滴率是平等的无论速度如何如果 (t_a > = 7 / _speed_final) {_speed_final = _speed_random + node_manager.gui_editor.get_ant_speed ();node_manager.drop_pheromone (这);重置信息素滴计时器t_a = 0;t_b + +; }如果我们得到或提供食物我们不做任何事此更新如果 (! _can_walk) {首先,我们不再是无法行走_can_walk = true;等待 2 秒,然后回去上班。收益新 WaitForSeconds (2); }7 信息素被删除后,在另一个方向移动了蚂蚁。如果 (t_b > = node_manager.gui_editor.get_change_direction_rate ()) {set_random_direction ();得到一个受信息素在附近的方向set_influence_from_pheromones ();最后,设置蚂蚁的速度,使它移动StartCoroutine (calculate_velocity ());重置计数器,t_b = 0; }如果我们处于边缘的 (我们有一个碰撞与 '墙' 网格的网格如果 (is_at_border ()) {重置计数器,所以蚂蚁不会改变方向。t_b = 0; } 收益率返回 null; } } /// 确保了蚂蚁不走出网格 /// bool is_at_border () {foreach (在 node_manager.borders 平原 p) {Vector3 射线;如果 (p.will_collide (出射线这,NodeManager.node_size)) {让蚂蚁在相反的方向走。p.reflect_velocity (ref velocity_final、 射线);让蚂蚁移动到新位置StartCoroutine (move_to_new_location (位置 + velocity_final,4));返回 true; } }返回 false; } /// 计算最终的速度,然后使蚂蚁朝着这个方向前进。 /// 私人 IEnumerator calculate_velocity () { update_velocity_smoothly ();然后,我们也在 4 秒内正朝着那速度收益 StartCoroutine (move_to_new_location (位置 + velocity_final,4)); } void OnTriggerEnter (对撞机其他) {开关 (other.gameObject.tag) {如果我们相撞巢"鸟巢"案例︰我们在找它如果 (状态 = = AntState.RETURNING_FOOD_TO_NEST) {状态 = AntState.LOOKING_FOR_FOOD;我们不能走在短时间内 (我们返回的食物)_can_walk = false; } 休息;如果我们与食物相撞"食品"案例︰和我们在寻找食物如果 (状态 = = AntState.LOOKING_FOR_FOOD) {由于食物可以消失我们吃了以后,返回如果它为 null如果 (other.gameObject = = null) 返回;否则为得到食物分量,告诉它我们吃它(.on_ant_took_food) (other.gameObject.GetComponent (typeof (食物)) 作为食品);状态 = AntState.RETURNING_FOOD_TO_NEST;_can_walk = false; }休息; } } 无效的 update_velocity_smoothly () {添加三个组件来召唤 to_velocity,大师的方向 !Vector3 to_velocity = (_velocity_random + _velocity_pheromone + _velocity_opposing).normalized * _speed_final;获得铁道部
正在翻譯中..
結果 (中文) 3:[復制]
復制成功!
使用UnityEngine;使用system.collections.generic;使用系统;使用系统;antstate枚举{looking_for_food,returning_food_to_nest,/ *被实施attacking_enemy,warning_allies* /};蚂蚁:MonoBehaviour类{蚂蚁的行为取决于他目前的状态公共antstate状态{得到;私人集;}公共Vector3位置{得到{ return transform.position;}集{ transform.position =值;} }最后一次信息素的参考。用于设置下一个信息素的方向公共信息last_placed_pheromone {有};集;/ /蚂蚁的最终速度是基于一个随机的方向,从信息素的影响。私人_velocity_random Vector3,_velocity_pheromone,_velocity_opposing;这是蚂蚁移动的实际速度到velocity_final公共;公共nodemanager node_manager {私拿;集;}到nest_position {私人得到公众;集;}/随机间隔,所以并不是所有的蚂蚁都在同一时间更新。私有_speed_random;最后一只蚂蚁移动的速度私有_speed_final;私人布尔_can_walk =真;/ / // / /启动功能是协程和功能更新功能。/ / /IEnumerator Start(){状态= antstate.looking_for_food;所有的蚂蚁都在巢里开始。位置= nest_position克隆();将一个随机元素给更新时间,所以更新时间是分散的_speed_random = unityengine.random.value * 2;/设置定时器,将火灾每这么多秒浮t_a = 7 / _speed_final,t_b = 51;虽然(真){t_a + =改变;在不同的时间间隔内的定时器火灾,取决于蚂蚁的速度。这种方式,信息素滴的速度是相等的,无论速度如果(t_a > = 7 / _speed_final){_speed_final = _speed_random + node_manager。gui_editor get_ant_speed();node_manager drop_pheromone(本);/复位信息素滴定时器t_a = 0;t_b + +;}如果我们正在获取或提供食物,我们不做任何这个更新如果(!_can_walk){/首先,我们不再不能走路了_can_walk =真;在回去工作之前2秒的时间。收益的新waitforseconds(2);}/ / 7后种群的下降,在另一个方向移动的蚂蚁。如果(t_b > = node_manager。gui_editor。get_change_direction_rate()){set_random_direction();/ /得到,是由附近的信息素的影响方向set_influence_from_pheromones();最后,设置了蚂蚁的速度,并使它移动StartCoroutine(calculate_velocity());/复位计数器,使t_b = 0;}如果我们是在网格的边缘(我们有一个与网格的“墙”碰撞如果(is_at_border()){/重置计数器,所以蚂蚁不改变方向。t_b = 0;}收益返回空值;}}/ / // /确保蚂蚁不走出网格/ / /布尔is_at_border(){foreach(纯P node_manager.borders){到射线;如果(p.will_collide(这nodemanager.node_size,Ray)){/使蚂蚁走在相反的方向。p.reflect_velocity(REF velocity_final,射线);使蚂蚁移动到新的位置StartCoroutine(move_to_new_location(位置+ velocity_final,4));返回true;}}返回false;}/ / // /计算最后的速度,然后使蚂蚁在该方向移动。/ / /私人IEnumerator calculate_velocity(){update_velocity_smoothly();/然后,我们正在朝着这个速度超过一段4秒收益startcoroutine(move_to_new_location(位置+ velocity_final,4));}OnTriggerEnter(Collider等)无效{开关(other.gameobject.tag){如果我们与巢相撞案例“鸟巢”:/ /我们正在寻找它如果(状态= = antstate.returning_food_to_nest){状态= antstate.looking_for_food;我们不能走很短的时间(我们正在返回食物)_can_walk = false;}打破;如果我们与食物相撞案例“食品”:我们正在寻找食物如果(状态= = antstate.looking_for_food){当我们吃了它所有的食物后,返回,如果它是空的如果(other.gameobject = = null)返回;否则,得到的食物成分,并告诉它,我们正在吃它(其他。gameObject. GetComponent(typeof(食品))作为食物)。on_ant_took_food();状态= antstate.returning_food_to_nest;_can_walk = false;}打破;}}update_velocity_smoothly(无效){/ /添加三成分的召唤to_velocity,掌握方向!到to_velocity =(_velocity_random + _velocity_pheromone + _velocity_opposing)。归一化* _speed_final;//获得铁道部
正在翻譯中..
 
其它語言
本翻譯工具支援: 世界語, 中文, 丹麥文, 亞塞拜然文, 亞美尼亞文, 伊博文, 俄文, 保加利亞文, 信德文, 偵測語言, 優魯巴文, 克林貢語, 克羅埃西亞文, 冰島文, 加泰羅尼亞文, 加里西亞文, 匈牙利文, 南非柯薩文, 南非祖魯文, 卡納達文, 印尼巽他文, 印尼文, 印度古哈拉地文, 印度文, 吉爾吉斯文, 哈薩克文, 喬治亞文, 土庫曼文, 土耳其文, 塔吉克文, 塞爾維亞文, 夏威夷文, 奇切瓦文, 威爾斯文, 孟加拉文, 宿霧文, 寮文, 尼泊爾文, 巴斯克文, 布爾文, 希伯來文, 希臘文, 帕施圖文, 庫德文, 弗利然文, 德文, 意第緒文, 愛沙尼亞文, 愛爾蘭文, 拉丁文, 拉脫維亞文, 挪威文, 捷克文, 斯洛伐克文, 斯洛維尼亞文, 斯瓦希里文, 旁遮普文, 日文, 歐利亞文 (奧里雅文), 毛利文, 法文, 波士尼亞文, 波斯文, 波蘭文, 泰文, 泰盧固文, 泰米爾文, 海地克里奧文, 烏克蘭文, 烏爾都文, 烏茲別克文, 爪哇文, 瑞典文, 瑟索托文, 白俄羅斯文, 盧安達文, 盧森堡文, 科西嘉文, 立陶宛文, 索馬里文, 紹納文, 維吾爾文, 緬甸文, 繁體中文, 羅馬尼亞文, 義大利文, 芬蘭文, 苗文, 英文, 荷蘭文, 菲律賓文, 葡萄牙文, 蒙古文, 薩摩亞文, 蘇格蘭的蓋爾文, 西班牙文, 豪沙文, 越南文, 錫蘭文, 阿姆哈拉文, 阿拉伯文, 阿爾巴尼亞文, 韃靼文, 韓文, 馬來文, 馬其頓文, 馬拉加斯文, 馬拉地文, 馬拉雅拉姆文, 馬耳他文, 高棉文, 等語言的翻譯.

Copyright ©2024 I Love Translation. All reserved.

E-mail: