public void ReturnToPool(PoolComponent ObjectPooled) { ObjectPooled.Reset(); ObjectPooled.gameObject.SetActive(false); ObjectPooled.transform.SetParent(_container); _listObjs.Enqueue(ObjectPooled.gameObject); }
private AudioMgr() { //加载场景后清空当前音效 UnityEngine.SceneManagement.SceneManager.activeSceneChanged += (a, b) => { //清空Player AudioPlayer[] arrPlayer = listActivePlayer?.ToArray(); if (arrPlayer != null) { for (int i = 0; i < arrPlayer.Length; i++) { arrPlayer[i]?.Destroy(); } } //清空音频播放器 poolAudioSource?.RecycleAll(); }; poolAudioSource = new PoolComponent <AudioSource>(); //切场景不删除,只清空clip poolAudioSource.EventOnCreateMember += (AudioSource player) => MonoBehaviour.DontDestroyOnLoad(player.gameObject); //获取时音量重置 poolAudioSource.EventOnGetMember += (AudioSource player) => player.volume = 1; bgmPlayer = new BGMAudioPlayer(poolAudioSource.GetMember, poolAudioSource.RecycleMember); }
public PoolComponent CreatePool(string key, GameObject objectTemplate, int objectsAmount) { if (!poolDictionary.ContainsKey(key)) { PoolComponent tempComponent = new PoolComponent(objectTemplate, objectsAmount); poolDictionary.Add(key, tempComponent); } return(GetPool(key)); }
void Awake() { searchInput = GetComponentInChildren <InputField>(); btnPrefab = GetComponentInChildren <Button>(); pool_Btn = new PoolComponent <Button>(btnPrefab); btnPrefab.gameObject.SetActive(false); searchInput.onValueChanged.AddListener(OnSearchInputChangge); }
public void Run() { foreach (var i in _poolEntities) { ref PoolComponent poolComponent = ref _poolEntities.Get1(i); foreach (var j in _spawnEntities) { var poolSpawnEvent = _spawnEntities.Get1(j); for (int k = 0; k < poolSpawnEvent.ToSpawn.Count; ++k) { if (poolSpawnEvent.ToSpawn[k].Tag == poolComponent.Tag) { Spawn(ref poolComponent.PoolData, poolSpawnEvent.ToSpawn[k]); } } } }
private void Awake() { if (prefabItem != null) { poolLogItem = new PoolComponent <UILogListenerItem>(prefabItem.gameObject); prefabItem.gameObject.SetActive(false); poolLogItem.EventOnCreateMember += (item) => { item.transform.SetParent(prefabItem.transform.parent); item.transform.localScale = Vector3.one; item.transform.localPosition = Vector3.zero; }; } listener = new UnityLogListener(this); }
public void Awake() { _trans = transform; _rigid = GetComponent <Rigidbody>(); _col = GetComponent <BoxCollider>(); _poolComponent = GetComponent <PoolComponent>(); _limitX = _demiLengthXRoad - _col.size.x / 2f; var meshs = GetComponentsInChildren <MeshRenderer>(); if (meshs != null) { _mats = new Material[meshs.Length]; for (int i = 0; i < meshs.Length; i++) { _mats[i] = meshs[i].material; } } }
public static GameObject InstantiateS(GameObject prefab, Vector3 position, Quaternion rotation, Transform Parent = null) { GameObject OutObject; if (!poolDictionary.ContainsKey(prefab.GetInstanceID())) { OutObject = Instantiate(prefab, position, rotation); EntityBase entityBase = OutObject.GetComponent <EntityBase>(); PoolComponent poolComponent = entityBase?.GetEntityComponent <PoolComponent>(); if (poolComponent != null) { poolComponent.id = prefab.GetInstanceID(); CreatePoolCell(prefab.GetComponent <EntityBase>(), entityBase, prefab.GetInstanceID(), poolComponent.start_pool_size); } return(OutObject); } else { return(poolDictionary[prefab.GetInstanceID()].GetFromPool(position, rotation, Parent)); } }
public void Setup(CharacterPrefabFactory characterFactory, PoolComponent prefabFactory) { CharacterFactory = characterFactory; PrefabFactory = prefabFactory; InitGameObjectInteractions(); }
public void Awake() { _poolComponent = GetComponent <PoolComponent>(); _behaviourMove = BehaviourMoveEnum(); }
private void Awake() { _poolComponent = GetComponent <PoolComponent>(); ResetTimer(); }
private void Start() { PoolComponent = GetComponent <PoolComponent>(); HasPoolComponent = PoolComponent != null; }
/// <summary> /// 设置对象池 /// </summary> /// <param name="pool"></param> public void setPool(PoolComponent pool) { m_pool = pool; }
protected override void OnInitFirst() { m_compPool = Singletons.Get <PoolComponent>("pool_comps"); m_compPool.getList <Bullet>().setTemplate(m_bulletTemplate); }
public override void OnInspectorGUI() { serializedObject.Update(); PoolComponent poolComponent = (PoolComponent)target; EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode); { //绘制滑动条 int clearInterval = (int)EditorGUILayout.Slider("Auto clear object pool interval", m_ClearCalssObjectInterval.floatValue, 10, 1800); if (clearInterval != m_ClearCalssObjectInterval.floatValue) { m_ClearCalssObjectInterval.floatValue = clearInterval; serializedObject.ApplyModifiedProperties(); } } EditorGUI.EndDisabledGroup(); if (!EditorApplication.isPlaying) { EditorGUILayout.HelpBox("Available during runtime only.", MessageType.Info); return; } //===================类对象池开始============================ GUILayout.Space(10); GUILayout.BeginVertical("box"); GUILayout.BeginHorizontal("box"); GUILayout.Label("Class name", GUILayout.MinWidth(50)); GUILayout.Label("Count in pool", GUILayout.Width(100)); GUILayout.Label("Permanent count", GUILayout.Width(100)); GUILayout.EndHorizontal(); foreach (var item in poolComponent.ClassObjetPoolDic) { string fullName = item.Key; GUILayout.BeginHorizontal("box"); GUILayout.Label(fullName, GUILayout.MinWidth(50)); GUILayout.Label(item.Value.Count.ToString(), GUILayout.Width(100)); byte resideCount = 0; poolComponent.ClassObjectCount.TryGetValue(fullName, out resideCount); GUILayout.Label(resideCount.ToString(), GUILayout.Width(100)); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); //===================类对象池结束============================ //===================变量计数开始============================ GUILayout.Space(10); GUILayout.BeginVertical("box"); GUILayout.BeginHorizontal("box"); GUILayout.Label("Var object type"); GUILayout.Label("Count in pool", GUILayout.Width(100)); GUILayout.EndHorizontal(); if (poolComponent != null) { foreach (var item in poolComponent.VarObjectDic) { GUILayout.BeginHorizontal("box"); GUILayout.Label(item.Key.Name); GUILayout.Label(item.Value.ToString(), GUILayout.Width(50)); GUILayout.EndHorizontal(); } } GUILayout.EndVertical(); //===================变量计数结束============================ if (PrefabUtility.GetPrefabType(poolComponent.gameObject) != PrefabType.Prefab) { EditorGUILayout.LabelField("Object Pool Count", poolComponent.Count.ToString()); ObjectPoolBase[] objectPools = poolComponent.GetAllObjectPools(true); foreach (ObjectPoolBase objectPool in objectPools) { DrawObjectPool(objectPool); } } serializedObject.ApplyModifiedProperties(); //重绘面板 Repaint(); }