Beispiel #1
0
    public override void Clear()
    {
        Task task;

        for (int i = 0; i < _taskCount; i++)
        {
            task = _taskList[i];
            if (task != null)
            {
                if (task.luaState != null)
                {
                    InterpreterManager.GetInstance().StopTaskThread(task.luaState, task.funcRef);
                }
                ObjectsPool.GetInstance().RestorePoolClassToPool <Task>(task);
            }
        }
        _taskList.Clear();
        _taskCount = 0;
        _bullet    = null;
    }
    public void RemoveTimer(string timerStr)
    {
        int   i;
        Timer timer;

        if (_timerDic.TryGetValue(timerStr, out timer))
        {
            _timerDic.Remove(timerStr);
            for (i = 0; i < _timerCount; i++)
            {
                timer = _timerList[i];
                if (timer != null && timer.timerStr == timerStr)
                {
                    _timerList[i] = null;
                    ObjectsPool.GetInstance().RestorePoolClassToPool <Timer>(timer);
                    break;
                }
            }
        }
    }
Beispiel #3
0
 public override void Clear()
 {
     if (_curColor != DefaultColor)
     {
         _bodySR.color    = DefaultColor;
         _border0SR.color = DefaultColor;
         _border1SR.color = DefaultColor;
         _curColor        = DefaultColor;
     }
     if (_curScale != DefaultScale)
     {
         _tf.localScale = DefaultScale;
         _curScale      = DefaultScale;
     }
     UIManager.GetInstance().HideGo(_go);
     ObjectsPool.GetInstance().RestorePrefabToPool(_prefabName, _go);
     _go        = null;
     _tf        = null;
     _border0Tf = null;
     _border1Tf = null;
 }
Beispiel #4
0
 protected void Shoot()
 {
     // 更新CD
     if (_curShootCD > 0)
     {
         _curShootCD--;
     }
     if (_character.CanShoot() && _character.IsInShootingStatus())
     {
         if (_curShootCD == 0)
         {
             float posX, posY;
             _character.GetPosition(out posX, out posY);
             BulletReimuASub1 bullet = ObjectsPool.GetInstance().CreateBullet(BulletType.ReimuA_Sub1) as BulletReimuASub1;
             bullet.ChangeStyleById("501000");
             bullet.SetPosition(posX + _subWeapon.transform.localPosition.x, posY + _subWeapon.transform.localPosition.y);
             bullet.DoMove(8, GetShootBulletAngle());
             _curShootCD = ShootCD;
         }
     }
 }
Beispiel #5
0
 public override void Init()
 {
     base.Init();
     _isMoving                  = false;
     _curTrailLen               = 0;
     _laserHalfWidth            = 5;
     _collisionRadius           = 3;
     _availableCount            = 0;
     _eliminateRangeListCount   = 0;
     _isCachedCollisionSegments = false;
     _collisionSegmentsList     = new List <Vector2>();
     _collisionSegmentsCount    = 0;
     _isPosModified             = false;
     _isInitPos                 = false;
     _isSourceEliminated        = false;
     if (_movableObj == null)
     {
         _movableObj = ObjectsPool.GetInstance().GetPoolClassAtPool <MovableObject>();
     }
     BulletsManager.GetInstance().RegisterEnemyBullet(this);
 }
Beispiel #6
0
    private void ClearTasks()
    {
        int  i;
        Task task;

        for (i = 0; i < _taskCount; i++)
        {
            task = _taskList[i];
            if (task != null)
            {
                if (!task.isFinish)
                {
                    InterpreterManager.GetInstance().StopTaskThread(task);
                    ObjectsPool.GetInstance().RestorePoolClassToPool <Task>(task);
                }
            }
        }
        _taskList.Clear();
        _taskCount = 0;
        _clearTime = 0;
    }
