zoukankan      html  css  js  c++  java
  • 泛型子弹池

    如需转载,请保留本文链接。

    核心思想:根据不同类的hashcode值不同,将其作为key值,将子弹存在对应key的list中。

    核心方法如下:

     //泛型添加子弹到dic
         void Add<T>(GameObject obj) where T:BulletBase
        {
            int hashcode = typeof(T).GetHashCode();
            if (TSleepBulletDic.ContainsKey(hashcode))
            {
                TSleepBulletDic[hashcode].Add(obj);
            }
            else
            {
                TSleepBulletDic.Add(hashcode, new List<GameObject>());
                TSleepBulletDic[hashcode].Add(obj);
            }
            obj.SetActive(false);
            obj.transform.parent = BulletRoot.transform;
        }
        //return泛型子弹
         GameObject getBullet<T>()
        {
            int hashcode = typeof(T).GetHashCode();
            int TSleepBulletDic_ListCout = TSleepBulletDic[hashcode].Count;
            if (TSleepBulletDic.ContainsKey(hashcode))
            {
                for (int i = 0; i < TSleepBulletDic_ListCout; i++)
                {
                    if (!TSleepBulletDic[hashcode][i].activeSelf)
                    {
                         TSleepBulletDic[hashcode][i].transform.position
                           = _instanceConfig.BulletBornPosition<T>();
                       
                        TSleepBulletDic[hashcode][i].SetActive(true);
                        ActiveBulletList.Add(TSleepBulletDic[hashcode][i]);
                        BulletOverflow();
                        return TSleepBulletDic[hashcode][i];
                    }
                }          
            }
            return null;
        }

    如有需要,附百度云Unity Package下载地址:https://pan.baidu.com/s/1dFEnQUH 密码: tm6a

  • 相关阅读:
    数据库添加字段的默认值
    Map中存放数组
    JSON字符串转换为Map
    java中Object转换成int或String类型方法
    Max_connect_errors – MySQL性能参数详解
    查看已经安装的软件
    eclipse远程调试tomcat
    eclipse控制台不限制显示的行数
    栈和堆(Stack && Heap)
    一道题引发的self和super
  • 原文地址:https://www.cnblogs.com/yikecaidechengzhangshi/p/7640577.html
Copyright © 2011-2022 走看看