Announcements, support questions, and discussion for the Dialogue System.
DeidreReay
Posts: 93 Joined: Wed Jan 22, 2020 1:20 pm
Post
by DeidreReay » Mon Jan 08, 2024 7:09 pm
So back again and not sure how to make this work correctly, or if just over thinking. I want to be able to call from dialogue system these methods to basically allow players a teleportation system, but not sure how to do this or if I need to with lua extensions. Any help would be appreciated.
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class ShellTeleportationSystem : MonoBehaviour
{
public Transform ViernesLocation;
public Transform PortNethreanLocation;
public Transform EasternWatchLocation;
public Transform PlayerTransform;
private void Awake()
{
}
void OnEnable()
{
// Register functions for Lua (if needed).
Lua.RegisterFunction(nameof(DebugLog), this, SymbolExtensions.GetMethodInfo(() => DebugLog(string.Empty)));
}
void OnDisable()
{
// Unregister functions from Lua (if needed).
Lua.UnregisterFunction(nameof(DebugLog));
}
public void DebugLog(string message)
{
Debug.Log(message);
}
public double AddOne(double value)
{
// Note: Lua always passes numbers as doubles.
return value + 1;
}
public void TeleportViernes()
{
if (ViernesLocation != null && PlayerTransform != null)
{
PlayerTransform.position = ViernesLocation.position;
}
}
public void TeleportPortNethrean()
{
if (PortNethreanLocation != null && PlayerTransform != null)
{
PlayerTransform.position = PortNethreanLocation.position;
}
}
public void TeleportEasternWatch()
{
if (EasternWatchLocation != null && PlayerTransform != null)
{
PlayerTransform.position = EasternWatchLocation.position;
}
}
}
Tony Li
Posts: 22112 Joined: Thu Jul 18, 2013 1:27 pm
Post
by Tony Li » Mon Jan 08, 2024 8:12 pm
Hi,
Try this version:
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class ShellTeleportationSystem : MonoBehaviour
{
public Transform ViernesLocation;
public Transform PortNethreanLocation;
public Transform EasternWatchLocation;
public Transform PlayerTransform;
[Tooltip("If this component is on your Dialogue Manager, leave this unticked so temporary Dialogue Managers don't unregister your functions.")]
public bool unregisterOnDisable = false;
void OnEnable()
{
Lua.RegisterFunction(nameof(TeleportViernes), this, SymbolExtensions.GetMethodInfo(() => TeleportViernes()));
Lua.RegisterFunction(nameof(TeleportPortNethrean), this, SymbolExtensions.GetMethodInfo(() => TeleportPortNethrean()));
Lua.RegisterFunction(nameof(TeleportEasternWatch), this, SymbolExtensions.GetMethodInfo(() => TeleportEasternWatch()));
}
void OnDisable()
{
if (unregisterOnDisable)
{
Lua.UnregisterFunction(nameof(TeleportViernes));
Lua.UnregisterFunction(nameof(TeleportPortNethrean));
Lua.UnregisterFunction(nameof(TeleportEasternWatch));
}
}
public void TeleportViernes()
{
if (ViernesLocation != null && PlayerTransform != null)
{
PlayerTransform.position = ViernesLocation.position;
}
}
public void TeleportPortNethrean()
{
if (PortNethreanLocation != null && PlayerTransform != null)
{
PlayerTransform.position = PortNethreanLocation.position;
}
}
public void TeleportEasternWatch()
{
if (EasternWatchLocation != null && PlayerTransform != null)
{
PlayerTransform.position = EasternWatchLocation.position;
}
}
}
Then create a Custom Lua Function Info asset like this so you can select your functions from the Script field's "..." dropdown:
customLuaFunctionInfo.png (37.88 KiB) Viewed 47602 times
To create a Custom Lua Function Info asset, select menu item Assets > Create > Pixel Crushers > Dialogue System > Custom Lua Function Info.