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


C# Eluant.LuaFunction类代码示例

本文整理汇总了C#中Eluant.LuaFunction的典型用法代码示例。如果您正苦于以下问题:C# LuaFunction类的具体用法?C# LuaFunction怎么用?C# LuaFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LuaFunction类属于Eluant命名空间,在下文中一共展示了LuaFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PlayMusic

		public void PlayMusic(string track = null, LuaFunction func = null)
		{
			if (!playlist.IsMusicAvailable)
				return;

			var musicInfo = !string.IsNullOrEmpty(track) ? GetMusicTrack(track)
				: playlist.GetNextSong();

			if (func != null)
			{
				var f = func.CopyReference() as LuaFunction;
				onComplete = () =>
				{
					try
					{
						using (f)
							f.Call().Dispose();
					}
					catch (LuaException e)
					{
						Context.FatalError(e.Message);
					}
				};

				playlist.Play(musicInfo, onComplete);
			}
			else
				playlist.Play(musicInfo);
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:29,代码来源:MediaGlobal.cs

示例2: OnAllKilled

        public void OnAllKilled(LuaTable actors, LuaFunction func)
        {
            List<Actor> group = new List<Actor>();
            foreach (var kv in actors)
            {
                Actor actor;
                if (!kv.Value.TryGetClrValue<Actor>(out actor))
                    throw new LuaException("OnAllKilled requires a table of int,Actor pairs. Recieved {0},{1}".F(kv.Key.GetType().Name, kv.Value.GetType().Name));

                group.Add(actor);
            }

            var copy = (LuaFunction)func.CopyReference();
            Action<Actor> OnMemberKilled = m =>
            {
                group.Remove(m);
                if (!group.Any())
                {
                    copy.Call();
                    copy.Dispose();
                }
            };

            foreach (var a in group)
                GetScriptTriggers(a).OnKilledInternal += OnMemberKilled;
        }
开发者ID:RunCraze,项目名称:OpenRA,代码行数:26,代码来源:TriggerGlobal.cs

示例3: Reinforce

		public Actor[] Reinforce(Player owner, string[] actorTypes, CPos[] entryPath, int interval = 25, LuaFunction actionFunc = null)
		{
			var actors = new List<Actor>();
			for (var i = 0; i < actorTypes.Length; i++)
			{
				var af = actionFunc != null ? actionFunc.CopyReference() as LuaFunction : null;
				var actor = CreateActor(owner, actorTypes[i], false, entryPath[0], entryPath.Length > 1 ? entryPath[1] : (CPos?)null);
				actors.Add(actor);

				var actionDelay = i * interval;
				Action actorAction = () =>
				{
					Context.World.Add(actor);
					for (var j = 1; j < entryPath.Length; j++)
						Move(actor, entryPath[j]);

					if (af != null)
					{
						actor.QueueActivity(new CallFunc(() =>
						{
							af.Call(actor.ToLuaValue(Context));
							af.Dispose();
						}));
					}
				};

				Context.World.AddFrameEndTask(w => w.Add(new DelayedAction(actionDelay, actorAction)));
			}

			return actors.ToArray();
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:31,代码来源:ReinforcementsGlobal.cs

示例4: GetPlayers

		public Player[] GetPlayers(LuaFunction filter)
		{
			return Context.World.Players
				.Where(p =>
				{
					using (var f = filter.Call(p.ToLuaValue(Context)))
						return f.First().ToBoolean();
				}).ToArray();
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:9,代码来源:PlayerGlobal.cs

示例5: Any

        public bool Any(LuaValue[] collection, LuaFunction func)
        {
            foreach (var c in collection)
                using (var ret = func.Call(c))
                using (var result = ret.FirstOrDefault())
                    if (result != null && result.ToBoolean())
                        return true;

            return false;
        }
开发者ID:pchote,项目名称:OpenRA,代码行数:10,代码来源:UtilsGlobal.cs

示例6: ActorsInCircle

		public LuaTable ActorsInCircle(WPos location, WRange radius, LuaFunction filter)
		{
			var actors = context.World.FindActorsInCircle(location, radius)
				.Select(a => a.ToLuaValue(context))
				.Where(a => 
				{
					using (var f = filter.Call(a))
						return f.First().ToBoolean();
				});
			return actors.ToLuaTable(context);
		}
开发者ID:Berzeger,项目名称:OpenRA,代码行数:11,代码来源:MapGlobal.cs

示例7: GetPlayers

		public LuaTable GetPlayers(LuaFunction filter)
		{
			var players = context.World.Players
				.Select(p => p.ToLuaValue(context))
				.Where(a =>
				{
					using (var f = filter.Call(a))
						return f.First().ToBoolean();
				});

			return players.ToLuaTable(context);
		}
开发者ID:JackKucan,项目名称:OpenRA,代码行数:12,代码来源:PlayerGlobal.cs

示例8: Any

        public bool Any(LuaTable table, LuaFunction func)
        {
            foreach (var kv in table)
            {
                using (var ret = func.Call(kv.Value))
                {
                    var result = ret.FirstOrDefault();
                    if (result != null && result.ToBoolean())
                        return true;
                }
            }

            return false;
        }
开发者ID:RunCraze,项目名称:OpenRA,代码行数:14,代码来源:UtilsGlobal.cs

示例9: All

		public bool All(LuaValue[] collection, LuaFunction func)
		{
			foreach (var c in collection)
			{
				using (var ret = func.Call(c))
				{
					var result = ret.FirstOrDefault();
					if (result == null || !result.ToBoolean())
						return false;
				}
			}

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

示例10: ActorsInBox

		public Actor[] ActorsInBox(WPos topLeft, WPos bottomRight, LuaFunction filter = null)
		{
			var actors = Context.World.ActorMap.ActorsInBox(topLeft, bottomRight);

			if (filter != null)
			{
				actors = actors.Where(a =>
				{
					using (var f = filter.Call(a.ToLuaValue(Context)))
						return f.First().ToBoolean();
				});
			}

			return actors.ToArray();
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:15,代码来源:MapGlobal.cs

示例11: ActorsInCircle

		public Actor[] ActorsInCircle(WPos location, WDist radius, LuaFunction filter = null)
		{
			var actors = Context.World.FindActorsInCircle(location, radius);

			if (filter != null)
			{
				actors = actors.Where(a =>
				{
					using (var f = filter.Call(a.ToLuaValue(Context)))
						return f.First().ToBoolean();
				});
			}

			return actors.ToArray();
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:15,代码来源:MapGlobal.cs

示例12: AfterDelay

        public void AfterDelay(int delay, LuaFunction func)
        {
            var f = (LuaFunction)func.CopyReference();
            Action doCall = () =>
            {
                try
                {
                    using (f)
                        f.Call().Dispose();
                }
                catch (Exception e)
                {
                    Context.FatalError(e.Message);
                }
            };

            Context.World.AddFrameEndTask(w => w.Add(new DelayedAction(delay, doCall)));
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:18,代码来源:TriggerGlobal.cs

示例13: PlayMovieFullscreen

        public void PlayMovieFullscreen(string movie, LuaFunction func = null)
        {
            if (func != null)
            {
                var f = func.CopyReference() as LuaFunction;
                onCompleteFullscreen = () =>
                {
                    try
                    {
                        using (f)
                            f.Call().Dispose();
                    }
                    catch (LuaException e)
                    {
                        Context.FatalError(e.Message);
                    }
                };
            }
            else
                onCompleteFullscreen = () => { };

            Media.PlayFMVFullscreen(world, movie, onCompleteFullscreen);
        }
开发者ID:ushardul,项目名称:OpenRA,代码行数:23,代码来源:MediaGlobal.cs

示例14: OnAllKilled

		public void OnAllKilled(Actor[] actors, LuaFunction func)
		{
			var group = actors.ToList();
			var copy = (LuaFunction)func.CopyReference();
			Action<Actor> onMemberKilled = m =>
			{
				try
				{
					group.Remove(m);
					if (!group.Any())
					{
						copy.Call();
						copy.Dispose();
					}
				}
				catch (Exception e)
				{
					Context.FatalError(e.Message);
				}
			};

			foreach (var a in group)
				GetScriptTriggers(a).OnKilledInternal += onMemberKilled;
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:24,代码来源:TriggerGlobal.cs

示例15: OnEnteredFootprint

        public int OnEnteredFootprint(CPos[] cells, LuaFunction func)
        {
            // We can't easily dispose onEntry, so we'll have to rely on finalization for it.
            var onEntry = (LuaFunction)func.CopyReference();
            var triggerId = 0;
            Action<Actor> invokeEntry = a =>
            {
                try
                {
                    using (var luaActor = a.ToLuaValue(Context))
                    using (var id = triggerId.ToLuaValue(Context))
                        onEntry.Call(luaActor, id).Dispose();
                }
                catch (Exception e)
                {
                    Context.FatalError(e.Message);
                }
            };

            triggerId = Context.World.ActorMap.AddCellTrigger(cells, invokeEntry, null);

            return triggerId;
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:23,代码来源:TriggerGlobal.cs


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