void Awake() { Instance = this; HashedObjectsPoolPropertiesList = new Dictionary <string, ObjectsPoolProperties>(); //ObjectsPool = new Dictionary<ObjectPrefabType, List<GameObject>>(); ObjectsPool = new Dictionary <string, List <GameObject> >(); NeedToCallOnActivate = new List <GameObject>(); NeedToCallOnDeactivate = new List <GameObject>(); CurrentlyUsedObjects = new HashSet <GameObject>(); InitPool(); }
public void AddGameObject() { GameObject BulletGO = ObjectsPoolManager.GetObject(mBullet.BulletType.ToString()); //从对象池中拿出物体 if (BulletGO != null) //如果对象池里有物体,则设置该物体的子弹属性 { mBullet.AnyBullet = BulletGO; } else //如果没有,就生成一个 { GameObject gameObject = FactoryManager.assetFactory.LoadBullet(mBullet.BulletType.ToString()); gameObject.AddComponent <BulletCollider>(); ObjectsPoolManager.PushObject(mBullet.BulletType.ToString(), gameObject); //往对象池中添加物体 mBullet.AnyBullet = gameObject; } }
public GameObject PlayEffectNow(Transform _Transform, string _EffectType, float _DestroyTime) { GameObject effect = ObjectsPoolManager.GetObject(_EffectType); //从对象池取出物体 //Debug.Log(effect); if (effect != null) { effect.transform.position = _Transform.position; effect.transform.rotation = _Transform.rotation; return(effect); } else { GameObject go = FactoryManager.assetFactory.LoadEffect(_EffectType); go.AddComponent <DestroyTime>().SetDestroyTime(_EffectType, _DestroyTime); //添加自动销毁(取消激活)的脚本 go.transform.position = _Transform.position; ObjectsPoolManager.PushObject(_EffectType, go); //往对象池中添加物体,要从assetfactory 里拿,不然传进来的是prefab,第一次实例的是clone return(go); } }
public GameObject PlayAudioNow(Transform _Transform, string _FeatureType) { GameObject audio = ObjectsPoolManager.GetObject(_FeatureType); //从对象池取出物体 //Debug.Log(audio); if (audio != null) { audio.transform.position = _Transform.position; audio.GetComponent <AudioSource>().Play(); return(audio); } else { GameObject go = new GameObject(_FeatureType.ToString()); AudioSource audioSource = go.AddComponent <AudioSource>(); AudioClip _audioClip = FactoryManager.assetFactory.LoadAudioClip(_FeatureType); audioSource.clip = _audioClip; go.transform.position = _Transform.position; audioSource.Play(); ObjectsPoolManager.PushObject(_FeatureType, go); //往对象池中添加物体,要从assetfactory 里拿,不然传进来的是prefab,第一次实例的是clone return(go); } }
void Awake() { _instance = this; }
public void Release() { ObjectsPoolManager.DestroyActiveObject(mAttr.PrefabName.ToString(), mAnyTank); //GameObject.Destroy(mAnyTank); }
/// <summary> /// 在坦克系统里增加改生成的坦克 /// </summary> public void AddInTankSystem() { GameFacade.Instance.AddTankOne(mTank as Tank1); ObjectsPoolManager.PushObject(mPrefabName, mTank.GameObject); }
private void DenyB() { ObjectsPoolManager.DestroyActiveObject(mFeature, gameObject); }
/// <summary> /// 销毁子弹 /// </summary> private void BulletDestroy() { GameFacade.Instance.RemoveBullet(mBullet.Owner); ObjectsPoolManager.DestroyActiveObject(mBullet.BulletType.ToString(), gameObject); }