Browse Source

Refactored LuaUtils to use ILuaUtils interface

master
Christopher 9 years ago
parent
commit
8e1584f8c6
  1. 72
      Assets/Fungus/Thirdparty/FungusLua/Scripts/ILuaUtils.cs
  2. 12
      Assets/Fungus/Thirdparty/FungusLua/Scripts/ILuaUtils.cs.meta
  3. 2
      Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaStore.cs
  4. 106
      Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaUtils.cs

72
Assets/Fungus/Thirdparty/FungusLua/Scripts/ILuaUtils.cs vendored

@ -0,0 +1,72 @@
using UnityEngine;
using System.Collections;
using System.Text;
namespace Fungus
{
public interface ILuaUtils
{
/// <summary>
/// Returns a string from the string table for this key.
/// The string returned depends on the active language.
/// </summary>
string GetString(string key);
/// <summary>
/// Implementation of StringSubstituter.ISubstitutionHandler
/// Substitutes specially formatted tokens in the text with global variables and string table values.
/// The string table value used depends on the currently loaded string table and active language.
/// </summary>
bool SubstituteStrings(StringBuilder input);
/// <summary>
/// Performs string substitution on the input string, replacing tokens of the form {$VarName} with
/// matching variables, localised strings, etc. in the scene.
/// </summary>
string Substitute(string input);
/// <summary>
/// Find a game object by name and returns it.
/// </summary>
GameObject Find(string name);
/// <summary>
/// Returns one active GameObject tagged tag. Returns null if no GameObject was found.
/// </summary>
GameObject FindWithTag(string tag);
/// <summary>
/// Returns a list of active GameObjects tagged tag. Returns empty array if no GameObject was found.
/// </summary>
GameObject[] FindGameObjectsWithTag(string tag);
/// <summary>
/// Create a copy of a GameObject.
/// Can be used to instantiate prefabs.
/// </summary>
GameObject Instantiate(GameObject go);
/// <summary>
/// Destroys an instance of a GameObject.
/// </summary>
void Destroy(GameObject go);
/// <summary>
/// Spawns an instance of a named prefab resource.
/// The prefab must exist in a Resources folder in the project.
/// </summary>
GameObject Spawn(string resourceName);
/// <summary>
/// Use the conversation manager to play out a conversation
/// </summary>
/// <param name="conv"></param>
IEnumerator DoConversation(string conv);
/// <summary>
/// Sync the active say dialog with what Lua thinks the SayDialog should be
/// </summary>
/// <param name="sayDialog"></param>
void SetSayDialog(ISayDialog sayDialog);
}
}

12
Assets/Fungus/Thirdparty/FungusLua/Scripts/ILuaUtils.cs.meta vendored

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d24a505bdb666456d84b02a983fe5bee
timeCreated: 1473674337
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

2
Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaStore.cs vendored

@ -24,7 +24,7 @@ namespace Fungus
protected static LuaStore instance;
public void Start()
protected virtual void Start()
{
Init();
}

106
Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaUtils.cs vendored

@ -15,7 +15,7 @@ namespace Fungus
/// <summary>
/// A collection of utilites to use in Lua for common Unity / Fungus tasks.
/// </summary>
public class LuaUtils : LuaEnvironment.Initializer, StringSubstituter.ISubstitutionHandler
public class LuaUtils : LuaEnvironment.Initializer, StringSubstituter.ISubstitutionHandler, ILuaUtils
{
public enum FungusModuleOptions
{
@ -71,37 +71,6 @@ namespace Fungus
protected ConversationManager conversationManager;
/// <summary>
/// Called by LuaEnvironment when initializing.
/// </summary>
public override void Initialize()
{
LuaEnv = GetComponent<ILuaEnvironment>();
if (LuaEnv == null)
{
Debug.LogError("No Lua Environment found");
return;
}
if (LuaEnv.Interpreter == null)
{
Debug.LogError("No Lua interpreter found");
return;
}
InitTypes();
InitFungusModule();
InitBindings();
}
/// <summary>
/// Called by LuaEnvironment prior to executing a script.
/// </summary>
public override string PreprocessScript(string input)
{
return input;
}
/// <summary>
/// Registers all listed c# types for interop with Lua.
/// You can also register types directly in the Awake method of any
@ -306,10 +275,40 @@ namespace Fungus
}
}
#region LuaEnvironment.Initializer implementation
public override void Initialize()
{
LuaEnv = GetComponent<ILuaEnvironment>();
if (LuaEnv == null)
{
Debug.LogError("No Lua Environment found");
return;
}
if (LuaEnv.Interpreter == null)
{
Debug.LogError("No Lua interpreter found");
return;
}
InitTypes();
InitFungusModule();
InitBindings();
}
/// <summary>
/// Returns a string from the string table for this key.
/// The string returned depends on the active language.
/// Called by LuaEnvironment prior to executing a script.
/// </summary>
public override string PreprocessScript(string input)
{
return input;
}
#endregion
#region ILuaUtils implementation
public virtual string GetString(string key)
{
if (stringTable != null)
@ -329,11 +328,6 @@ namespace Fungus
return "";
}
/// <summary>
/// Implementation of StringSubstituter.ISubstitutionHandler
/// Substitutes specially formatted tokens in the text with global variables and string table values.
/// The string table value used depends on the currently loaded string table and active language.
/// </summary>
[MoonSharpHidden]
public virtual bool SubstituteStrings(StringBuilder input)
{
@ -402,60 +396,36 @@ namespace Fungus
return modified;
}
/// <summary>
/// Performs string substitution on the input string, replacing tokens of the form {$VarName} with
/// matching variables, localised strings, etc. in the scene.
/// </summary>
public virtual string Substitute(string input)
{
return stringSubstituter.SubstituteStrings(input);
}
/// <summary>
/// Find a game object by name and returns it.
/// </summary>
public virtual GameObject Find(string name)
{
return GameObject.Find(name);
}
/// <summary>
/// Returns one active GameObject tagged tag. Returns null if no GameObject was found.
/// </summary>
public virtual GameObject FindWithTag(string tag)
{
return GameObject.FindGameObjectWithTag(tag);
}
/// <summary>
/// Returns a list of active GameObjects tagged tag. Returns empty array if no GameObject was found.
/// </summary>
public virtual GameObject[] FindGameObjectsWithTag(string tag)
{
return GameObject.FindGameObjectsWithTag(tag);
}
/// <summary>
/// Create a copy of a GameObject.
/// Can be used to instantiate prefabs.
/// </summary>
public virtual GameObject Instantiate(GameObject go)
{
return GameObject.Instantiate(go);
}
/// <summary>
/// Destroys an instance of a GameObject.
/// </summary>
public virtual void Destroy(GameObject go)
{
GameObject.Destroy(go);
}
/// <summary>
/// Spawns an instance of a named prefab resource.
/// The prefab must exist in a Resources folder in the project.
/// </summary>
public virtual GameObject Spawn(string resourceName)
{
// Auto spawn a say dialog object from the prefab
@ -469,22 +439,16 @@ namespace Fungus
return null;
}
/// <summary>
/// Use the conversation manager to play out a conversation
/// </summary>
/// <param name="conv"></param>
public virtual IEnumerator DoConversation(string conv)
{
return conversationManager.DoConversation(conv);
}
/// <summary>
/// Sync the active say dialog with what Lua thinks the SayDialog should be
/// </summary>
/// <param name="sayDialog"></param>
public void SetSayDialog(ISayDialog sayDialog)
{
SayDialog.activeSayDialog = sayDialog;
}
#endregion
}
}
Loading…
Cancel
Save