Beispiel #1
0
        public void Shot()
        {
            GameObject bullet = PoolMgr.GetInstance().PopObj("PeaBall");

            bullet.tag = "PlayerBullet";
            bullet.GetComponent <BaseBullet>().SetShotDir(10, targetPos, shotPoint);
        }
Beispiel #2
0
    private float shotCounter;           //射击倒计时

    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            PoolMgr.GetInstance().GetObj(bulletName, (bullet) =>
            {
                bullet.transform.position = this.transform.position;
                bullet.transform.rotation = this.transform.rotation;
            });
            shotCounter = timeBetweenShots;
        }

        if (Input.GetMouseButton(0))
        {
            shotCounter -= Time.deltaTime;

            if (shotCounter <= 0f)
            {
                PoolMgr.GetInstance().GetObj(bulletName, (bullet) =>
                {
                    bullet.transform.position = this.transform.position;
                    bullet.transform.rotation = this.transform.rotation;
                });

                shotCounter = timeBetweenShots;
            }
        }
    }
Beispiel #3
0
        public SpawnPool Create(string poolName)
        {
            var owner = new GameObject(poolName + "Pool");

            owner.transform.SetParent(PoolMgr.GetInstance().transform);
            return(owner.GetOrAddComponent <SpawnPool>());
        }
Beispiel #4
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         PoolMgr.GetInstance().GetObj("Prafebs/Test/Cube", null);
     }
 }
Beispiel #5
0
 public static void Init()
 {
     if (_inst == null)
     {
         _inst = new PoolMgr();
     }
 }
Beispiel #6
0
 public override void OnUnspawn()
 {
     base.OnUnspawn();
     //在进去的时候 拿一个特效
     PoolMgr.GetInstance().GetObj(Consts.ParticleName.Bullet_Impact_Effect, (effect) =>
     {
         effect.transform.position = this.transform.position;
     });
 }
Beispiel #7
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        PoolMgr.GetInstance().PushObj(Consts.BulletGame.Enemy_Bullet_0, this.gameObject);

        if (other.CompareTag(Consts.Tags.Player))
        {
            other.GetComponentInParent <IDamage>().GetHurtrd(force);
        }
    }
Beispiel #8
0
//    private void OnDrawGizmos()
//    {
//        Vector2 checkSize;
//        if(box.bounds.size.x > box.bounds.size.y)
//            checkSize = new Vector2(box.bounds.size.x,box.bounds.size.x) * 2;
//        else
//            checkSize = new Vector2(box.bounds.size.y,box.bounds.size.y) * 2;
//        Vector2 checkPoint = (Vector2)transform.position + box.offset;
//        Gizmos.DrawWireCube(checkPoint, checkSize);
//    }

    void FireFireBall()
    {
        if (attackTarget == null || !attackTarget.gameObject.activeSelf)
        {
            return;
        }
        GameObject bullet = PoolMgr.GetInstance().PopObj("FireBall");

        bullet.tag = "EnemyBullet";
        bullet.GetComponent <BaseBullet>().SetShotDir(curAtk, attackTarget.position, transform.position);
    }
 private static void InitSelf()
 {
     if (_single == null)
     {
         _single = new PoolMgr();
     }
     if (_selfGo == null)
     {
         _selfGo = new GameObject("PoolMgr");
     }
 }
Beispiel #10
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         PoolMgr.GetInstance().GetObj("Test/Cube", (obj) => { Debug.Log("实例化了1"); });
     }
     if (Input.GetMouseButtonDown(1))
     {
         PoolMgr.GetInstance().GetObj("Test/Sphere", (obj) => { Debug.Log("实例化了2"); });
     }
 }
Beispiel #11
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         PoolMgr.GetInstance().GetObj("Cube", (o) => { o.transform.position = new Vector3(2, 2, 2); o.AddComponent <PoolPush>(); });
     }
     if (Input.GetMouseButtonDown(1))
     {
         ResMgr.GetInstance().LoadAsync <GameObject>("Cube", o => { o.name = "张鹏笨蛋"; });
         ResMgr.GetInstance().Load <GameObject>("Cube").gameObject.name = "王鹏笨蛋";
     }
 }
Beispiel #12
0
    public Dictionary <string, PoolData> PoolDic = new Dictionary <string, PoolData>();        //动态池

    //private GameObject poolObj = new GameObject("pool");

    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }
//        DontDestroyOnLoad(gameObject);
    }
        public virtual void Attack()
        {
            if (_enemy == null)
            {
                return;
            }

            GameObject bullet = PoolMgr.GetInstance().PopObj("PeaBall");

            bullet.tag = "PlayerBullet";
            bullet.GetComponent <BaseBullet>().SetShotDir(_curProperty.atk, _enemy.transform.position, transform.position);
        }
