-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mmextension): updating the object pools
- Loading branch information
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
packages/mmextensions/mmextensions/ObjectPool/DelayedDisableSelf.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using Cysharp.Threading.Tasks; | ||
using UnityEngine; | ||
|
||
public class DelayedDisableSelf : MonoBehaviour | ||
{ | ||
public int delayMillis; | ||
|
||
// Start is called once before the first execution of Update after the MonoBehaviour is created | ||
void OnEnable() | ||
{ | ||
DoAfterSeconds(delayMillis, () => gameObject.SetActive(false)); | ||
} | ||
|
||
private async UniTask DoAfterSeconds(int millisDelay, Action action) | ||
{ | ||
await UniTask.Delay(millisDelay); | ||
|
||
action.Invoke(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/mmextensions/mmextensions/ObjectPool/DelayedDisableSelf.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
packages/mmextensions/mmextensions/ObjectPool/DelayedObjectSpawner.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using Cysharp.Threading.Tasks; | ||
using KBVE.MMExtensions.ObjectPool; | ||
using MoreMountains.Tools; | ||
using UnityEngine; | ||
|
||
public class DelayedObjectSpawner : MonoBehaviour | ||
{ | ||
public MMObjectPooler objectPool; | ||
public int millisToWait; | ||
|
||
// Start is called once before the first execution of Update after the MonoBehaviour is created | ||
void OnEnable() | ||
{ | ||
DoAfterSeconds(millisToWait, () => SetupPooledObject(objectPool.GetPooledGameObject())); | ||
} | ||
|
||
private async UniTask DoAfterSeconds(int millisDelay, Action action) | ||
{ | ||
Debug.Log("a"); | ||
await UniTask.Delay(millisDelay); | ||
Debug.Log("b"); | ||
|
||
action.Invoke(); | ||
} | ||
|
||
private void SetupPooledObject(GameObject pooledGameObject) | ||
{ | ||
pooledGameObject.SetActive(true); | ||
pooledGameObject.transform.position = gameObject.transform.position; | ||
pooledGameObject.transform.rotation = Quaternion.identity; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/mmextensions/mmextensions/ObjectPool/DelayedObjectSpawner.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.