相关链接:
http://blog.csdn.net/u010665359/article/details/50950989
http://blog.csdn.net/u010665359/article/details/51013433
在lua中使用DOTween
1.先下载一些东西:http://pan.baidu.com/s/1pLOSxx5
2.在Assets\LuaFramework\Editor下建两个文件夹,分别命名为LuaExtensions和Wrap,然后在LuaExtensions文件夹内放入ToLuaFile.cs和ToLuaFileExport.cs,然后点击菜单栏Lua/Export ToLuaExtendFile,如无意外就会看到:
3.将项目中的ToLuaExport.cs进行一些修改,当然你可以不修改,直接将下载的ToLuaExport.cs替换原来的,注意最好备份。要修改的地方用红色标明了:
static void SaveFile(string file)
{
using (StreamWriter textWriter = new StreamWriter(file, false, Encoding.UTF8))
{
StringBuilder usb = new StringBuilder();
usb.AppendLineEx("//this source code was auto-generated by tolua#, do not modify it");
foreach (string str in usingList)
{
usb.AppendFormat("using {0};\r\n", str);
}
usb.AppendLineEx("using LuaInterface;");
if (ambig == ObjAmbig.All)
{
usb.AppendLineEx("using Object = UnityEngine.Object;");
}
if (NeedDotweenNamespace())//给导出dotween的文件新增dotween的命名空间
{
usb.AppendLine("using DG.Tweening;");
}
usb.AppendLineEx();
textWriter.Write(usb.ToString());
textWriter.Write(sb.ToString());
textWriter.Flush();
textWriter.Close();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static bool NeedDotweenNamespace()
{
//UnityEngine.Debug.Log(libClassName);
switch (libClassName)
{
case "Transform":
case "AudioSource":
case "Camera":
case "Component":
case "Light":
case "Material":
case "Sequence":
case "Tween":
case "Tweener":
case "Rigidbody":
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void ProcessExtends(List<MethodInfo> list)
{
extendName = "ToLua_" + className.Replace(".", "_");
extendType = Type.GetType(extendName + ", Assembly-CSharp-Editor");
List<string> removeMd = new List<string>();
if (extendType != null)
{
List<MethodInfo> list2 = new List<MethodInfo>();
list2.AddRange(extendType.GetMethods(BindingFlags.Instance | binding | BindingFlags.DeclaredOnly));
for (int i = list2.Count - 1; i >= 0; i--)
{
if (list2[i].Name.Contains("op_") || list2[i].Name.Contains("add_") || list2[i].Name.Contains("remove_"))
{
if (!IsNeedOp(list2[i].Name))
{
//list2.RemoveAt(i);
continue;
}
}
string removeMdName = list2[i].Name;
if (!removeMd.Contains(removeMdName))//防止扩展函数里面重载函数被去除
{
removeMd.Add(removeMdName);
list.RemoveAll((md) => { return md.Name == removeMdName; });
}
//list.RemoveAll((md) => { return md.Name == list2[i].Name; });
if (!IsObsolete(list2[i]))
{
list.Add(list2[i]);
}
}
FieldInfo field = extendType.GetField("AdditionNameSpace");
if (field != null)
{
string str = field.GetValue(null) as string;
string[] spaces = str.Split(new char[] { ';' });
for (int i = 0; i < spaces.Length; i++)
{
usingList.Add(spaces[i]);
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
打开CustomSettings.cs:
_GT(typeof(DG.Tweening.AutoPlay)),
_GT(typeof(DG.Tweening.AxisConstraint)),
_GT(typeof(DG.Tweening.Ease)),
_GT(typeof(DG.Tweening.LogBehaviour)),
_GT(typeof(DG.Tweening.LoopType)),
_GT(typeof(DG.Tweening.PathMode)),
_GT(typeof(DG.Tweening.PathType)),
_GT(typeof(DG.Tweening.RotateMode)),
_GT(typeof(DG.Tweening.ScrambleMode)),
_GT(typeof(DG.Tweening.TweenType)),
_GT(typeof(DG.Tweening.UpdateType)),
_GT(typeof(DG.Tweening.DOTween)),
_GT(typeof(DG.Tweening.DOVirtual)),
_GT(typeof(DG.Tweening.EaseFactory)),
_GT(typeof(DG.Tweening.Tweener)),
_GT(typeof(DG.Tweening.Tween)),
_GT(typeof(DG.Tweening.Sequence)),
_GT(typeof(DG.Tweening.TweenParams)),
_GT(typeof(DG.Tweening.DOTweenAnimation)),
_GT(typeof(DG.Tweening.DOTweenPath)),
_GT(typeof(DG.Tweening.DOTweenVisualManager)),
_GT(typeof(DG.Tweening.Core.ABSSequentiable)),
_GT(typeof(DG.Tweening.Core.TweenerCore<Vector3, Vector3, DG.Tweening.Plugins.Options.VectorOptions>)).SetWrapName("TweenerCoreV3V3VO").SetLibName("TweenerCoreV3V3VO"),
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4.重新生成wrap,然后测试:transform:DOMove(Vector3.zero, 3, false);
5.以DOMove为例,它需要的参数个数和类型可以看ToLua_UnityEngine_Transform