public Actor(World world, ActorInit init) : base(init.Position, null) { World = world; Type = init.Type; Team = init.Team; IsPlayer = init.IsPlayer; IsBot = init.IsBot; Height = init.Height; ID = init.ID; this.init = init; CurrentTerrain = world.TerrainAt(TerrainPosition); // Parts partManager = new PartManager(); foreach (var partinfo in init.Type.PartInfos) { if (partinfo is BotPartInfo && !IsBot) { continue; } var part = partinfo.Create(this); partManager.Add(part); // Cache some important parts if (part is MobilePart mobile) { Mobile = mobile; } if (part is MotorPart motor) { Motor = motor; } else if (part is HealthPart health) { Health = health; } else if (part is RevealsShroudPart revealsShroud) { RevealsShroud = revealsShroud; } else if (part is WeaponPart weapon) { Weapon = weapon; } else if (part is WorldPart worldPart) { WorldPart = worldPart; } else if (part is BotPart botPart) { Bot = botPart; } else if (part is PlayerSwitchPart) { IsPlayerSwitch = true; } } if (IsBot && Bot == null) { IsBot = false; // BotPart is not there, thus there's no bot } if (IsPlayer) { partManager.Add(new PlayerPart(this)); } tickParts = partManager.GetPartsOrDefault <ITick>(); editorTickParts = partManager.GetPartsOrDefault <ITickInEditor>(); renderParts = partManager.GetPartsOrDefault <IRenderable>(); accelerationParts = partManager.GetPartsOrDefault <INoticeAcceleration>(); moveParts = partManager.GetPartsOrDefault <INoticeMove>(); stopParts = partManager.GetPartsOrDefault <INoticeStop>(); Physics = Type.Physics == null ? SimplePhysics.Empty : new SimplePhysics(this, Type.Physics.Type); if (Health != null && init.Health >= 0f) { Health.RelativeHP = init.Health; } var hoverPart = GetPartOrDefault <HoverPart>(); if (hoverPart != null) { Height = hoverPart.DefaultHeight; } }
public MotorPart motor; //马达零件 //重置方法 public void Reset() { wheel = Resources.Load <WheelPart>(wheelPath + "DefaultWheel"); cover = Resources.Load <CoverPart>(coverPath + "DefaultCover"); motor = Resources.Load <MotorPart>(motorPath + "DefaultMotor"); }