Skip to content

Commit

Permalink
feat(mmextension): updating the object pools
Browse files Browse the repository at this point in the history
  • Loading branch information
h0lybyte committed Jan 5, 2025
1 parent 7ed6a1f commit 9caf2a8
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
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();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9caf2a8

Please sign in to comment.