Beispiel #14
0
        static void InitActionSystem()
        {
            //动作加载代理
            ACT.ActionSystem.Instance.LoadActionFileDelegate = (actionName) => {
                return(AosBaseFramework.FileHelper.LoadBytesFile($"{actionName}.bytes", AosBaseFramework.PathHelper.EBytesFileType.Action));
            };

            //特效
            ACT.ActionSystem.Instance.SpawnEffectDelegate = () => { return(PoolMgr.GetObjectPool <EffectObject>().Spawn()); };

            //
            ACT.InputBoxExtra.Instance.SetJoystickDelegate(UGUIJoystick.JoystickPressed, UGUIJoystick.JoystickDelta);
        }
Beispiel #15
0
 private void EndDragItemCell(ItemCell itemCell)
 {
     isDraging = false;
     ChangeEquip();
     //清空当前选中的格子
     nowSelItem = null;
     nowInItem  = null;
     //结束拖动 移除这个图片
     if (nowSelItemImg == null)
     {
         return;
     }
     PoolMgr.GetInstance().PushObj(nowSelItemImg.name, nowSelItemImg.gameObject);
 }
Beispiel #16
0
    public void GetHurtrd(int force)
    {
        health -= force;
        //释放受伤特效 由于下一帧可能销毁 所以还是要同步
        GameObject effect = PoolMgr.GetInstance().GetObj(Consts.ParticleName.Enemy_Hurted_Effect);

        effect.transform.position = this.transform.position;
        if (health <= 0)
        {
            //生成死亡状态物 这里由于下一帧就要销毁只能同步
            GameObject splatter = PoolMgr.GetInstance().GetObj("Splatter/Splatter01");
            splatter.transform.position = this.transform.position;
            //TODO以后设置关卡再用对象池
            Destroy(this.gameObject);
        }
    }
Beispiel #17
0
 void Shot(Vector3 dir)
 {
     shotCounter -= Time.deltaTime;
     if (shotCounter <= 0f)
     {
         shotCounter = timeBetweenShots;
         //生成一个子弹
         PoolMgr.GetInstance().GetObj(Consts.BulletGame.Enemy_Bullet_0, (bullet) =>
         {
             //设置他的位置
             bullet.transform.position = this.transform.position;
             bullet.transform.rotation = this.transform.rotation;
             //设计他的方向
             bullet.transform.right = dir;
         });
     }
 }
Beispiel #18
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            PoolMgr.GetInstance().GetObj("Test/Cube", (o) =>
            {
                o.transform.localScale = Vector3.one * 2;
                StartCoroutine(destroyObj("Test/Cube", o));
            });
            //GameObject obj = ResMgr.GetInstance().Load<GameObject>("Test/Cube");
        }

        if (Input.GetMouseButtonDown(1))
        {
            PoolMgr.GetInstance().GetObj("Test/Sphere", (o) =>
            {
                StartCoroutine(destroyObj("Test/Sphere", o));
            });
        }
    }
Beispiel #19
0
    private IEnumerator Init(Action endAction)
    {
        //如果是通用语言,则根据手机的语言系统进行语言的选择
        if (GameMain.Inst.lngType == LngType.Auto)
        {
            switch (Application.systemLanguage)
            {
            case SystemLanguage.Chinese:
            case SystemLanguage.ChineseSimplified:
            case SystemLanguage.ChineseTraditional:
                GameMain.Inst.lngType = LngType.CN;
                break;

            case SystemLanguage.English:
                GameMain.Inst.lngType = LngType.EN;
                break;

            case SystemLanguage.Japanese:
                GameMain.Inst.lngType = LngType.JP;
                break;

            default:
                GameMain.Inst.lngType = LngType.CN;    //默认使用中文
                break;
            }
        }
        PoolMgr.Init();
        gameObject.AddComponent <ResMgr>();
        ResMgr.Inst.Init();
        gameObject.AddComponent <DatabaseMgr>();
        gameObject.AddComponent <UIMgr>();
        gameObject.AddComponent <AudioMgr>();
        gameObject.AddComponent <TimerMgr>();
        gameObject.AddComponent <LuaMgr>();
        LuaMgr.Inst.Init();
        gameObject.AddComponent <NetworkMgr>();
        Localization.Init();
        yield return(null);

        endAction();
    }
Beispiel #20
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag(Consts.Tags.Player))
        {
            //随机生成碎片个数
            int piecesToDrop = Random.Range(1, 6);


            //循环生成碎片
            for (int i = 0; i < piecesToDrop; ++i)
            {
                //随机生成碎片种类
                int randomPiece = Random.Range(1, 7);
                //先生成碎片 由于要销毁 所以同步加载
                GameObject obj = PoolMgr.GetInstance().GetObj(Consts.BreakableName.BrokenPiece + randomPiece);
                obj.transform.position = this.transform.position;
            }
            //TODO以后缓存池
            Destroy(this.gameObject);
        }
    }
Beispiel #21
0
    private void Update()
    {
        //让碎片朝着不同方向飞起来
        this.transform.position += moveDir * Time.deltaTime;
        //不断的降低碎片飞的方向 让他停下来
        moveDir = Vector3.Lerp(moveDir, Vector3.zero, deceleration * Time.deltaTime);

        //不断计时检测是否销毁
        lifeTime -= Time.deltaTime;
        if (lifeTime <= 0)
        {
            theSR.color = new Color(theSR.color.r, theSR.color.g, theSR.color.b,
                                    Mathf.MoveTowards(theSR.color.a, 0f, fadeSpeed * Time.deltaTime));

            if (theSR.color.a < 0)
            {
                //放入对象池
                PoolMgr.GetInstance().PushObj(Consts.BreakableName.BrokenPiece + index, this.gameObject);
            }
        }
    }
Beispiel #22
0
    private void BeginDragItemCell(ItemCell itemCell)
    {
        isDraging = true;
        //记录当前选中的格子
        nowSelItem = itemCell;
        //创建一个拖动的图片
        PoolMgr.GetInstance().GetObj("UI/imgIcon", (obj) =>
        {
            nowSelItemImg        = obj.GetComponent <Image>();
            nowSelItemImg.sprite = itemCell.imgIcon.sprite;

            //设置父对象 改变缩小大小相关
            nowSelItemImg.transform.SetParent(UIManager.GetInstance().canvas);
            nowSelItemImg.transform.localScale = Vector3.one;
            //入过异步加载结束,拖动就已经结束了,那么就直接隐藏
            if (!isDraging)
            {
                PoolMgr.GetInstance().PushObj(nowSelItemImg.name, nowSelItemImg.gameObject);
            }
        });
    }
Beispiel #23
0
 private void Awake()
 {
     PoolMgr.m_instance = this;
     this.LoadAllAudioPrefab();
 }
Beispiel #24
0
 void Destory()
 {
     PoolMgr.GetInstance().PushObj("Splatter/Splatter01", this.gameObject);
 }
Beispiel #25
0
 /// <summary>
 /// 放入缓存池
 /// </summary>
 public void Push()
 {
     PoolMgr.GetInstance().PushObj(this.gameObject.name, this.gameObject);
     Destroy(this.GetComponentInChildren <PoolPush>());
 }
Beispiel #26
0
    public void CheckShowOrHide()
    {
        if (content.anchoredPosition.y < 0)
        {
            return;
        }

        int minIndex = (int)(content.anchoredPosition.y / itemH) * col;
        int maxIndex = (int)((content.anchoredPosition.y + viewPortH) / itemH) * col + 2;

        //最小值判断
        if (minIndex < 0)
        {
            minIndex = 0;
        }

        if (maxIndex >= items.Count)
        {
            maxIndex = items.Count - 1;
        }
        //往下移动,删除上面的东西
        for (int i = oldMinIndex; i < minIndex; ++i)
        {
            if (nowShowItems.ContainsKey(i))
            {
                if (nowShowItems[i] != null)
                {
                    PoolMgr.GetInstance().PushObj(itemResName, nowShowItems[i]);
                }
                nowShowItems.Remove(i);
            }
        }
        ////往上移动,删除下面的东西
        for (int i = maxIndex + 1; i <= oldMaxIndex; i++)
        {
            if (nowShowItems.ContainsKey(i))
            {
                if (nowShowItems[i] != null)
                {
                    PoolMgr.GetInstance().PushObj(itemResName, nowShowItems[i]);
                }
                nowShowItems.Remove(i);
            }
        }
        oldMinIndex = minIndex;
        oldMaxIndex = maxIndex;

        for (int i = minIndex; i <= maxIndex; i++)
        {
            if (nowShowItems.ContainsKey(i))
            {
                continue;
            }
            else
            {
                int index = i;                 //先占坑,避免异步加载时候坑位不对
                nowShowItems.Add(index, null); //先占坑,避免异步加载时候坑位不对
                PoolMgr.GetInstance().GetObj(itemResName, (obj) =>
                {
                    //当格子创建出来后我们要做什么
                    //设置它的父对象
                    obj.transform.SetParent(content);
                    //重置相对缩放大小
                    obj.transform.localScale = Vector3.one;
                    //重置位置
                    obj.transform.localPosition = new Vector3((index % col) * itemW + 90, -index / col * itemH - 90, 0);
                    //更新格子信息
                    obj.GetComponent <K>().InitInfo(items[index]);
                    //判断有没有这个坑位
                    if (nowShowItems.ContainsKey(index))
                    {
                        nowShowItems[index] = obj;
                    }
                    else //这里是,如果往下移动的特别快,那么就会出现,前面Add占完坑了,但是还没异步加载出来资源,nowShowItems就已经在update里被Remove删除了,这时候再加载进来就会走进else
                    //就是拖得比创建的还要快
                    {
                        PoolMgr.GetInstance().PushObj(itemResName, obj);
                    }
                });
            }
        }
    }
