diff --git a/Project Undercover/Assets/Models/YBot/YBoyAnimator.controller b/Project Undercover/Assets/Models/YBot/YBoyAnimator.controller index c30050e..386b04a 100644 --- a/Project Undercover/Assets/Models/YBot/YBoyAnimator.controller +++ b/Project Undercover/Assets/Models/YBot/YBoyAnimator.controller @@ -13,19 +13,19 @@ AnimatorController: m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: Interrupted m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: PassingMessage m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} m_AnimatorLayers: - serializedVersion: 5 m_Name: Base Layer @@ -170,6 +170,30 @@ AnimatorStateTransition: m_InterruptionSource: 0 m_OrderedInterruption: 1 m_CanTransitionToSelf: 1 +--- !u!1101 &1101234958992700582 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: + m_Conditions: + - m_ConditionMode: 1 + m_ConditionEvent: Interrupted + m_EventTreshold: 0 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: 1102150790202348572} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0 + m_TransitionOffset: 0.00047320855 + m_ExitTime: 1.0000001 + m_HasExitTime: 0 + m_HasFixedDuration: 1 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 1 --- !u!1101 &1101240174848402812 AnimatorStateTransition: m_ObjectHideFlags: 3 @@ -279,6 +303,7 @@ AnimatorState: m_Transitions: - {fileID: 1101240174848402812} - {fileID: 1101154328280627494} + - {fileID: 1101234958992700582} m_StateMachineBehaviours: [] m_Position: {x: 50, y: 50, z: 0} m_IKOnFeet: 0 diff --git a/Project Undercover/Assets/Resources/PhotonServerSettings.asset b/Project Undercover/Assets/Resources/PhotonServerSettings.asset index ba65a14..af4e331 100644 --- a/Project Undercover/Assets/Resources/PhotonServerSettings.asset +++ b/Project Undercover/Assets/Resources/PhotonServerSettings.asset @@ -23,7 +23,7 @@ MonoBehaviour: VoiceServerPort: 5055 JoinLobby: 0 EnableLobbyStatistics: 0 - PunLogging: 1 + PunLogging: 0 NetworkLogging: 1 RunInBackground: 1 RpcList: diff --git a/Project Undercover/Assets/Resources/Spy.prefab b/Project Undercover/Assets/Resources/Spy.prefab index 87ab7aa..195dd5a 100644 --- a/Project Undercover/Assets/Resources/Spy.prefab +++ b/Project Undercover/Assets/Resources/Spy.prefab @@ -2152,7 +2152,8 @@ MonoBehaviour: _queuedInteractorId: -1 _isInteracting: 0 interactions: [] - spyInteractions: [] + spyInteractions: + - {fileID: 11400000, guid: 218e2ddac8223e349a855bdae23819ab, type: 2} currentState: {fileID: 11400000, guid: 1c694dfd46dd4e44b94f7853724fa1c0, type: 2} remainState: {fileID: 11400000, guid: 5eb84557ff3e09f42b843e0b09653774, type: 2} navMeshAgent: {fileID: 0} diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/IdleClickAction.cs b/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/IdleClickAction.cs index af1407b..1a53285 100644 --- a/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/IdleClickAction.cs +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/IdleClickAction.cs @@ -12,10 +12,16 @@ public class IdleClickAction : Action { ProgressPanelController.ActivePanel.Hide(); controller.SelectedInteraction = null; + controller.Interactor = null; + controller.SelectedObject = null; } public override void Act(StateController controller) { + // Decline interactions here + if (Input.GetKeyDown(KeyCode.D)) + controller.Interactor = null; + Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Input.GetMouseButtonDown(0)) { @@ -25,7 +31,6 @@ public class IdleClickAction : Action { // Debug.Log("Selected object set to " + selectableObject.name); controller.SelectedObject = selectableObject; - controller.Destination = selectableObject.gameObject.transform.position; return; } @@ -34,6 +39,8 @@ public class IdleClickAction : Action controller.SelectedObject = null; RaycastToMoveController(controller, ray); } + if (controller.SelectedObject && !controller.IsInteracting) + controller.Destination = controller.SelectedObject.transform.position; } // Check if StateController clicked on a Selectable Object @@ -45,7 +52,7 @@ public class IdleClickAction : Action if (Physics.Raycast(ray, out hit, 100.0f, mask)) { SelectableObject selectable = hit.collider.gameObject.GetComponentInParent(); - if (selectable != null && (StateController)selectable != controller && selectable.HasInteractions()) + if (selectable != null && selectable != controller && selectable.HasInteractions()) { selectableObject = selectable; return true; diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/PromptInteractionsAction.cs b/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/PromptInteractionsAction.cs index 886da02..5e400b9 100644 --- a/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/PromptInteractionsAction.cs +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/PromptInteractionsAction.cs @@ -10,7 +10,7 @@ public class PromptInteractionsAction : Action { string objectInteractionText = "Press 'E' to interact with "; if (ReceivedInteraction(controller)) { - InteractionPanelController.Reveal(controller.Interactor.name); + InteractionPanelController.Reveal(controller.Interactor.name/* + " is trying to " + controller.Interactor.SelectedInteraction.interactionDescription*/); } else if (SelectedObjectAvailable(controller)) { diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/SpyInteractAction.cs b/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/SpyInteractAction.cs index 6703903..a9de47e 100644 --- a/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/SpyInteractAction.cs +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/SpyInteractAction.cs @@ -6,12 +6,16 @@ public class SpyInteractAction : Action { public override void StartAct(StateController controller) { - controller.FaceSelectedObject(); controller.characterAnimator.SetTrigger(controller.SelectedInteraction.characterInteraction); + Vector3 awayDirection =(controller.transform.position - controller.SelectedObject.transform.position).normalized; + Vector3 newPos = controller.SelectedObject.transform.position + awayDirection * controller.SelectedInteraction.interactionDistance; + controller.navMeshAgent.stoppingDistance = 0.0f; + controller.Destination = newPos; } public override void Act(StateController controller) { + controller.FaceSelectedObject(); AnimatorStateInfo info = controller.animator.GetCurrentAnimatorStateInfo(0); if (info.IsName(CharacterAnimator.GetParamName(controller.SelectedInteraction.characterInteraction))) { diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/WaitForInteractionAcceptance.cs b/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/WaitForInteractionAcceptance.cs index d3c421f..c88c455 100644 --- a/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/WaitForInteractionAcceptance.cs +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/WaitForInteractionAcceptance.cs @@ -6,7 +6,7 @@ public class WaitForInteractionAcceptance : Action public override void StartAct(StateController controller) { // Todo: Remove this line once the "interaction selector" UI is finished - controller.SelectedInteraction = controller.SelectedObject.interactions[0]; + controller.SelectedInteraction = GetFirstInteraction(controller); controller.InitiateInteractionWithSelectedObject(); ProgressPanelController.ActivePanel.Reveal(controller.SelectedInteraction.interactionDescription); } @@ -15,5 +15,12 @@ public class WaitForInteractionAcceptance : Action { //Debug.Log("Finished waiting for acceptance"); } + + private Interaction GetFirstInteraction(StateController controller) + { + if (controller.SelectedObject.interactions.Length > 0) + return controller.SelectedObject.interactions[0]; + return controller.SelectedObject.spyInteractions[0]; + } } diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/WaitInPlaceAction.cs b/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/WaitInPlaceAction.cs index 20403e4..346d0a8 100644 --- a/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/WaitInPlaceAction.cs +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/ActionScripts/WaitInPlaceAction.cs @@ -8,13 +8,22 @@ public class WaitInPlaceAction : Action { public override void StartAct(StateController controller) { // Debug.Log("Waiting in place!"); - controller.FaceInteractor(); + if (!controller.IsInteracting) + controller.IsInteracting = true; controller.Destination = controller.transform.position; } + public override void Act(StateController controller) + { + controller.FaceInteractor(); + } + public override void EndAct(StateController controller) { // Debug.Log("Done waiting in place!"); + if (controller.characterAnimator.GetTrigger(CharacterAnimator.Params.Interrupted)) + controller.Interactor.characterAnimator.SetTrigger(CharacterAnimator.Params.Interrupted); + controller.Interactor = null; } } diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/InitiatedInteractionDecision.cs b/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/InitiatedInteractionDecision.cs index 05fad40..128b1a6 100644 --- a/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/InitiatedInteractionDecision.cs +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/InitiatedInteractionDecision.cs @@ -9,8 +9,6 @@ public class InitiatedInteractionDecision : Decision { return Input.GetKeyDown(KeyCode.E) && InteractionPanelController.InteractionPrompted() && - controller.SelectedObject != null;/* && - !controller.SelectedObject.IsInteracting && - controller.SelectedObject.Interactor == null;*/ + controller.SelectedObject != null; } } \ No newline at end of file diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/InteractionAcceptedDecision.cs b/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/ObjectAcceptedInteractionDecision.cs similarity index 58% rename from Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/InteractionAcceptedDecision.cs rename to Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/ObjectAcceptedInteractionDecision.cs index 45ee5da..c33585d 100644 --- a/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/InteractionAcceptedDecision.cs +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/ObjectAcceptedInteractionDecision.cs @@ -2,8 +2,8 @@ using System.Collections.Generic; using UnityEngine; -[CreateAssetMenu(menuName = "CharacterStateMachine/Decisions/InteractionAccepted")] -public class InteractionAcceptedDecision : Decision +[CreateAssetMenu(menuName = "CharacterStateMachine/Decisions/ObjectAcceptedInteraction")] +public class ObjectAcceptedInteractionDecision : Decision { public override bool Decide(StateController controller) { diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/InteractionAcceptedDecision.cs.meta b/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/ObjectAcceptedInteractionDecision.cs.meta similarity index 100% rename from Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/InteractionAcceptedDecision.cs.meta rename to Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/ObjectAcceptedInteractionDecision.cs.meta diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/ObjectDeclinedInteractionDecision.cs b/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/ObjectDeclinedInteractionDecision.cs new file mode 100644 index 0000000..21a9d99 --- /dev/null +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/ObjectDeclinedInteractionDecision.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; + +[CreateAssetMenu(menuName = "CharacterStateMachine/Decisions/ObjectDeclinedInteraction")] +class ObjectDeclinedInteractionDecision : Decision +{ + public override bool Decide(StateController controller) + { + return controller.IsInteractionRejected(); + } +} + diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/ObjectDeclinedInteractionDecision.cs.meta b/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/ObjectDeclinedInteractionDecision.cs.meta new file mode 100644 index 0000000..d5bcd75 --- /dev/null +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/ObjectDeclinedInteractionDecision.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: bf964d8e3b4f70d4187bbc4b0e7061db +timeCreated: 1507493070 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/WaitForTransitionDecision.cs b/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/WaitForTransitionDecision.cs index 6fdd758..adb3a02 100644 --- a/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/WaitForTransitionDecision.cs +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/WaitForTransitionDecision.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using UnityEngine; -[CreateAssetMenu(menuName = "CharacterStateMachine/Decisions/WaitForAnimation")] +[CreateAssetMenu(menuName = "CharacterStateMachine/Decisions/WaitForTransition")] public class WaitForTransitionDecision : Decision { public string fromState, toState; @@ -13,6 +13,7 @@ public class WaitForTransitionDecision : Decision var currentTransition = controller.animator.GetAnimatorTransitionInfo(0); if (currentTransition.IsName(transitionName)) { + controller.SelectedInteraction.ExecuteResult(controller); return true; } return false; diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/YouAcceptedInteractionDecision.cs b/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/YouAcceptedInteractionDecision.cs new file mode 100644 index 0000000..c2fa1a7 --- /dev/null +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/YouAcceptedInteractionDecision.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; + +[CreateAssetMenu(menuName = "CharacterStateMachine/Decisions/YouAcceptedInteraction")] +class YouAcceptedInteractionDecision : Decision +{ + public override bool Decide(StateController controller) + { + if (Input.GetKeyDown(KeyCode.E)) + return controller.Interactor != null; + return false; + } +} + diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/YouAcceptedInteractionDecision.cs.meta b/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/YouAcceptedInteractionDecision.cs.meta new file mode 100644 index 0000000..a0f2412 --- /dev/null +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/DecisionScripts/YouAcceptedInteractionDecision.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: fe5a2c8c5f93bef4aafc593da5decd3b +timeCreated: 1507361522 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/Interfaces/Interaction.cs b/Project Undercover/Assets/Scripts/CharacterStateMachine/Interfaces/Interaction.cs index d872995..6815f8e 100644 --- a/Project Undercover/Assets/Scripts/CharacterStateMachine/Interfaces/Interaction.cs +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/Interfaces/Interaction.cs @@ -7,9 +7,33 @@ public class Interaction : ScriptableObject public string interactionDescription; public CharacterAnimator.Params characterInteraction; public InteractionResult result; + public float initialRotation; + public float objectInitialRotation; + public float interactionDistance = 1.0f; public enum InteractionResult { Nothing, SpyMissionComplete } + + public void ExecuteResult(StateController controller) + { + switch(result) + { + case InteractionResult.Nothing: + break; + case InteractionResult.SpyMissionComplete: + SpyMissionComplete(controller); + break; + default: + Debug.LogError("Invalid result selected for execution"); + break; + } + } + + //--------------------------------- Result functions --------------------------------- + void SpyMissionComplete(StateController controller) + { + Debug.Log("Completed mission"); + } } diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/Interfaces/SelectableObject.cs b/Project Undercover/Assets/Scripts/CharacterStateMachine/Interfaces/SelectableObject.cs index 3fc8911..fc08303 100644 --- a/Project Undercover/Assets/Scripts/CharacterStateMachine/Interfaces/SelectableObject.cs +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/Interfaces/SelectableObject.cs @@ -1,8 +1,9 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using UnityEngine; -public abstract class SelectableObject : Photon.PunBehaviour +public abstract class SelectableObject : Photon.PunBehaviour, IEquatable { // PhotonView Id of interacting character [SerializeField] @@ -99,4 +100,9 @@ public abstract class SelectableObject : Photon.PunBehaviour { _queuedInteractorId = viewId; } + + public virtual bool Equals(SelectableObject other) + { + return photonView.viewID == other.photonView.viewID; + } } diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/InteractionAccepted.asset b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/ObjectAcceptedInteraction.asset similarity index 90% rename from Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/InteractionAccepted.asset rename to Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/ObjectAcceptedInteraction.asset index c9b08d7..03d7ddf 100644 --- a/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/InteractionAccepted.asset +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/ObjectAcceptedInteraction.asset @@ -9,5 +9,5 @@ MonoBehaviour: m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 3f9fa98245568d74ca9c5ea641087346, type: 3} - m_Name: InteractionAccepted + m_Name: ObjectAcceptedInteraction m_EditorClassIdentifier: diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/InteractionAccepted.asset.meta b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/ObjectAcceptedInteraction.asset.meta similarity index 100% rename from Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/InteractionAccepted.asset.meta rename to Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/ObjectAcceptedInteraction.asset.meta diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/RemainState.asset b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/ObjectDeclinedInteraction.asset similarity index 66% rename from Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/RemainState.asset rename to Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/ObjectDeclinedInteraction.asset index 52908d5..942ff3f 100644 --- a/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/RemainState.asset +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/ObjectDeclinedInteraction.asset @@ -8,8 +8,6 @@ MonoBehaviour: m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 5a6a367e35acd7e44a0a598eaa1d6700, type: 3} - m_Name: RemainState + m_Script: {fileID: 11500000, guid: bf964d8e3b4f70d4187bbc4b0e7061db, type: 3} + m_Name: ObjectDeclinedInteraction m_EditorClassIdentifier: - actions: [] - transitions: [] diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/RemainState.asset.meta b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/ObjectDeclinedInteraction.asset.meta similarity index 69% rename from Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/RemainState.asset.meta rename to Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/ObjectDeclinedInteraction.asset.meta index b27b4f2..8603822 100644 --- a/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/RemainState.asset.meta +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/ObjectDeclinedInteraction.asset.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 5eb84557ff3e09f42b843e0b09653774 -timeCreated: 1506923361 +guid: a3e30efde30a6294ba3fee0fa08b7417 +timeCreated: 1507493116 licenseType: Free NativeFormatImporter: mainObjectFileID: 11400000 diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/InteractionCompleted.asset b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/YouAcceptedInteraction.asset similarity index 69% rename from Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/InteractionCompleted.asset rename to Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/YouAcceptedInteraction.asset index 1577ca0..b3b8ccb 100644 --- a/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/InteractionCompleted.asset +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/YouAcceptedInteraction.asset @@ -8,6 +8,6 @@ MonoBehaviour: m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 56a0f4e2f06493a4e97f596ad8d0ead1, type: 3} - m_Name: InteractionCompleted + m_Script: {fileID: 11500000, guid: fe5a2c8c5f93bef4aafc593da5decd3b, type: 3} + m_Name: YouAcceptedInteraction m_EditorClassIdentifier: diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/InteractionCompleted.asset.meta b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/YouAcceptedInteraction.asset.meta similarity index 69% rename from Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/InteractionCompleted.asset.meta rename to Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/YouAcceptedInteraction.asset.meta index 91124ed..7be9ad6 100644 --- a/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/InteractionCompleted.asset.meta +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Decisions/Player/YouAcceptedInteraction.asset.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: b7c91a8a56fb7a54abe6a9098297f8bb -timeCreated: 1507182216 +guid: 4e6653d3fb6849f408ed8adb9005a439 +timeCreated: 1507362010 licenseType: Free NativeFormatImporter: mainObjectFileID: 11400000 diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/Interactions.meta b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Interactions.meta similarity index 100% rename from Project Undercover/Assets/Scripts/CharacterStateMachine/Interactions.meta rename to Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Interactions.meta diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/Interactions/TellSecret.asset b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Interactions/TellSecret.asset similarity index 87% rename from Project Undercover/Assets/Scripts/CharacterStateMachine/Interactions/TellSecret.asset rename to Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Interactions/TellSecret.asset index 84de706..1b63288 100644 --- a/Project Undercover/Assets/Scripts/CharacterStateMachine/Interactions/TellSecret.asset +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Interactions/TellSecret.asset @@ -13,4 +13,6 @@ MonoBehaviour: m_EditorClassIdentifier: interactionDescription: Telling Secret... characterInteraction: 1 - result: 0 + result: 1 + initialRotation: -60 + objectInitialRotation: -60 diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/Interactions/TellSecret.asset.meta b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Interactions/TellSecret.asset.meta similarity index 100% rename from Project Undercover/Assets/Scripts/CharacterStateMachine/Interactions/TellSecret.asset.meta rename to Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/Interactions/TellSecret.asset.meta diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/Idle.asset b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/Idle.asset index eabb192..93ab7f7 100644 --- a/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/Idle.asset +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/Idle.asset @@ -17,4 +17,7 @@ MonoBehaviour: transitions: - decision: {fileID: 11400000, guid: ce72eaa68e3e07147a3aa891ff8f4a13, type: 2} trueState: {fileID: 11400000, guid: ed2af5dc9d7af8b4580705c19d61fb57, type: 2} - falseState: {fileID: 11400000, guid: 5eb84557ff3e09f42b843e0b09653774, type: 2} + transitionValue: 1 + - decision: {fileID: 11400000, guid: 4e6653d3fb6849f408ed8adb9005a439, type: 2} + trueState: {fileID: 11400000, guid: 32814da7acb45a64792eaf699c6043da, type: 2} + transitionValue: 1 diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/WaitingForAcceptance.asset b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/WaitingForAcceptance.asset index eace114..62d28ad 100644 --- a/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/WaitingForAcceptance.asset +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/WaitingForAcceptance.asset @@ -21,3 +21,6 @@ MonoBehaviour: - decision: {fileID: 11400000, guid: d1e5ed22b1756104794e4cdad03e7bd0, type: 2} trueState: {fileID: 11400000, guid: f92df2056f917ce45921c2f8b94c75dd, type: 2} transitionValue: 1 + - decision: {fileID: 11400000, guid: a3e30efde30a6294ba3fee0fa08b7417, type: 2} + trueState: {fileID: 11400000, guid: 1c694dfd46dd4e44b94f7853724fa1c0, type: 2} + transitionValue: 1 diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/WaitingForOtherToCompleteInteraction.asset b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/WaitingForOtherToCompleteInteraction.asset new file mode 100644 index 0000000..d9618db --- /dev/null +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/WaitingForOtherToCompleteInteraction.asset @@ -0,0 +1,23 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5a6a367e35acd7e44a0a598eaa1d6700, type: 3} + m_Name: WaitingForOtherToCompleteInteraction + m_EditorClassIdentifier: + actions: + - {fileID: 11400000, guid: b241bf77cda4ed84992fa09741f347ef, type: 2} + - {fileID: 11400000, guid: a239cb93f4d18fa4baf7a01d44718dbb, type: 2} + transitions: + - decision: {fileID: 11400000, guid: aca961c852aa698469b7c4d36142c175, type: 2} + trueState: {fileID: 11400000, guid: 1c694dfd46dd4e44b94f7853724fa1c0, type: 2} + transitionValue: 0 + - decision: {fileID: 11400000, guid: 54c4574724be54540892c8db5aff93d1, type: 2} + trueState: {fileID: 11400000, guid: 1c694dfd46dd4e44b94f7853724fa1c0, type: 2} + transitionValue: 1 diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/WaitingForOtherToCompleteInteraction.asset.meta b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/WaitingForOtherToCompleteInteraction.asset.meta new file mode 100644 index 0000000..0c79a91 --- /dev/null +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/ScriptableObjects/States/Player/WaitingForOtherToCompleteInteraction.asset.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 32814da7acb45a64792eaf699c6043da +timeCreated: 1507361581 +licenseType: Free +NativeFormatImporter: + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Project Undercover/Assets/Scripts/CharacterStateMachine/StateController.cs b/Project Undercover/Assets/Scripts/CharacterStateMachine/StateController.cs index cba7dc1..5c5bc2d 100644 --- a/Project Undercover/Assets/Scripts/CharacterStateMachine/StateController.cs +++ b/Project Undercover/Assets/Scripts/CharacterStateMachine/StateController.cs @@ -19,6 +19,8 @@ public class StateController : SelectableObject private SelectableObject _selectedObject; private Interaction _selectedInteraction; private Coroutine _roamCoroutine; + private static float _startInteractionProgressLimit = 0.3f; + private static float _endInteractionProgressLimit = 0.8f; void Awake() @@ -44,8 +46,6 @@ public class StateController : SelectableObject if (photonView.isMine) { currentState.UpdateState(this); - if (SelectedObject) - Destination = SelectedObject.transform.position; } } @@ -143,12 +143,22 @@ public class StateController : SelectableObject { return IsInteracting && SelectedObject.IsInteracting && SelectedObject.Interactor == this; } + public bool IsInteractionRejected() + { + return SelectedObject.Interactor != this; + } + public void FinishInteraction() { - IsInteracting = false; - SelectedObject.Interactor = null; - SelectedObject = null; + if (IsInteracting) + IsInteracting = false; + if (SelectedObject) + { + if (SelectedObject.IsInteracting) + SelectedObject.IsInteracting = false; + SelectedObject = null; + } } public Interaction SelectedInteraction @@ -163,22 +173,6 @@ public class StateController : SelectableObject } } - public void FaceInteractor() - { - if (Interactor == null) - Debug.LogError("Cannot face a null Interactor"); - - transform.LookAt(Interactor.transform); - } - - public void FaceSelectedObject() - { - if (SelectedObject == null) - Debug.LogError("Cannot face a null SelectedObject"); - - transform.LookAt(SelectedObject.transform); - } - public void StartRoaming() { _roamCoroutine = StartCoroutine(Roam()); @@ -197,4 +191,45 @@ public class StateController : SelectableObject Destination = GetRandomLocation(); } } + + public void FaceSelectedObject() + { + float progress = animator.GetCurrentAnimatorStateInfo(0).normalizedTime; + Vector3 otherPos = SelectedObject.transform.position; + float initialRotation = SelectedInteraction.initialRotation; + SetFacingRotation(otherPos, progress, initialRotation); + } + + public void FaceInteractor() + { + if (Interactor == null) + Debug.LogError("Cannot face a null Interactor"); + + float progress = Interactor.animator.GetCurrentAnimatorStateInfo(0).normalizedTime; + Vector3 otherPos = Interactor.transform.position; + if (Interactor.SelectedInteraction == null) + return; + float initialRotation = Interactor.SelectedInteraction.objectInitialRotation; + SetFacingRotation(otherPos, progress, initialRotation); + } + + private void SetFacingRotation(Vector3 otherPos, float progress, float initialRotation) + { + if (progress > _startInteractionProgressLimit && progress < _endInteractionProgressLimit) + return; + + Vector3 pos = transform.position; + Vector3 facingDirection = (otherPos - pos).normalized; + Quaternion facingRotation = Quaternion.FromToRotation(Vector3.forward, facingDirection); + + if (progress < _startInteractionProgressLimit) + { + Quaternion adjustedRotation = facingRotation * Quaternion.Euler(0, initialRotation, 0); + transform.rotation = Quaternion.Slerp(transform.rotation, adjustedRotation, Time.deltaTime * 5.0f); + } + else + { + transform.rotation = Quaternion.Slerp(transform.rotation, facingRotation, Time.deltaTime * 5.0f); + } + } }