Beispiel #7
0
    public static int CreateLaser(ILuaState luaState)
    {
        string id            = luaState.ToString(-7);
        float  posX          = (float)luaState.ToNumber(-6);
        float  posY          = (float)luaState.ToNumber(-5);
        float  angle         = (float)luaState.ToNumber(-4);
        float  length        = (float)luaState.ToNumber(-3);
        float  width         = (float)luaState.ToNumber(-2);
        int    existDuration = luaState.ToInteger(-1);

        luaState.Pop(7);
        EnemyLaser laser = ObjectsPool.GetInstance().CreateBullet(BulletType.Enemy_Laser) as EnemyLaser;

        laser.SetStyleById(id);
        laser.SetPosition(posX, posY);
        laser.SetRotation(angle);
        laser.SetSize(width, length);
        laser.SetLaserExistDuration(existDuration);
        luaState.PushLightUserData(laser);
        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);
    }
    public virtual void Clear()
    {
        int i;

        foreach (BgBlockContainer container in _containerList)
        {
            container.Clear();
        }
        _containerList.Clear();
        BgSpriteObject spObj;

        for (i = 0; i < _spriteObjCount; i++)
        {
            spObj = _spriteObjList[i];
            if (spObj != null)
            {
                ObjectsPool.GetInstance().RestorePoolClassToPool(spObj);
            }
        }
        _spriteObjList.Clear();
        _spriteObjCount = 0;
    }
 public override void SetStyleById(string id)
 {
     EnemyLinearLaserCfg cfg = BulletsManager.GetInstance().GetLinearLaserCfgById(id);
     if (cfg == null)
     {
         Logger.LogError("LaserCfg with id " + id + " is not exist!");
         return;
     }
     if ( _laserObj != null )
     {
         ObjectsPool.GetInstance().RestorePrefabToPool(_prefabName, _laserObj);
     }
     _cfg = cfg;
     _prefabName = _cfg.id;
     _laserObj = BulletsManager.GetInstance().CreateBulletGameObject(BulletType.Enemy_Laser, _cfg.id);
     _objTrans = _laserObj.transform;
     _laserTrans = _objTrans.Find("LaserSprite");
     _laser = _laserTrans.GetComponent<SpriteRenderer>();
     _sourceTf = _objTrans.Find("Source");
     _sourceSp = _sourceTf.GetComponent<SpriteRenderer>();
     _isDirty = true;
 }
Beispiel #11
0
    public void UpdateDialogTask()
    {
        int dTime = 1;

        _timeSinceLastSkip++;
        if (!_dialogTask.isFinish)
        {
            if (CheckCanSkip())
            {
                dTime = _dialogTask.totalWaitTime - _dialogTask.curWaitTime;
                _dialogTask.curWaitTime = _dialogTask.totalWaitTime;
                _timeSinceLastSkip      = 0;
            }
            CommandManager.GetInstance().RunCommand(CommandConsts.UpdateDialog, dTime);
            InterpreterManager.GetInstance().CallTaskCoroutine(_dialogTask);
        }
        if (_dialogTask.isFinish)
        {
            _isInDialogMode = false;
            ObjectsPool.GetInstance().RestorePoolClassToPool <Task>(_dialogTask);
            _dialogTask = null;
        }
    }
Beispiel #12
0
    private void CheckDestroyBullets()
    {
        BulletBase tmpBullet;
        int        tmpCount, i;

        for (i = 0, tmpCount = _playerBullets.Count; i < tmpCount; i++)
        {
            tmpBullet = _playerBullets[i];
            if (tmpBullet.ClearFlag == 1)
            {
                _playerBullets[i] = null;
                _clearList.Add(tmpBullet);
            }
        }
        tmpCount = _clearList.Count;
        for (i = 0; i < tmpCount; i++)
        {
            tmpBullet = _clearList[i];
            tmpBullet.Clear();
            ObjectsPool.GetInstance().RestoreBullet(tmpBullet);
        }
        _clearList.Clear();
    }
    /// <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 override void Clear()
    {
        // 清除多余的LaserSegment
        int          i;
        LaserSegment segment;

        for (i = 0; i < _laserSegmentCount; i++)
        {
            _laserSegmentList[i].Clear();
        }
        _laserSegmentList.Clear();
        _laserSegmentCount = 0;
        while (_laserSegmentPool.Count > 0)
        {
            segment = _laserSegmentPool.Pop();
            segment.Clear();
        }
        _laserSegmentProtoType = null;
        // 隐藏source
        if (_laserSourceGo != null)
        {
            _laserSourceGo.SetActive(false);
        }
        _laserSourceGo = null;
        _laserSourceTf = null;
        // LaserObject
        ObjectsPool.GetInstance().RestorePrefabToPool(_prefabName, _laserObj);
        _laserObj = null;
        _objTrans = null;
        _pathList.Clear();
        // movableObject
        ObjectsPool.GetInstance().RestorePoolClassToPool <MovableObject>(_movableObj);
        _movableObj = null;
        _collisionSegmentList.Clear();
        _laserSegmentList.Clear();
        base.Clear();
    }
