Example #1
0
    /// <summary>
    /// 创建可发射的直线激光
    /// <para>texture 暂时指向于etama9的激光贴图</para>
    /// <para>laserLen 激光长度</para>
    /// <para>posX</para>
    /// <para>posY</para>
    /// </summary>
    /// <param name="luaState"></param>
    /// <returns></returns>
    public static int CreateLinearLaser(ILuaState luaState)
    {
        string id       = luaState.ToString(-4);
        int    laserLen = luaState.ToInteger(-3);
        float  posX     = (float)luaState.ToNumber(-2);
        float  posY     = (float)luaState.ToNumber(-1);

        luaState.Pop(4);
        EnemyLinearLaser laser = ObjectsPool.GetInstance().CreateBullet(BulletType.Enemy_LinearLaser) as EnemyLinearLaser;

        laser.SetStyleById(id);
        laser.SetLength(laserLen);
        laser.SetPosition(posX, posY);
        luaState.PushLightUserData(laser);
        return(1);
    }
Example #2
0
    public static int CreateCustomizedLinearLaser(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);
        int    initFuncRef    = InterpreterManager.GetInstance().GetBulletInitFuncRef(customizedName);

        luaState.RawGetI(LuaDef.LUA_REGISTRYINDEX, initFuncRef);
        // 将本体插入执行栈中
        EnemyLinearLaser laser = ObjectsPool.GetInstance().CreateBullet(BulletType.Enemy_LinearLaser) as EnemyLinearLaser;

        laser.AddOrGetComponent <BCCustomizedTask>();
        laser.SetPosition(posX, posY);
        luaState.PushLightUserData(laser);
        for (int i = 0; i < numArgs; i++)
        {
            luaState.PushValue(-2 - numArgs);
        }
        luaState.Call(numArgs + 1, 0);
        // 将返回值压入栈中
        luaState.PushLightUserData(laser);
        return(1);
    }
    public static bool Set(object o, TValue key, ref TValue value)
    {
        EnemyLinearLaser bullet = (EnemyLinearLaser)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 "checkBorder":
            {
                bullet.SetCheckOutOfBorder(value.BValue());
                return(true);
            }
                #endregion
            }
        }
        value.SetSValue(string.Format("SetField of userData fail!Invalid key {0} for type {1}", key, typeof(EnemySimpleBullet).Name));
        return(false);
    }