diff --git a/Assets/Prefabs/GameSystem.prefab b/Assets/Prefabs/GameSystem.prefab index 08f47d4..de9c8b4 100644 --- a/Assets/Prefabs/GameSystem.prefab +++ b/Assets/Prefabs/GameSystem.prefab @@ -1,5 +1,49 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: +--- !u!1 &221308801621687712 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 183449879215217602} + - component: {fileID: 7408334756516261553} + m_Layer: 0 + m_Name: EventManager + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &183449879215217602 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 221308801621687712} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 2157073180203202247} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &7408334756516261553 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 221308801621687712} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 71c5cbaefd379ae48875ee243e0435c9, type: 3} + m_Name: + m_EditorClassIdentifier: + range: 10 --- !u!1 &2157073178696562865 GameObject: m_ObjectHideFlags: 0 @@ -73,7 +117,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 2157073180203202247} - m_RootOrder: 2 + m_RootOrder: 3 m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0} --- !u!114 &2157073178828809470 MonoBehaviour: @@ -137,7 +181,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 2157073180203202247} - m_RootOrder: 1 + m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &2157073179154264261 MonoBehaviour: @@ -214,7 +258,7 @@ Transform: m_Children: - {fileID: 2157073179686492908} m_Father: {fileID: 2157073180203202247} - m_RootOrder: 3 + m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2157073180013227982 GameObject: @@ -244,7 +288,7 @@ Transform: m_LocalScale: {x: 0.1, y: 0.1, z: 0.1} m_Children: [] m_Father: {fileID: 2157073180203202247} - m_RootOrder: 4 + m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2157073180203202245 GameObject: @@ -275,6 +319,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 2157073178696562864} + - {fileID: 183449879215217602} - {fileID: 2157073179154264258} - {fileID: 2157073178828809457} - {fileID: 2157073179837706944} diff --git a/Assets/Prefabs/Workshops/Production_workshop.prefab b/Assets/Prefabs/Workshops/Production_workshop.prefab index cd19356..6a4c0a9 100644 --- a/Assets/Prefabs/Workshops/Production_workshop.prefab +++ b/Assets/Prefabs/Workshops/Production_workshop.prefab @@ -85,7 +85,7 @@ SpriteRenderer: m_SpriteTileMode: 0 m_WasSpriteAssigned: 1 m_MaskInteraction: 0 - m_SpriteSortPoint: 0 + m_SpriteSortPoint: 1 --- !u!61 &4478636634695997808 BoxCollider2D: m_ObjectHideFlags: 0 @@ -130,7 +130,7 @@ MonoBehaviour: product_name: beer product_value: 10 product_sprite: {fileID: 21300000, guid: 17d59b2d4d882c04480a40119a442279, type: 3} - stock: 5 + initial_stock: 5 --- !u!1 &8573757128841810314 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Resources/Events.meta b/Assets/Resources/Events.meta new file mode 100644 index 0000000..8e38069 --- /dev/null +++ b/Assets/Resources/Events.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 44acad361b97731448f488b641b0e467 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Tests/SampleScene.unity b/Assets/Scenes/Tests/SampleScene.unity index 03f098b..097bf25 100644 --- a/Assets/Scenes/Tests/SampleScene.unity +++ b/Assets/Scenes/Tests/SampleScene.unity @@ -3682,6 +3682,11 @@ PrefabInstance: propertyPath: m_SortingLayer value: 0 objectReference: {fileID: 0} + - target: {fileID: 4478636634695997811, guid: 3baa223794d1dea4c986a5384a835c16, + type: 3} + propertyPath: m_SortingOrder + value: 5 + objectReference: {fileID: 0} - target: {fileID: 4478636634695997811, guid: 3baa223794d1dea4c986a5384a835c16, type: 3} propertyPath: m_SortingLayerID @@ -32623,6 +32628,16 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 7408334756516261553, guid: dfb09d229e85c1446bee2e4f9357610e, + type: 3} + propertyPath: range + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 7408334756516261553, guid: dfb09d229e85c1446bee2e4f9357610e, + type: 3} + propertyPath: nbMaxEvents + value: 3 + objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: dfb09d229e85c1446bee2e4f9357610e, type: 3} --- !u!1 &1809057616 diff --git a/Assets/Scripts/Client_controller.cs b/Assets/Scripts/Client_controller.cs index 7fb4bfe..3880613 100644 --- a/Assets/Scripts/Client_controller.cs +++ b/Assets/Scripts/Client_controller.cs @@ -136,6 +136,8 @@ public class Client_controller : MonoBehaviour, IUsable if(status=="entering" && !agent.pathPending && agent.remainingDistance==0) //Reached seat ? { + EventManager.Instance.spawnEvent(transform.position); + status="waiting"; waitTimer=waitingTime; order = ClientManager.Instance.assignOrder(); diff --git a/Assets/Scripts/GameSystems/ClientManager.cs b/Assets/Scripts/GameSystems/ClientManager.cs index 05d5efb..521627a 100644 --- a/Assets/Scripts/GameSystems/ClientManager.cs +++ b/Assets/Scripts/GameSystems/ClientManager.cs @@ -27,6 +27,7 @@ public sealed class ClientManager : MonoBehaviour float maxTimeNewClients = 2.0f; //Longest waiting time for new clients bool clientSpawnReady = false; + [SerializeField] string ClientRessourceFolder = "Clients"; private Object[] clients; GameObject ClientContainer = null; diff --git a/Assets/Scripts/GameSystems/EventManager.cs b/Assets/Scripts/GameSystems/EventManager.cs new file mode 100644 index 0000000..549f7cb --- /dev/null +++ b/Assets/Scripts/GameSystems/EventManager.cs @@ -0,0 +1,105 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.AI; + +//Define the system managing the events. (Singleton) +public sealed class EventManager : MonoBehaviour +{ + //Singleton + private static EventManager _instance=null; + public static EventManager Instance { get + { + if(_instance is null) + Debug.LogError("Missing EventManager instance"); + return _instance; + } + } + + [HideInInspector] + public bool ready = false; //Wether the ClientManager is initialized + + [SerializeField] + float SpawnRange = 1.0f; + [SerializeField] + int nbMaxEvents = 1; //Maximum active clients + [SerializeField] + float eventSpawnTimer = 0.5f; //Intial time before first spawn (pseudo-random after that) + [SerializeField] + float maxTimeNewEvents = 2.0f; //Longest waiting time for new clients + bool eventSpawnReady = false; + + [SerializeField] + string EventRessourceFolder = "Events"; + private Object[] events; + GameObject EventContainer=null; + List eventIDs = new List(); + + //Try to find a random point on NavMesh inside a range circle. A result would at a maximum distance of 2*range. + bool RandomPoint(Vector3 center, float range, out Vector3 result) + { + for (int i = 0; i < 50; i++) + { + Vector3 randomPoint = center + (Vector3)Random.insideUnitCircle * range; + NavMeshHit hit; + if (NavMesh.SamplePosition(randomPoint, out hit, range, NavMesh.AllAreas)) + { + result = hit.position; + return true; + } + } + result = Vector3.zero; + return false; + } + + public void spawnEvent(Vector3 position) + { + Vector3 spawnPoint; + if (eventSpawnReady && eventIDs.Count