Beispiel #15
0
    private GameObject CreateEnemyLinearLaserProtoType(string bulletId)
    {
        GameObject original  = Resources.Load <GameObject>("BulletPrefab/LinearLaser");
        GameObject protoType = GameObject.Instantiate <GameObject>(original);
        // 读取配置
        EnemyLinearLaserCfg cfg = GetLinearLaserCfgById(bulletId);
        string protoTypeName    = "EnemyLinearLaser" + bulletId;
        // 激光发射源
        SpriteRenderer sourceSp = protoType.transform.Find("Source").GetComponent <SpriteRenderer>();

        sourceSp.sprite = ResourceManager.GetInstance().GetSprite(Consts.STGBulletsAtlasName, "Bullet" + cfg.laserSourceTexId);
        // 设置sprite以及material
        protoType.name = protoTypeName;
        // 激光段tf
        Transform segmentTf = protoType.transform.Find("Segment");
        // 激光本体
        SpriteRenderer sp = segmentTf.Find("LaserSprite").GetComponent <SpriteRenderer>();

        sp.sprite = ResourceManager.GetInstance().GetSprite(cfg.laserAtlasName, cfg.laserTexName);
        if (cfg.blendMode != eBlendMode.Normal)
        {
            sp.material = ResourceManager.GetInstance().GetSpriteMatByBlendMode(cfg.blendMode);
        }
        // 设置尺寸为0
        sp.size = Vector2.zero;
        // 激光头部
        sp        = segmentTf.Find("HeadSprite").GetComponent <SpriteRenderer>();
        sp.sprite = ResourceManager.GetInstance().GetSprite(Consts.STGBulletsAtlasName, cfg.laserHeadTexName);
        // 将原型放置在敌机弹幕层
        UIManager.GetInstance().AddGoToLayer(protoType, LayerId.EnemyBarrage);
        // 添加原型到缓存池中
        ObjectsPool.GetInstance().AddProtoType(bulletId, protoType);
#if LogCreateBulletProto
        Logger.Log("Create Bullet ProtoType " + protoTypeName);
#endif
        return(protoType);
    }
    protected void UpdateSpriteObjects()
    {
        BgSpriteObject spObj;

        for (int i = 0; i < _spriteObjCount; i++)
        {
            spObj = _spriteObjList[i];
            if (spObj != null)
            {
                spObj.Update();
                if (!spObj.IsActive)
                {
                    ObjectsPool.GetInstance().RestorePoolClassToPool(spObj);
                    _spriteObjList[i] = null;
                }
            }
        }
        _clearTime++;
        if (_clearTime >= ClearDuration)
        {
            _clearTime      = 0;
            _spriteObjCount = CommonUtils.RemoveNullElementsInList <BgSpriteObject>(_spriteObjList, _spriteObjCount);
        }
    }
Beispiel #17
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);
    }
