I have a query regarding passing dynamic values to custom functions registered with Lua and/or scene independent events.
Context is an rts style strategy game where your units (volunteers) are instantiated at runtime on a strategymap.
These units are each named Actors in the database. The 3d model for the Actor in the gameworld is named "Actorname+VolunteerModel"
At runtime, under certain conditions, these actors can have conversations initiated with NPC conversants (simulating a police/army checkpoint) where the potential outcomes vary from no effect to the unit is killed/arrested.
The plan is to use one generic Checkpoint conversation and dynamically assign actor/conversant at runtime depending which unit initiates the Checkpoint conversation. The player then acts as that Actor for the particular conversation.
I have a custom Lua Function registered called ArrestVolunteer:
Code: Select all
public class CheckpointFunctions : MonoBehaviour // Rename this class.
{
WMSK map;// reference to the strategy map
[Tooltip("Typically leave unticked so temporary Dialogue Managers don't unregister your functions.")]
public bool unregisterOnDisable = false;
void OnEnable()
{
map = WMSK.instance;
// Make the functions available to Lua: (Replace these lines with your own.)
Lua.RegisterFunction("ArrestVolunteer", this, SymbolExtensions.GetMethodInfo(() => ArrestVolunteer(string.Empty)));
//Lua.RegisterFunction("AddOne", this, SymbolExtensions.GetMethodInfo(() => AddOne((double)0)));
}
void OnDisable()
{
if (unregisterOnDisable)
{
// Remove the functions from Lua: (Replace these lines with your own.)
Lua.UnregisterFunction("ArrestVolunteer");
// Lua.UnregisterFunction("AddOne");
}
}
public void ArrestVolunteer(string volunteername)
{
GameObject go = GameObject.Find(volunteername + "VolunteerModel");
VolunteerModel vm = go.GetComponent<VolunteerModel>();
vm.VolunteerData.VolunteerStatus = VolunteerStatus.Custody;
GameObjectAnimator anim = go.GetComponent<GameObjectAnimator>();
map.VGOUnRegisterGameObject(anim);
DestroyImmediate(go);
}
I also have a scriptable object based custom GameEvent asset which I would like to be able to pass the same string to by raising it as the target of a Scene Independent Event with a string parameter.
Question is, how would I go about passing the Actor name dynamically as a string (or partially dynamic, like:
ArrestVolunteer(CurrentActorName+"VolunteerModel")
when I wont know the Actors name ahead of runtime? and essentially the same question for passing CurrentActor Name as a parameter to a scene independent Event.
Thanks in advance for any help.
Cheers,
JC