Example #1
0
    /// <summary>
    /// 创建EnemyLaser的原型
    /// </summary>
    /// <param name="bulletId"></param>
    /// <returns></returns>
    private GameObject CreateEnemyLaserProtoType(string bulletId)
    {
        GameObject original  = Resources.Load <GameObject>("BulletPrefab/Laser");
        GameObject protoType = GameObject.Instantiate <GameObject>(original);
        // 读取配置
        EnemyLinearLaserCfg cfg = GetLinearLaserCfgById(bulletId);
        string protoTypeName    = "EnemyLaser" + bulletId;

        // 设置sprite以及material
        protoType.name = protoTypeName;
        // 激光发射源
        SpriteRenderer sp = protoType.transform.Find("Source").GetComponent <SpriteRenderer>();

        sp.sprite = ResourceManager.GetInstance().GetSprite(Consts.STGBulletsAtlasName, "Bullet" + cfg.laserSourceTexId);
        // 激光本体
        sp        = protoType.transform.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);
        }
        UIManager.GetInstance().AddGoToLayer(protoType, LayerId.EnemyBarrage);
        // 添加原型到缓存池中
        ObjectsPool.GetInstance().AddProtoType(bulletId, protoType);
#if LogCreateBulletProto
        Logger.Log("Create Bullet ProtoType " + protoTypeName);
#endif
        return(protoType);
    }
 public override void SetStyleById(string id)
 {
     _cfg = BulletsManager.GetInstance().GetLinearLaserCfgById(id);
     if (_cfg == null)
     {
         Logger.LogError("LinearLaserCfg with id " + id + " is not exist!");
         return;
     }
     _prefabName = _cfg.id.ToString();
     _laserObj   = BulletsManager.GetInstance().CreateBulletGameObject(BulletType.Enemy_LinearLaser, _cfg.id);
     _objTrans   = _laserObj.transform;
     // 发射源
     _laserSourceTf = _objTrans.Find("Source");
     _laserSourceGo = _laserSourceTf.gameObject;
     // segment原型
     _laserSegmentProtoType = _objTrans.Find("Segment").gameObject;
 }
Example #3
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;
 }