Beispiel #18
0
    private void CheckDestroyBullets <T>(List <T> list)
        where T : BulletBase
    {
        BulletBase tmpBullet;
        int        tmpCount, i;

        for (i = 0, tmpCount = list.Count; i < tmpCount; i++)
        {
            tmpBullet = list[i];
            if (tmpBullet.ClearFlag == 1)
            {
                list[i] = null;
                _clearList.Add(tmpBullet);
            }
        }
        tmpCount = _clearList.Count;
        for (i = 0; i < tmpCount; i++)
        {
            tmpBullet = _clearList[i];
            tmpBullet.Clear();
            ObjectsPool.GetInstance().RestoreBullet(tmpBullet);
        }
        _clearList.Clear();
    }
Beispiel #19
0
 public override void RestoreToPool()
 {
     ObjectsPool.GetInstance().RestorePoolClassToPool <TweenRotation>(this);
 }
    public void SetSprite(string atlasName, string spName, eBlendMode blendMode = eBlendMode.Normal, LayerId layerId = LayerId.STGNormalEffect, bool isUsingCache = false)
    {
        _isUsingCache = isUsingCache;
        // 不使用缓存,直接创建
        if (!isUsingCache)
        {
            _effectGo   = ResourceManager.GetInstance().GetPrefab("Prefab/Effects", "SpriteEffect");
            _effectTf   = _effectGo.transform;
            _spRenderer = _effectTf.Find("Sprite").GetComponent <SpriteRenderer>();
            if (blendMode != eBlendMode.Normal)
            {
                _spRenderer.material = ResourceManager.GetInstance().GetSpriteMatByBlendMode(blendMode);
            }
            _spRenderer.sprite = ResourceManager.GetInstance().GetSprite(atlasName, spName);
            UIManager.GetInstance().AddGoToLayer(_effectGo, layerId);
        }
        else
        {
            _effectGoName = "SpriteEffect_" + atlasName + "_" + spName + "_" + blendMode;
            _effectGo     = ObjectsPool.GetInstance().GetPrefabAtPool(_effectGoName);
            if (_effectGo == null)
            {
                GameObject protoType = ObjectsPool.GetInstance().GetProtoType(_effectGoName);
                if (protoType == null)
                {
                    protoType      = ResourceManager.GetInstance().GetPrefab("Prefab/Effects", "SpriteEffect");
                    protoType.name = _effectGoName;
                    Transform tf = protoType.transform;
                    tf.localPosition = new Vector3(2000, 2000, 0);
                    SpriteRenderer sr = tf.Find("Sprite").GetComponent <SpriteRenderer>();
                    if (blendMode != eBlendMode.Normal)
                    {
                        sr.material = ResourceManager.GetInstance().GetSpriteMatByBlendMode(blendMode);
                    }
                    sr.sprite = ResourceManager.GetInstance().GetSprite(atlasName, spName);
                    UIManager.GetInstance().AddGoToLayer(protoType, LayerId.STGNormalEffect);
                    ObjectsPool.GetInstance().AddProtoType(_effectGoName, protoType);
                }
                _effectGo = GameObject.Instantiate <GameObject>(protoType);
                UIManager.GetInstance().AddGoToLayer(_effectGo, layerId);
            }
            _effectTf   = _effectGo.transform;
            _spRenderer = _effectTf.Find("Sprite").GetComponent <SpriteRenderer>();
        }
        // 获取sprite对象的原始尺寸
        Sprite sp = _spRenderer.sprite;

        if (sp != null)
        {
            Vector3 size = sp.bounds.extents * 2 * sp.pixelsPerUnit;
            _originalWidth  = size.x;
            _originalHeight = size.y;
            // 计算实际尺寸
            _curWidth  = _originalWidth;
            _curHeight = _originalHeight;
        }
        else
        {
            _originalWidth  = 0;
            _originalHeight = 0;
            // 计算实际尺寸
            _curWidth  = 0;
            _curHeight = 0;
        }
    }
 public override void RestoreToPool()
 {
     ObjectsPool.GetInstance().RestorePoolClassToPool <TweenAnchoredPos>(this);
 }
    /// <summary>
    /// 创建一个tween对象
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <returns></returns>
    public T Create <T>() where T : TweenBase, new()
    {
        T tween = ObjectsPool.GetInstance().GetPoolClassAtPool <T>();

        return(tween);
    }