Client_controller status + client navigation (leaving)
This commit is contained in:
parent
2db3e27a47
commit
7a7fcb6ac1
3 changed files with 63 additions and 24 deletions
|
@ -7310,7 +7310,7 @@ Transform:
|
|||
m_GameObject: {fileID: 1486551543}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 4.963482, y: -3.7325091, z: -3.6281848}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_LocalScale: {x: 0.1, y: 0.1, z: 0.1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1160225022}
|
||||
m_RootOrder: 1
|
||||
|
@ -32161,8 +32161,8 @@ Transform:
|
|||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1678986451}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: -6.6, y: -2.112, z: 2.5482712}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_LocalPosition: {x: -0.349, y: -1.345, z: 2.5482712}
|
||||
m_LocalScale: {x: 0.1, y: 0.1, z: 0.1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1863361785}
|
||||
m_RootOrder: 0
|
||||
|
|
|
@ -10,11 +10,24 @@ public class Client_controller : MonoBehaviour, IUsable
|
|||
{
|
||||
public float consumeTime = 3.0f; //Time to consume currentMug
|
||||
public float waitingTime = 10.0f; //Patience after ordering
|
||||
|
||||
string _status;
|
||||
HashSet<string> _availStatus = new HashSet<string>(){"entering", "waiting", "consuming", "leaving"};
|
||||
public string status
|
||||
{
|
||||
get{ return _status;}
|
||||
set{
|
||||
if (_availStatus.Contains(value))
|
||||
_status = value;
|
||||
Debug.Log(gameObject.name+" "+_status);
|
||||
}
|
||||
}
|
||||
|
||||
float consumeTimer;
|
||||
float waitTimer;
|
||||
GameObject currentMug = null; //Mug currently held by the client
|
||||
|
||||
Transform target;
|
||||
//Navigation
|
||||
Vector2 destination;
|
||||
NavMeshAgent agent;
|
||||
|
||||
|
@ -30,7 +43,8 @@ public class Client_controller : MonoBehaviour, IUsable
|
|||
Mug mug = object_used.GetComponent<Mug>();
|
||||
if (mug!= null && mug.content != null)
|
||||
{
|
||||
Debug.Log(gameObject.name+" take "+object_used.name+ " of "+mug.content.Type);
|
||||
status = "consuming";
|
||||
Debug.Log(gameObject.name+" "+status+" "+object_used.name+ " of "+mug.content.Type);
|
||||
currentMug = object_used;
|
||||
consumeTimer=consumeTime;
|
||||
return true;
|
||||
|
@ -62,27 +76,43 @@ public class Client_controller : MonoBehaviour, IUsable
|
|||
if(gameObject.tag != "Usable")
|
||||
Debug.LogWarning(gameObject.name+" tag should be set to 'Usable' to work properly");
|
||||
|
||||
status = "entering";
|
||||
|
||||
// Navigation //
|
||||
agent = GetComponent<NavMeshAgent>();
|
||||
//Prevent rotation of the ground at movement
|
||||
agent.updateRotation = false;
|
||||
agent.updateUpAxis = false;
|
||||
//Get target
|
||||
agent.destination = ClientManager.Instance.assignTarget().position;
|
||||
agent.destination = ClientManager.Instance.assignTarget();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
//Navigation
|
||||
// if (Vector2.Distance(destination, target.position) > 1.0f)
|
||||
// {
|
||||
// destination = target.position;
|
||||
// agent.destination = destination;
|
||||
// }
|
||||
// Debug.Log(gameObject.name + " navigation : "+ agent.isStopped + " " + agent.remainingDistance);
|
||||
|
||||
//Timer
|
||||
if (currentMug!= null) //Consuming mug if there's one
|
||||
//Reached seat
|
||||
if(status=="entering" && agent.remainingDistance==0)
|
||||
{
|
||||
status="waiting";
|
||||
waitTimer=waitingTime;
|
||||
}
|
||||
|
||||
if(status=="waiting")
|
||||
{
|
||||
waitTimer -= Time.deltaTime;
|
||||
if (waitTimer < 0) //Waited too long
|
||||
{
|
||||
//Leave tavern
|
||||
status = "leaving";
|
||||
agent.destination = ClientManager.Instance.assignTarget(agent.destination); //Request next target
|
||||
}
|
||||
}
|
||||
|
||||
//Consume Timer
|
||||
if (status=="consuming" && agent.remainingDistance==0) //Consuming mug if there's one and reached destination
|
||||
{
|
||||
consumeTimer -= Time.deltaTime;
|
||||
if (consumeTimer < 0) //Finished consuming mug ?
|
||||
|
@ -95,6 +125,10 @@ public class Client_controller : MonoBehaviour, IUsable
|
|||
obj.drop(gameObject.transform.position+ (Vector3)Vector2.down * 0.2f);
|
||||
currentMug=null;
|
||||
}
|
||||
|
||||
//Leave tavern
|
||||
status = "leaving";
|
||||
agent.destination = ClientManager.Instance.assignTarget(agent.destination); //Request next target
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ public sealed class ClientManager : MonoBehaviour
|
|||
string ClientRessourceFolder = "Clients";
|
||||
private Object[] clients;
|
||||
|
||||
Vector3 spawnPosition = new Vector3(0, 0, 0); //TODO : Use gameObject
|
||||
Dictionary<Transform, bool> targets_dict; //Dict with target and wether they're taken by a client
|
||||
Vector2 spawnPoint;
|
||||
Dictionary<Vector2, bool> targets_dict; //Dict with target and wether they're taken by a client
|
||||
|
||||
//Request new client
|
||||
//Return wether a new client was created
|
||||
|
@ -26,7 +26,7 @@ public sealed class ClientManager : MonoBehaviour
|
|||
{
|
||||
GameObject newClient = (GameObject)clients[Random.Range(0, clients.Length)];
|
||||
// Debug.Log("Spawning "+clientPrefab.name+" at "+spawnPosition);
|
||||
Instantiate(newClient, spawnPosition, Quaternion.identity);
|
||||
Instantiate(newClient, spawnPoint, Quaternion.identity);
|
||||
currentNbClient+=1;
|
||||
clientSpawnTimer=Random.Range(1.0f, maxTimeNewClients); //Need more random ?
|
||||
clientSpawnReady=false;
|
||||
|
@ -36,15 +36,20 @@ public sealed class ClientManager : MonoBehaviour
|
|||
return false; //No new client
|
||||
}
|
||||
|
||||
//Assign a random available target
|
||||
public Transform assignTarget()
|
||||
//Assign a random available target.
|
||||
public Vector2 assignTarget(Vector2? prevTarget=null)
|
||||
{
|
||||
List<Transform> avail_tgt = new List<Transform>();
|
||||
foreach(KeyValuePair<Transform, bool> tgt in targets_dict)
|
||||
if(prevTarget != null)
|
||||
{
|
||||
targets_dict[(Vector2)prevTarget]=false; //Free prevTarget
|
||||
return spawnPoint;
|
||||
}
|
||||
List<Vector2> avail_tgt = new List<Vector2>();
|
||||
foreach(KeyValuePair<Vector2, bool> tgt in targets_dict)
|
||||
if(tgt.Value is false)
|
||||
avail_tgt.Add(tgt.Key);
|
||||
|
||||
Transform target = avail_tgt[Random.Range(0, avail_tgt.Count)];
|
||||
Vector2 target = avail_tgt[Random.Range(0, avail_tgt.Count)];
|
||||
targets_dict[target]=true;
|
||||
return target;
|
||||
}
|
||||
|
@ -74,10 +79,10 @@ public sealed class ClientManager : MonoBehaviour
|
|||
GameObject spawnObj = GameObject.Find("/GameSystem/ClientSpawn");
|
||||
if (spawnObj is null)
|
||||
throw new System.Exception("No ClientSpawn GameObject found under GameSystem");
|
||||
spawnPosition = spawnObj.transform.position;
|
||||
spawnPoint = spawnObj.transform.position;
|
||||
|
||||
// Load Client targets //
|
||||
targets_dict = new Dictionary<Transform, bool>();
|
||||
targets_dict = new Dictionary<Vector2, bool>();
|
||||
GameObject targetsObj = GameObject.Find("/GameSystem/Targets");
|
||||
if (targetsObj is null)
|
||||
throw new System.Exception("No Targets GameObject found under GameSystem");
|
||||
|
@ -89,7 +94,7 @@ public sealed class ClientManager : MonoBehaviour
|
|||
{
|
||||
if(target.gameObject.name != "Targets")
|
||||
{
|
||||
targets_dict.Add(target, false);
|
||||
targets_dict.Add(target.position, false);
|
||||
Debug.Log("Client target : "+ target.gameObject.name + target.position);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue