/// <summary> /// 创建自定义的simpleBullet /// <para>customizedName 自定义的子弹名称</para> /// <para>float posX</para> /// <para>float posY</para> /// <para>args...</para> /// </summary> /// <param name="luaState"></param> /// <returns></returns> public static int CreateCustomizedBullet(ILuaState luaState) { int numArgs = luaState.GetTop() - 3; string customizedName = luaState.ToString(-3 - numArgs); float posX = (float)luaState.ToNumber(-2 - numArgs); float posY = (float)luaState.ToNumber(-1 - numArgs); EnemySimpleBullet bullet = ObjectsPool.GetInstance().CreateBullet(BulletType.Enemy_Simple) as EnemySimpleBullet; bullet.SetPosition(posX, posY); // 设置自定义的数据 BCCustomizedTask bc = bullet.AddOrGetComponent <BCCustomizedTask>(); int funcRef = InterpreterManager.GetInstance().GetBulletInitFuncRef(customizedName); luaState.RawGetI(LuaDef.LUA_REGISTRYINDEX, funcRef); if (!luaState.IsFunction(-1)) { Logger.LogError("InitFuncRef of " + customizedName + " is not point to a function"); } luaState.PushLightUserData(bullet); for (int i = 0; i < numArgs; i++) { luaState.PushValue(-2 - numArgs); } luaState.Call(numArgs + 1, 0); luaState.PushLightUserData(bullet); return(1); }
/// <summary> /// 创建自定义的simpleBullet /// <para>customizedName 自定义的子弹名称</para> /// <para>id 默认的id</para> /// <para>float posX</para> /// <para>float posY</para> /// </summary> /// <param name="luaState"></param> /// <returns></returns> public static int CreateCustomizedBullet2(ILuaState luaState) { int numArgs = luaState.ToInteger(-1); string customizedName = luaState.ToString(-5 - numArgs); string sysId; if (luaState.Type(-4 - numArgs) == LuaType.LUA_TNUMBER) { sysId = luaState.ToNumber(-4 - numArgs).ToString(); } else { sysId = luaState.ToString(-4 - numArgs); } float posX = (float)luaState.ToNumber(-3 - numArgs); float posY = (float)luaState.ToNumber(-2 - numArgs); luaState.Pop(1); EnemySimpleBullet bullet = ObjectsPool.GetInstance().CreateBullet(BulletType.Enemy_Simple) as EnemySimpleBullet; bullet.SetStyleById(sysId); bullet.SetPosition(posX, posY); // 设置自定义的数据 BCCustomizedTask bc = bullet.AddOrGetComponent <BCCustomizedTask>(); int funcRef = InterpreterManager.GetInstance().GetBulletInitFuncRef(customizedName); luaState.RawGetI(LuaDef.LUA_REGISTRYINDEX, funcRef); if (!luaState.IsFunction(-1)) { Logger.LogError("InitFuncRef of " + customizedName + " is not point to a function"); } luaState.PushLightUserData(bullet); luaState.Replace(-3 - numArgs); luaState.Replace(-3 - numArgs); luaState.Call(numArgs + 1, 0); // 弹出剩余两个参数 luaState.Pop(2); luaState.PushLightUserData(bullet); return(1); }
/// <summary> /// 根据id创建SimpleBullet /// <para>id 配置里面的id</para> /// <para>float posX</para> /// <para>float posY</para> /// </summary> /// <param name="luaState"></param> /// <returns></returns> public static int CreateSimpleBulletById(ILuaState luaState) { string sysId; if (luaState.Type(-3) == LuaType.LUA_TNUMBER) { sysId = luaState.ToNumber(-3).ToString(); } else { sysId = luaState.ToString(-3); } float posX = (float)luaState.ToNumber(-2); float posY = (float)luaState.ToNumber(-1); luaState.Pop(3); EnemySimpleBullet bullet = ObjectsPool.GetInstance().CreateBullet(BulletType.Enemy_Simple) as EnemySimpleBullet; bullet.SetStyleById(sysId); bullet.SetPosition(posX, posY); luaState.PushLightUserData(bullet); return(1); }
public static bool Set(object o, TValue key, ref TValue value) { EnemySimpleBullet bullet = (EnemySimpleBullet)o; if (key.TtIsString()) { switch (key.SValue()) { #region 基础变量 case "x": { Vector2 pos = bullet.GetPosition(); pos.x = (float)value.NValue; bullet.SetPosition(pos); return(true); } case "y": { Vector2 pos = bullet.GetPosition(); pos.y = (float)value.NValue; bullet.SetPosition(pos); return(true); } case "rot": { bullet.SetRotation((float)value.NValue); return(true); } #endregion #region 运动相关变量 case "v": { bullet.Velocity = (float)value.NValue; return(true); } case "vx": { bullet.Vx = (float)value.NValue; return(true); } case "vy": { bullet.Vy = (float)value.NValue; return(true); } case "vAngle": { bullet.VAngle = (float)value.NValue; return(true); } case "maxV": { bullet.MaxVelocity = (float)value.NValue; return(true); } case "acce": { bullet.Acce = (float)value.NValue; return(true); } case "accAngle": { bullet.AccAngle = (float)value.NValue; return(true); } #endregion #region 子弹类专属变量 case "orderInLayer": { bullet.SetOrderInLayer((int)value.NValue); return(true); } case "checkCollision": { bullet.SetDetectCollision(value.BValue()); return(true); } case "navi": { bullet.SetRotatedByVelocity(value.BValue()); return(true); } case "checkBorder": { bullet.SetCheckOutOfBorder(value.BValue()); return(true); } case "alpha": { bullet.SetAlpha((float)value.NValue); return(true); } case "omega": { bullet.SetSelfRotation((float)value.NValue); return(true); } case "scale": { bullet.SetScale((float)value.NValue); return(true); } case "scaleX": { bullet.SetBulletPara(BulletParaType.ScaleX, (float)value.NValue); return(true); } case "scaleY": { bullet.SetBulletPara(BulletParaType.ScaleY, (float)value.NValue); return(true); } #endregion } } value.SetSValue(string.Format("SetField of userData fail!Invalid key {0} for type {1}", key, typeof(EnemySimpleBullet).Name)); return(false); }