From 1a03b20e0e5409b75615386ebc557d8c33e01aed Mon Sep 17 00:00:00 2001 From: Jiaqi Liu Date: Wed, 11 Oct 2023 20:49:46 -0700 Subject: [PATCH] More abstractions and bug fixes --- .../Scripts/Engine/Abstraction/IGameEntity.cs | 38 ------ .../Engine/Abstraction/IManagedObject.cs | 14 --- .../Scripts/Engine/Abstraction/ITransform.cs | 45 -------- .../Scripts/Engine/Animation/CoreAnimation.cs | 2 +- Assets/Scripts/Engine/Core.meta | 3 + .../Engine/{ => Core}/Abstraction.meta | 0 .../Engine/Core/Abstraction/IGameEntity.cs | 96 +++++++++++++++ .../Abstraction/IGameEntity.cs.meta | 0 .../Engine/Core/Abstraction/IManagedObject.cs | 23 ++++ .../Abstraction/IManagedObject.cs.meta | 0 .../Engine/Core/Abstraction/ITransform.cs | 109 ++++++++++++++++++ .../{ => Core}/Abstraction/ITransform.cs.meta | 0 .../Scripts/Engine/Core/Implementation.meta | 3 + .../Implementation}/GameEntity.cs | 14 ++- .../Implementation}/GameEntity.cs.meta | 0 .../Implementation/GameEntityFactory.cs} | 24 +++- .../Implementation/GameEntityFactory.cs.meta} | 0 .../Implementation}/GameEntityScript.cs | 3 +- .../Implementation}/GameEntityScript.cs.meta | 0 .../TickableGameEntityScript.cs | 2 +- .../TickableGameEntityScript.cs.meta | 0 .../Implementation}/Transform.cs | 3 +- .../Implementation}/Transform.cs.meta | 0 .../Coroutine/CoroutineYieldInstruction.cs | 13 +++ .../Renderer/AnimatedBillboardRenderer.cs | 2 +- .../Scripts/Engine/Renderer/SkyBoxRenderer.cs | 3 +- .../Renderer/StaticBillboardRenderer.cs | 2 +- .../Engine/Renderer/StaticMeshRenderer.cs | 2 +- .../Engine/Services/IGameTimeProvider.cs | 27 +++-- .../Engine/Services/IPhysicsManager.cs | 55 +++++++++ .../Engine/Services/IPhysicsManager.cs.meta | 3 + .../Scripts/Engine/Services/PhysicsManager.cs | 80 +++++++++++++ .../Engine/Services/PhysicsManager.cs.meta | 3 + .../Scripts/Engine/Services/ServiceLocator.cs | 4 +- .../Engine/Utilities/UnityEngineUtility.cs | 17 --- .../Contract/Constants/ScriptConstants.cs | 4 +- .../Scripts/Pal3.Game/Actor/ActorFactory.cs | 7 +- .../Controllers/ActorActionController.cs | 11 +- .../Actor/Controllers/ActorController.cs | 7 +- .../Controllers/ActorMovementController.cs | 3 +- .../Controllers/CombatActorController.cs | 2 +- .../Controllers/FlyingActorController.cs | 2 +- .../Actor/Controllers/HuaYingController.cs | 2 +- .../Actor/Controllers/LongKuiController.cs | 2 +- .../Scripts/Pal3.Game/Audio/AudioManager.cs | 6 +- .../Scripts/Pal3.Game/Camera/CameraManager.cs | 7 +- .../Pal3.Game/Command/CommandDispatcher.cs | 2 +- .../Command/CommandExecutorRegistry.cs | 2 +- .../AttachSfxToGameEntityRequest.cs | 2 +- .../StopSfxPlayingAtGameEntityRequest.cs | 2 +- .../Presenters/CombatActorInfoPresenter.cs | 2 +- .../Presenters/LightSourceInfoPresenter.cs | 2 +- .../Dev/Presenters/MaterialInfoPresenter.cs | 2 +- .../Dev/Presenters/NpcInfoPresenter.cs | 2 +- .../Presenters/SceneObjectInfoPresenter.cs | 2 +- .../Scripts/Pal3.Game/Effect/CombatEffect.cs | 7 +- .../Scripts/Pal3.Game/Effect/EffectManager.cs | 17 +-- Assets/Scripts/Pal3.Game/Effect/FireEffect.cs | 7 +- .../Scripts/Pal3.Game/Effect/PortalEffect.cs | 10 +- .../Pal3.Game/Effect/RotatingSpriteEffect.cs | 7 +- .../GamePlay/PlayerGamePlayManager.Climb.cs | 2 +- .../PlayerGamePlayManager.Interaction.cs | 2 +- .../GamePlay/PlayerGamePlayManager.Jump.cs | 22 ++-- .../PlayerGamePlayManager.Movement.cs | 84 +++++++------- .../GamePlay/PlayerGamePlayManager.cs | 14 ++- .../Pal3.Game/GameResourceInitializer.cs | 2 +- .../GameSystems/Combat/CombatCoordinator.cs | 2 +- .../GameSystems/Combat/CombatManager.cs | 3 +- .../GameSystems/Minimap/MinimapManager.cs | 2 +- .../Pal3.Game/GameSystems/Team/TeamManager.cs | 2 +- Assets/Scripts/Pal3.Game/Pal3.cs | 10 +- .../Rendering/Renderer/CvdModelRenderer.cs | 50 ++++---- .../Rendering/Renderer/Mv3ModelRenderer.cs | 54 +++++---- .../Rendering/Renderer/PolyModelRenderer.cs | 7 +- .../Renderer/SkeletalModelRenderer.cs | 11 +- Assets/Scripts/Pal3.Game/Scene/CombatScene.cs | 10 +- Assets/Scripts/Pal3.Game/Scene/NavMesh.cs | 53 +++++++++ .../Scripts/Pal3.Game/Scene/NavMesh.cs.meta | 3 + Assets/Scripts/Pal3.Game/Scene/Scene.cs | 59 +++------- Assets/Scripts/Pal3.Game/Scene/SceneBase.cs | 2 +- .../Scripts/Pal3.Game/Scene/SceneManager.cs | 11 +- .../Scene/SceneObjects/AutoTriggerObject.cs | 13 ++- .../Scene/SceneObjects/ChestObject.cs | 2 +- .../Scene/SceneObjects/ClimbableObject.cs | 11 +- .../Scene/SceneObjects/CollidableObject.cs | 4 +- .../Common/BoundsTriggerController.cs | 3 +- .../Common/SceneObjectMeshCollider.cs | 2 +- .../Common/StandingPlatformController.cs | 3 +- .../Common/TilemapTriggerController.cs | 2 +- .../SceneObjects/DivineTreeFlowerObject.cs | 2 +- .../SceneObjects/DivineTreePortalObject.cs | 8 +- .../Scene/SceneObjects/DoorObject.cs | 2 +- .../Scene/SceneObjects/ElementSwitchObject.cs | 2 +- .../Scene/SceneObjects/ElevatorDoorObject.cs | 4 +- .../Scene/SceneObjects/ElevatorObject.cs | 4 +- .../Scene/SceneObjects/ElevatorPedalObject.cs | 2 +- .../Scene/SceneObjects/EyeBallObject.cs | 2 +- .../SceneObjects/FallableObstacleObject.cs | 2 +- .../Scene/SceneObjects/GeneralSceneObject.cs | 2 +- .../Scene/SceneObjects/GravitySwitchObject.cs | 2 +- .../Scene/SceneObjects/ImpulsiveObject.cs | 9 +- .../InvestigationTriggerObject.cs | 2 +- .../Scene/SceneObjects/JumpableAreaObject.cs | 4 +- .../SceneObjects/LiftingPlatformObject.cs | 2 +- .../SceneObjects/MovableCarrierObject.cs | 2 +- .../SceneObjects/MushroomBridgeObject.cs | 2 +- .../Scene/SceneObjects/PedalSwitchObject.cs | 2 +- .../Scene/SceneObjects/PiranhaFlowerObject.cs | 2 +- .../Scene/SceneObjects/PushableObject.cs | 56 ++++----- .../Scene/SceneObjects/RareChestObject.cs | 2 +- .../SceneObjects/RetractableBlockerObject.cs | 2 +- .../RoadElevatorOrBlockerObject.cs | 2 +- .../SceneObjects/RotatingBridgeObject.cs | 2 +- .../Scene/SceneObjects/RotatingWallObject.cs | 8 +- .../Scene/SceneObjects/SceneObject.cs | 5 +- .../Scene/SceneObjects/SceneSfxObject.cs | 2 +- .../Scene/SceneObjects/SectorBridgeObject.cs | 2 +- .../Scene/SceneObjects/SlideWayObject.cs | 2 +- .../Scene/SceneObjects/SpecialSwitchObject.cs | 2 +- .../SceneObjects/StaticOrAnimatedObject.cs | 3 +- .../SceneObjects/SuspensionBridgeObject.cs | 4 +- .../Scene/SceneObjects/SwitchObject.cs | 9 +- .../Scene/SceneObjects/SwordBridgeObject.cs | 2 +- .../Scene/SceneObjects/TeapotObject.cs | 2 +- .../SceneObjects/ThreePhaseBridgeObject.cs | 2 +- .../SceneObjects/ThreePhaseSwitchObject.cs | 2 +- .../Scene/SceneObjects/ToggleSwitchObject.cs | 2 +- .../Scene/SceneObjects/TrapObject.cs | 2 +- .../Scene/SceneObjects/WaterSurface.cs | 2 +- .../WaterSurfaceRoadBlockerObject.cs | 2 +- .../Scripts/Pal3.Game/Script/ScriptManager.cs | 2 +- Assets/Scripts/Pal3.Game/State/SaveManager.cs | 2 +- Packages/manifest.json | 8 +- Packages/packages-lock.json | 8 +- ProjectSettings/DynamicsManager.asset | 7 +- ProjectSettings/TagManager.asset | 2 +- 136 files changed, 872 insertions(+), 485 deletions(-) delete mode 100644 Assets/Scripts/Engine/Abstraction/IGameEntity.cs delete mode 100644 Assets/Scripts/Engine/Abstraction/IManagedObject.cs delete mode 100644 Assets/Scripts/Engine/Abstraction/ITransform.cs create mode 100644 Assets/Scripts/Engine/Core.meta rename Assets/Scripts/Engine/{ => Core}/Abstraction.meta (100%) create mode 100644 Assets/Scripts/Engine/Core/Abstraction/IGameEntity.cs rename Assets/Scripts/Engine/{ => Core}/Abstraction/IGameEntity.cs.meta (100%) create mode 100644 Assets/Scripts/Engine/Core/Abstraction/IManagedObject.cs rename Assets/Scripts/Engine/{ => Core}/Abstraction/IManagedObject.cs.meta (100%) create mode 100644 Assets/Scripts/Engine/Core/Abstraction/ITransform.cs rename Assets/Scripts/Engine/{ => Core}/Abstraction/ITransform.cs.meta (100%) create mode 100644 Assets/Scripts/Engine/Core/Implementation.meta rename Assets/Scripts/Engine/{Abstraction => Core/Implementation}/GameEntity.cs (96%) rename Assets/Scripts/Engine/{Abstraction => Core/Implementation}/GameEntity.cs.meta (100%) rename Assets/Scripts/Engine/{Abstraction/PrefabFactory.cs => Core/Implementation/GameEntityFactory.cs} (55%) rename Assets/Scripts/Engine/{Abstraction/PrefabFactory.cs.meta => Core/Implementation/GameEntityFactory.cs.meta} (100%) rename Assets/Scripts/Engine/{Abstraction => Core/Implementation}/GameEntityScript.cs (97%) rename Assets/Scripts/Engine/{Abstraction => Core/Implementation}/GameEntityScript.cs.meta (100%) rename Assets/Scripts/Engine/{Abstraction => Core/Implementation}/TickableGameEntityScript.cs (96%) rename Assets/Scripts/Engine/{Abstraction => Core/Implementation}/TickableGameEntityScript.cs.meta (100%) rename Assets/Scripts/Engine/{Abstraction => Core/Implementation}/Transform.cs (98%) rename Assets/Scripts/Engine/{Abstraction => Core/Implementation}/Transform.cs.meta (100%) create mode 100644 Assets/Scripts/Engine/Services/IPhysicsManager.cs create mode 100644 Assets/Scripts/Engine/Services/IPhysicsManager.cs.meta create mode 100644 Assets/Scripts/Engine/Services/PhysicsManager.cs create mode 100644 Assets/Scripts/Engine/Services/PhysicsManager.cs.meta create mode 100644 Assets/Scripts/Pal3.Game/Scene/NavMesh.cs create mode 100644 Assets/Scripts/Pal3.Game/Scene/NavMesh.cs.meta diff --git a/Assets/Scripts/Engine/Abstraction/IGameEntity.cs b/Assets/Scripts/Engine/Abstraction/IGameEntity.cs deleted file mode 100644 index bf2a8b92..00000000 --- a/Assets/Scripts/Engine/Abstraction/IGameEntity.cs +++ /dev/null @@ -1,38 +0,0 @@ -// --------------------------------------------------------------------------------------------- -// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved. -// See LICENSE file in the project root for license information. -// --------------------------------------------------------------------------------------------- - -namespace Engine.Abstraction -{ - using System; - - public interface IGameEntity : IManagedObject - { - public string Name { get; set; } - - public bool IsStatic { get; set; } - - public ITransform Transform { get; } - - public void SetParent(IGameEntity parent, bool worldPositionStays); - - public T AddComponent() where T : class; - - public object AddComponent(Type type); - - public T GetComponent() where T : class; - - public T GetComponentInChildren() where T : class; - - public T[] GetComponentsInChildren() where T : class; - - public T GetOrAddComponent() where T : class; - - public void SetLayer(int layerIndex); - - public IGameEntity FindChild(string name); - - public void Destroy(); - } -} \ No newline at end of file diff --git a/Assets/Scripts/Engine/Abstraction/IManagedObject.cs b/Assets/Scripts/Engine/Abstraction/IManagedObject.cs deleted file mode 100644 index 14ebb6bd..00000000 --- a/Assets/Scripts/Engine/Abstraction/IManagedObject.cs +++ /dev/null @@ -1,14 +0,0 @@ -// --------------------------------------------------------------------------------------------- -// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved. -// See LICENSE file in the project root for license information. -// --------------------------------------------------------------------------------------------- - -namespace Engine.Abstraction -{ - public interface IManagedObject - { - public object NativeObject { get; } - - public bool IsNativeObjectDisposed { get; } - } -} \ No newline at end of file diff --git a/Assets/Scripts/Engine/Abstraction/ITransform.cs b/Assets/Scripts/Engine/Abstraction/ITransform.cs deleted file mode 100644 index 258414a2..00000000 --- a/Assets/Scripts/Engine/Abstraction/ITransform.cs +++ /dev/null @@ -1,45 +0,0 @@ -// --------------------------------------------------------------------------------------------- -// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved. -// See LICENSE file in the project root for license information. -// --------------------------------------------------------------------------------------------- - -namespace Engine.Abstraction -{ - using Quaternion = UnityEngine.Quaternion; - using Vector3 = UnityEngine.Vector3; - - public interface ITransform : IManagedObject - { - public Vector3 Position { get; set; } - - public Vector3 LocalPosition { get; set; } - - public Quaternion Rotation { get; set; } - - public Quaternion LocalRotation { get; set; } - - public Vector3 LocalScale { get; set; } - - public Vector3 Forward { get; set; } - - public Vector3 Right { get; set; } - - public Vector3 Up { get; set; } - - public Vector3 EulerAngles { get; set; } - - public void Translate(Vector3 translation); - - public void GetPositionAndRotation(out Vector3 position, out Quaternion rotation); - - public void SetPositionAndRotation(Vector3 position, Quaternion rotation); - - public void GetLocalPositionAndRotation(out Vector3 position, out Quaternion rotation); - - public void SetLocalPositionAndRotation(Vector3 position, Quaternion rotation); - - public void LookAt(Vector3 target); - - public void RotateAround(Vector3 centerPoint, Vector3 axis, float angle); - } -} \ No newline at end of file diff --git a/Assets/Scripts/Engine/Animation/CoreAnimation.cs b/Assets/Scripts/Engine/Animation/CoreAnimation.cs index 7cf6bd54..6ee1d71d 100644 --- a/Assets/Scripts/Engine/Animation/CoreAnimation.cs +++ b/Assets/Scripts/Engine/Animation/CoreAnimation.cs @@ -8,7 +8,7 @@ namespace Engine.Animation using System; using System.Collections; using System.Threading; - using Abstraction; + using Core.Abstraction; using Pal3.Core.Utilities; using Services; diff --git a/Assets/Scripts/Engine/Core.meta b/Assets/Scripts/Engine/Core.meta new file mode 100644 index 00000000..fa622992 --- /dev/null +++ b/Assets/Scripts/Engine/Core.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9ef6c3bf5b624020a27bfc25b422e590 +timeCreated: 1697047338 \ No newline at end of file diff --git a/Assets/Scripts/Engine/Abstraction.meta b/Assets/Scripts/Engine/Core/Abstraction.meta similarity index 100% rename from Assets/Scripts/Engine/Abstraction.meta rename to Assets/Scripts/Engine/Core/Abstraction.meta diff --git a/Assets/Scripts/Engine/Core/Abstraction/IGameEntity.cs b/Assets/Scripts/Engine/Core/Abstraction/IGameEntity.cs new file mode 100644 index 00000000..c52230c5 --- /dev/null +++ b/Assets/Scripts/Engine/Core/Abstraction/IGameEntity.cs @@ -0,0 +1,96 @@ +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Engine.Core.Abstraction +{ + using System; + + /// + /// Represents a game entity that can be added to the game world. + /// + public interface IGameEntity : IManagedObject + { + /// + /// Gets or sets the name of the game entity. + /// + public string Name { get; set; } + + /// + /// Gets or sets a value indicating whether the game entity is static. + /// + public bool IsStatic { get; set; } + + /// + /// Gets or sets the layer of the game entity. + /// + public int Layer { get; set; } + + /// + /// Gets the transform of the game entity. + /// + public ITransform Transform { get; } + + /// + /// Sets the parent of the game entity. + /// + /// The parent game entity. + /// Whether to keep the world position of the game entity. + public void SetParent(IGameEntity parent, bool worldPositionStays); + + /// + /// Adds a component of the specified type to the game entity. + /// + /// The type of the component to add. + /// The added component. + public T AddComponent() where T : class; + + /// + /// Adds a component of the specified type to the game entity. + /// + /// The type of the component to add. + /// The added component. + public object AddComponent(Type type); + + /// + /// Gets the component of the specified type from the game entity. + /// + /// The type of the component to get. + /// The component of the specified type. + public T GetComponent() where T : class; + + /// + /// Gets the component of the specified type from the children of the game entity. + /// + /// The type of the component to get. + /// The component of the specified type. + public T GetComponentInChildren() where T : class; + + /// + /// Gets all the components of the specified type from the children of the game entity. + /// + /// The type of the components to get. + /// All the components of the specified type. + public T[] GetComponentsInChildren() where T : class; + + /// + /// Gets the component of the specified type from the game entity, or adds it if it doesn't exist. + /// + /// The type of the component to get or add. + /// The component of the specified type. + public T GetOrAddComponent() where T : class; + + /// + /// Finds the child game entity with the specified name. + /// + /// The name of the child game entity. + /// The child game entity with the specified name. + public IGameEntity FindChild(string name); + + /// + /// Destroys the game entity. + /// + public void Destroy(); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Engine/Abstraction/IGameEntity.cs.meta b/Assets/Scripts/Engine/Core/Abstraction/IGameEntity.cs.meta similarity index 100% rename from Assets/Scripts/Engine/Abstraction/IGameEntity.cs.meta rename to Assets/Scripts/Engine/Core/Abstraction/IGameEntity.cs.meta diff --git a/Assets/Scripts/Engine/Core/Abstraction/IManagedObject.cs b/Assets/Scripts/Engine/Core/Abstraction/IManagedObject.cs new file mode 100644 index 00000000..d9176d2c --- /dev/null +++ b/Assets/Scripts/Engine/Core/Abstraction/IManagedObject.cs @@ -0,0 +1,23 @@ +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Engine.Core.Abstraction +{ + /// + /// Interface for managed objects that wrap native objects. + /// + public interface IManagedObject + { + /// + /// Gets the underlying native object. + /// + object NativeObject { get; } + + /// + /// Gets a value indicating whether the underlying native object has been disposed. + /// + bool IsNativeObjectDisposed { get; } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Engine/Abstraction/IManagedObject.cs.meta b/Assets/Scripts/Engine/Core/Abstraction/IManagedObject.cs.meta similarity index 100% rename from Assets/Scripts/Engine/Abstraction/IManagedObject.cs.meta rename to Assets/Scripts/Engine/Core/Abstraction/IManagedObject.cs.meta diff --git a/Assets/Scripts/Engine/Core/Abstraction/ITransform.cs b/Assets/Scripts/Engine/Core/Abstraction/ITransform.cs new file mode 100644 index 00000000..4bb47685 --- /dev/null +++ b/Assets/Scripts/Engine/Core/Abstraction/ITransform.cs @@ -0,0 +1,109 @@ +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Engine.Core.Abstraction +{ + using Quaternion = UnityEngine.Quaternion; + using Vector3 = UnityEngine.Vector3; + + /// + /// Interface for a transform object, which represents the position, rotation, and scale of a game object. + /// + public interface ITransform : IManagedObject + { + /// + /// The position of the transform in world space. + /// + public Vector3 Position { get; set; } + + /// + /// The position of the transform relative to the parent transform. + /// + public Vector3 LocalPosition { get; set; } + + /// + /// The rotation of the transform in world space. + /// + public Quaternion Rotation { get; set; } + + /// + /// The rotation of the transform relative to the parent transform. + /// + public Quaternion LocalRotation { get; set; } + + /// + /// The scale of the transform relative to the parent transform. + /// + public Vector3 LocalScale { get; set; } + + /// + /// The forward direction of the transform in world space. + /// + public Vector3 Forward { get; set; } + + /// + /// The right direction of the transform in world space. + /// + public Vector3 Right { get; set; } + + /// + /// The up direction of the transform in world space. + /// + public Vector3 Up { get; set; } + + /// + /// The rotation of the transform expressed as euler angles. + /// + public Vector3 EulerAngles { get; set; } + + /// + /// Translates the transform by the given vector. + /// + /// The vector to translate by. + public void Translate(Vector3 translation); + + /// + /// Gets the position and rotation of the transform in world space. + /// + /// The position of the transform. + /// The rotation of the transform. + public void GetPositionAndRotation(out Vector3 position, out Quaternion rotation); + + /// + /// Sets the position and rotation of the transform in world space. + /// + /// The new position of the transform. + /// The new rotation of the transform. + public void SetPositionAndRotation(Vector3 position, Quaternion rotation); + + /// + /// Gets the position and rotation of the transform relative to the parent transform. + /// + /// The local position of the transform. + /// The local rotation of the transform. + public void GetLocalPositionAndRotation(out Vector3 position, out Quaternion rotation); + + /// + /// Sets the position and rotation of the transform relative to the parent transform. + /// + /// The new local position of the transform. + /// The new local rotation of the transform. + public void SetLocalPositionAndRotation(Vector3 position, Quaternion rotation); + + /// + /// Rotates the transform to face the given target position. + /// + /// The position to look at. + public void LookAt(Vector3 target); + + /// + /// Rotates the transform around the given axis by the given angle. + /// + /// The point to rotate around. + /// The axis to rotate around. + /// The angle to rotate by. + public void RotateAround(Vector3 centerPoint, Vector3 axis, float angle); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Engine/Abstraction/ITransform.cs.meta b/Assets/Scripts/Engine/Core/Abstraction/ITransform.cs.meta similarity index 100% rename from Assets/Scripts/Engine/Abstraction/ITransform.cs.meta rename to Assets/Scripts/Engine/Core/Abstraction/ITransform.cs.meta diff --git a/Assets/Scripts/Engine/Core/Implementation.meta b/Assets/Scripts/Engine/Core/Implementation.meta new file mode 100644 index 00000000..188bf3ae --- /dev/null +++ b/Assets/Scripts/Engine/Core/Implementation.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 71c833e2c02a4823afe8d7832e814abc +timeCreated: 1697047365 \ No newline at end of file diff --git a/Assets/Scripts/Engine/Abstraction/GameEntity.cs b/Assets/Scripts/Engine/Core/Implementation/GameEntity.cs similarity index 96% rename from Assets/Scripts/Engine/Abstraction/GameEntity.cs rename to Assets/Scripts/Engine/Core/Implementation/GameEntity.cs index fd34fb46..a8242774 100644 --- a/Assets/Scripts/Engine/Abstraction/GameEntity.cs +++ b/Assets/Scripts/Engine/Core/Implementation/GameEntity.cs @@ -3,9 +3,10 @@ // See LICENSE file in the project root for license information. // --------------------------------------------------------------------------------------------- -namespace Engine.Abstraction +namespace Engine.Core.Implementation { using System; + using Abstraction; using Extensions; using Pal3.Core.Utilities; using UnityEngine; @@ -50,6 +51,12 @@ namespace Engine.Abstraction set => _gameObject.isStatic = value; } + public int Layer + { + get => _gameObject.layer; + set => _gameObject.layer = value; + } + public void SetParent(IGameEntity parent, bool worldPositionStays) { _gameObject.transform.SetParent((UnityEngine.Transform)parent?.Transform.NativeObject, worldPositionStays); @@ -114,11 +121,6 @@ namespace Engine.Abstraction return component; } - public void SetLayer(int layerIndex) - { - _gameObject.layer = layerIndex; - } - public IGameEntity FindChild(string name) { UnityEngine.Transform childTransform = _gameObject.transform.Find(name); diff --git a/Assets/Scripts/Engine/Abstraction/GameEntity.cs.meta b/Assets/Scripts/Engine/Core/Implementation/GameEntity.cs.meta similarity index 100% rename from Assets/Scripts/Engine/Abstraction/GameEntity.cs.meta rename to Assets/Scripts/Engine/Core/Implementation/GameEntity.cs.meta diff --git a/Assets/Scripts/Engine/Abstraction/PrefabFactory.cs b/Assets/Scripts/Engine/Core/Implementation/GameEntityFactory.cs similarity index 55% rename from Assets/Scripts/Engine/Abstraction/PrefabFactory.cs rename to Assets/Scripts/Engine/Core/Implementation/GameEntityFactory.cs index 82e2b9ca..7a08e32e 100644 --- a/Assets/Scripts/Engine/Abstraction/PrefabFactory.cs +++ b/Assets/Scripts/Engine/Core/Implementation/GameEntityFactory.cs @@ -3,13 +3,26 @@ // See LICENSE file in the project root for license information. // --------------------------------------------------------------------------------------------- -namespace Engine.Abstraction +namespace Engine.Core.Implementation { using System; + using Abstraction; - public static class PrefabFactory + public static class GameEntityFactory { - public static IGameEntity Instantiate(object prefab, ITransform transform, bool worldPositionStays = false) + public static IGameEntity Create(string name) + { + return name != null ? new GameEntity(name) : new GameEntity(); + } + + public static IGameEntity Create(string name, IGameEntity parent, bool worldPositionStays = false) + { + IGameEntity gameEntity = Create(name); + gameEntity.SetParent(parent, worldPositionStays); + return gameEntity; + } + + public static IGameEntity Create(string name, object prefab, IGameEntity parent, bool worldPositionStays = false) { if (prefab.GetType() != typeof(UnityEngine.Object) && !prefab.GetType().IsSubclassOf(typeof(UnityEngine.Object))) { @@ -18,14 +31,15 @@ namespace Engine.Abstraction Object gameObject = UnityEngine.Object.Instantiate( (UnityEngine.Object) prefab, - (UnityEngine.Transform) transform.NativeObject, + (UnityEngine.Transform) parent?.Transform?.NativeObject, worldPositionStays); if (gameObject == null || gameObject.GetType() != typeof(UnityEngine.GameObject)) { - throw new NullReferenceException("The instantiated object is not UnityEngine.GameObject or game object is null"); + throw new NullReferenceException("The instantiated object is not UnityEngine.GameObject or prefab is not found"); } + ((UnityEngine.GameObject)gameObject).name = name; return new GameEntity((UnityEngine.GameObject) gameObject); } } diff --git a/Assets/Scripts/Engine/Abstraction/PrefabFactory.cs.meta b/Assets/Scripts/Engine/Core/Implementation/GameEntityFactory.cs.meta similarity index 100% rename from Assets/Scripts/Engine/Abstraction/PrefabFactory.cs.meta rename to Assets/Scripts/Engine/Core/Implementation/GameEntityFactory.cs.meta diff --git a/Assets/Scripts/Engine/Abstraction/GameEntityScript.cs b/Assets/Scripts/Engine/Core/Implementation/GameEntityScript.cs similarity index 97% rename from Assets/Scripts/Engine/Abstraction/GameEntityScript.cs rename to Assets/Scripts/Engine/Core/Implementation/GameEntityScript.cs index cf6ab377..fc3afa94 100644 --- a/Assets/Scripts/Engine/Abstraction/GameEntityScript.cs +++ b/Assets/Scripts/Engine/Core/Implementation/GameEntityScript.cs @@ -3,10 +3,11 @@ // See LICENSE file in the project root for license information. // --------------------------------------------------------------------------------------------- -namespace Engine.Abstraction +namespace Engine.Core.Implementation { using System; using System.Collections; + using Abstraction; using UnityEngine; public abstract class GameEntityScript : MonoBehaviour diff --git a/Assets/Scripts/Engine/Abstraction/GameEntityScript.cs.meta b/Assets/Scripts/Engine/Core/Implementation/GameEntityScript.cs.meta similarity index 100% rename from Assets/Scripts/Engine/Abstraction/GameEntityScript.cs.meta rename to Assets/Scripts/Engine/Core/Implementation/GameEntityScript.cs.meta diff --git a/Assets/Scripts/Engine/Abstraction/TickableGameEntityScript.cs b/Assets/Scripts/Engine/Core/Implementation/TickableGameEntityScript.cs similarity index 96% rename from Assets/Scripts/Engine/Abstraction/TickableGameEntityScript.cs rename to Assets/Scripts/Engine/Core/Implementation/TickableGameEntityScript.cs index d3ae352d..ee04b64b 100644 --- a/Assets/Scripts/Engine/Abstraction/TickableGameEntityScript.cs +++ b/Assets/Scripts/Engine/Core/Implementation/TickableGameEntityScript.cs @@ -3,7 +3,7 @@ // See LICENSE file in the project root for license information. // --------------------------------------------------------------------------------------------- -namespace Engine.Abstraction +namespace Engine.Core.Implementation { using UnityEngine; diff --git a/Assets/Scripts/Engine/Abstraction/TickableGameEntityScript.cs.meta b/Assets/Scripts/Engine/Core/Implementation/TickableGameEntityScript.cs.meta similarity index 100% rename from Assets/Scripts/Engine/Abstraction/TickableGameEntityScript.cs.meta rename to Assets/Scripts/Engine/Core/Implementation/TickableGameEntityScript.cs.meta diff --git a/Assets/Scripts/Engine/Abstraction/Transform.cs b/Assets/Scripts/Engine/Core/Implementation/Transform.cs similarity index 98% rename from Assets/Scripts/Engine/Abstraction/Transform.cs rename to Assets/Scripts/Engine/Core/Implementation/Transform.cs index 1ae43002..2c6083b3 100644 --- a/Assets/Scripts/Engine/Abstraction/Transform.cs +++ b/Assets/Scripts/Engine/Core/Implementation/Transform.cs @@ -3,9 +3,10 @@ // See LICENSE file in the project root for license information. // --------------------------------------------------------------------------------------------- -namespace Engine.Abstraction +namespace Engine.Core.Implementation { using System.Runtime.CompilerServices; + using Abstraction; using UnityEngine; public sealed class Transform : ITransform diff --git a/Assets/Scripts/Engine/Abstraction/Transform.cs.meta b/Assets/Scripts/Engine/Core/Implementation/Transform.cs.meta similarity index 100% rename from Assets/Scripts/Engine/Abstraction/Transform.cs.meta rename to Assets/Scripts/Engine/Core/Implementation/Transform.cs.meta diff --git a/Assets/Scripts/Engine/Coroutine/CoroutineYieldInstruction.cs b/Assets/Scripts/Engine/Coroutine/CoroutineYieldInstruction.cs index 5b5b877c..cdaa461b 100644 --- a/Assets/Scripts/Engine/Coroutine/CoroutineYieldInstruction.cs +++ b/Assets/Scripts/Engine/Coroutine/CoroutineYieldInstruction.cs @@ -8,13 +8,26 @@ namespace Engine.Coroutine using System; using UnityEngine; + /// + /// A static class that provides yield instructions for coroutines. + /// public static class CoroutineYieldInstruction { + /// + /// Waits for the specified number of seconds before continuing the coroutine. + /// + /// The number of seconds to wait. + /// A yield instruction that waits for the specified number of seconds. public static object WaitForSeconds(float seconds) { return new WaitForSeconds(seconds); } + /// + /// Waits until the specified predicate returns true before continuing the coroutine. + /// + /// The predicate to evaluate. + /// A yield instruction that waits until the predicate returns true. public static object WaitUntil(Func predicate) { return new WaitUntil(predicate); diff --git a/Assets/Scripts/Engine/Renderer/AnimatedBillboardRenderer.cs b/Assets/Scripts/Engine/Renderer/AnimatedBillboardRenderer.cs index f33e8db2..c244bd7f 100644 --- a/Assets/Scripts/Engine/Renderer/AnimatedBillboardRenderer.cs +++ b/Assets/Scripts/Engine/Renderer/AnimatedBillboardRenderer.cs @@ -7,7 +7,7 @@ namespace Engine.Renderer { using System.Collections; using System.Threading; - using Abstraction; + using Core.Implementation; using Coroutine; using Extensions; using UnityEngine; diff --git a/Assets/Scripts/Engine/Renderer/SkyBoxRenderer.cs b/Assets/Scripts/Engine/Renderer/SkyBoxRenderer.cs index 18ac4a3c..aec2dcce 100644 --- a/Assets/Scripts/Engine/Renderer/SkyBoxRenderer.cs +++ b/Assets/Scripts/Engine/Renderer/SkyBoxRenderer.cs @@ -5,7 +5,8 @@ namespace Engine.Renderer { - using Abstraction; + using Core.Abstraction; + using Core.Implementation; using Extensions; using UnityEngine; diff --git a/Assets/Scripts/Engine/Renderer/StaticBillboardRenderer.cs b/Assets/Scripts/Engine/Renderer/StaticBillboardRenderer.cs index 1f00d2b9..fe47d1f3 100644 --- a/Assets/Scripts/Engine/Renderer/StaticBillboardRenderer.cs +++ b/Assets/Scripts/Engine/Renderer/StaticBillboardRenderer.cs @@ -5,7 +5,7 @@ namespace Engine.Renderer { - using Abstraction; + using Core.Implementation; using UnityEngine; public class StaticBillboardRenderer : TickableGameEntityScript diff --git a/Assets/Scripts/Engine/Renderer/StaticMeshRenderer.cs b/Assets/Scripts/Engine/Renderer/StaticMeshRenderer.cs index 4f4f60d9..0a9bd8c6 100644 --- a/Assets/Scripts/Engine/Renderer/StaticMeshRenderer.cs +++ b/Assets/Scripts/Engine/Renderer/StaticMeshRenderer.cs @@ -6,7 +6,7 @@ namespace Engine.Renderer { using System; - using Abstraction; + using Core.Implementation; using Extensions; using UnityEngine; diff --git a/Assets/Scripts/Engine/Services/IGameTimeProvider.cs b/Assets/Scripts/Engine/Services/IGameTimeProvider.cs index e0dee01b..58a401d9 100644 --- a/Assets/Scripts/Engine/Services/IGameTimeProvider.cs +++ b/Assets/Scripts/Engine/Services/IGameTimeProvider.cs @@ -5,15 +5,24 @@ namespace Engine.Services { - /// - /// Tracks the time since the game started and the delta time between frames. - /// - public interface IGameTimeProvider - { - public double TimeSinceStartup { get; } + /// + /// Interface for providing game time information. + /// + public interface IGameTimeProvider + { + /// + /// The time since the game started, in seconds. + /// + public double TimeSinceStartup { get; } - public double RealTimeSinceStartup { get; } + /// + /// The real time since the game started, in seconds. + /// + public double RealTimeSinceStartup { get; } - public float DeltaTime { get; } - } + /// + /// The time in seconds it took to complete the last frame. + /// + public float DeltaTime { get; } + } } \ No newline at end of file diff --git a/Assets/Scripts/Engine/Services/IPhysicsManager.cs b/Assets/Scripts/Engine/Services/IPhysicsManager.cs new file mode 100644 index 00000000..b67e6181 --- /dev/null +++ b/Assets/Scripts/Engine/Services/IPhysicsManager.cs @@ -0,0 +1,55 @@ +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Engine.Services +{ + using Core.Abstraction; + using UnityEngine; + + /// + /// Interface for managing physics in the game. + /// + public interface IPhysicsManager + { + public int MaxRaycastHitCount { get; } + + /// + /// Attempts to perform a raycast from a screen point in the camera's view. + /// + /// The screen point to cast the ray from. + /// The resulting hit point and collider game entity, if any. + /// The maximum distance to cast the ray. + /// True if the raycast hit a collider, false otherwise. + public bool TryCameraRaycastFromScreenPoint(Vector2 screenPoint, + out (Vector3 hitPoint, IGameEntity colliderGameEntity) hitResult, + float maxDistance = float.PositiveInfinity); + + /// + /// Casts a ray from a screen point into the scene and returns information about any colliders hit. + /// + /// The screen point to cast the ray from. + /// An array of hit results, each containing information about the hit point and the game entity of the collider. + /// The maximum distance to cast the ray. + /// The number of colliders hit. + public int CameraRaycastFromScreenPoint(Vector2 screenPoint, + (Vector3 hitPoint, IGameEntity colliderGameEntity)[] hitResults, + float maxDistance = float.PositiveInfinity); + + /// + /// Casts a box along a ray and returns all hits in the path. + /// + /// The center of the box. + /// Half the size of the box in each dimension. + /// The direction in which to cast the box. + /// The orientation of the box. + /// An array of hit results, each containing the hit point and the game entity of the collider. + /// The number of hits found. + public int BoxCast(Vector3 center, + Vector3 halfExtents, + Vector3 direction, + Quaternion orientation, + (Vector3 hitPoint, IGameEntity colliderGameEntity)[] hitResults); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Engine/Services/IPhysicsManager.cs.meta b/Assets/Scripts/Engine/Services/IPhysicsManager.cs.meta new file mode 100644 index 00000000..ad91492f --- /dev/null +++ b/Assets/Scripts/Engine/Services/IPhysicsManager.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 006dda9e830047ac9c97267bfaa594ff +timeCreated: 1697053885 \ No newline at end of file diff --git a/Assets/Scripts/Engine/Services/PhysicsManager.cs b/Assets/Scripts/Engine/Services/PhysicsManager.cs new file mode 100644 index 00000000..1d4fe93b --- /dev/null +++ b/Assets/Scripts/Engine/Services/PhysicsManager.cs @@ -0,0 +1,80 @@ +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Engine.Services +{ + using System; + using Core.Abstraction; + using Core.Implementation; + using UnityEngine; + + public sealed class PhysicsManager : IPhysicsManager + { + private const int MAX_RAYCAST_HIT_COUNT = 10; + private readonly RaycastHit[] _raycastHits = new RaycastHit[MAX_RAYCAST_HIT_COUNT]; // Cache + private readonly Camera _camera; + + public PhysicsManager(Camera camera) + { + _camera = camera; + } + + public int MaxRaycastHitCount => MAX_RAYCAST_HIT_COUNT; + + public bool TryCameraRaycastFromScreenPoint(Vector2 screenPoint, + out (Vector3 hitPoint, IGameEntity colliderGameEntity) hitResult, + float maxDistance = float.PositiveInfinity) + { + Ray ray = _camera.ScreenPointToRay(screenPoint); + + if (Physics.Raycast(ray, out RaycastHit hit)) + { + hitResult = (hit.point, new GameEntity(hit.collider.gameObject)); + return true; + } + else + { + hitResult = default; + return false; + } + } + + public int CameraRaycastFromScreenPoint(Vector2 screenPoint, + (Vector3 hitPoint, IGameEntity colliderGameEntity)[] hitResults, + float maxDistance = float.PositiveInfinity) + { + Ray ray = _camera.ScreenPointToRay(screenPoint); + + int hitCount = Physics.RaycastNonAlloc(ray, _raycastHits, maxDistance); + + for (int i = 0; i < Math.Min(hitCount, hitResults.Length); i++) + { + hitResults[i] = (_raycastHits[i].point, new GameEntity(_raycastHits[i].collider.gameObject)); + } + + return hitCount; + } + + public int BoxCast(Vector3 center, + Vector3 halfExtents, + Vector3 direction, + Quaternion orientation, + (Vector3 hitPoint, IGameEntity colliderGameEntity)[] hitResults) + { + int hitCount = Physics.BoxCastNonAlloc(center, + halfExtents, + direction, + _raycastHits, + orientation); + + for (int i = 0; i < Math.Min(hitCount, hitResults.Length); i++) + { + hitResults[i] = (_raycastHits[i].point, new GameEntity(_raycastHits[i].collider.gameObject)); + } + + return hitCount; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Engine/Services/PhysicsManager.cs.meta b/Assets/Scripts/Engine/Services/PhysicsManager.cs.meta new file mode 100644 index 00000000..680a52e2 --- /dev/null +++ b/Assets/Scripts/Engine/Services/PhysicsManager.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8a062bd2de8345afb86e6e2f6971ce71 +timeCreated: 1697053568 \ No newline at end of file diff --git a/Assets/Scripts/Engine/Services/ServiceLocator.cs b/Assets/Scripts/Engine/Services/ServiceLocator.cs index d4602447..3c492c5e 100644 --- a/Assets/Scripts/Engine/Services/ServiceLocator.cs +++ b/Assets/Scripts/Engine/Services/ServiceLocator.cs @@ -13,8 +13,10 @@ namespace Engine.Services /// /// ServiceLocator singleton. /// - public class ServiceLocator : Singleton + public sealed class ServiceLocator : Singleton { + private ServiceLocator() { } // Hide constructor, use Instance instead. + /// /// Currently registered services. /// diff --git a/Assets/Scripts/Engine/Utilities/UnityEngineUtility.cs b/Assets/Scripts/Engine/Utilities/UnityEngineUtility.cs index 3504daf2..25b9d92f 100644 --- a/Assets/Scripts/Engine/Utilities/UnityEngineUtility.cs +++ b/Assets/Scripts/Engine/Utilities/UnityEngineUtility.cs @@ -10,23 +10,6 @@ namespace Engine.Utilities public static class UnityEngineUtility { - public static unsafe void ApplyTransparencyBasedOnColorLuminance(Texture2D texture) - { - var pixels = texture.GetPixels(); - - fixed (float* src = &pixels[0].r) - { - var p = src; - for (var i = 0; i < texture.width * texture.height; i++, p += 4) - { - *(p + 3) = 0.299f * *p + 0.587f * *(p + 1) + 0.114f * *(p + 2); - } - } - - texture.SetPixels(pixels); - texture.Apply(updateMipmaps: false); - } - public static bool IsHandheldDevice() { return SystemInfo.deviceType == DeviceType.Handheld; diff --git a/Assets/Scripts/Pal3.Core/Contract/Constants/ScriptConstants.cs b/Assets/Scripts/Pal3.Core/Contract/Constants/ScriptConstants.cs index a11862ed..baf889d5 100644 --- a/Assets/Scripts/Pal3.Core/Contract/Constants/ScriptConstants.cs +++ b/Assets/Scripts/Pal3.Core/Contract/Constants/ScriptConstants.cs @@ -11,10 +11,12 @@ namespace Pal3.Core.Contract.Constants public const int InvalidScriptId = 0; - public const int SystemScriptIdMax = 99; + public const int SystemScriptIdMax = 100; public const int CommandIdMax = 512; + public const int PortalScriptIdMax = 1000; + public const short MainStoryVariableName = -0x8000; } } \ No newline at end of file diff --git a/Assets/Scripts/Pal3.Game/Actor/ActorFactory.cs b/Assets/Scripts/Pal3.Game/Actor/ActorFactory.cs index d681b1a3..d93275b8 100644 --- a/Assets/Scripts/Pal3.Game/Actor/ActorFactory.cs +++ b/Assets/Scripts/Pal3.Game/Actor/ActorFactory.cs @@ -11,7 +11,8 @@ namespace Pal3.Game.Actor using Core.Contract.Enums; using Data; using Dev.Presenters; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using GameSystems.Combat; using Scene; @@ -30,7 +31,7 @@ namespace Pal3.Game.Actor float movementMaxYDifferentialCrossPlatform, Func> getAllActiveActorBlockingTilePositions) { - var actorGameEntity = new GameEntity($"Actor_{actor.Id}_{actor.Name}"); + var actorGameEntity = GameEntityFactory.Create($"Actor_{actor.Id}_{actor.Name}"); // Attach ScnNpcInfo to the GameEntity for better debuggability #if UNITY_EDITOR @@ -115,7 +116,7 @@ namespace Pal3.Game.Actor ElementPosition elementPosition, bool isDropShadowEnabled) { - var actorGameEntity = new GameEntity($"CombatActor_{actor.Id}_{actor.Name}"); + IGameEntity actorGameEntity = GameEntityFactory.Create($"CombatActor_{actor.Id}_{actor.Name}"); // Attach CombatActorInfo to the GameEntity for better debuggability #if UNITY_EDITOR diff --git a/Assets/Scripts/Pal3.Game/Actor/Controllers/ActorActionController.cs b/Assets/Scripts/Pal3.Game/Actor/Controllers/ActorActionController.cs index 9037fd5b..d6597cb1 100644 --- a/Assets/Scripts/Pal3.Game/Actor/Controllers/ActorActionController.cs +++ b/Assets/Scripts/Pal3.Game/Actor/Controllers/ActorActionController.cs @@ -14,7 +14,8 @@ namespace Pal3.Game.Actor.Controllers using Core.Contract.Constants; using Core.Contract.Enums; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.Extensions; using Engine.Logging; using Engine.Renderer; @@ -228,8 +229,8 @@ namespace Pal3.Game.Actor.Controllers private void RenderShadow() { - _shadow = new GameEntity("Shadow"); - _shadow.SetParent(GameEntity, worldPositionStays: false); + _shadow = GameEntityFactory.Create("Shadow", + GameEntity, worldPositionStays: false); ITransform shadowTransform = _shadow.Transform; shadowTransform.LocalRotation = Quaternion.Euler(90f, 0f, 0f); shadowTransform.LocalScale = new Vector3(1.4f, 1.4f, 1f); @@ -253,8 +254,8 @@ namespace Pal3.Game.Actor.Controllers var sprites = _resourceProvider.GetEmojiSprites(emojiType); - var emojiGameEntity = new GameEntity($"Emoji_{emojiType.ToString()}"); - emojiGameEntity.SetParent(GameEntity, worldPositionStays: false); + IGameEntity emojiGameEntity = GameEntityFactory.Create($"Emoji_{emojiType.ToString()}", + GameEntity, worldPositionStays: false); emojiGameEntity.Transform.LocalScale = new Vector3(1.5f, 1.5f, 1.5f); emojiGameEntity.Transform.LocalPosition = new Vector3(0f, GetActorHeight(), 0f); diff --git a/Assets/Scripts/Pal3.Game/Actor/Controllers/ActorController.cs b/Assets/Scripts/Pal3.Game/Actor/Controllers/ActorController.cs index abb9515c..7e38f1c2 100644 --- a/Assets/Scripts/Pal3.Game/Actor/Controllers/ActorController.cs +++ b/Assets/Scripts/Pal3.Game/Actor/Controllers/ActorController.cs @@ -13,15 +13,18 @@ namespace Pal3.Game.Actor.Controllers using Core.Command.SceCommands; using Core.Contract.Constants; using Core.Contract.Enums; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.Extensions; using Engine.Navigation; using Engine.Services; using Input; using GamePlay; using Script.Waiter; - using UnityEngine; + + using Quaternion = UnityEngine.Quaternion; + using Vector3 = UnityEngine.Vector3; public class ActorController : GameEntityScript, ICommandExecutor, diff --git a/Assets/Scripts/Pal3.Game/Actor/Controllers/ActorMovementController.cs b/Assets/Scripts/Pal3.Game/Actor/Controllers/ActorMovementController.cs index 46a41a87..2010beab 100644 --- a/Assets/Scripts/Pal3.Game/Actor/Controllers/ActorMovementController.cs +++ b/Assets/Scripts/Pal3.Game/Actor/Controllers/ActorMovementController.cs @@ -18,7 +18,8 @@ namespace Pal3.Game.Actor.Controllers using Core.DataReader.Nav; using Core.Primitives; using Core.Utilities; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.Coroutine; using Engine.Extensions; using Engine.Logging; diff --git a/Assets/Scripts/Pal3.Game/Actor/Controllers/CombatActorController.cs b/Assets/Scripts/Pal3.Game/Actor/Controllers/CombatActorController.cs index 278ddcb8..f26f530f 100644 --- a/Assets/Scripts/Pal3.Game/Actor/Controllers/CombatActorController.cs +++ b/Assets/Scripts/Pal3.Game/Actor/Controllers/CombatActorController.cs @@ -7,8 +7,8 @@ namespace Pal3.Game.Actor.Controllers { using System; using System.Collections; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Implementation; using Engine.Coroutine; using GameSystems.Combat; using Scene; diff --git a/Assets/Scripts/Pal3.Game/Actor/Controllers/FlyingActorController.cs b/Assets/Scripts/Pal3.Game/Actor/Controllers/FlyingActorController.cs index 9ca2d8ac..06ab8566 100644 --- a/Assets/Scripts/Pal3.Game/Actor/Controllers/FlyingActorController.cs +++ b/Assets/Scripts/Pal3.Game/Actor/Controllers/FlyingActorController.cs @@ -13,7 +13,7 @@ namespace Pal3.Game.Actor.Controllers using Core.Command.SceCommands; using Core.Contract.Enums; using Core.Primitives; - using Engine.Abstraction; + using Engine.Core.Implementation; using Engine.Extensions; using Engine.Services; using Script.Waiter; diff --git a/Assets/Scripts/Pal3.Game/Actor/Controllers/HuaYingController.cs b/Assets/Scripts/Pal3.Game/Actor/Controllers/HuaYingController.cs index ff36e56f..d70a803d 100644 --- a/Assets/Scripts/Pal3.Game/Actor/Controllers/HuaYingController.cs +++ b/Assets/Scripts/Pal3.Game/Actor/Controllers/HuaYingController.cs @@ -11,7 +11,7 @@ namespace Pal3.Game.Actor.Controllers using Core.Command; using Core.Command.SceCommands; using Core.Contract.Enums; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Services; using Scene; diff --git a/Assets/Scripts/Pal3.Game/Actor/Controllers/LongKuiController.cs b/Assets/Scripts/Pal3.Game/Actor/Controllers/LongKuiController.cs index b7ca1e5a..60fb1686 100644 --- a/Assets/Scripts/Pal3.Game/Actor/Controllers/LongKuiController.cs +++ b/Assets/Scripts/Pal3.Game/Actor/Controllers/LongKuiController.cs @@ -11,7 +11,7 @@ namespace Pal3.Game.Actor.Controllers using Core.Command; using Core.Command.SceCommands; using Core.Contract.Constants; - using Engine.Abstraction; + using Engine.Core.Implementation; public sealed class LongKuiController : GameEntityScript, ICommandExecutor diff --git a/Assets/Scripts/Pal3.Game/Audio/AudioManager.cs b/Assets/Scripts/Pal3.Game/Audio/AudioManager.cs index 3b7bbd0a..9d1ad6ee 100644 --- a/Assets/Scripts/Pal3.Game/Audio/AudioManager.cs +++ b/Assets/Scripts/Pal3.Game/Audio/AudioManager.cs @@ -18,7 +18,8 @@ namespace Pal3.Game.Audio using Core.DataReader.Scn; using Core.Utilities; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.Coroutine; using Engine.Extensions; using Scene; @@ -202,8 +203,7 @@ namespace Pal3.Game.Audio IGameEntity audioSourceParent = parent.FindChild(audioSourceName); if (audioSourceParent == null) { - audioSourceParent = new GameEntity(audioSourceName); - audioSourceParent.SetParent(parent, worldPositionStays: true); + audioSourceParent = GameEntityFactory.Create(audioSourceName, parent, worldPositionStays: true); audioSourceParent.Transform.Position = parent.Transform.Position; } diff --git a/Assets/Scripts/Pal3.Game/Camera/CameraManager.cs b/Assets/Scripts/Pal3.Game/Camera/CameraManager.cs index 52544579..4378711c 100644 --- a/Assets/Scripts/Pal3.Game/Camera/CameraManager.cs +++ b/Assets/Scripts/Pal3.Game/Camera/CameraManager.cs @@ -19,8 +19,8 @@ namespace Pal3.Game.Camera using Core.DataReader.Scn; using Core.Primitives; using Core.Utilities; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Engine.Extensions; using Engine.Utilities; using GamePlay; @@ -497,11 +497,6 @@ namespace Pal3.Game.Camera _cameraOffset = cameraPosition - _lastLookAtPoint; } - public Ray ScreenPointToRay(Vector2 position) - { - return _camera.ScreenPointToRay(position); - } - public float GetFieldOfView() { return _camera.fieldOfView; diff --git a/Assets/Scripts/Pal3.Game/Command/CommandDispatcher.cs b/Assets/Scripts/Pal3.Game/Command/CommandDispatcher.cs index 5085f080..6f208a55 100644 --- a/Assets/Scripts/Pal3.Game/Command/CommandDispatcher.cs +++ b/Assets/Scripts/Pal3.Game/Command/CommandDispatcher.cs @@ -29,7 +29,7 @@ namespace Pal3.Game.Command private readonly Dictionary _commandExecutorExecuteMethodInfoCache = new(); - private CommandDispatcher() { } + private CommandDispatcher() { } // Hide constructor, use Instance instead. private CommandDispatcher(ICommandExecutorRegistry commandExecutorRegistry) { diff --git a/Assets/Scripts/Pal3.Game/Command/CommandExecutorRegistry.cs b/Assets/Scripts/Pal3.Game/Command/CommandExecutorRegistry.cs index aa8c7c70..379d3ce1 100644 --- a/Assets/Scripts/Pal3.Game/Command/CommandExecutorRegistry.cs +++ b/Assets/Scripts/Pal3.Game/Command/CommandExecutorRegistry.cs @@ -22,7 +22,7 @@ namespace Pal3.Game.Command private readonly Dictionary> _executors = new (); - private CommandExecutorRegistry() { } + private CommandExecutorRegistry() { } // Hide constructor, use Instance instead. /// public void Register(ICommandExecutor executor) where T : TCommand diff --git a/Assets/Scripts/Pal3.Game/Command/Extensions/AttachSfxToGameEntityRequest.cs b/Assets/Scripts/Pal3.Game/Command/Extensions/AttachSfxToGameEntityRequest.cs index 3af428bc..b26641d4 100644 --- a/Assets/Scripts/Pal3.Game/Command/Extensions/AttachSfxToGameEntityRequest.cs +++ b/Assets/Scripts/Pal3.Game/Command/Extensions/AttachSfxToGameEntityRequest.cs @@ -6,7 +6,7 @@ namespace Pal3.Game.Command.Extensions { using Core.Command; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Newtonsoft.Json; public class AttachSfxToGameEntityRequest : ICommand diff --git a/Assets/Scripts/Pal3.Game/Command/Extensions/StopSfxPlayingAtGameEntityRequest.cs b/Assets/Scripts/Pal3.Game/Command/Extensions/StopSfxPlayingAtGameEntityRequest.cs index 279e35c3..b890d012 100644 --- a/Assets/Scripts/Pal3.Game/Command/Extensions/StopSfxPlayingAtGameEntityRequest.cs +++ b/Assets/Scripts/Pal3.Game/Command/Extensions/StopSfxPlayingAtGameEntityRequest.cs @@ -6,7 +6,7 @@ namespace Pal3.Game.Command.Extensions { using Core.Command; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Newtonsoft.Json; public class StopSfxPlayingAtGameEntityRequest : ICommand diff --git a/Assets/Scripts/Pal3.Game/Dev/Presenters/CombatActorInfoPresenter.cs b/Assets/Scripts/Pal3.Game/Dev/Presenters/CombatActorInfoPresenter.cs index 18db5382..0beefb3b 100644 --- a/Assets/Scripts/Pal3.Game/Dev/Presenters/CombatActorInfoPresenter.cs +++ b/Assets/Scripts/Pal3.Game/Dev/Presenters/CombatActorInfoPresenter.cs @@ -6,7 +6,7 @@ namespace Pal3.Game.Dev.Presenters { using Core.DataReader.Gdb; - using Engine.Abstraction; + using Engine.Core.Implementation; /// /// CombatActorInfo holder component to present ScnObjectInfo in the Unity inspector. diff --git a/Assets/Scripts/Pal3.Game/Dev/Presenters/LightSourceInfoPresenter.cs b/Assets/Scripts/Pal3.Game/Dev/Presenters/LightSourceInfoPresenter.cs index 831ef185..58c77634 100644 --- a/Assets/Scripts/Pal3.Game/Dev/Presenters/LightSourceInfoPresenter.cs +++ b/Assets/Scripts/Pal3.Game/Dev/Presenters/LightSourceInfoPresenter.cs @@ -6,7 +6,7 @@ namespace Pal3.Game.Dev.Presenters { using Core.DataReader.Lgt; - using Engine.Abstraction; + using Engine.Core.Implementation; /// /// LightNode holder component to present LightNode in the Unity inspector. diff --git a/Assets/Scripts/Pal3.Game/Dev/Presenters/MaterialInfoPresenter.cs b/Assets/Scripts/Pal3.Game/Dev/Presenters/MaterialInfoPresenter.cs index 2108f9f0..73558512 100644 --- a/Assets/Scripts/Pal3.Game/Dev/Presenters/MaterialInfoPresenter.cs +++ b/Assets/Scripts/Pal3.Game/Dev/Presenters/MaterialInfoPresenter.cs @@ -6,7 +6,7 @@ namespace Pal3.Game.Dev.Presenters { using Core.Primitives; - using Engine.Abstraction; + using Engine.Core.Implementation; /// /// BlendFlag and GameBoxMaterial holder component to present MaterialInfo in the Unity inspector. diff --git a/Assets/Scripts/Pal3.Game/Dev/Presenters/NpcInfoPresenter.cs b/Assets/Scripts/Pal3.Game/Dev/Presenters/NpcInfoPresenter.cs index e2ebf203..39c38474 100644 --- a/Assets/Scripts/Pal3.Game/Dev/Presenters/NpcInfoPresenter.cs +++ b/Assets/Scripts/Pal3.Game/Dev/Presenters/NpcInfoPresenter.cs @@ -6,7 +6,7 @@ namespace Pal3.Game.Dev.Presenters { using Core.DataReader.Scn; - using Engine.Abstraction; + using Engine.Core.Implementation; /// /// ScnNpcInfo holder component to present ScnNpcInfo in the Unity inspector. diff --git a/Assets/Scripts/Pal3.Game/Dev/Presenters/SceneObjectInfoPresenter.cs b/Assets/Scripts/Pal3.Game/Dev/Presenters/SceneObjectInfoPresenter.cs index 43df3f1a..f82f49e0 100644 --- a/Assets/Scripts/Pal3.Game/Dev/Presenters/SceneObjectInfoPresenter.cs +++ b/Assets/Scripts/Pal3.Game/Dev/Presenters/SceneObjectInfoPresenter.cs @@ -6,7 +6,7 @@ namespace Pal3.Game.Dev.Presenters { using Core.DataReader.Scn; - using Engine.Abstraction; + using Engine.Core.Implementation; /// /// ScnObjectInfo holder component to present ScnObjectInfo in the Unity inspector. diff --git a/Assets/Scripts/Pal3.Game/Effect/CombatEffect.cs b/Assets/Scripts/Pal3.Game/Effect/CombatEffect.cs index 3a8ad22c..c476b919 100644 --- a/Assets/Scripts/Pal3.Game/Effect/CombatEffect.cs +++ b/Assets/Scripts/Pal3.Game/Effect/CombatEffect.cs @@ -6,7 +6,8 @@ namespace Pal3.Game.Effect { using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.Extensions; using Vector3 = UnityEngine.Vector3; @@ -80,8 +81,8 @@ namespace Pal3.Game.Effect object vfxPrefab = resourceProvider.GetVfxEffectPrefab((int)effectParameter); if (vfxPrefab != null) { - _effect = PrefabFactory.Instantiate(vfxPrefab, Transform, worldPositionStays: false); - _effect.Name = "VFX_" + effectParameter; + _effect = GameEntityFactory.Create(name: $"VFX_{effectParameter}", + vfxPrefab, GameEntity, worldPositionStays: false); } } } diff --git a/Assets/Scripts/Pal3.Game/Effect/EffectManager.cs b/Assets/Scripts/Pal3.Game/Effect/EffectManager.cs index 0a79dd1a..d7d0526d 100644 --- a/Assets/Scripts/Pal3.Game/Effect/EffectManager.cs +++ b/Assets/Scripts/Pal3.Game/Effect/EffectManager.cs @@ -17,7 +17,8 @@ namespace Pal3.Game.Effect using Core.Primitives; using Core.Utilities; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.Extensions; using Scene; @@ -94,13 +95,13 @@ namespace Pal3.Game.Effect object vfxPrefab = _resourceProvider.GetVfxEffectPrefab(command.EffectGroupId); if (vfxPrefab != null) { - ITransform parentTransform = null; + IGameEntity parent = null; Vector3 localPosition = Vector3.zero; if (_effectPositionCommand is EffectSetPositionCommand positionCommand && _sceneManager.GetSceneRootGameEntity() is {} sceneRootGameEntity) { - parentTransform = sceneRootGameEntity.Transform; + parent = sceneRootGameEntity; localPosition = new GameBoxVector3( positionCommand.GameBoxXPosition, positionCommand.GameBoxYPosition, @@ -108,14 +109,14 @@ namespace Pal3.Game.Effect } else if (_effectPositionCommand is EffectAttachToActorCommand actorCommand) { - parentTransform = currentScene.GetActorGameEntity(actorCommand.ActorId).Transform; + parent = currentScene.GetActorGameEntity(actorCommand.ActorId); } - if (parentTransform != null) + if (parent != null) { - IGameEntity vfx = PrefabFactory.Instantiate(vfxPrefab, parentTransform, false); - vfx.Name = "VFX_" + command.EffectGroupId; - vfx.Transform.LocalPosition += localPosition; + IGameEntity effectEntity = GameEntityFactory.Create(name: $"VFX_{command.EffectGroupId}", + vfxPrefab, parent, worldPositionStays: false); + effectEntity.Transform.LocalPosition += localPosition; } } diff --git a/Assets/Scripts/Pal3.Game/Effect/FireEffect.cs b/Assets/Scripts/Pal3.Game/Effect/FireEffect.cs index 1a081b84..0beabb69 100644 --- a/Assets/Scripts/Pal3.Game/Effect/FireEffect.cs +++ b/Assets/Scripts/Pal3.Game/Effect/FireEffect.cs @@ -12,7 +12,8 @@ namespace Pal3.Game.Effect using Core.DataReader.Pol; using Core.Utilities; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.DataLoader; using Engine.Extensions; using Engine.Renderer; @@ -74,8 +75,8 @@ namespace Pal3.Game.Effect yPosition = _sceneObjectRenderer.GetMeshBounds().max.y; } - EffectGameEntity = new GameEntity($"Effect_{GraphicsEffectType.Fire.ToString()}_{FireEffectType.ToString()}"); - EffectGameEntity.SetParent(GameEntity, worldPositionStays: false); + EffectGameEntity = GameEntityFactory.Create($"Effect_{GraphicsEffectType.Fire.ToString()}_{FireEffectType.ToString()}", + GameEntity, worldPositionStays: false); EffectGameEntity.Transform.LocalScale = new Vector3(info.Size, info.Size, info.Size); EffectGameEntity.Transform.LocalPosition = new Vector3(0f, yPosition, 0f); diff --git a/Assets/Scripts/Pal3.Game/Effect/PortalEffect.cs b/Assets/Scripts/Pal3.Game/Effect/PortalEffect.cs index ab9b8d36..1bc910e1 100644 --- a/Assets/Scripts/Pal3.Game/Effect/PortalEffect.cs +++ b/Assets/Scripts/Pal3.Game/Effect/PortalEffect.cs @@ -6,7 +6,8 @@ namespace Pal3.Game.Effect { using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.Extensions; using Vector3 = UnityEngine.Vector3; @@ -21,6 +22,7 @@ namespace Pal3.Game.Effect private const float PORTAL_DEFAULT_SIZE = 1.3f; private const float PORTAL_ANIMATION_ROTATION_SPEED = 5f; + private const int PORTAL_RAY_EFFECT_ID = 0; private RotatingSpriteEffect _baseEffect; private IGameEntity _rayEffect; @@ -38,11 +40,11 @@ namespace Pal3.Game.Effect new Vector3(PORTAL_DEFAULT_SIZE, PORTAL_DEFAULT_SIZE, PORTAL_DEFAULT_SIZE), PORTAL_ANIMATION_ROTATION_SPEED); - object rayEffectPrefab = resourceProvider.GetVfxEffectPrefab(0); + object rayEffectPrefab = resourceProvider.GetVfxEffectPrefab(PORTAL_RAY_EFFECT_ID); if (rayEffectPrefab != null) { - _rayEffect = PrefabFactory.Instantiate(rayEffectPrefab, Transform, worldPositionStays: false); - _rayEffect.Name = "VFX_0"; + _rayEffect = GameEntityFactory.Create($"VFX_{PORTAL_RAY_EFFECT_ID}", + rayEffectPrefab, GameEntity, worldPositionStays: false); } } diff --git a/Assets/Scripts/Pal3.Game/Effect/RotatingSpriteEffect.cs b/Assets/Scripts/Pal3.Game/Effect/RotatingSpriteEffect.cs index 711a62bb..b240ccdc 100644 --- a/Assets/Scripts/Pal3.Game/Effect/RotatingSpriteEffect.cs +++ b/Assets/Scripts/Pal3.Game/Effect/RotatingSpriteEffect.cs @@ -7,7 +7,8 @@ namespace Pal3.Game.Effect { using System; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.Extensions; using UnityEngine; @@ -33,8 +34,8 @@ namespace Pal3.Game.Effect Texture2D texture = resourceProvider.GetEffectTexture(textureName, out var hasAlphaChannel); - _root = new GameEntity($"RotatingSpriteEffect_{textureName}"); - _root.SetParent(GameEntity, worldPositionStays: false); + _root = GameEntityFactory.Create($"RotatingSpriteEffect_{textureName}", + GameEntity, worldPositionStays: false); _spriteRenderer = _root.AddComponent(); diff --git a/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.Climb.cs b/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.Climb.cs index c572fbd4..4d157ae4 100644 --- a/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.Climb.cs +++ b/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.Climb.cs @@ -14,7 +14,7 @@ namespace Pal3.Game.GamePlay using Core.Contract.Constants; using Core.Contract.Enums; using Core.Primitives; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Extensions; using Engine.Logging; using Engine.Renderer; diff --git a/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.Interaction.cs b/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.Interaction.cs index 8ed3d30c..3a9302e7 100644 --- a/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.Interaction.cs +++ b/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.Interaction.cs @@ -15,7 +15,7 @@ namespace Pal3.Game.GamePlay using Core.Command.SceCommands; using Core.Contract.Constants; using Core.Contract.Enums; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Logging; using Scene; using Scene.SceneObjects; diff --git a/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.Jump.cs b/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.Jump.cs index 5e62229f..a21fd22b 100644 --- a/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.Jump.cs +++ b/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.Jump.cs @@ -12,14 +12,18 @@ namespace Pal3.Game.GamePlay using Core.Contract.Constants; using Core.Contract.Enums; using Core.DataReader.Nav; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.Coroutine; using Engine.Extensions; using Engine.Renderer; using Scene; using State; - using UnityEngine; + + using Vector2 = UnityEngine.Vector2; + using Vector2Int = UnityEngine.Vector2Int; + using Vector3 = UnityEngine.Vector3; public partial class PlayerGamePlayManager { @@ -37,14 +41,12 @@ namespace Pal3.Game.GamePlay { if (!_lastInputTapPosition.HasValue) return; - Ray ray = _cameraManager.ScreenPointToRay(_lastInputTapPosition.Value); + if (!_physicsManager.TryCameraRaycastFromScreenPoint(_lastInputTapPosition.Value, + out (Vector3 hitPoint, IGameEntity colliderGameEntity) hitResult)) return; - if (!Physics.Raycast(ray, out RaycastHit hit)) return; - - if (_sceneManager.GetCurrentScene() - .GetMeshColliders().Any(_ => _.Value == hit.collider)) + if (hitResult.colliderGameEntity.GetComponent() != null) { - Pal3.Instance.StartCoroutine(JumpAsync(hit.point)); + Pal3.Instance.StartCoroutine(JumpAsync(hitResult.hitPoint)); } } @@ -54,8 +56,8 @@ namespace Pal3.Game.GamePlay { var sprites = _resourceProvider.GetJumpIndicatorSprites(); - _jumpIndicatorGameEntity = new GameEntity($"JumpIndicator"); - _jumpIndicatorGameEntity.SetParent(_playerActorGameEntity, worldPositionStays: false); + _jumpIndicatorGameEntity = GameEntityFactory.Create($"JumpIndicator", + _playerActorGameEntity, worldPositionStays: false); _jumpIndicatorGameEntity.Transform.LocalScale = new Vector3(3f, 3f, 3f); _jumpIndicatorGameEntity.Transform.LocalPosition = new Vector3(0f, _playerActorActionController.GetActorHeight() + 1f, 0f); diff --git a/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.Movement.cs b/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.Movement.cs index b01024fb..fc3ee348 100644 --- a/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.Movement.cs +++ b/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.Movement.cs @@ -6,7 +6,6 @@ namespace Pal3.Game.GamePlay { using System.Collections.Generic; - using System.Linq; using Actor.Controllers; using Command; using Command.Extensions; @@ -14,10 +13,13 @@ namespace Pal3.Game.GamePlay using Core.Contract.Constants; using Core.Contract.Enums; using Core.DataReader.Nav; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Scene; using Scene.SceneObjects.Common; - using UnityEngine; + + using Quaternion = UnityEngine.Quaternion; + using Vector2 = UnityEngine.Vector2; + using Vector3 = UnityEngine.Vector3; public partial class PlayerGamePlayManager { @@ -46,94 +48,96 @@ namespace Pal3.Game.GamePlay { if (!_lastInputTapPosition.HasValue) return; - Ray ray = _cameraManager.ScreenPointToRay(_lastInputTapPosition.Value); - - if (!Physics.Raycast(ray, out RaycastHit hit)) return; + if (!_physicsManager.TryCameraRaycastFromScreenPoint(_lastInputTapPosition.Value, + out (Vector3 hitPoint, IGameEntity colliderGameEntity) hitResult)) return; int layerIndex; bool isPositionOnStandingPlatform; - if (hit.collider.gameObject.GetComponent() is { } standingPlatformController) + if (hitResult.colliderGameEntity.GetComponent() is { } standingPlatformController) { layerIndex = standingPlatformController.LayerIndex; isPositionOnStandingPlatform = true; } - else + else if (hitResult.colliderGameEntity.GetComponent() is { } navMesh) { - var meshColliders = _sceneManager.GetCurrentScene() - .GetMeshColliders(); - - if (meshColliders.Any(_ => _.Value == hit.collider)) - { - layerIndex = meshColliders.First(_ => _.Value == hit.collider).Key; - isPositionOnStandingPlatform = false; - } - else - { - // Raycast hit a collider that is not a mesh collider or a standing platform - return; - } + layerIndex = navMesh.NavLayerIndex; + isPositionOnStandingPlatform = false; + } + else // Raycast hit a collider that is neither a standing platform nor a navmesh + { + return; // Do nothing } - _playerActorMovementController.PortalToPosition(hit.point, layerIndex, isPositionOnStandingPlatform); + _playerActorMovementController.PortalToPosition(hitResult.hitPoint, layerIndex, isPositionOnStandingPlatform); } // Raycast caches to avoid GC - private readonly RaycastHit[] _raycastHits = new RaycastHit[4]; - private readonly Dictionary _tapPoints = new (); + private readonly (Vector3 hitPoint, IGameEntity colliderGameEntity)[] _hitResults = new (Vector3, IGameEntity)[10]; + private readonly Dictionary _validTapPoints = new (); private void MoveToTapPosition(bool isDoubleTap) { if (!_lastInputTapPosition.HasValue) return; Scene currentScene = _sceneManager.GetCurrentScene(); - var meshColliders = currentScene.GetMeshColliders(); - Ray ray = _cameraManager.ScreenPointToRay(_lastInputTapPosition.Value); + int hitCount = _physicsManager.CameraRaycastFromScreenPoint( + _lastInputTapPosition.Value, + _hitResults); - var hitCount = Physics.RaycastNonAlloc(ray, _raycastHits, 500f); if (hitCount == 0) return; Tilemap tilemap = currentScene.GetTilemap(); - _tapPoints.Clear(); + _validTapPoints.Clear(); for (var i = 0; i < hitCount; i++) { - RaycastHit hit = _raycastHits[i]; + (Vector3 hitPoint, IGameEntity colliderGameEntity) = _hitResults[i]; - if (hit.collider.gameObject.GetComponent() is { } + if (colliderGameEntity.GetComponent() != null) + { + continue; // Ignore actor + } + + if (colliderGameEntity.GetComponent() is { } standingPlatformController) { - _tapPoints[standingPlatformController.LayerIndex] = (hit.point, true); + _validTapPoints[standingPlatformController.LayerIndex] = (hitPoint, true); continue; } - var layerIndex = meshColliders.FirstOrDefault(_ => _.Value == hit.collider).Key; + int layerIndex = _playerActorManager.LastKnownLayerIndex ?? 0; - if (!tilemap.TryGetTile(hit.point, layerIndex, out NavTile _)) + if (colliderGameEntity.GetComponent() is { } navMesh) + { + layerIndex = navMesh.NavLayerIndex; + } + + if (!tilemap.TryGetTile(hitPoint, layerIndex, out NavTile _)) { continue; } Vector3 cameraPosition = _cameraManager.GetCameraTransform().Position; - var distanceToCamera = Vector3.Distance(cameraPosition, hit.point); + var distanceToCamera = Vector3.Distance(cameraPosition, hitPoint); - if (_tapPoints.ContainsKey(layerIndex)) + if (_validTapPoints.ContainsKey(layerIndex)) { - var existingDistance = Vector3.Distance(cameraPosition, _tapPoints[layerIndex].point); + var existingDistance = Vector3.Distance(cameraPosition, _validTapPoints[layerIndex].point); if (distanceToCamera < existingDistance) { - _tapPoints[layerIndex] = (hit.point, false); + _validTapPoints[layerIndex] = (hitPoint, false); } } else { - _tapPoints[layerIndex] = (hit.point, false); + _validTapPoints[layerIndex] = (hitPoint, false); } } - if (_tapPoints.Count > 0) + if (_validTapPoints.Count > 0) { - _playerActorMovementController.MoveToTapPoint(_tapPoints, isDoubleTap); + _playerActorMovementController.MoveToTapPoint(_validTapPoints, isDoubleTap); } } diff --git a/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.cs b/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.cs index 362847df..2e89a112 100644 --- a/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.cs +++ b/Assets/Scripts/Pal3.Game/GamePlay/PlayerGamePlayManager.cs @@ -20,16 +20,21 @@ namespace Pal3.Game.GamePlay using Core.DataReader.Scn; using Core.Utilities; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Logging; + using Engine.Services; using GameSystems.Team; using Input; using Scene; using Scene.SceneObjects; using State; - using UnityEngine; using UnityEngine.InputSystem; + using Quaternion = UnityEngine.Quaternion; + using Vector2 = UnityEngine.Vector2; + using Vector2Int = UnityEngine.Vector2Int; + using Vector3 = UnityEngine.Vector3; + public partial class PlayerGamePlayManager : IDisposable, ICommandExecutor, ICommandExecutor, @@ -49,6 +54,7 @@ namespace Pal3.Game.GamePlay private readonly PlayerInputActions _inputActions; private readonly SceneManager _sceneManager; private readonly CameraManager _cameraManager; + private readonly IPhysicsManager _physicsManager; private string _currentMovementSfxAudioName = string.Empty; @@ -79,7 +85,8 @@ namespace Pal3.Game.GamePlay TeamManager teamManager, PlayerInputActions inputActions, SceneManager sceneManager, - CameraManager cameraManager) + CameraManager cameraManager, + IPhysicsManager physicsManager) { _resourceProvider = Requires.IsNotNull(resourceProvider, nameof(resourceProvider)); _gameStateManager = Requires.IsNotNull(gameStateManager, nameof(gameStateManager)); @@ -88,6 +95,7 @@ namespace Pal3.Game.GamePlay _inputActions = Requires.IsNotNull(inputActions, nameof(inputActions)); _sceneManager = Requires.IsNotNull(sceneManager, nameof(sceneManager)); _cameraManager = Requires.IsNotNull(cameraManager, nameof(cameraManager)); + _physicsManager = Requires.IsNotNull(physicsManager, nameof(physicsManager)); _inputActions.Gameplay.OnTap.performed += OnTapPerformed; _inputActions.Gameplay.OnMove.performed += OnMovePerformed; diff --git a/Assets/Scripts/Pal3.Game/GameResourceInitializer.cs b/Assets/Scripts/Pal3.Game/GameResourceInitializer.cs index 079931ee..84f5d0d8 100644 --- a/Assets/Scripts/Pal3.Game/GameResourceInitializer.cs +++ b/Assets/Scripts/Pal3.Game/GameResourceInitializer.cs @@ -20,8 +20,8 @@ namespace Pal3.Game using Core.FileSystem; using Core.Utilities; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Implementation; using Engine.Extensions; using Engine.Logging; using Engine.Services; diff --git a/Assets/Scripts/Pal3.Game/GameSystems/Combat/CombatCoordinator.cs b/Assets/Scripts/Pal3.Game/GameSystems/Combat/CombatCoordinator.cs index 7608e8f3..4c30b9a1 100644 --- a/Assets/Scripts/Pal3.Game/GameSystems/Combat/CombatCoordinator.cs +++ b/Assets/Scripts/Pal3.Game/GameSystems/Combat/CombatCoordinator.cs @@ -21,7 +21,7 @@ namespace Pal3.Game.GameSystems.Combat using Core.DataReader.Txt; using Core.Utilities; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Logging; using GamePlay; using Scene; diff --git a/Assets/Scripts/Pal3.Game/GameSystems/Combat/CombatManager.cs b/Assets/Scripts/Pal3.Game/GameSystems/Combat/CombatManager.cs index ae9a779c..03db999b 100644 --- a/Assets/Scripts/Pal3.Game/GameSystems/Combat/CombatManager.cs +++ b/Assets/Scripts/Pal3.Game/GameSystems/Combat/CombatManager.cs @@ -20,7 +20,7 @@ namespace Pal3.Game.GameSystems.Combat using Core.Primitives; using Core.Utilities; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Extensions; using Engine.Logging; using Scene; @@ -118,6 +118,7 @@ namespace Pal3.Game.GameSystems.Combat { // Stop combat music CommandDispatcher.Instance.Dispatch(new StopScriptMusicCommand()); + CommandDispatcher.Instance.Dispatch(new CameraFadeInCommand()); _sceneManager.UnloadCombatScene(); ResetCameraPosition(); } diff --git a/Assets/Scripts/Pal3.Game/GameSystems/Minimap/MinimapManager.cs b/Assets/Scripts/Pal3.Game/GameSystems/Minimap/MinimapManager.cs index 34924d45..c1292fe2 100644 --- a/Assets/Scripts/Pal3.Game/GameSystems/Minimap/MinimapManager.cs +++ b/Assets/Scripts/Pal3.Game/GameSystems/Minimap/MinimapManager.cs @@ -12,7 +12,7 @@ namespace Pal3.Game.GameSystems.Minimap using Core.Contract.Enums; using Core.DataReader.Nav; using Core.Utilities; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Extensions; using Scene; using State; diff --git a/Assets/Scripts/Pal3.Game/GameSystems/Team/TeamManager.cs b/Assets/Scripts/Pal3.Game/GameSystems/Team/TeamManager.cs index d45a8993..0418b65f 100644 --- a/Assets/Scripts/Pal3.Game/GameSystems/Team/TeamManager.cs +++ b/Assets/Scripts/Pal3.Game/GameSystems/Team/TeamManager.cs @@ -15,7 +15,7 @@ namespace Pal3.Game.GameSystems.Team using Core.Command.SceCommands; using Core.Contract.Enums; using Core.Utilities; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Logging; using GamePlay; using Scene; diff --git a/Assets/Scripts/Pal3.Game/Pal3.cs b/Assets/Scripts/Pal3.Game/Pal3.cs index ec00d5e0..4705ac6d 100644 --- a/Assets/Scripts/Pal3.Game/Pal3.cs +++ b/Assets/Scripts/Pal3.Game/Pal3.cs @@ -24,7 +24,8 @@ namespace Pal3.Game using Data; using Dev; using Effect; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.Coroutine; using Engine.Extensions; using Engine.Logging; @@ -144,6 +145,7 @@ namespace Pal3.Game private GameSettings _gameSettings; private ICpkFileSystem _fileSystem; private GameResourceProvider _gameResourceProvider; + private IPhysicsManager _physicsManager; private FileSystemCacheManager _fileSystemCacheManager; private PlayerInputActions _inputActions; private InputManager _inputManager; @@ -209,6 +211,9 @@ namespace Pal3.Game _gameResourceProvider = ServiceLocator.Instance.Get(); _gameResourceProvider.UseTextureCache(_textureCache); + ServiceLocator.Instance.Register(_physicsManager = + new PhysicsManager(mainCamera)); + ServiceLocator.Instance.Register(_fileSystemCacheManager = new FileSystemCacheManager(_fileSystem) ); @@ -379,7 +384,8 @@ namespace Pal3.Game _teamManager, _inputActions, _sceneManager, - _cameraManager) + _cameraManager, + _physicsManager) ); ServiceLocator.Instance.Register(_minimapManager = diff --git a/Assets/Scripts/Pal3.Game/Rendering/Renderer/CvdModelRenderer.cs b/Assets/Scripts/Pal3.Game/Rendering/Renderer/CvdModelRenderer.cs index 1bb21472..c5d75e81 100644 --- a/Assets/Scripts/Pal3.Game/Rendering/Renderer/CvdModelRenderer.cs +++ b/Assets/Scripts/Pal3.Game/Rendering/Renderer/CvdModelRenderer.cs @@ -12,7 +12,8 @@ namespace Pal3.Game.Rendering.Renderer using Core.DataReader.Cvd; using Core.Utilities; using Dev.Presenters; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.DataLoader; using Engine.Extensions; using Engine.Logging; @@ -32,7 +33,7 @@ namespace Pal3.Game.Rendering.Renderer private Color _tintColor; - private float _currentTime; + private float _currentAnimationTime; private float _animationDuration; private CancellationTokenSource _animationCts = new (); @@ -56,14 +57,15 @@ namespace Pal3.Game.Rendering.Renderer _materialFactory = materialFactory; _animationDuration = cvdFile.AnimationDuration; _tintColor = tintColor ?? Color.White; - _currentTime = initTime; + _currentAnimationTime = initTime; foreach (CvdGeometryNode node in cvdFile.RootNodes) { BuildTextureCache(node, textureProvider, _textureCache); } - var root = new GameEntity("Cvd Mesh"); + IGameEntity root = GameEntityFactory.Create("Cvd Mesh", + GameEntity, worldPositionStays: false); for (var i = 0; i < cvdFile.RootNodes.Length; i++) { @@ -75,13 +77,11 @@ namespace Pal3.Game.Rendering.Renderer _textureCache, root); } - - root.SetParent(GameEntity, worldPositionStays: false); } - public float GetCurrentTime() + public float GetCurrentAnimationTime() { - return _currentTime; + return _currentAnimationTime; } public void SetCurrentTime(float time) @@ -212,8 +212,7 @@ namespace Pal3.Game.Rendering.Renderer Dictionary textureCache, IGameEntity parent) { - var meshEntity = new GameEntity(meshName); - meshEntity.SetParent(parent, worldPositionStays: false); + IGameEntity meshEntity = GameEntityFactory.Create(meshName, parent, worldPositionStays: false); if (node.IsGeometryNode) { @@ -253,7 +252,8 @@ namespace Pal3.Game.Rendering.Renderer if (string.IsNullOrEmpty(textureName) || !textureCache.ContainsKey(textureName)) continue; - var meshSectionEntity = new GameEntity($"{sectionHashKey}"); + IGameEntity meshSectionEntity = GameEntityFactory.Create($"{sectionHashKey}", + meshEntity, worldPositionStays: false); // Attach BlendFlag and GameBoxMaterial to the GameEntity for better debuggability. #if UNITY_EDITOR @@ -289,8 +289,6 @@ namespace Pal3.Game.Rendering.Renderer MeshRenderer = meshRenderer, MeshDataBuffer = meshDataBuffer }; - - meshSectionEntity.SetParent(meshEntity, worldPositionStays: false); } _renderers.Add(nodeMeshes); @@ -343,7 +341,7 @@ namespace Pal3.Game.Rendering.Renderer private void UpdateMesh(float time) { - _currentTime = time; + _currentAnimationTime = time; foreach ((CvdGeometryNode node, var renderMeshComponents) in _renderers) { @@ -462,30 +460,22 @@ namespace Pal3.Game.Rendering.Renderer bool startFromBeginning, CancellationToken cancellationToken) { - double startTime; - - if (startFromBeginning) - { - startTime = GameTimeProvider.Instance.TimeSinceStartup; - } - else - { - startTime = GameTimeProvider.Instance.TimeSinceStartup - _currentTime; - } + double startTime = GameTimeProvider.Instance.TimeSinceStartup - (startFromBeginning ? 0 : _currentAnimationTime); while (!cancellationToken.IsCancellationRequested) { - var currentTime = timeScale > 0 ? - (float)(GameTimeProvider.Instance.TimeSinceStartup - startTime) * timeScale : - (duration - (float)(GameTimeProvider.Instance.TimeSinceStartup - startTime)) * -timeScale; + // Calculate the elapsed time and adjust it based on the time scale. + float elapsed = (float)(GameTimeProvider.Instance.TimeSinceStartup - startTime); + float adjustedTime = timeScale > 0 ? elapsed * timeScale : (duration - elapsed) * -timeScale; - if ((timeScale > 0f && currentTime >= duration) || - (timeScale < 0f && currentTime <= 0f)) + // Check if the animation is complete based on the time scale and either the duration or the zero-bound. + bool isComplete = timeScale > 0 ? adjustedTime >= duration : adjustedTime <= 0; + if (isComplete) { yield break; } - UpdateMesh(currentTime); + UpdateMesh(adjustedTime); yield return null; } diff --git a/Assets/Scripts/Pal3.Game/Rendering/Renderer/Mv3ModelRenderer.cs b/Assets/Scripts/Pal3.Game/Rendering/Renderer/Mv3ModelRenderer.cs index 3838bc58..834c7030 100644 --- a/Assets/Scripts/Pal3.Game/Rendering/Renderer/Mv3ModelRenderer.cs +++ b/Assets/Scripts/Pal3.Game/Rendering/Renderer/Mv3ModelRenderer.cs @@ -14,7 +14,8 @@ namespace Pal3.Game.Rendering.Renderer using Core.Utilities; using Dev; using Dev.Presenters; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.DataLoader; using Engine.Extensions; using Engine.Logging; @@ -55,6 +56,7 @@ namespace Pal3.Game.Rendering.Renderer private IGameEntity[] _meshEntities; // Tag node + private PolFile _tagNodePolFile; private Mv3TagNode[] _tagNodesInfo; private uint[][] _tagNodeFrameTicks; private IGameEntity[] _tagNodes; @@ -87,6 +89,7 @@ namespace Pal3.Game.Rendering.Renderer _materialFactory = materialFactory; _textureProvider = textureProvider; _tintColor = tintColor ?? Color.White; + _tagNodePolFile = tagNodePolFile; _events = mv3File.AnimationEvents; _totalGameBoxTicks = mv3File.TotalGameBoxTicks; @@ -146,7 +149,7 @@ namespace Pal3.Game.Rendering.Renderer InitSubMeshes(i, ref mesh, ref material); } - if (tagNodePolFile != null) + if (_tagNodePolFile != null) { for (var i = 0; i < _tagNodesInfo.Length; i++) { @@ -156,15 +159,16 @@ namespace Pal3.Game.Rendering.Renderer continue; } - _tagNodes[i] = new GameEntity(tagNodePolFile.NodeDescriptions[0].Name); + _tagNodes[i] = GameEntityFactory.Create(_tagNodePolFile.NodeDescriptions[0].Name, + GameEntity, worldPositionStays: true); + var tagNodeRenderer = _tagNodes[i].AddComponent(); - tagNodeRenderer.Render(tagNodePolFile, + tagNodeRenderer.Render(_tagNodePolFile, tagNodeTextureProvider, _materialFactory, isStaticObject: false, tagNodeTintColor); - _tagNodes[i].SetParent(GameEntity, worldPositionStays: true); _tagNodes[i].Transform.SetLocalPositionAndRotation( mv3File.TagNodes[i].TagFrames[0].GameBoxPosition.ToUnityPosition(UnityPrimitivesConvertor.GameBoxMv3UnitToUnityUnit), mv3File.TagNodes[i].TagFrames[0].GameBoxRotation.Mv3QuaternionToUnityQuaternion()); @@ -198,7 +202,8 @@ namespace Pal3.Game.Rendering.Renderer _frameTicks[index][i] = keyFrames[i].GameBoxTick; } - _meshEntities[index] = new GameEntity(mv3Mesh.Name); + _meshEntities[index] = GameEntityFactory.Create(mv3Mesh.Name, + GameEntity, worldPositionStays: false); // Attach BlendFlag and GameBoxMaterial to the GameEntity for better debuggability #if UNITY_EDITOR @@ -252,8 +257,6 @@ namespace Pal3.Game.Rendering.Renderer _renderMeshComponents[index].Mesh = renderMesh; _renderMeshComponents[index].MeshRenderer = meshRenderer; - - _meshEntities[index].SetParent(GameEntity, worldPositionStays: false); } public void StartAnimation(int loopCount = -1) @@ -428,6 +431,8 @@ namespace Pal3.Game.Rendering.Renderer continue; } + if (cancellationToken.IsCancellationRequested) yield break; + // Animates the mesh for (var i = 0; i < _meshCount; i++) { @@ -457,27 +462,30 @@ namespace Pal3.Game.Rendering.Renderer } // Animates the tag nodes - for (var i = 0; i < _tagNodesInfo.Length; i++) + if (_tagNodePolFile != null) { - if (_tagNodes[i] == null) continue; + for (var i = 0; i < _tagNodesInfo.Length; i++) + { + if (_tagNodes[i] == null) continue; - var frameTicks = _tagNodeFrameTicks[i]; + var frameTicks = _tagNodeFrameTicks[i]; - var currentFrameIndex = CoreUtility.GetFloorIndex(frameTicks, tick); - var currentFrameTick = _tagNodeFrameTicks[i][currentFrameIndex]; - var nextFrameIndex = currentFrameIndex < frameTicks.Length - 1 ? currentFrameIndex + 1 : 0; - var nextFrameTick = nextFrameIndex == 0 ? endTick : _tagNodeFrameTicks[i][nextFrameIndex]; + var currentFrameIndex = CoreUtility.GetFloorIndex(frameTicks, tick); + var currentFrameTick = _tagNodeFrameTicks[i][currentFrameIndex]; + var nextFrameIndex = currentFrameIndex < frameTicks.Length - 1 ? currentFrameIndex + 1 : 0; + var nextFrameTick = nextFrameIndex == 0 ? endTick : _tagNodeFrameTicks[i][nextFrameIndex]; - var influence = (float)(tick - currentFrameTick) / (nextFrameTick - currentFrameTick); + var influence = (float)(tick - currentFrameTick) / (nextFrameTick - currentFrameTick); - Vector3 position = Vector3.Lerp( - _tagNodesInfo[i].TagFrames[currentFrameIndex].GameBoxPosition.ToUnityPosition(), - _tagNodesInfo[i].TagFrames[nextFrameIndex].GameBoxPosition.ToUnityPosition(), influence); - Quaternion rotation = Quaternion.Slerp( - _tagNodesInfo[i].TagFrames[currentFrameIndex].GameBoxRotation.Mv3QuaternionToUnityQuaternion(), - _tagNodesInfo[i].TagFrames[nextFrameIndex].GameBoxRotation.Mv3QuaternionToUnityQuaternion(), influence); + Vector3 position = Vector3.Lerp( + _tagNodesInfo[i].TagFrames[currentFrameIndex].GameBoxPosition.ToUnityPosition(), + _tagNodesInfo[i].TagFrames[nextFrameIndex].GameBoxPosition.ToUnityPosition(), influence); + Quaternion rotation = Quaternion.Slerp( + _tagNodesInfo[i].TagFrames[currentFrameIndex].GameBoxRotation.Mv3QuaternionToUnityQuaternion(), + _tagNodesInfo[i].TagFrames[nextFrameIndex].GameBoxRotation.Mv3QuaternionToUnityQuaternion(), influence); - _tagNodes[i].Transform.SetLocalPositionAndRotation(position, rotation); + _tagNodes[i].Transform.SetLocalPositionAndRotation(position, rotation); + } } yield return null; diff --git a/Assets/Scripts/Pal3.Game/Rendering/Renderer/PolyModelRenderer.cs b/Assets/Scripts/Pal3.Game/Rendering/Renderer/PolyModelRenderer.cs index 3a0bf61f..9af9d4df 100644 --- a/Assets/Scripts/Pal3.Game/Rendering/Renderer/PolyModelRenderer.cs +++ b/Assets/Scripts/Pal3.Game/Rendering/Renderer/PolyModelRenderer.cs @@ -12,7 +12,8 @@ namespace Pal3.Game.Rendering.Renderer using Core.DataReader.Pol; using Core.Primitives; using Dev.Presenters; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.Coroutine; using Engine.DataLoader; using Engine.Extensions; @@ -162,7 +163,7 @@ namespace Pal3.Game.Rendering.Renderer return; } - IGameEntity meshEntity = new GameEntity(meshNode.Name); + IGameEntity meshEntity = GameEntityFactory.Create(meshNode.Name, GameEntity, worldPositionStays: false); meshEntity.IsStatic = _isStaticObject; // Attach BlendFlag and GameBoxMaterial to the GameEntity for better debuggability @@ -234,8 +235,6 @@ namespace Pal3.Game.Rendering.Renderer materials, false); } - - meshEntity.SetParent(GameEntity, worldPositionStays: false); } } diff --git a/Assets/Scripts/Pal3.Game/Rendering/Renderer/SkeletalModelRenderer.cs b/Assets/Scripts/Pal3.Game/Rendering/Renderer/SkeletalModelRenderer.cs index ca96a118..a66697ff 100644 --- a/Assets/Scripts/Pal3.Game/Rendering/Renderer/SkeletalModelRenderer.cs +++ b/Assets/Scripts/Pal3.Game/Rendering/Renderer/SkeletalModelRenderer.cs @@ -14,7 +14,8 @@ namespace Pal3.Game.Rendering.Renderer using Core.DataReader.Mtl; using Core.Primitives; using Core.Utilities; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.DataLoader; using Engine.Extensions; using Engine.Logging; @@ -294,9 +295,9 @@ namespace Pal3.Game.Rendering.Renderer private void SetupBone(BoneNode boneNode, Bone parentBone) { - IGameEntity boneEntity = new GameEntity($"{boneNode.Id}_{boneNode.Name}_{boneNode.Type}"); + IGameEntity boneEntity = GameEntityFactory.Create($"{boneNode.Id}_{boneNode.Name}_{boneNode.Type}", + parentBone == null ? GameEntity : parentBone.GameEntity, worldPositionStays: true); - boneEntity.SetParent(parentBone == null ? GameEntity : parentBone.GameEntity, worldPositionStays: true); boneEntity.Transform.SetLocalPositionAndRotation(boneNode.GameBoxTranslation.ToUnityPosition(), boneNode.GameBoxRotation.MshQuaternionToUnityQuaternion()); @@ -341,8 +342,8 @@ namespace Pal3.Game.Rendering.Renderer private void RenderSubMesh(MshMesh subMesh, int subMeshIndex) { - _meshEntities[subMeshIndex] = new GameEntity($"SubMesh_{subMeshIndex}"); - _meshEntities[subMeshIndex].SetParent(GameEntity, worldPositionStays: false); + _meshEntities[subMeshIndex] = GameEntityFactory.Create($"SubMesh_{subMeshIndex}", + GameEntity, worldPositionStays: false); _vertexBuffer[subMeshIndex] = new Vector3[subMesh.Vertices.Length]; diff --git a/Assets/Scripts/Pal3.Game/Scene/CombatScene.cs b/Assets/Scripts/Pal3.Game/Scene/CombatScene.cs index 91ac6cd9..169103d7 100644 --- a/Assets/Scripts/Pal3.Game/Scene/CombatScene.cs +++ b/Assets/Scripts/Pal3.Game/Scene/CombatScene.cs @@ -15,13 +15,14 @@ namespace Pal3.Game.Scene using Core.DataReader.Ini; using Core.DataReader.Pol; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.DataLoader; using Engine.Extensions; using GameSystems.Combat; using Rendering.Material; using Rendering.Renderer; - + using Vector3 = UnityEngine.Vector3; using Quaternion = UnityEngine.Quaternion; @@ -76,12 +77,11 @@ namespace Pal3.Game.Scene private void RenderMesh(PolFile polFile, ITextureResourceProvider textureProvider) { // Render mesh - _mesh = new GameEntity($"Mesh_{_combatSceneName}"); + _mesh = GameEntityFactory.Create($"Mesh_{_combatSceneName}", + _parent, worldPositionStays: false); _mesh.IsStatic = true; // Combat Scene mesh is static var polyMeshRenderer = _mesh.AddComponent(); - _mesh.SetParent(_parent, worldPositionStays: false); - polyMeshRenderer.Render(polFile, textureProvider, _materialFactory, diff --git a/Assets/Scripts/Pal3.Game/Scene/NavMesh.cs b/Assets/Scripts/Pal3.Game/Scene/NavMesh.cs new file mode 100644 index 00000000..d4ad366b --- /dev/null +++ b/Assets/Scripts/Pal3.Game/Scene/NavMesh.cs @@ -0,0 +1,53 @@ +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2021-2023, Jiaqi Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Pal3.Game.Scene +{ + using Core.DataReader.Nav; + using Engine.Core.Implementation; + using Engine.Extensions; + using UnityEngine; + + /// + /// Represents a navigation mesh used for pathfinding in a game scene. + /// + public sealed class NavMesh : GameEntityScript + { + public int NavLayerIndex { get; private set; } + + private MeshCollider _meshCollider; + + protected override void OnEnableGameEntity() + { + // Set layer to NavMeshes for the attached GameEntity + // Because NavMeshes should not collide with anything else, it is only used for raycast. + // This behaviour is configured in Physics settings (Edit -> Project Settings -> Physics) + GameEntity.Layer = LayerMask.NameToLayer("NavMeshes"); + } + + protected override void OnDisableGameEntity() + { + if (_meshCollider != null) + { + _meshCollider.sharedMesh.Destroy(); + _meshCollider.Destroy(); + _meshCollider = null; + } + } + + public void Init(int layerIndex, NavFaceLayer navFaceLayer) + { + NavLayerIndex = layerIndex; + + _meshCollider = GameEntity.AddComponent(); + _meshCollider.convex = false; + _meshCollider.sharedMesh = new Mesh() + { + vertices = navFaceLayer.GameBoxVertices.ToUnityPositions(), + triangles = navFaceLayer.GameBoxTriangles.ToUnityTriangles(), + }; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Pal3.Game/Scene/NavMesh.cs.meta b/Assets/Scripts/Pal3.Game/Scene/NavMesh.cs.meta new file mode 100644 index 00000000..03eeb782 --- /dev/null +++ b/Assets/Scripts/Pal3.Game/Scene/NavMesh.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e789e40b014a4aa0b93814523e02f422 +timeCreated: 1697055751 \ No newline at end of file diff --git a/Assets/Scripts/Pal3.Game/Scene/Scene.cs b/Assets/Scripts/Pal3.Game/Scene/Scene.cs index b355078b..83d89e54 100644 --- a/Assets/Scripts/Pal3.Game/Scene/Scene.cs +++ b/Assets/Scripts/Pal3.Game/Scene/Scene.cs @@ -22,8 +22,9 @@ namespace Pal3.Game.Scene using Core.Primitives; using Data; using Effect; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.Extensions; using Engine.Logging; using Engine.Navigation; @@ -60,8 +61,7 @@ namespace Pal3.Game.Scene private Light _mainLight; private readonly List _pointLights = new(); - private readonly List _navMeshLayers = new (); - private readonly Dictionary _meshColliders = new (); + private readonly List _navMeshEntities = new (); private readonly HashSet _activatedSceneObjects = new (); private readonly Dictionary _actorEntities = new (); @@ -89,15 +89,9 @@ namespace Pal3.Game.Scene _mesh.Destroy(); - foreach (MeshCollider meshCollider in _meshColliders.Values) + foreach (IGameEntity navMeshEntity in _navMeshEntities) { - meshCollider.sharedMesh.Destroy(); - meshCollider.Destroy(); - } - - foreach (IGameEntity navMeshLayer in _navMeshLayers) - { - navMeshLayer.Destroy(); + navMeshEntity.Destroy(); } foreach (int sceneObjectId in _activatedSceneObjects) @@ -221,11 +215,6 @@ namespace Pal3.Game.Scene return _actorEntities; } - public Dictionary GetMeshColliders() - { - return _meshColliders; - } - public bool IsPositionInsideJumpableArea(int layerIndex, Vector2Int tilePosition) { foreach (var objectId in _activatedSceneObjects) @@ -245,12 +234,11 @@ namespace Pal3.Game.Scene private void RenderMesh() { // Render mesh - _mesh = new GameEntity($"Mesh_{ScnFile.SceneInfo.CityName}_{ScnFile.SceneInfo.SceneName}"); + _mesh = GameEntityFactory.Create($"Mesh_{ScnFile.SceneInfo.CityName}_{ScnFile.SceneInfo.SceneName}", + _parent, worldPositionStays: false); _mesh.IsStatic = true; // Scene mesh is static var polyMeshRenderer = _mesh.AddComponent(); - _mesh.SetParent(_parent, worldPositionStays: false); - polyMeshRenderer.Render(ScenePolyMesh.PolFile, ScenePolyMesh.TextureProvider, _materialFactory, @@ -291,25 +279,16 @@ namespace Pal3.Game.Scene return; } - int raycastOnlyLayer = LayerMask.NameToLayer("RaycastOnly"); - for (var i = 0; i < NavFile.FaceLayers.Length; i++) { - var navMesh = new GameEntity($"NavMesh_Layer_{i}"); - navMesh.IsStatic = true; // NavMesh is static - navMesh.SetLayer(raycastOnlyLayer); - navMesh.SetParent(_parent, worldPositionStays: false); + IGameEntity navMeshGameEntity = GameEntityFactory.Create($"NavMesh_Layer_{i}", + _parent, worldPositionStays: false); + navMeshGameEntity.IsStatic = true; // NavMesh is static - var meshCollider = navMesh.AddComponent(); - meshCollider.convex = false; - meshCollider.sharedMesh = new Mesh() - { - vertices = NavFile.FaceLayers[i].GameBoxVertices.ToUnityPositions(), - triangles = NavFile.FaceLayers[i].GameBoxTriangles.ToUnityTriangles(), - }; + NavMesh navMesh = navMeshGameEntity.AddComponent(); + navMesh.Init(layerIndex: i, NavFile.FaceLayers[i]); - _meshColliders[i] = meshCollider; - _navMeshLayers.Add(navMesh); + _navMeshEntities.Add(navMeshGameEntity); } } @@ -340,8 +319,8 @@ namespace Pal3.Game.Scene // }); // } - var mainLightEntity = new GameEntity($"LightSource_Main"); - mainLightEntity.SetParent(_parent, worldPositionStays: false); + IGameEntity mainLightEntity = GameEntityFactory.Create($"LightSource_Main", + _parent, worldPositionStays: false); mainLightEntity.Transform.SetPositionAndRotation(mainLightPosition, mainLightRotation); _mainLight = mainLightEntity.AddComponent(); @@ -388,8 +367,8 @@ namespace Pal3.Game.Scene private void AddPointLight(IGameEntity parent, float yOffset) { // Add a point light to the fire fx - var lightSource = new GameEntity($"LightSource_Point"); - lightSource.SetParent(parent, worldPositionStays: false); + IGameEntity lightSource = GameEntityFactory.Create($"LightSource_Point", + parent, worldPositionStays: false); lightSource.Transform.LocalPosition = new Vector3(0f, yOffset, 0f); var lightComponent = lightSource.AddComponent(); @@ -491,6 +470,7 @@ namespace Pal3.Game.Scene private void CreateActorObject(Actor actor, Color tintColor, Tilemap tileMap) { if (_actorEntities.ContainsKey(actor.Id)) return; + IGameEntity actorGameEntity = ActorFactory.CreateActorGameEntity(_resourceProvider, actor, tileMap, @@ -500,9 +480,8 @@ namespace Pal3.Game.Scene ActorMovementMaxYDifferentialCrossLayer, ActorMovementMaxYDifferentialCrossPlatform, GetAllActiveActorBlockingTilePositions); + actorGameEntity.SetParent(_parent, worldPositionStays: false); - int layerIndex = LayerMask.NameToLayer("Ignore Raycast"); - actorGameEntity.SetLayer(layerIndex); // Ignore raycast for all actors _actorEntities[actor.Id] = actorGameEntity; } diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneBase.cs b/Assets/Scripts/Pal3.Game/Scene/SceneBase.cs index 6aa44eef..44f6f775 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneBase.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneBase.cs @@ -17,7 +17,7 @@ namespace Pal3.Game.Scene using Core.DataReader.Scn; using Core.Utilities; using Data; - using Engine.Abstraction; + using Engine.Core.Implementation; using Engine.DataLoader; using SceneObjects; using State; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneManager.cs b/Assets/Scripts/Pal3.Game/Scene/SceneManager.cs index 49ba4ff8..418e2a74 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneManager.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneManager.cs @@ -18,7 +18,8 @@ namespace Pal3.Game.Scene using Core.DataReader.Scn; using Core.Utilities; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.Extensions; using Engine.Logging; using Newtonsoft.Json; @@ -102,8 +103,8 @@ namespace Pal3.Game.Scene CommandDispatcher.Instance.Dispatch(new ScenePreLoadingNotification(scnFile.SceneInfo)); EngineLogger.Log("Loading scene: " + JsonConvert.SerializeObject(scnFile.SceneInfo)); - _currentSceneRoot = new GameEntity($"Scene_{sceneCityName}_{sceneName}"); - _currentSceneRoot.SetParent(null, worldPositionStays: false); + _currentSceneRoot = GameEntityFactory.Create($"Scene_{sceneCityName}_{sceneName}", + null, worldPositionStays: false); _currentScene = _currentSceneRoot.AddComponent(); _currentScene.Init(_resourceProvider, _sceneStateManager, @@ -140,8 +141,8 @@ namespace Pal3.Game.Scene HideCurrentScene(); - _currentCombatSceneRoot = new GameEntity($"CombatScene_{combatSceneName}"); - _currentCombatSceneRoot.SetParent(null, worldPositionStays: false); + _currentCombatSceneRoot = GameEntityFactory.Create($"CombatScene_{combatSceneName}", + null, worldPositionStays: false); _currentCombatScene = _currentCombatSceneRoot.AddComponent(); _currentCombatScene.Init(_resourceProvider); diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/AutoTriggerObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/AutoTriggerObject.cs index eff80829..1e30b0b8 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/AutoTriggerObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/AutoTriggerObject.cs @@ -14,7 +14,7 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Extensions; using Engine.Services; @@ -48,11 +48,18 @@ namespace Pal3.Game.Scene.SceneObjects } else { + var effectiveTime = GameTimeProvider.Instance.RealTimeSinceStartup; + // This is to prevent player from entering back to previous // scene when holding the stick while transferring between scenes. // We simply disable the auto trigger for a short time window after - // a fresh scene load. - var effectiveTime = GameTimeProvider.Instance.RealTimeSinceStartup + 0.35f; // 0.35 seconds + // a fresh scene load if the auto trigger is used for scene transfer. + if (ObjectInfo.ScriptId != ScriptConstants.InvalidScriptId && + ObjectInfo.ScriptId < ScriptConstants.PortalScriptIdMax) + { + effectiveTime += 1f; // 1 second + } + _triggerController = sceneObjectGameEntity.AddComponent(); _triggerController.Init(ObjectInfo.TileMapTriggerRect, ObjectInfo.LayerIndex, effectiveTime); _triggerController.OnPlayerActorEntered += OnPlayerActorEntered; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ChestObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ChestObject.cs index e4537c1a..cf402a4c 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ChestObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ChestObject.cs @@ -16,7 +16,7 @@ namespace Pal3.Game.Scene.SceneObjects using Core.DataReader.Scn; using Core.Primitives; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Extensions; [ScnSceneObject(SceneObjectType.Chest)] diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ClimbableObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ClimbableObject.cs index 6f675c39..3b66af47 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ClimbableObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ClimbableObject.cs @@ -17,7 +17,8 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Primitives; using Core.Utilities; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.DataLoader; using Engine.Extensions; using Engine.Services; @@ -79,8 +80,8 @@ namespace Pal3.Game.Scene.SceneObjects // Upper indicator { - _upperInteractionIndicatorGameEntity = new GameEntity("Climbable_Interaction_Indicator_Upper"); - _upperInteractionIndicatorGameEntity.SetParent(sceneObjectGameEntity, worldPositionStays: false); + _upperInteractionIndicatorGameEntity = GameEntityFactory.Create("Climbable_Interaction_Indicator_Upper", + sceneObjectGameEntity, worldPositionStays: false); _upperInteractionIndicatorGameEntity.Transform.LocalScale = new Vector3(1f, -1f, 1f); _upperInteractionIndicatorGameEntity.Transform.Position = upperPosition; _upperInteractionIndicatorRenderer = _upperInteractionIndicatorGameEntity.AddComponent(); @@ -96,8 +97,8 @@ namespace Pal3.Game.Scene.SceneObjects // Lower indicator { - _lowerInteractionIndicatorGameEntity = new GameEntity("Climbable_Interaction_Indicator_Lower"); - _lowerInteractionIndicatorGameEntity.SetParent(sceneObjectGameEntity, worldPositionStays: false); + _lowerInteractionIndicatorGameEntity = GameEntityFactory.Create("Climbable_Interaction_Indicator_Lower", + sceneObjectGameEntity, worldPositionStays: false); _lowerInteractionIndicatorGameEntity.Transform.LocalScale = new Vector3(1f, 1f, 1f); _lowerInteractionIndicatorGameEntity.Transform.Position = lowerPosition; _lowerInteractionIndicatorRenderer = _lowerInteractionIndicatorGameEntity.AddComponent(); diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/CollidableObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/CollidableObject.cs index 6a65e92e..15073b34 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/CollidableObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/CollidableObject.cs @@ -10,10 +10,10 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Extensions; using Rendering.Renderer; - + using Color = Core.Primitives.Color; #if PAL3 diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/Common/BoundsTriggerController.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/Common/BoundsTriggerController.cs index b6f25543..c6c61b8f 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/Common/BoundsTriggerController.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/Common/BoundsTriggerController.cs @@ -7,7 +7,8 @@ namespace Pal3.Game.Scene.SceneObjects.Common { using System; using Actor.Controllers; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.Extensions; using Engine.Services; using GamePlay; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/Common/SceneObjectMeshCollider.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/Common/SceneObjectMeshCollider.cs index 1d3aff21..f0db1c4e 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/Common/SceneObjectMeshCollider.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/Common/SceneObjectMeshCollider.cs @@ -5,7 +5,7 @@ namespace Pal3.Game.Scene.SceneObjects.Common { - using Engine.Abstraction; + using Engine.Core.Implementation; using Engine.Extensions; using Rendering.Renderer; using UnityEngine; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/Common/StandingPlatformController.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/Common/StandingPlatformController.cs index 4fe497df..9af3289a 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/Common/StandingPlatformController.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/Common/StandingPlatformController.cs @@ -7,7 +7,8 @@ namespace Pal3.Game.Scene.SceneObjects.Common { using System; using Actor.Controllers; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.Extensions; using Engine.Services; using GamePlay; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/Common/TilemapTriggerController.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/Common/TilemapTriggerController.cs index a2e60ef0..a492ec50 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/Common/TilemapTriggerController.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/Common/TilemapTriggerController.cs @@ -10,7 +10,7 @@ namespace Pal3.Game.Scene.SceneObjects.Common using Command.Extensions; using Core.Command; using Core.Primitives; - using Engine.Abstraction; + using Engine.Core.Implementation; using Engine.Services; public sealed class TilemapTriggerController : GameEntityScript, diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/DivineTreeFlowerObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/DivineTreeFlowerObject.cs index 1bb62954..743df1ca 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/DivineTreeFlowerObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/DivineTreeFlowerObject.cs @@ -13,7 +13,7 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Extensions; using Engine.Services; using State; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/DivineTreePortalObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/DivineTreePortalObject.cs index 3b558aa6..361c0796 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/DivineTreePortalObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/DivineTreePortalObject.cs @@ -16,8 +16,8 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Engine.Coroutine; using Engine.Extensions; @@ -153,7 +153,11 @@ namespace Pal3.Game.Scene.SceneObjects public override void Deactivate() { - _cancellationTokenSource.Cancel(); + if (!_cancellationTokenSource.IsCancellationRequested) + { + _cancellationTokenSource.Cancel(); + } + _isInteractionInProgress = false; if (_platformController != null) diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/DoorObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/DoorObject.cs index 7ceacd02..37ffa7e1 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/DoorObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/DoorObject.cs @@ -10,7 +10,7 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Extensions; using Engine.Services; using Rendering.Renderer; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ElementSwitchObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ElementSwitchObject.cs index 80cc8cbe..1c601670 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ElementSwitchObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ElementSwitchObject.cs @@ -17,7 +17,7 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Coroutine; using Engine.Extensions; using Rendering.Renderer; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ElevatorDoorObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ElevatorDoorObject.cs index dcb489ac..71512dd2 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ElevatorDoorObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ElevatorDoorObject.cs @@ -12,10 +12,10 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Engine.Extensions; - + using Color = Core.Primitives.Color; using Vector3 = UnityEngine.Vector3; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ElevatorObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ElevatorObject.cs index 76410af8..2f721ca5 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ElevatorObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ElevatorObject.cs @@ -14,12 +14,12 @@ namespace Pal3.Game.Scene.SceneObjects using Core.DataReader.Scn; using Core.Primitives; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Engine.Extensions; using Engine.Services; using State; - + using Color = Core.Primitives.Color; using Vector2Int = UnityEngine.Vector2Int; using Vector3 = UnityEngine.Vector3; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ElevatorPedalObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ElevatorPedalObject.cs index c5587783..ebabfb20 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ElevatorPedalObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ElevatorPedalObject.cs @@ -13,8 +13,8 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Engine.Extensions; using Engine.Services; using State; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/EyeBallObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/EyeBallObject.cs index c5eb1cbd..e82d90f7 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/EyeBallObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/EyeBallObject.cs @@ -15,7 +15,7 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Services; using Color = Core.Primitives.Color; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/FallableObstacleObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/FallableObstacleObject.cs index 0af2c687..24774972 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/FallableObstacleObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/FallableObstacleObject.cs @@ -17,8 +17,8 @@ namespace Pal3.Game.Scene.SceneObjects using Core.DataReader.Nav; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Engine.Extensions; using Color = Core.Primitives.Color; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/GeneralSceneObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/GeneralSceneObject.cs index cff3c50a..a9d883b8 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/GeneralSceneObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/GeneralSceneObject.cs @@ -11,7 +11,7 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Extensions; using Engine.Renderer; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/GravitySwitchObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/GravitySwitchObject.cs index 2ae56d84..a40fad17 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/GravitySwitchObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/GravitySwitchObject.cs @@ -16,8 +16,8 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Engine.Extensions; using Engine.Services; using GameSystems.Team; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ImpulsiveObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ImpulsiveObject.cs index 4da908b3..80d5ecd5 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ImpulsiveObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ImpulsiveObject.cs @@ -22,8 +22,9 @@ namespace Pal3.Game.Scene.SceneObjects using Core.DataReader.Scn; using Core.Utilities; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.Coroutine; using Engine.DataLoader; using Engine.Extensions; @@ -64,7 +65,8 @@ namespace Pal3.Game.Scene.SceneObjects IGameEntity sceneObjectGameEntity = base.Activate(resourceProvider, tintColor); - _subObjectGameEntity = new GameEntity($"Object_{ObjectInfo.Id}_{ObjectInfo.Type}_SubObject"); + _subObjectGameEntity = GameEntityFactory.Create($"Object_{ObjectInfo.Id}_{ObjectInfo.Type}_SubObject", + sceneObjectGameEntity, worldPositionStays: false); var subObjectModelPath = ModelFileVirtualPath.Insert(ModelFileVirtualPath.LastIndexOf('.'), "a"); PolFile polFile = resourceProvider.GetGameResourceFile(subObjectModelPath); @@ -80,9 +82,6 @@ namespace Pal3.Game.Scene.SceneObjects _subObjectController = _subObjectGameEntity.AddComponent(); _subObjectController.Init(); _subObjectController.OnPlayerActorHit += OnPlayerActorHit; - - _subObjectGameEntity.SetParent(sceneObjectGameEntity, worldPositionStays: false); - return sceneObjectGameEntity; } diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/InvestigationTriggerObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/InvestigationTriggerObject.cs index 83f29201..3cb6ee18 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/InvestigationTriggerObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/InvestigationTriggerObject.cs @@ -14,7 +14,7 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Coroutine; using Color = Core.Primitives.Color; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/JumpableAreaObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/JumpableAreaObject.cs index 5beabfbf..155c5300 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/JumpableAreaObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/JumpableAreaObject.cs @@ -10,11 +10,11 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Extensions; using Engine.Services; using GamePlay; - + using Color = Core.Primitives.Color; [ScnSceneObject(SceneObjectType.JumpableArea)] diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/LiftingPlatformObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/LiftingPlatformObject.cs index 3759708e..5da9b1b6 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/LiftingPlatformObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/LiftingPlatformObject.cs @@ -14,8 +14,8 @@ namespace Pal3.Game.Scene.SceneObjects using Core.DataReader.Scn; using Core.Primitives; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Engine.Extensions; using Engine.Services; using State; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/MovableCarrierObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/MovableCarrierObject.cs index 513cbfb1..91f0a762 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/MovableCarrierObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/MovableCarrierObject.cs @@ -16,8 +16,8 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Engine.Extensions; using Bounds = UnityEngine.Bounds; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/MushroomBridgeObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/MushroomBridgeObject.cs index f3b3e996..608e51cf 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/MushroomBridgeObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/MushroomBridgeObject.cs @@ -13,7 +13,7 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Extensions; using Engine.Services; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/PedalSwitchObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/PedalSwitchObject.cs index d029111a..5f52f3cf 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/PedalSwitchObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/PedalSwitchObject.cs @@ -12,8 +12,8 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Engine.Extensions; using Engine.Services; using State; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/PiranhaFlowerObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/PiranhaFlowerObject.cs index 8ff51fbe..f0697afd 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/PiranhaFlowerObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/PiranhaFlowerObject.cs @@ -16,7 +16,7 @@ namespace Pal3.Game.Scene.SceneObjects using Core.DataReader.Scn; using Core.Primitives; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Extensions; using Color = Core.Primitives.Color; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/PushableObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/PushableObject.cs index 53519edb..cd0d96e0 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/PushableObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/PushableObject.cs @@ -20,13 +20,18 @@ namespace Pal3.Game.Scene.SceneObjects using Core.DataReader.Nav; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Engine.Extensions; + using Engine.Logging; using Engine.Services; using State; - using UnityEngine; + + using Bounds = UnityEngine.Bounds; using Color = Core.Primitives.Color; + using Quaternion = UnityEngine.Quaternion; + using Vector2 = UnityEngine.Vector2; + using Vector3 = UnityEngine.Vector3; [ScnSceneObject(SceneObjectType.Pushable)] public sealed class PushableObject : SceneObject @@ -38,19 +43,19 @@ namespace Pal3.Game.Scene.SceneObjects private readonly SceneStateManager _sceneStateManager; private readonly Tilemap _tilemap; + private readonly IPhysicsManager _physicsManager; private bool _isInteractionInProgress; private int _bidiPushableCurrentState; private int _bidiPushableGoalState; - private readonly RaycastHit[] _raycastHits = new RaycastHit[10]; - public PushableObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo) : base(objectInfo, sceneInfo) { _sceneStateManager = ServiceLocator.Instance.Get(); _tilemap = ServiceLocator.Instance.Get().GetCurrentScene().GetTilemap(); + _physicsManager = ServiceLocator.Instance.Get(); } public override IGameEntity Activate(GameResourceProvider resourceProvider, Color tintColor) @@ -347,6 +352,7 @@ namespace Pal3.Game.Scene.SceneObjects return true; } + private readonly (Vector3 hitPoint, IGameEntity colliderGameEntity)[] _hitResults = new (Vector3, IGameEntity)[10]; private bool IsDirectionBlockedByOtherObjects(Vector3 direction, float distanceCheckRange) { IGameEntity pushableEntity = GetGameEntity(); @@ -354,35 +360,31 @@ namespace Pal3.Game.Scene.SceneObjects Bounds meshBounds = GetMeshBounds(); Bounds rendererBounds = GetRendererBounds(); - var hitCount = Physics.BoxCastNonAlloc(rendererBounds.center, - new Vector3(meshBounds.size.x / 2f * 0.8f, + int hitCount = _physicsManager.BoxCast(rendererBounds.center, + halfExtents: new Vector3(meshBounds.size.x / 2f * 0.8f, meshBounds.size.y / 2f * 0.8f, // 0.8f is to make sure the boxcast is meshBounds.size.z / 2f * 0.8f), // smaller than the mesh for tolerance - direction, - _raycastHits, - Quaternion.LookRotation(direction)); + direction: direction, + orientation: Quaternion.LookRotation(direction), + _hitResults); - int raycastOnlyLayer = LayerMask.NameToLayer("RaycastOnly"); - - if (hitCount > 0) + for (var i = 0; i < hitCount; i++) { - for (var i = 0; i < hitCount; i++) + (Vector3 _, IGameEntity colliderGameEntity) = _hitResults[i]; + + // Ignore NavMesh, Actors and self + if (colliderGameEntity.GetComponent() != null || + colliderGameEntity.GetComponent() != null || + colliderGameEntity.Name.Equals(pushableEntity.Name, StringComparison.Ordinal)) { - GameObject colliderObject = _raycastHits[i].collider.gameObject; + continue; + } - // Ignore raycast only objects (NavMesh in this case) or self - if (colliderObject.layer == raycastOnlyLayer || - colliderObject.gameObject == (GameObject)pushableEntity.NativeObject) - { - continue; - } - - // Can't push if there is an object in front of it within the distance - if (Vector3.Distance(pushableEntity.Transform.Position, - colliderObject.transform.position) < distanceCheckRange) - { - return true; - } + // Can't push if there is an object in front of it within the distance + if (Vector3.Distance(pushableEntity.Transform.Position, + colliderGameEntity.Transform.Position) < distanceCheckRange) + { + return true; } } diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RareChestObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RareChestObject.cs index 65e7199c..9b1e159c 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RareChestObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RareChestObject.cs @@ -15,7 +15,7 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Extensions; using Color = Core.Primitives.Color; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RetractableBlockerObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RetractableBlockerObject.cs index 279c6060..54a0d648 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RetractableBlockerObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RetractableBlockerObject.cs @@ -12,8 +12,8 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Engine.Extensions; using Color = Core.Primitives.Color; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RoadElevatorOrBlockerObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RoadElevatorOrBlockerObject.cs index a8e12937..e8ffc9d3 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RoadElevatorOrBlockerObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RoadElevatorOrBlockerObject.cs @@ -13,8 +13,8 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Engine.Extensions; using Rendering.Renderer; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RotatingBridgeObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RotatingBridgeObject.cs index b5a04cea..3ba54ef5 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RotatingBridgeObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RotatingBridgeObject.cs @@ -13,8 +13,8 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Engine.Extensions; using Bounds = UnityEngine.Bounds; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RotatingWallObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RotatingWallObject.cs index 277a6ddb..4838d251 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RotatingWallObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/RotatingWallObject.cs @@ -15,8 +15,9 @@ namespace Pal3.Game.Scene.SceneObjects using Core.DataReader.Scn; using Core.Utilities; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.DataLoader; using Engine.Extensions; using Rendering.Renderer; @@ -50,7 +51,8 @@ namespace Pal3.Game.Scene.SceneObjects // Add sub-component to the main object. if (ModelFileVirtualPath.EndsWith("1.pol")) { - _subObjectGameEntity = new GameEntity($"Object_{ObjectInfo.Id}_{ObjectInfo.Type}_SubObject"); + _subObjectGameEntity = GameEntityFactory.Create($"Object_{ObjectInfo.Id}_{ObjectInfo.Type}_SubObject", + sceneObjectGameEntity, worldPositionStays: false); var subObjectModelPath = ModelFileVirtualPath.Replace("1.pol", "2.pol"); PolFile polFile = resourceProvider.GetGameResourceFile(subObjectModelPath); @@ -66,8 +68,6 @@ namespace Pal3.Game.Scene.SceneObjects // Sub-object should block player as well, so let's add mesh collider to it _subObjectMeshCollider = _subObjectGameEntity.AddComponent(); _subObjectMeshCollider.Init(new Vector3(0f, 0f, -1f)); - - _subObjectGameEntity.SetParent(sceneObjectGameEntity, worldPositionStays: false); } return sceneObjectGameEntity; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SceneObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SceneObject.cs index a7aee5ec..95214ace 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SceneObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SceneObject.cs @@ -25,8 +25,9 @@ namespace Pal3.Game.Scene.SceneObjects using Data; using Dev.Presenters; using Effect; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.Coroutine; using Engine.DataLoader; using Engine.Extensions; @@ -131,7 +132,7 @@ namespace Pal3.Game.Scene.SceneObjects { if (IsActivated) return _sceneObjectGameEntity; - _sceneObjectGameEntity = new GameEntity($"Object_{ObjectInfo.Id}_{ObjectInfo.Type}"); + _sceneObjectGameEntity = GameEntityFactory.Create($"Object_{ObjectInfo.Id}_{ObjectInfo.Type}"); // Attach SceneObjectInfo to the GameEntity for better debuggability #if UNITY_EDITOR diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SceneSfxObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SceneSfxObject.cs index 3729118b..5cc9b317 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SceneSfxObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SceneSfxObject.cs @@ -14,7 +14,7 @@ namespace Pal3.Game.Scene.SceneObjects using Core.DataReader.Scn; using Core.Utilities; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Color = Core.Primitives.Color; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SectorBridgeObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SectorBridgeObject.cs index ea9617a5..3928474a 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SectorBridgeObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SectorBridgeObject.cs @@ -12,7 +12,7 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Extensions; using Rendering.Renderer; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SlideWayObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SlideWayObject.cs index 201a5ac9..a97b9447 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SlideWayObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SlideWayObject.cs @@ -11,7 +11,7 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Extensions; using Engine.Navigation; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SpecialSwitchObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SpecialSwitchObject.cs index e8eb6e99..3f37dba5 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SpecialSwitchObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SpecialSwitchObject.cs @@ -19,7 +19,7 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Coroutine; using Engine.Extensions; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/StaticOrAnimatedObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/StaticOrAnimatedObject.cs index ebd2ae40..dee86efa 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/StaticOrAnimatedObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/StaticOrAnimatedObject.cs @@ -13,7 +13,8 @@ namespace Pal3.Game.Scene.SceneObjects using Core.DataReader.Scn; using Core.Utilities; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.Coroutine; using Engine.Services; using Rendering.Renderer; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SuspensionBridgeObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SuspensionBridgeObject.cs index e20e2182..cdb413ca 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SuspensionBridgeObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SuspensionBridgeObject.cs @@ -12,10 +12,10 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Extensions; using Rendering.Renderer; - + using Bounds = UnityEngine.Bounds; using Color = Core.Primitives.Color; using Vector3 = UnityEngine.Vector3; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SwitchObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SwitchObject.cs index 0c076f78..28578632 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SwitchObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SwitchObject.cs @@ -21,14 +21,15 @@ namespace Pal3.Game.Scene.SceneObjects using Core.DataReader.Scn; using Core.Utilities; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; using Engine.DataLoader; using Engine.Extensions; using Rendering.Renderer; using Color = Core.Primitives.Color; using Vector3 = UnityEngine.Vector3; - + [ScnSceneObject(SceneObjectType.Switch)] public sealed class SwitchObject : SceneObject { @@ -75,8 +76,8 @@ namespace Pal3.Game.Scene.SceneObjects INTERACTION_INDICATOR_MODEL_FILE_NAME); Vector3 switchPosition = sceneObjectGameEntity.Transform.Position; - _interactionIndicatorGameEntity = new GameEntity("Switch_Interaction_Indicator"); - _interactionIndicatorGameEntity.SetParent(sceneObjectGameEntity, worldPositionStays: false); + _interactionIndicatorGameEntity = GameEntityFactory.Create("Switch_Interaction_Indicator", + sceneObjectGameEntity, worldPositionStays: false); _interactionIndicatorGameEntity.Transform.Position = new Vector3(switchPosition.x, GetRendererBounds().max.y + 1f, switchPosition.z); diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SwordBridgeObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SwordBridgeObject.cs index 50279721..4ff1aa77 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SwordBridgeObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/SwordBridgeObject.cs @@ -13,7 +13,7 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Extensions; using Bounds = UnityEngine.Bounds; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/TeapotObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/TeapotObject.cs index 4770aca2..62fb4f4d 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/TeapotObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/TeapotObject.cs @@ -12,8 +12,8 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Color = Core.Primitives.Color; using Quaternion = UnityEngine.Quaternion; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ThreePhaseBridgeObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ThreePhaseBridgeObject.cs index b98df16c..40495971 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ThreePhaseBridgeObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ThreePhaseBridgeObject.cs @@ -15,8 +15,8 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Engine.Extensions; using Engine.Services; using State; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ThreePhaseSwitchObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ThreePhaseSwitchObject.cs index fcff22fe..d7405332 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ThreePhaseSwitchObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ThreePhaseSwitchObject.cs @@ -17,8 +17,8 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Engine.Extensions; using Engine.Services; using State; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ToggleSwitchObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ToggleSwitchObject.cs index 5c904d91..8a34ea9d 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ToggleSwitchObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/ToggleSwitchObject.cs @@ -18,8 +18,8 @@ namespace Pal3.Game.Scene.SceneObjects using Core.DataReader.Scn; using Core.Primitives; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Engine.Coroutine; using Engine.Extensions; using Rendering.Renderer; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/TrapObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/TrapObject.cs index 64f00c3b..9a59f6ef 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/TrapObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/TrapObject.cs @@ -15,8 +15,8 @@ namespace Pal3.Game.Scene.SceneObjects using Core.DataReader.Scn; using Core.Primitives; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Engine.Extensions; using UnityEngine; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/WaterSurface.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/WaterSurface.cs index 61400322..e8f3f2ad 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/WaterSurface.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/WaterSurface.cs @@ -12,8 +12,8 @@ namespace Pal3.Game.Scene.SceneObjects using Common; using Core.Contract.Enums; using Core.DataReader.Scn; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Vector3 = UnityEngine.Vector3; diff --git a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/WaterSurfaceRoadBlockerObject.cs b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/WaterSurfaceRoadBlockerObject.cs index 3663390a..2073cb6d 100644 --- a/Assets/Scripts/Pal3.Game/Scene/SceneObjects/WaterSurfaceRoadBlockerObject.cs +++ b/Assets/Scripts/Pal3.Game/Scene/SceneObjects/WaterSurfaceRoadBlockerObject.cs @@ -13,8 +13,8 @@ namespace Pal3.Game.Scene.SceneObjects using Core.Contract.Enums; using Core.DataReader.Scn; using Data; - using Engine.Abstraction; using Engine.Animation; + using Engine.Core.Abstraction; using Engine.Extensions; using Engine.Services; diff --git a/Assets/Scripts/Pal3.Game/Script/ScriptManager.cs b/Assets/Scripts/Pal3.Game/Script/ScriptManager.cs index 2db7b489..8a94c543 100644 --- a/Assets/Scripts/Pal3.Game/Script/ScriptManager.cs +++ b/Assets/Scripts/Pal3.Game/Script/ScriptManager.cs @@ -110,7 +110,7 @@ namespace Pal3.Game.Script scriptRunner = PalScriptRunner.Create(_worldMapSceFile, PalScriptType.WorldMap, scriptId, _globalVariables, _cmdPreprocessor); } - else if (scriptId <= ScriptConstants.SystemScriptIdMax) + else if (scriptId < ScriptConstants.SystemScriptIdMax) { EngineLogger.Log($"Add System script id: {scriptId}"); scriptRunner = PalScriptRunner.Create(_systemSceFile, diff --git a/Assets/Scripts/Pal3.Game/State/SaveManager.cs b/Assets/Scripts/Pal3.Game/State/SaveManager.cs index 41663c64..1dd92ba5 100644 --- a/Assets/Scripts/Pal3.Game/State/SaveManager.cs +++ b/Assets/Scripts/Pal3.Game/State/SaveManager.cs @@ -23,7 +23,7 @@ namespace Pal3.Game.State using Core.Primitives; using Core.Utilities; using Effect.PostProcessing; - using Engine.Abstraction; + using Engine.Core.Abstraction; using Engine.Extensions; using Engine.Logging; using Engine.Services; diff --git a/Packages/manifest.json b/Packages/manifest.json index dee796d5..5cee65ba 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -1,10 +1,10 @@ { "dependencies": { "com.github-glitchenzo.nugetforunity": "https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity", - "com.unity.ai.navigation": "1.1.4", + "com.unity.ai.navigation": "1.1.5", "com.unity.feature.development": "1.0.1", - "com.unity.ide.rider": "3.0.25", - "com.unity.ide.visualstudio": "2.0.21", + "com.unity.ide.rider": "3.0.26", + "com.unity.ide.visualstudio": "2.0.22", "com.unity.ide.vscode": "1.2.5", "com.unity.inputsystem": "1.7.0", "com.unity.memoryprofiler": "1.0.0", @@ -12,7 +12,7 @@ "com.unity.postprocessing": "3.2.2", "com.unity.test-framework": "1.1.33", "com.unity.textmeshpro": "3.0.6", - "com.unity.timeline": "1.7.5", + "com.unity.timeline": "1.7.6", "com.unity.toolchain.macos-x86_64-linux-x86_64": "2.0.6", "com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.6", "com.unity.ugui": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index eaf0781a..614f942d 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -8,7 +8,7 @@ "hash": "2a728b401a9f7687dffec4f354e27ddd3d613fa5" }, "com.unity.ai.navigation": { - "version": "1.1.4", + "version": "1.1.5", "depth": 0, "source": "registry", "dependencies": { @@ -45,7 +45,7 @@ } }, "com.unity.ide.rider": { - "version": "3.0.25", + "version": "3.0.26", "depth": 0, "source": "registry", "dependencies": { @@ -54,7 +54,7 @@ "url": "https://packages.unity.com" }, "com.unity.ide.visualstudio": { - "version": "2.0.21", + "version": "2.0.22", "depth": 0, "source": "registry", "dependencies": { @@ -164,7 +164,7 @@ "url": "https://packages.unity.com" }, "com.unity.timeline": { - "version": "1.7.5", + "version": "1.7.6", "depth": 0, "source": "registry", "dependencies": { diff --git a/ProjectSettings/DynamicsManager.asset b/ProjectSettings/DynamicsManager.asset index ba46b569..87421d2d 100644 --- a/ProjectSettings/DynamicsManager.asset +++ b/ProjectSettings/DynamicsManager.asset @@ -3,7 +3,7 @@ --- !u!55 &1 PhysicsManager: m_ObjectHideFlags: 0 - serializedVersion: 13 + serializedVersion: 14 m_Gravity: {x: 0, y: -9.81, z: 0} m_DefaultMaterial: {fileID: 0} m_BounceThreshold: 2 @@ -18,10 +18,11 @@ PhysicsManager: m_ClothInterCollisionDistance: 0 m_ClothInterCollisionStiffness: 0 m_ContactsGeneration: 1 - m_LayerCollisionMatrix: ffffffffffffffffbfffffffffffffffffffffffffffffff3bffffffbfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff - m_AutoSimulation: 1 + m_LayerCollisionMatrix: 3fffffff3fffffff3fffffff3fffffff3fffffff3fffffff00ffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff + m_SimulationMode: 0 m_AutoSyncTransforms: 0 m_ReuseCollisionCallbacks: 1 + m_InvokeCollisionCallbacks: 1 m_ClothInterCollisionSettingsToggle: 0 m_ClothGravity: {x: 0, y: -9.81, z: 0} m_ContactPairsMode: 0 diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index e61745a4..35f066ad 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -12,7 +12,7 @@ TagManager: - VFX - Water - UI - - RaycastOnly + - NavMeshes - - -