Beispiel #27
0
 public void push()
 {
     PoolMgr.GetInstance().PushObj(this.gameObject.name, this.gameObject);
 }
Beispiel #28
0
 void Destroy()
 {
     PoolMgr.GetInstance().PushObj(effectName, this.gameObject);
 }
Beispiel #29
0
 public PoolMgr GetPoolMgr()
 {
     return(PoolMgr.GetInstance());
 }
    /// <summary>
    /// 更新格子
    /// </summary>
    public void CheckShowOrHide()
    {
        /*
         * 假设一个各组的大小为80*80
         * 90/80=1*3=3
         * 使用可视范围的起始位置Y/一个格子的高=》
         * 其实现实的是哪一行*哪一行有多少格子=起始位置显示的索引值
         * 330/80=4*3=12+2=14
         *
         * 使用可视范围的结束位置Y/一个格子的高度=》
         * 结束位置时哪一行+(一行格子数-1)=结束位置显示的索引值
         */
        //检测哪些格子应该显示出来
        int minIndex = (int)(content.anchoredPosition.y / itemH) * col;
        int maxIndex = (int)((content.anchoredPosition.y + viewPortH) / itemH) * col + col - 1;

        //最小值判断
        if (minIndex < 0)
        {
            minIndex = 0;
        }
        //超出最大数量
        if (maxIndex >= BagMrg.GetInstance().itemList.Count)
        {
            maxIndex = BagMrg.GetInstance().itemList.Count - 1;
        }
        //不等于之后在更新
        if (minIndex != oldMaxIndex || maxIndex != oldMaxIndex)
        {
            for (int i = oldMinIndex; i < minIndex; ++i)
            {
                if (nowShowItems.ContainsKey(i))
                {
                    if (nowShowItems[i] != null)
                    {
                        PoolMgr.GetInstance().PushObj("UI/BagItem", nowShowItems[i]);
                    }
                    nowShowItems.Remove(i);
                }
            }

            for (int i = maxIndex; i <= oldMaxIndex; ++i)
            {
                if (nowShowItems.ContainsKey(i))
                {
                    if (nowShowItems[i] != null)
                    {
                        PoolMgr.GetInstance().PushObj(itemsResName, nowShowItems[i]);
                    }
                    nowShowItems.Remove(i);
                }
            }
        }



        //根据上一次索引和这一次新算出来的索引  来判断 哪些该移除
        oldMaxIndex = maxIndex;
        oldMinIndex = minIndex;

        //创建指定索引范围值格子
        for (int i = minIndex; i <= maxIndex; ++i)
        {
            if (nowShowItems.ContainsKey(i))
            {
                continue;
            }
            else
            {
                int index = i;
                nowShowItems.Add(index, null);
                PoolMgr.GetInstance().GetObj(itemsResName, (obj) =>
                {
                    //当格子创建出来需要做什么
                    //设置父对象
                    obj.transform.parent = content.transform;
                    //重置相对大小
                    obj.transform.localScale = Vector3.one;
                    //充值位置
                    // obj.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
                    // obj.transform.localPosition=Vector3.zero;
                    // Debug.Log(transform.localPosition.x+"|"+transform.localPosition.y);
                    //Debug.Log((index%3)*240+"|"+-index/3*190);
                    // obj.GetComponent<RectTransform>().anchoredPosition = new Vector3((index%3)*240,-index/3*190,0);
                    obj.transform.localPosition = new Vector3((index % col) * itemW, -index / col * itemH, 0);
                    //充值格子信息
                    /////-------obj.GetComponent<BagItem>().InitItemsInfo(BagMrg.GetInstance().itemList[index]);
                    obj.GetComponent <K>().InitInfo(items[index]);

                    //先判断有没有这个坑
                    if (nowShowItems.ContainsKey(index))
                    {
                        nowShowItems[index] = obj;
                    }
                    else
                    {
                        PoolMgr.GetInstance().PushObj(itemsResName, obj);
                    }
                });
            }
        }
    }