当前位置: 首页>>代码示例>>C#>>正文


C# ActorInfo.TraitInfoOrDefault方法代码示例

本文整理汇总了C#中ActorInfo.TraitInfoOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# ActorInfo.TraitInfoOrDefault方法的具体用法?C# ActorInfo.TraitInfoOrDefault怎么用?C# ActorInfo.TraitInfoOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ActorInfo的用法示例。


在下文中一共展示了ActorInfo.TraitInfoOrDefault方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Render

		public IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
		{
			var jamsMissiles = ai.TraitInfoOrDefault<JamsMissilesInfo>();
			if (jamsMissiles != null)
			{
				yield return new RangeCircleRenderable(
					centerPosition,
					jamsMissiles.Range,
					0,
					Color.FromArgb(128, Color.Red),
					Color.FromArgb(96, Color.Black));
			}

			var jamsRadar = ai.TraitInfoOrDefault<JamsRadarInfo>();
			if (jamsRadar != null)
			{
				yield return new RangeCircleRenderable(
					centerPosition,
					jamsRadar.Range,
					0,
					Color.FromArgb(128, Color.Blue),
					Color.FromArgb(96, Color.Black));
			}

			foreach (var a in w.ActorsWithTrait<RenderJammerCircle>())
				if (a.Actor.Owner.IsAlliedWith(w.RenderPlayer))
					foreach (var r in a.Trait.RenderAfterWorld(wr))
						yield return r;
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:29,代码来源:RenderJammerCircle.cs

示例2: ValidActor

		bool ValidActor(ActorInfo a, IEnumerable<CPos> cells)
		{
			foreach (var c in cells)
			{
				var mi = a.TraitInfoOrDefault<MobileInfo>();
				if (mi != null && mi.CanEnterCell(self.World, self, c))
					return true;
			}

			return false;
		}
开发者ID:GraionDilach,项目名称:OpenRA.Mods.AS,代码行数:11,代码来源:GiveRandomActorCrateAction.cs

示例3: EditorActorBrush

        public EditorActorBrush(EditorViewportControllerWidget editorWidget, ActorInfo actor, PlayerReference owner, WorldRenderer wr)
        {
            this.editorWidget = editorWidget;
            worldRenderer = wr;
            world = wr.World;
            editorLayer = world.WorldActor.Trait<EditorActorLayer>();

            Actor = actor;
            this.owner = owner;

            preview = editorWidget.Get<ActorPreviewWidget>("DRAG_ACTOR_PREVIEW");
            preview.GetScale = () => worldRenderer.Viewport.Zoom;
            preview.IsVisible = () => editorWidget.CurrentBrush == this;

            var buildingInfo = actor.TraitInfoOrDefault<BuildingInfo>();
            if (buildingInfo != null)
            {
                locationOffset = -FootprintUtils.AdjustForBuildingSize(buildingInfo);
                previewOffset = FootprintUtils.CenterOffset(world, buildingInfo);
            }

            var td = new TypeDictionary();
            td.Add(new FacingInit(facing));
            td.Add(new TurretFacingInit(facing));
            td.Add(new OwnerInit(owner.Name));
            td.Add(new FactionInit(owner.Faction));
            preview.SetPreview(actor, td);

            var ios = actor.TraitInfoOrDefault<IOccupySpaceInfo>();
            if (ios != null)
                footprint = ios.OccupiedCells(actor, CPos.Zero)
                    .Select(c => c.Key - CPos.Zero)
                    .ToArray();
            else
                footprint = new CVec[0];

            // The preview widget may be rendered by the higher-level code before it is ticked.
            // Force a manual tick to ensure the bounds are set correctly for this first draw.
            Tick();
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:40,代码来源:EditorActorBrush.cs

示例4: Produce

		public override bool Produce(Actor self, ActorInfo producee, string factionVariant)
		{
			var location = self.World.Map.ChooseClosestEdgeCell(self.Location);
			var pos = self.World.Map.CenterOfCell(location);

			// If aircraft, spawn at cruise altitude
			var aircraftInfo = producee.TraitInfoOrDefault<AircraftInfo>();
			if (aircraftInfo != null)
				pos += new WVec(0, 0, aircraftInfo.CruiseAltitude.Length);

			var initialFacing = self.World.Map.FacingBetween(location, self.Location, 0);

			self.World.AddFrameEndTask(w =>
				{
					var td = new TypeDictionary
					{
						new OwnerInit(self.Owner),
						new LocationInit(location),
						new CenterPositionInit(pos),
						new FacingInit(initialFacing)
					};

					if (factionVariant != null)
						td.Add(new FactionInit(factionVariant));

					var newUnit = self.World.CreateActor(producee.Name, td);

					var move = newUnit.TraitOrDefault<IMove>();
					if (move != null)
						newUnit.QueueActivity(move.MoveIntoWorld(newUnit, self.Location));

					newUnit.SetTargetLine(Target.FromCell(self.World, self.Location), Color.Green, false);

					if (!self.IsDead)
						foreach (var t in self.TraitsImplementing<INotifyProduction>())
							t.UnitProduced(self, newUnit, self.Location);

					var notifyOthers = self.World.ActorsWithTrait<INotifyOtherProduction>();
					foreach (var notify in notifyOthers)
						notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit);

					foreach (var t in newUnit.TraitsImplementing<INotifyBuildComplete>())
						t.BuildingComplete(newUnit);
				});

			return true;
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:47,代码来源:ProductionFromMapEdge.cs

示例5: HasAdequateAirUnitReloadBuildings

		// For mods like RA (number of building must match the number of aircraft)
		bool HasAdequateAirUnitReloadBuildings(ActorInfo actorInfo)
		{
			var aircraftInfo = actorInfo.TraitInfoOrDefault<AircraftInfo>();
			if (aircraftInfo == null)
				return true;

			var ammoPoolsInfo = actorInfo.TraitInfos<AmmoPoolInfo>();

			if (ammoPoolsInfo.Any(x => !x.SelfReloads))
			{
				var countOwnAir = CountUnits(actorInfo.Name, Player);
				var countBuildings = aircraftInfo.RearmBuildings.Sum(b => CountBuilding(b, Player));
				if (countOwnAir >= countBuildings)
					return false;
			}

			return true;
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:19,代码来源:HackyAI.cs

示例6: DoProduction

        public virtual void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, string factionVariant)
        {
            var exit = CPos.Zero;
            var exitLocation = CPos.Zero;
            var target = Target.Invalid;

            var bi = producee.TraitInfoOrDefault<BuildableInfo>();
            if (bi != null && bi.ForceFaction != null)
                factionVariant = bi.ForceFaction;

            var td = new TypeDictionary
            {
                new OwnerInit(self.Owner),
            };

            if (self.OccupiesSpace != null)
            {
                exit = self.Location + exitinfo.ExitCell;
                var spawn = self.CenterPosition + exitinfo.SpawnOffset;
                var to = self.World.Map.CenterOfCell(exit);

                var initialFacing = exitinfo.Facing;
                if (exitinfo.Facing < 0)
                {
                    var delta = to - spawn;
                    if (delta.HorizontalLengthSquared == 0)
                    {
                        var fi = producee.TraitInfoOrDefault<IFacingInfo>();
                        initialFacing = fi != null ? fi.GetInitialFacing() : 0;
                    }
                    else
                        initialFacing = delta.Yaw.Facing;
                }

                exitLocation = rp.Value != null ? rp.Value.Location : exit;
                target = Target.FromCell(self.World, exitLocation);

                td.Add(new LocationInit(exit));
                td.Add(new CenterPositionInit(spawn));
                td.Add(new FacingInit(initialFacing));
            }

            self.World.AddFrameEndTask(w =>
            {
                if (factionVariant != null)
                    td.Add(new FactionInit(factionVariant));

                var newUnit = self.World.CreateActor(producee.Name, td);

                var move = newUnit.TraitOrDefault<IMove>();
                if (move != null)
                {
                    if (exitinfo.MoveIntoWorld)
                    {
                        if (exitinfo.ExitDelay > 0)
                            newUnit.QueueActivity(new Wait(exitinfo.ExitDelay, false));

                        newUnit.QueueActivity(move.MoveIntoWorld(newUnit, exit));
                        newUnit.QueueActivity(new AttackMoveActivity(
                            newUnit, move.MoveTo(exitLocation, 1)));
                    }
                }

                newUnit.SetTargetLine(target, rp.Value != null ? Color.Red : Color.Green, false);

                if (!self.IsDead)
                    foreach (var t in self.TraitsImplementing<INotifyProduction>())
                        t.UnitProduced(self, newUnit, exit);

                var notifyOthers = self.World.ActorsWithTrait<INotifyOtherProduction>();
                foreach (var notify in notifyOthers)
                    notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit);

                foreach (var t in newUnit.TraitsImplementing<INotifyBuildComplete>())
                    t.BuildingComplete(newUnit);
            });
        }
开发者ID:pchote,项目名称:OpenRA,代码行数:77,代码来源:Production.cs

示例7: CanUseExit

        static bool CanUseExit(Actor self, ActorInfo producee, ExitInfo s)
        {
            var mobileInfo = producee.TraitInfoOrDefault<MobileInfo>();

            self.NotifyBlocker(self.Location + s.ExitCell);

            return mobileInfo == null ||
                mobileInfo.CanEnterCell(self.World, self, self.Location + s.ExitCell, self);
        }
开发者ID:pchote,项目名称:OpenRA,代码行数:9,代码来源:Production.cs

示例8: GetBuildTime

        public virtual int GetBuildTime(ActorInfo unit, BuildableInfo bi)
        {
            if (developerMode.FastBuild)
                return 0;

            var time = bi.BuildDuration;
            if (time == -1)
            {
                var valued = unit.TraitInfoOrDefault<ValuedInfo>();
                time = valued != null ? valued.Cost : 0;
            }

            time = time * bi.BuildDurationModifier * Info.BuildDurationModifier / 10000;
            return time;
        }
开发者ID:OpenRA,项目名称:OpenRA,代码行数:15,代码来源:ProductionQueue.cs


注:本文中的ActorInfo.TraitInfoOrDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。