Platformer level management
This commit is contained in:
1 parent
72070901ec
commit
1aceea1b79
94 files changed
+3656
-197
No files matched your search
@@ -10,15 +10,16 @@ using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Code.Example.Platformer.Entity
|
||||
{
|
||||
public interface IPlatformerPlayerFactory
|
||||
{
|
||||
UniTaskVoid LoadPlayer();
|
||||
UniTaskVoid WarmPlayer();
|
||||
void ReleasePlayer();
|
||||
|
||||
UniTaskVoid SpawnPlayer(Vector3 position);
|
||||
void SpawnPlayer(Vector3 position);
|
||||
}
|
||||
|
||||
public class PlatformerPlayerFactory : IPlatformerPlayerFactory, IDisposable
|
||||
@@ -50,7 +51,7 @@ namespace Code.Example.Platformer.Entity
|
||||
_eventBus.RaiseEvent<IPlatformerPlayerFactoryInitializedHandle>(x => x.PlatformerPlayerFactoryInitialized());
|
||||
}
|
||||
|
||||
public async UniTaskVoid LoadPlayer()
|
||||
public async UniTaskVoid WarmPlayer()
|
||||
{
|
||||
if (_playerPrefabHandle.IsValid())
|
||||
{
|
||||
@@ -63,8 +64,6 @@ namespace Code.Example.Platformer.Entity
|
||||
_playerPrefabHandle = Addressables.LoadAssetAsync<GameObject>(_playerConfig.prefabReference);
|
||||
|
||||
await _playerPrefabHandle.ToUniTask();
|
||||
var racer = _playerPrefabHandle.Result.GetComponent<Entity>();
|
||||
racer.SetData(_playerConfig.EntityData);
|
||||
|
||||
_eventBus.RaiseEvent<IPlatformerPlayerLoadedHandle>(x => x.PlatformerPlayerLoaded());
|
||||
}
|
||||
@@ -74,11 +73,20 @@ namespace Code.Example.Platformer.Entity
|
||||
_playerPrefabHandle.Release();
|
||||
}
|
||||
|
||||
public async UniTaskVoid SpawnPlayer(Vector3 position)
|
||||
public void SpawnPlayer(Vector3 position)
|
||||
{
|
||||
var player = await Addressables.InstantiateAsync(_playerConfig.prefabReference, position, Quaternion.identity).ToUniTask();
|
||||
var player = Object.Instantiate(_playerPrefabHandle.Result, position, Quaternion.identity);
|
||||
|
||||
var racer = player.GetComponent<Entity>();
|
||||
racer.SetData(_playerConfig.EntityData);
|
||||
|
||||
var health = player.GetComponent<EntityHealth>();
|
||||
health.Setup(_playerConfig.EntityData.maxHealth, _playerConfig.EntityData.damageRecieveThreshold);
|
||||
|
||||
GameObjectInjector.InjectObject(player, Container.RootContainer); // TODO САМОЕ НЕСТАБИЛЬНОЕ ДЕРЬМО ВО ВСЕЛЕННОЙ КОНТЕЙНЕР ДОЛЖЕН БЫТЬ КОНТЕКСТНЫМ
|
||||
_eventBus.RaiseEvent<IPlatformerPlayerSpawnedHandle>(x => x.PlatformerPlayerSpawned(player.GetComponent<Entity>()));
|
||||
|
||||
_eventBus.RaiseEvent<IPlatformerPlayerSpawnedHandle>(
|
||||
x => x.PlatformerPlayerSpawned(player.GetComponent<Entity>()));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
Reference in new issue
Block a user