Refactoring of status system to prevent bug w/ events
This commit is contained in:
parent
fd8306645b
commit
e89483d612
13 changed files with 487 additions and 113 deletions
|
@ -10,10 +10,27 @@ AnimatorStateMachine:
|
|||
m_Name: Base Layer
|
||||
m_ChildStates:
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: 7592019148465692952}
|
||||
m_Position: {x: 200, y: 0, z: 0}
|
||||
m_State: {fileID: 689161243993804840}
|
||||
m_Position: {x: 340, y: -110, z: 0}
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: 945483523725794433}
|
||||
m_Position: {x: 340, y: -50, z: 0}
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: -6546835001122497277}
|
||||
m_Position: {x: 340, y: 10, z: 0}
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: 5193190183145152303}
|
||||
m_Position: {x: 340, y: 70, z: 0}
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: 4275546792374664699}
|
||||
m_Position: {x: 340, y: 130, z: 0}
|
||||
m_ChildStateMachines: []
|
||||
m_AnyStateTransitions: []
|
||||
m_AnyStateTransitions:
|
||||
- {fileID: -8060406279278162474}
|
||||
- {fileID: 1527863355288071821}
|
||||
- {fileID: 4293475117908034052}
|
||||
- {fileID: -7101533724053556337}
|
||||
- {fileID: -7668192276894405300}
|
||||
m_EntryTransitions: []
|
||||
m_StateMachineTransitions: {}
|
||||
m_StateMachineBehaviours: []
|
||||
|
@ -21,37 +38,296 @@ AnimatorStateMachine:
|
|||
m_EntryPosition: {x: 50, y: 120, z: 0}
|
||||
m_ExitPosition: {x: 800, y: 120, z: 0}
|
||||
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
|
||||
m_DefaultState: {fileID: 7592019148465692952}
|
||||
--- !u!91 &9100000
|
||||
AnimatorController:
|
||||
m_ObjectHideFlags: 0
|
||||
m_DefaultState: {fileID: 689161243993804840}
|
||||
--- !u!1101 &-8060406279278162474
|
||||
AnimatorStateTransition:
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: oldman_animator
|
||||
serializedVersion: 5
|
||||
m_AnimatorParameters: []
|
||||
m_AnimatorLayers:
|
||||
- serializedVersion: 5
|
||||
m_Name: Base Layer
|
||||
m_StateMachine: {fileID: -8547104927243203257}
|
||||
m_Mask: {fileID: 0}
|
||||
m_Motions: []
|
||||
m_Behaviours: []
|
||||
m_BlendingMode: 0
|
||||
m_SyncedLayerIndex: -1
|
||||
m_DefaultWeight: 0
|
||||
m_IKPass: 0
|
||||
m_SyncedLayerAffectsTiming: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
--- !u!1102 &7592019148465692952
|
||||
m_Name:
|
||||
m_Conditions:
|
||||
- m_ConditionMode: 1
|
||||
m_ConditionEvent: entering
|
||||
m_EventTreshold: 0
|
||||
m_DstStateMachine: {fileID: 0}
|
||||
m_DstState: {fileID: 689161243993804840}
|
||||
m_Solo: 0
|
||||
m_Mute: 0
|
||||
m_IsExit: 0
|
||||
serializedVersion: 3
|
||||
m_TransitionDuration: 0.25
|
||||
m_TransitionOffset: 0
|
||||
m_ExitTime: 0.75
|
||||
m_HasExitTime: 0
|
||||
m_HasFixedDuration: 1
|
||||
m_InterruptionSource: 2
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!1101 &-7668192276894405300
|
||||
AnimatorStateTransition:
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name:
|
||||
m_Conditions:
|
||||
- m_ConditionMode: 1
|
||||
m_ConditionEvent: event
|
||||
m_EventTreshold: 0
|
||||
m_DstStateMachine: {fileID: 0}
|
||||
m_DstState: {fileID: 4275546792374664699}
|
||||
m_Solo: 0
|
||||
m_Mute: 0
|
||||
m_IsExit: 0
|
||||
serializedVersion: 3
|
||||
m_TransitionDuration: 0.25
|
||||
m_TransitionOffset: 0
|
||||
m_ExitTime: 0.75
|
||||
m_HasExitTime: 0
|
||||
m_HasFixedDuration: 1
|
||||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!1101 &-7101533724053556337
|
||||
AnimatorStateTransition:
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name:
|
||||
m_Conditions:
|
||||
- m_ConditionMode: 1
|
||||
m_ConditionEvent: leaving
|
||||
m_EventTreshold: 0
|
||||
m_DstStateMachine: {fileID: 0}
|
||||
m_DstState: {fileID: 5193190183145152303}
|
||||
m_Solo: 0
|
||||
m_Mute: 0
|
||||
m_IsExit: 0
|
||||
serializedVersion: 3
|
||||
m_TransitionDuration: 0.25
|
||||
m_TransitionOffset: 0
|
||||
m_ExitTime: 0.75
|
||||
m_HasExitTime: 0
|
||||
m_HasFixedDuration: 1
|
||||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!1102 &-6546835001122497277
|
||||
AnimatorState:
|
||||
serializedVersion: 5
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: oldman
|
||||
m_Name: Consuming
|
||||
m_Speed: 1
|
||||
m_CycleOffset: 0
|
||||
m_Transitions: []
|
||||
m_StateMachineBehaviours: []
|
||||
m_Position: {x: 50, y: 50, z: 0}
|
||||
m_IKOnFeet: 0
|
||||
m_WriteDefaultValues: 1
|
||||
m_Mirror: 0
|
||||
m_SpeedParameterActive: 0
|
||||
m_MirrorParameterActive: 0
|
||||
m_CycleOffsetParameterActive: 0
|
||||
m_TimeParameterActive: 0
|
||||
m_Motion: {fileID: 7400000, guid: 9548536878b3c884282e98f25bbc699b, type: 2}
|
||||
m_Tag:
|
||||
m_SpeedParameter:
|
||||
m_MirrorParameter:
|
||||
m_CycleOffsetParameter:
|
||||
m_TimeParameter:
|
||||
--- !u!91 &9100000
|
||||
AnimatorController:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: oldman_animator
|
||||
serializedVersion: 5
|
||||
m_AnimatorParameters:
|
||||
- m_Name: entering
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
- m_Name: waiting
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
- m_Name: consuming
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
- m_Name: leaving
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
- m_Name: event
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_AnimatorLayers:
|
||||
- serializedVersion: 5
|
||||
m_Name: Base Layer
|
||||
m_StateMachine: {fileID: -8547104927243203257}
|
||||
m_Mask: {fileID: 0}
|
||||
m_Motions: []
|
||||
m_Behaviours: []
|
||||
m_BlendingMode: 0
|
||||
m_SyncedLayerIndex: -1
|
||||
m_DefaultWeight: 0
|
||||
m_IKPass: 0
|
||||
m_SyncedLayerAffectsTiming: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
--- !u!1102 &689161243993804840
|
||||
AnimatorState:
|
||||
serializedVersion: 5
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Entering
|
||||
m_Speed: 1
|
||||
m_CycleOffset: 0
|
||||
m_Transitions: []
|
||||
m_StateMachineBehaviours: []
|
||||
m_Position: {x: 50, y: 50, z: 0}
|
||||
m_IKOnFeet: 0
|
||||
m_WriteDefaultValues: 1
|
||||
m_Mirror: 0
|
||||
m_SpeedParameterActive: 0
|
||||
m_MirrorParameterActive: 0
|
||||
m_CycleOffsetParameterActive: 0
|
||||
m_TimeParameterActive: 0
|
||||
m_Motion: {fileID: 7400000, guid: 9548536878b3c884282e98f25bbc699b, type: 2}
|
||||
m_Tag:
|
||||
m_SpeedParameter:
|
||||
m_MirrorParameter:
|
||||
m_CycleOffsetParameter:
|
||||
m_TimeParameter:
|
||||
--- !u!1102 &945483523725794433
|
||||
AnimatorState:
|
||||
serializedVersion: 5
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Waiting
|
||||
m_Speed: 1
|
||||
m_CycleOffset: 0
|
||||
m_Transitions: []
|
||||
m_StateMachineBehaviours: []
|
||||
m_Position: {x: 50, y: 50, z: 0}
|
||||
m_IKOnFeet: 0
|
||||
m_WriteDefaultValues: 1
|
||||
m_Mirror: 0
|
||||
m_SpeedParameterActive: 0
|
||||
m_MirrorParameterActive: 0
|
||||
m_CycleOffsetParameterActive: 0
|
||||
m_TimeParameterActive: 0
|
||||
m_Motion: {fileID: 7400000, guid: 9548536878b3c884282e98f25bbc699b, type: 2}
|
||||
m_Tag:
|
||||
m_SpeedParameter:
|
||||
m_MirrorParameter:
|
||||
m_CycleOffsetParameter:
|
||||
m_TimeParameter:
|
||||
--- !u!1101 &1527863355288071821
|
||||
AnimatorStateTransition:
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name:
|
||||
m_Conditions:
|
||||
- m_ConditionMode: 1
|
||||
m_ConditionEvent: waiting
|
||||
m_EventTreshold: 0
|
||||
m_DstStateMachine: {fileID: 0}
|
||||
m_DstState: {fileID: 945483523725794433}
|
||||
m_Solo: 0
|
||||
m_Mute: 0
|
||||
m_IsExit: 0
|
||||
serializedVersion: 3
|
||||
m_TransitionDuration: 0.25
|
||||
m_TransitionOffset: 0
|
||||
m_ExitTime: 0.75
|
||||
m_HasExitTime: 0
|
||||
m_HasFixedDuration: 1
|
||||
m_InterruptionSource: 2
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!1102 &4275546792374664699
|
||||
AnimatorState:
|
||||
serializedVersion: 5
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: In event
|
||||
m_Speed: 1
|
||||
m_CycleOffset: 0
|
||||
m_Transitions: []
|
||||
m_StateMachineBehaviours: []
|
||||
m_Position: {x: 50, y: 50, z: 0}
|
||||
m_IKOnFeet: 0
|
||||
m_WriteDefaultValues: 1
|
||||
m_Mirror: 0
|
||||
m_SpeedParameterActive: 0
|
||||
m_MirrorParameterActive: 0
|
||||
m_CycleOffsetParameterActive: 0
|
||||
m_TimeParameterActive: 0
|
||||
m_Motion: {fileID: 7400000, guid: 9548536878b3c884282e98f25bbc699b, type: 2}
|
||||
m_Tag:
|
||||
m_SpeedParameter:
|
||||
m_MirrorParameter:
|
||||
m_CycleOffsetParameter:
|
||||
m_TimeParameter:
|
||||
--- !u!1101 &4293475117908034052
|
||||
AnimatorStateTransition:
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name:
|
||||
m_Conditions:
|
||||
- m_ConditionMode: 1
|
||||
m_ConditionEvent: consuming
|
||||
m_EventTreshold: 0
|
||||
m_DstStateMachine: {fileID: 0}
|
||||
m_DstState: {fileID: -6546835001122497277}
|
||||
m_Solo: 0
|
||||
m_Mute: 0
|
||||
m_IsExit: 0
|
||||
serializedVersion: 3
|
||||
m_TransitionDuration: 0.25
|
||||
m_TransitionOffset: 0
|
||||
m_ExitTime: 0.75
|
||||
m_HasExitTime: 0
|
||||
m_HasFixedDuration: 1
|
||||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!1102 &5193190183145152303
|
||||
AnimatorState:
|
||||
serializedVersion: 5
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Leaving
|
||||
m_Speed: 1
|
||||
m_CycleOffset: 0
|
||||
m_Transitions: []
|
||||
|
|
|
@ -43,7 +43,14 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 71c5cbaefd379ae48875ee243e0435c9, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
range: 10
|
||||
ready: 0
|
||||
SpawnRange: 1
|
||||
spawnChance: 100
|
||||
maxSoftObs: 1
|
||||
maxHardObs: 1
|
||||
SoftObsRessourceFolder: Events/SoftObstacles
|
||||
HardObsRessourceFolder: Events/HardObstacles
|
||||
coroutineRefreshRate: 1
|
||||
--- !u!1 &2157073178696562865
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -197,8 +204,9 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
ready: 0
|
||||
nbMaxClients: 10
|
||||
clientSpawnTimer: 0.5
|
||||
maxTimeNewClients: 2
|
||||
clientSpawnChance: 100
|
||||
clientFrequency: 1
|
||||
ClientRessourceFolder: Clients
|
||||
--- !u!1 &2157073179686492906
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -285,7 +293,7 @@ Transform:
|
|||
m_GameObject: {fileID: 2157073180013227982}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 4.86, y: -3.7, z: -3.6281848}
|
||||
m_LocalScale: {x: 0.1, y: 0.1, z: 0.1}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 2157073180203202247}
|
||||
m_RootOrder: 5
|
||||
|
@ -340,5 +348,6 @@ MonoBehaviour:
|
|||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
ready: 0
|
||||
serviceOpen: 0
|
||||
serviceTime: 60
|
||||
slowScale: 0.5
|
||||
|
|
|
@ -159,4 +159,5 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 6bcb4ca5242cefc4bb06adff707d9c5f, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
lifeTime: 3
|
||||
lifeTime: 20
|
||||
waitTime: 30
|
||||
|
|
|
@ -32589,10 +32589,15 @@ PrefabInstance:
|
|||
propertyPath: clientSpawnChance
|
||||
value: 100
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 2157073179837706944, guid: dfb09d229e85c1446bee2e4f9357610e,
|
||||
type: 3}
|
||||
propertyPath: m_LocalScale.x
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 2157073180203202244, guid: dfb09d229e85c1446bee2e4f9357610e,
|
||||
type: 3}
|
||||
propertyPath: serviceTime
|
||||
value: 120
|
||||
value: 60
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 2157073180203202245, guid: dfb09d229e85c1446bee2e4f9357610e,
|
||||
type: 3}
|
||||
|
@ -32677,6 +32682,16 @@ PrefabInstance:
|
|||
- target: {fileID: 7408334756516261553, guid: dfb09d229e85c1446bee2e4f9357610e,
|
||||
type: 3}
|
||||
propertyPath: spawnChance
|
||||
value: 10
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7408334756516261553, guid: dfb09d229e85c1446bee2e4f9357610e,
|
||||
type: 3}
|
||||
propertyPath: spawnChanceHard
|
||||
value: 10
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7408334756516261553, guid: dfb09d229e85c1446bee2e4f9357610e,
|
||||
type: 3}
|
||||
propertyPath: spawnChanceSoft
|
||||
value: 30
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7408334756516261553, guid: dfb09d229e85c1446bee2e4f9357610e,
|
||||
|
|
8
Assets/Scripts/Characters.meta
Normal file
8
Assets/Scripts/Characters.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 960e132629e28d84dad6b20f39361d54
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -18,56 +18,26 @@ public class Client_controller : MonoBehaviour, IUsable
|
|||
Animator animator;
|
||||
string _status;
|
||||
string _prevStatus;
|
||||
string _lastStatusRequest=null;
|
||||
// private readonly object balanceLock = new object();
|
||||
// bool updatingStatus=false;
|
||||
HashSet<string> _availStatus = new HashSet<string>(){"entering", "waiting", "consuming", "leaving", "event"};
|
||||
public string status
|
||||
{
|
||||
get{ return _status;}
|
||||
//BEWARE : Set is only a request. The status is only really set in update.
|
||||
set{
|
||||
if (_availStatus.Contains(value))
|
||||
_prevStatus=_status;
|
||||
_status = value;
|
||||
animator.SetTrigger(_status); //Update status in animator
|
||||
// Debug.Log(gameObject.name+" "+_status);
|
||||
switch (value)
|
||||
{
|
||||
case "entering":
|
||||
navObstacle.enabled = false;
|
||||
agent.enabled = true;
|
||||
if(UIWaitingTimer != null)
|
||||
UIWaitingTimer.gameObject.SetActive(false);
|
||||
break;
|
||||
case "waiting":
|
||||
EventManager.Instance.startCoroutine(gameObject);
|
||||
//Switch Agent to obstacle if waiting
|
||||
agent.Warp(assigedPos); //Make sure agent become static at right position
|
||||
agent.enabled = false;
|
||||
navObstacle.enabled = true;
|
||||
|
||||
if(UIWaitingTimer != null)
|
||||
if(value==_status)
|
||||
Debug.LogWarning(gameObject.name+" status is set twice to:"+value);
|
||||
else //Request change of status
|
||||
{
|
||||
UIWaitingTimer.DisplayIcon(true);
|
||||
UIWaitingTimer.SetValue(1.0f);
|
||||
UIWaitingTimer.gameObject.SetActive(true);
|
||||
// if(_lastStatusRequest!=null)
|
||||
// Debug.LogWarning(gameObject.name+" status request("+_lastStatusRequest+") is overriden by : "+value);
|
||||
_lastStatusRequest = value;
|
||||
}
|
||||
break;
|
||||
case "consuming":
|
||||
EventManager.Instance.startCoroutine(gameObject);
|
||||
if(UIWaitingTimer != null)
|
||||
UIWaitingTimer.gameObject.SetActive(false);
|
||||
break;
|
||||
case "event":
|
||||
case "leaving":
|
||||
EventManager.Instance.stopCoroutine(gameObject);
|
||||
navObstacle.enabled = false;
|
||||
agent.enabled = true;
|
||||
if(UIWaitingTimer != null)
|
||||
UIWaitingTimer.gameObject.SetActive(false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// navObstacle.enabled = value=="waiting";
|
||||
// agent.enabled = value!="waiting";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,6 +48,7 @@ public class Client_controller : MonoBehaviour, IUsable
|
|||
|
||||
//Navigation
|
||||
Vector2 assigedPos; //Chair to sit or destination to stay (leave)
|
||||
Vector2 currentObjective; //Current destination to reach
|
||||
NavMeshAgent agent;
|
||||
NavMeshObstacle navObstacle; //Obstacle for other agents
|
||||
|
||||
|
@ -125,21 +96,66 @@ public class Client_controller : MonoBehaviour, IUsable
|
|||
if(destination is null)
|
||||
{
|
||||
status=_prevStatus;
|
||||
// NavMeshHit hit;
|
||||
// NavMesh.SamplePosition(gameObject.transform.position, out hit, agent.height*2, NavMesh.AllAreas);
|
||||
// agent.Warp(hit.position);
|
||||
if(agent.enabled)
|
||||
agent.SetDestination(assigedPos);
|
||||
else
|
||||
gameObject.transform.position=assigedPos;
|
||||
currentObjective=assigedPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
status="event";
|
||||
agent.SetDestination((Vector2)destination);
|
||||
currentObjective=(Vector2)destination;
|
||||
}
|
||||
}
|
||||
|
||||
//Update client attributes in fonction of the newStatus. Should only be called once by Update.
|
||||
protected void updateStatus(string newStatus)
|
||||
{
|
||||
switch (newStatus)
|
||||
{
|
||||
case "entering":
|
||||
navObstacle.enabled = false;
|
||||
agent.enabled = true;
|
||||
if(UIWaitingTimer != null)
|
||||
UIWaitingTimer.gameObject.SetActive(false);
|
||||
break;
|
||||
case "waiting":
|
||||
EventManager.Instance.startCoroutine(gameObject);
|
||||
//Switch Agent to obstacle if waiting
|
||||
// agent.Warp(assigedPos); //Make sure agent become static at right position
|
||||
agent.enabled = false;
|
||||
navObstacle.enabled = true;
|
||||
|
||||
if(UIWaitingTimer != null)
|
||||
{
|
||||
UIWaitingTimer.DisplayIcon(true);
|
||||
UIWaitingTimer.gameObject.SetActive(true);
|
||||
}
|
||||
break;
|
||||
case "consuming":
|
||||
EventManager.Instance.startCoroutine(gameObject);
|
||||
if(UIWaitingTimer != null)
|
||||
UIWaitingTimer.gameObject.SetActive(false);
|
||||
break;
|
||||
case "event":
|
||||
case "leaving":
|
||||
EventManager.Instance.stopCoroutine(gameObject);
|
||||
navObstacle.enabled = false;
|
||||
agent.enabled = true;
|
||||
if(UIWaitingTimer != null)
|
||||
UIWaitingTimer.gameObject.SetActive(false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//Navigation
|
||||
if(agent.enabled) //Assign destination
|
||||
agent.SetDestination(currentObjective);
|
||||
else //Warp to destination
|
||||
gameObject.transform.position=currentObjective;
|
||||
|
||||
if(status=="event"&&!agent.enabled)
|
||||
Debug.LogWarning("Wrong status update : "+ gameObject.name + _prevStatus + status +" "+ _lastStatusRequest);
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
@ -163,8 +179,8 @@ public class Client_controller : MonoBehaviour, IUsable
|
|||
agent.updateRotation = false;
|
||||
agent.updateUpAxis = false;
|
||||
//Get target
|
||||
assigedPos = ClientManager.Instance.assignTarget(); //Chair to go
|
||||
agent.SetDestination(assigedPos);
|
||||
currentObjective = assigedPos = ClientManager.Instance.assignTarget(); //Chair to go
|
||||
// agent.SetDestination(assigedPos);
|
||||
//Assign Random priority to prevent two agent blocking each other
|
||||
agent.avoidancePriority=Random.Range(0, 99);
|
||||
|
||||
|
@ -174,8 +190,24 @@ public class Client_controller : MonoBehaviour, IUsable
|
|||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
//Update status if it was requested
|
||||
if(_lastStatusRequest !=null)
|
||||
{
|
||||
_prevStatus=_status;
|
||||
_status = _lastStatusRequest;
|
||||
|
||||
animator.SetTrigger(_status); //Update status in animator
|
||||
updateStatus(_status);
|
||||
|
||||
_lastStatusRequest = null;
|
||||
|
||||
// Debug.Log(gameObject.name+" "+_status);
|
||||
}
|
||||
|
||||
//Navigation
|
||||
// Debug.Log(gameObject.name + " navigation : "+ agent.isStopped + " " + agent.remainingDistance);
|
||||
Debug.DrawLine(gameObject.transform.position, agent.destination, Color.blue, 0.0f);
|
||||
|
||||
|
||||
if(status=="entering" && !agent.pathPending && agent.remainingDistance==0) //Reached seat ?
|
||||
{
|
||||
|
@ -193,8 +225,8 @@ public class Client_controller : MonoBehaviour, IUsable
|
|||
{
|
||||
//Leave tavern
|
||||
status = "leaving";
|
||||
assigedPos = ClientManager.Instance.assignTarget(assigedPos, true); //Request leaving target
|
||||
agent.SetDestination(assigedPos);
|
||||
currentObjective = assigedPos = ClientManager.Instance.assignTarget(assigedPos, true); //Request leaving target
|
||||
// agent.SetDestination(assigedPos);
|
||||
}
|
||||
else if(UIWaitingTimer != null) //Update UI Waiting timer
|
||||
UIWaitingTimer.SetValue(waitTimer/waitingTime);
|
||||
|
@ -228,10 +260,15 @@ public class Client_controller : MonoBehaviour, IUsable
|
|||
}
|
||||
}
|
||||
|
||||
else if(status=="leaving" && !agent.pathPending && agent.remainingDistance==0)
|
||||
else if(status=="leaving" && !agent.pathPending && agent.remainingDistance<0.5) //Reached exit ?
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
else if(status=="event" && !agent.pathPending && agent.remainingDistance==0) //Reached event ?
|
||||
{
|
||||
assignToEvent(); //In case events already finished, come back to normal
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
|
@ -10,7 +10,7 @@ using UnityEngine.AI;
|
|||
public class HardObstacle : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
float lifeTime = -1.0f; //Time before self-destruct (Negative value to prevent self-destruct)
|
||||
float lifeTime= -1.0f, waitTime= 30.0f; //Time active/waiting before self-destruct (Negative value to prevent self-destruct)
|
||||
float lifeTimer;
|
||||
|
||||
List<Client_controller> angryClients = new List<Client_controller>(); //Clients in the fight
|
||||
|
@ -25,7 +25,7 @@ public class HardObstacle : MonoBehaviour
|
|||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
lifeTimer=lifeTime;
|
||||
lifeTimer=waitTime; //Start by waiting client
|
||||
|
||||
ObsCollider = GetComponent<Collider2D>();
|
||||
|
||||
|
@ -38,15 +38,11 @@ public class HardObstacle : MonoBehaviour
|
|||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if(animator.GetBool("active fight") && lifeTimer>0)
|
||||
{
|
||||
lifeTimer -= Time.deltaTime;
|
||||
if(lifeTimer<0)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D other)
|
||||
|
@ -54,11 +50,13 @@ public class HardObstacle : MonoBehaviour
|
|||
Client_controller newClient = other.GetComponent<Client_controller>();
|
||||
if(newClient!=null && !angryClients.Contains(newClient))
|
||||
{
|
||||
angryClients.RemoveAll(item => item == null); //In case clients have been destroyed before event start, remove them
|
||||
|
||||
if(newClient.status!="event") //Make sure to set right status
|
||||
newClient.assignToEvent(gameObject.transform.position);
|
||||
angryClients.Add(newClient);
|
||||
// Debug.Log("New fighting client. Current nb : "+angryClients.Count);
|
||||
|
||||
// Debug.Log("New fighting client. Current nb : "+angryClients.Count);
|
||||
if(angryClients.Count>1)//Start fight
|
||||
{
|
||||
foreach(Client_controller client in angryClients) //Turn off client (to merge for a fight)
|
||||
|
@ -69,6 +67,8 @@ public class HardObstacle : MonoBehaviour
|
|||
//Block movement
|
||||
Obstacle.enabled=true;
|
||||
ObsCollider.isTrigger=false; //Trigger becoming solid
|
||||
|
||||
lifeTimer=lifeTime; //Time before end of the fight
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ public class HardObstacle : MonoBehaviour
|
|||
client.assignToEvent(); //Restore previous behavior
|
||||
}
|
||||
|
||||
EventManager.Instance.destroyEvent(gameObject);
|
||||
EventManager.Instance.removeEvent(gameObject);
|
||||
}
|
||||
|
||||
void OnApplicationQuit()
|
||||
|
|
|
@ -62,6 +62,6 @@ public class SoftObstacle : MonoBehaviour
|
|||
|
||||
void OnDestroy()
|
||||
{
|
||||
EventManager.Instance.destroyEvent(gameObject);
|
||||
EventManager.Instance.removeEvent(gameObject);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public sealed class EventManager : MonoBehaviour
|
|||
[SerializeField]
|
||||
float SpawnRange = 1.0f; //Range of an event spawn from its origin (real max distance = 2*range)
|
||||
[SerializeField]
|
||||
float spawnChance = 100.0f; //Probability of an event to spawn (%)
|
||||
float spawnChanceSoft = 100.0f, spawnChanceHard = 100.0f; //Probability of an event to spawn (%)
|
||||
[SerializeField]
|
||||
int maxSoftObs = 1, maxHardObs = 1; //Maximum active events
|
||||
|
||||
|
@ -39,7 +39,7 @@ public sealed class EventManager : MonoBehaviour
|
|||
private Dictionary<string,Object[]> eventPrefabs = new Dictionary<string,Object[]>();
|
||||
GameObject EventContainer=null;
|
||||
|
||||
//List of active event ID
|
||||
//List of active event
|
||||
List<GameObject> softObsList = new List<GameObject>();
|
||||
List<GameObject> hardObsList = new List<GameObject>();
|
||||
|
||||
|
@ -81,12 +81,31 @@ public sealed class EventManager : MonoBehaviour
|
|||
}
|
||||
|
||||
//Remove an event from the EventManager
|
||||
public void destroyEvent(GameObject eventObj)
|
||||
public void removeEvent(GameObject eventObj)
|
||||
{
|
||||
softObsList.Remove(eventObj);
|
||||
hardObsList.Remove(eventObj);
|
||||
}
|
||||
|
||||
//Destroy registered events. Levels : 2 = All events, 1 = Hard Obstacles
|
||||
public void cleanUp(int level=2)
|
||||
{
|
||||
if(level<1)
|
||||
Debug.Log("EventManager : Called cleanup w/ level inferior to 1. Nothing was done.");
|
||||
if(level>0) //Clean HardObstacles
|
||||
{
|
||||
foreach(GameObject obs in hardObsList)
|
||||
Destroy(obs);
|
||||
hardObsList.Clear();
|
||||
}
|
||||
if(level>1) //Clean SoftObstacles
|
||||
{
|
||||
foreach(GameObject obs in softObsList)
|
||||
Destroy(obs);
|
||||
softObsList.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
//Start an event coroutine for client
|
||||
public void startCoroutine(GameObject client)
|
||||
{
|
||||
|
@ -122,8 +141,9 @@ public sealed class EventManager : MonoBehaviour
|
|||
if(GameSystem.Instance.serviceOpen)
|
||||
{
|
||||
//Try to spawn softObs or hardObs randomly
|
||||
if(Random.value<0.5 && client.status=="consuming")
|
||||
EventManager.Instance.spawnSoftObs(clientObj.transform.position, spawnChance);
|
||||
if(Random.value<0.5f)
|
||||
if(client.status=="consuming") //Only spawn soft obs while consuming
|
||||
EventManager.Instance.spawnSoftObs(clientObj.transform.position, spawnChanceSoft);
|
||||
else
|
||||
{
|
||||
List<GameObject> otherClients = findNearClients(clientObj, 1.0f);
|
||||
|
@ -137,7 +157,7 @@ public sealed class EventManager : MonoBehaviour
|
|||
//TODO : Compute spawnChance w/ clients happiness
|
||||
Vector2 eventPos=(clientObj.transform.position+tgtClient.transform.position)/2; //Event pos between clients
|
||||
List<Client_controller> targetClients = new List<Client_controller>(){client, tgtClient.GetComponent<Client_controller>()};
|
||||
EventManager.Instance.spawnHardObs(targetClients, eventPos, spawnChance);
|
||||
EventManager.Instance.spawnHardObs(targetClients, eventPos, spawnChanceHard);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -228,5 +248,6 @@ public sealed class EventManager : MonoBehaviour
|
|||
void OnDestroy()
|
||||
{
|
||||
StopAllCoroutines();
|
||||
cleanUp();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,16 @@ public sealed class GameSystem : MonoBehaviour
|
|||
{
|
||||
serviceTimer=serviceTime;
|
||||
serviceOpen=true;
|
||||
|
||||
Debug.Log("Service open !");
|
||||
}
|
||||
|
||||
public void endService()
|
||||
{
|
||||
serviceOpen=false;
|
||||
EventManager.Instance.cleanUp(1); //Remove hard obstacle
|
||||
|
||||
Debug.Log("Service closed !");
|
||||
}
|
||||
|
||||
//Change time scale
|
||||
|
@ -127,10 +137,7 @@ public sealed class GameSystem : MonoBehaviour
|
|||
if(UIServiceTimer != null)
|
||||
UIServiceTimer.SetValue(serviceTimer/serviceTime);
|
||||
if (serviceTimer < 0)
|
||||
{
|
||||
serviceOpen = false;
|
||||
Debug.Log("Service closed");
|
||||
}
|
||||
endService();
|
||||
}
|
||||
|
||||
//Temporary manual slowmode toggle
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue