本文整理汇总了C#中Eluant.LuaFunction.CopyReference方法的典型用法代码示例。如果您正苦于以下问题:C# LuaFunction.CopyReference方法的具体用法?C# LuaFunction.CopyReference怎么用?C# LuaFunction.CopyReference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Eluant.LuaFunction
的用法示例。
在下文中一共展示了LuaFunction.CopyReference方法的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);
}
示例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;
}
示例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();
}
示例4: 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)));
}
示例5: 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);
}
示例6: 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;
}
示例7: 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;
}
示例8: OnAnyKilled
public void OnAnyKilled(Actor[] actors, LuaFunction func)
{
var called = false;
var f = (LuaFunction)func.CopyReference();
Action<Actor> onMemberKilled = m =>
{
try
{
if (called)
return;
using (f)
using (var killed = m.ToLuaValue(Context))
f.Call(killed).Dispose();
called = true;
}
catch (Exception e)
{
Context.FatalError(e.Message);
}
};
foreach (var a in actors)
GetScriptTriggers(a).OnKilledInternal += onMemberKilled;
}
示例9: OnAllRemovedFromWorld
public void OnAllRemovedFromWorld(Actor[] actors, LuaFunction func)
{
var group = actors.ToList();
var f = (LuaFunction)func.CopyReference();
Action<Actor> onMemberRemoved = m =>
{
try
{
if (!group.Remove(m))
return;
if (!group.Any())
using (f)
f.Call().Dispose();
}
catch (Exception e)
{
Context.FatalError(e.Message);
}
};
foreach (var a in group)
GetScriptTriggers(a).OnRemovedInternal += onMemberRemoved;
}
示例10: Triggerable
public Triggerable(LuaFunction function, ScriptContext context, Actor self)
{
Function = (LuaFunction)function.CopyReference();
Context = context;
Self = self.ToLuaValue(Context);
}
示例11: ReinforceWithTransport
public LuaTable ReinforceWithTransport(Player owner, string actorType, string[] cargoTypes, CPos[] entryPath, CPos[] exitPath = null,
LuaFunction actionFunc = null, LuaFunction exitFunc = null)
{
var transport = CreateActor(owner, actorType, true, entryPath[0], entryPath.Length > 1 ? entryPath[1] : (CPos?)null);
var cargo = transport.TraitOrDefault<Cargo>();
var passengers = new List<Actor>();
if (cargo != null && cargoTypes != null)
{
foreach (var cargoType in cargoTypes)
{
var passenger = CreateActor(owner, cargoType, false, entryPath[0]);
passengers.Add(passenger);
cargo.Load(transport, passenger);
}
}
for (var i = 1; i < entryPath.Length; i++)
Move(transport, entryPath[i]);
if (actionFunc != null)
{
var af = actionFunc.CopyReference() as LuaFunction;
transport.QueueActivity(new CallFunc(() =>
{
af.Call(transport.ToLuaValue(Context), passengers.ToArray().ToLuaValue(Context));
af.Dispose();
}));
}
else
{
var aircraftInfo = transport.TraitOrDefault<Aircraft>();
if (aircraftInfo != null)
{
if (!aircraftInfo.IsPlane)
{
transport.QueueActivity(new Turn(transport, aircraftInfo.Info.InitialFacing));
transport.QueueActivity(new HeliLand(transport, true));
}
else
{
transport.QueueActivity(new Land(transport, Target.FromCell(transport.World, entryPath.Last())));
}
transport.QueueActivity(new Wait(15));
}
if (cargo != null)
{
transport.QueueActivity(new UnloadCargo(transport, true));
transport.QueueActivity(new WaitFor(() => cargo.IsEmpty(transport)));
}
transport.QueueActivity(new Wait(aircraftInfo != null ? 50 : 25));
}
if (exitFunc != null)
{
var ef = exitFunc.CopyReference() as LuaFunction;
transport.QueueActivity(new CallFunc(() =>
{
ef.Call(transport.ToLuaValue(Context));
ef.Dispose();
}));
}
else if (exitPath != null)
{
foreach (var wpt in exitPath)
Move(transport, wpt);
transport.QueueActivity(new RemoveSelf());
}
var ret = Context.CreateTable();
ret.Add(1, transport.ToLuaValue(Context));
ret.Add(2, passengers.ToArray().ToLuaValue(Context));
return ret;
}
示例12: RegisterCallback
public void RegisterCallback(Trigger trigger, LuaFunction func, ScriptContext context)
{
Triggers[trigger].Add(Pair.New((LuaFunction)func.CopyReference(), context));
}
示例13: PlayMusic
public void PlayMusic(string track = null, LuaFunction func = null)
{
if (!Game.Settings.Sound.MapMusic)
return;
var music = world.Map.Rules.InstalledMusic.Select(a => a.Value).ToArray();
if (!music.Any())
return;
var musicInfo = !string.IsNullOrEmpty(track) ? world.Map.Rules.Music[track]
: Game.Settings.Sound.Repeat && previousMusic != null ? previousMusic
: Game.Settings.Sound.Shuffle ? music.Random(Game.CosmeticRandom)
: previousMusic == null ? music.First()
: music.SkipWhile(s => s != previousMusic).Skip(1).First();
if (func != null)
{
var f = func.CopyReference() as LuaFunction;
onComplete = () =>
{
try
{
using (f)
f.Call().Dispose();
}
catch (LuaException e)
{
Context.FatalError(e.Message);
}
};
}
else
onComplete = () => { };
Sound.PlayMusicThen(musicInfo, onComplete);
previousMusic = Sound.CurrentMusic;
}
示例14: PlayMovieInRadar
public bool PlayMovieInRadar(string movie, LuaFunction playComplete = null)
{
if (playComplete != null)
{
var f = playComplete.CopyReference() as LuaFunction;
onCompleteRadar = () =>
{
try
{
using (f)
f.Call().Dispose();
}
catch (LuaException e)
{
Context.FatalError(e.Message);
}
};
}
else
onCompleteRadar = () => { };
Stream s = null;
try
{
s = GlobalFileSystem.Open(movie);
}
catch (FileNotFoundException e)
{
Log.Write("lua", "Couldn't play movie {0}! File doesn't exist.", e.FileName);
onCompleteRadar();
return false;
}
AsyncLoader l = new AsyncLoader(Media.LoadVqa);
IAsyncResult ar = l.BeginInvoke(s, null, null);
onLoadComplete = () =>
{
Media.StopFMVInRadar();
world.AddFrameEndTask(_ => Media.PlayFMVInRadar(world, l.EndInvoke(ar), onCompleteRadar));
};
world.AddFrameEndTask(w => w.Add(new AsyncAction(ar, onLoadComplete)));
return true;
}
示例15: OnExitedProximityTrigger
public int OnExitedProximityTrigger(WPos pos, WDist range, LuaFunction func)
{
// We can't easily dispose onExit, so we'll have to rely on finalization for it.
var onExit = (LuaFunction)func.CopyReference();
var triggerId = 0;
Action<Actor> invokeExit = a =>
{
try
{
using (var luaActor = a.ToLuaValue(Context))
using (var id = triggerId.ToLuaValue(Context))
onExit.Call(luaActor, id).Dispose();
}
catch (Exception e)
{
Context.FatalError(e.Message);
}
};
triggerId = Context.World.ActorMap.AddProximityTrigger(pos, range, null, invokeExit);
return triggerId;
}