character interactions are good yo

This commit is contained in:
Steven 2017-10-10 12:43:11 -05:00
parent c2d8c78028
commit 21397a8ee4
23 changed files with 222 additions and 22 deletions

View file

@ -0,0 +1,13 @@
%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: 3a68114b6ee7c444a90e241327d93bdc, type: 3}
m_Name: NpcApproachingTarget
m_EditorClassIdentifier:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 9d5f7cb18596843449c520a3adde576a
timeCreated: 1507654071
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,7 +1,7 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: aed8389bb6c1d4d49ad5bf1d04d7be17 guid: aed8389bb6c1d4d49ad5bf1d04d7be17
folderAsset: yes folderAsset: yes
timeCreated: 1506987054 timeCreated: 1507593469
licenseType: Free licenseType: Free
DefaultImporter: DefaultImporter:
userData: userData:

View file

@ -0,0 +1,13 @@
%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: 5087e9722bba7ee478933f94f035b990, type: 3}
m_Name: ObjectAlreadyHasInteractor
m_EditorClassIdentifier:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 4078502a092bd9a41be210395f51aef0
timeCreated: 1507653787
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,13 @@
%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: f3ee18a0ee4867f4980c76b7ceb7d74e, type: 3}
m_Name: ObjectInRangeAndAvailable
m_EditorClassIdentifier:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 5b77ad8a89f818e47be8530f8148553b
timeCreated: 1507653546
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,25 @@
%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: NpcApproachingTarget
m_EditorClassIdentifier:
actions:
- {fileID: 11400000, guid: 9d5f7cb18596843449c520a3adde576a, type: 2}
transitions:
- decision: {fileID: 11400000, guid: 5b77ad8a89f818e47be8530f8148553b, type: 2}
trueState: {fileID: 11400000, guid: a70ae0bc5f16c9648ab8c7b1963547ac, type: 2}
transitionValue: 1
- decision: {fileID: 11400000, guid: 010846579b426744d84ebd4f5f2ce837, type: 2}
trueState: {fileID: 11400000, guid: 963f4d74f828ef94d85740708e8ce1d0, type: 2}
transitionValue: 1
- decision: {fileID: 11400000, guid: 4078502a092bd9a41be210395f51aef0, type: 2}
trueState: {fileID: 11400000, guid: 78ec31c429ad5074bb50d001b1a49a77, type: 2}
transitionValue: 1

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 67adff9f9e4c58941b86d56c6faaade4
timeCreated: 1507653176
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -18,5 +18,5 @@ MonoBehaviour:
trueState: {fileID: 11400000, guid: 963f4d74f828ef94d85740708e8ce1d0, type: 2} trueState: {fileID: 11400000, guid: 963f4d74f828ef94d85740708e8ce1d0, type: 2}
transitionValue: 1 transitionValue: 1
- decision: {fileID: 11400000, guid: c14d2053399388247b9cfde51ce5f57c, type: 2} - decision: {fileID: 11400000, guid: c14d2053399388247b9cfde51ce5f57c, type: 2}
trueState: {fileID: 11400000, guid: a70ae0bc5f16c9648ab8c7b1963547ac, type: 2} trueState: {fileID: 11400000, guid: 67adff9f9e4c58941b86d56c6faaade4, type: 2}
transitionValue: 1 transitionValue: 1

View file

@ -1598,7 +1598,7 @@ MonoBehaviour:
NPCPrefab: {fileID: 1249949894527080, guid: ea4aade53c5c4714b8b9c335e8100cf0, type: 2} NPCPrefab: {fileID: 1249949894527080, guid: ea4aade53c5c4714b8b9c335e8100cf0, type: 2}
cameraRigPrefab: {fileID: 1009033979625728, guid: 1764211b5690c164d82aa46fa4ec707d, cameraRigPrefab: {fileID: 1009033979625728, guid: 1764211b5690c164d82aa46fa4ec707d,
type: 2} type: 2}
numNpcs: 5 numNpcs: 10
spyMissionsComplete: 0 spyMissionsComplete: 0
waitBetweenMissions: 5 waitBetweenMissions: 5
onMissionCooldown: 0 onMissionCooldown: 0

View file

@ -0,0 +1,21 @@
using System;
using UnityEngine;
[CreateAssetMenu(menuName = "CharacterStateMachine/Actions/NpcApproachingTarget")]
public class NpcApproachingTargetAction : Action
{
public override void StartAct(StateController controller)
{
//Debug.Log("Approaching object");
}
public override void Act(StateController controller)
{
controller.Destination = controller.SelectedObject.transform.position;
}
public override void EndAct(StateController controller)
{
//Debug.Log("No longer approaching object");
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 3a68114b6ee7c444a90e241327d93bdc
timeCreated: 1507654026
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,7 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine; using UnityEngine;
[CreateAssetMenu(menuName = "CharacterStateMachine/Actions/NpcWaitForInteractionAcceptance")] [CreateAssetMenu(menuName = "CharacterStateMachine/Actions/NpcWaitForInteractionAcceptance")]
@ -11,7 +8,6 @@ public class NpcWaitForInteractionAcceptanceAction : Action
public override void StartAct(StateController controller) public override void StartAct(StateController controller)
{ {
controller.InitiateInteractionWithSelectedObject(); controller.InitiateInteractionWithSelectedObject();
//controller.Destination = controller.SelectedObject.transform.position;
} }
} }

View file

@ -7,9 +7,15 @@ public class RoamAction : Action
{ {
public override void StartAct(StateController controller) public override void StartAct(StateController controller)
{ {
// Debug.Log("Started Roaming");
controller.StartRoaming(); controller.StartRoaming();
controller.characterAnimator.SetBool(CharacterAnimator.Params.Interacting, false); controller.characterAnimator.SetBool(CharacterAnimator.Params.Interacting, false);
if (controller.SelectedObject)
{
controller.SelectedObject.IsInteracting = false;
controller.SelectedObject = null;
}
if (controller.IsInteracting)
controller.IsInteracting = false;
} }
public override void Act(StateController controller) public override void Act(StateController controller)

View file

@ -0,0 +1,12 @@
using UnityEngine;
[CreateAssetMenu(menuName = "CharacterStateMachine/Decisions/ObjectAlreadyHasInteractor")]
public class ObjectAlreadyHasInteractorDecision : Decision
{
public override bool Decide(StateController controller)
{
if (controller.SelectedObject.Interactor != null)
return controller.SelectedObject.Interactor != controller;
return false;
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5087e9722bba7ee478933f94f035b990
timeCreated: 1507653758
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
[CreateAssetMenu(menuName = "CharacterStateMachine/Decisions/ObjectInRangeAndAvailable")]
public class ObjectInRangeAndAvailableDecision : Decision
{
public override bool Decide(StateController controller)
{
return controller.InRangeOfSelectedObject() && controller.SelectedObject.Interactor == null;
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f3ee18a0ee4867f4980c76b7ceb7d74e
timeCreated: 1507653505
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -18,11 +18,16 @@ public class Interaction : ScriptableObject
{ {
Nothing, SpyMissionComplete Nothing, SpyMissionComplete
} }
/*
public override int GetHashCode() public int GetHash()
{ {
return interactionDescription.GetHashCode() ^ (int)characterInteraction; return interactionDescription.Length + (int)initiatorAnimationTrigger + (int)objectAnimationTrigger;
}*/ }
public bool CompareHash(int hash)
{
return hash == GetHash();
}
public void ExecuteResult(StateController controller) public void ExecuteResult(StateController controller)
{ {

View file

@ -180,7 +180,6 @@ public abstract class SelectableObject : Photon.PunBehaviour, IEquatable<Selecta
public void AcceptInteraction() public void AcceptInteraction()
{ {
Debug.Log("Accepted Interaction");
IsInteracting = true; IsInteracting = true;
} }

View file

@ -90,7 +90,7 @@ public class StateController : SelectableObject
Debug.LogError("Attempted to set interactor as self"); Debug.LogError("Attempted to set interactor as self");
if (SelectedObject.IsInteracting) if (SelectedObject.IsInteracting)
Debug.Log(SelectedObject.name + " is busy and cannot interact with " + name); return;
// Debug.Log("Sending interaction request..."); // Debug.Log("Sending interaction request...");
IsInteracting = true; IsInteracting = true;
@ -174,7 +174,7 @@ public class StateController : SelectableObject
{ {
int hash = 0; int hash = 0;
if (value != null) if (value != null)
hash = value.GetHashCode(); hash = value.GetHash();
photonView.RPC("SetSelectedInteractionRPC", PhotonTargets.All, hash); photonView.RPC("SetSelectedInteractionRPC", PhotonTargets.All, hash);
} }
} }
@ -185,7 +185,7 @@ public class StateController : SelectableObject
Interaction[] foundInteractions = (Interaction[])Resources.FindObjectsOfTypeAll(typeof(Interaction)); Interaction[] foundInteractions = (Interaction[])Resources.FindObjectsOfTypeAll(typeof(Interaction));
foreach (var interaction in foundInteractions) foreach (var interaction in foundInteractions)
{ {
if (interaction.GetHashCode() == hash) if (interaction.CompareHash(hash))
{ {
_selectedInteraction = interaction; _selectedInteraction = interaction;
return; return;
@ -208,10 +208,10 @@ public class StateController : SelectableObject
{ {
while (true) while (true)
{ {
yield return new WaitForSeconds(UnityEngine.Random.value * 2.0f + 2.0f); yield return new WaitForSeconds(UnityEngine.Random.value * 10.0f + 0.5f);
if (IsInteracting) if (IsInteracting)
Debug.LogError("Should have stopped this coroutine by now"); Debug.LogError("Should have stopped this coroutine by now");
if (UnityEngine.Random.value > 0.5f) if (UnityEngine.Random.value < 0.2f)
{ {
SelectableObject randomObject = GetRandomAvailableSelectableObject(); SelectableObject randomObject = GetRandomAvailableSelectableObject();
if (randomObject != null) if (randomObject != null)
@ -220,7 +220,6 @@ public class StateController : SelectableObject
IsInteracting = true; IsInteracting = true;
Interaction randomInteraction = SelectedObject.GetRandomNpcInteraction(); Interaction randomInteraction = SelectedObject.GetRandomNpcInteraction();
SelectedInteraction = randomInteraction; SelectedInteraction = randomInteraction;
Debug.Log(SelectedObject.name);
yield return null; yield return null;
} }
} }
@ -291,4 +290,9 @@ public class StateController : SelectableObject
navMeshAgent.stoppingDistance = 0.0f; navMeshAgent.stoppingDistance = 0.0f;
Destination = newPos; Destination = newPos;
} }
public bool InRangeOfSelectedObject()
{
return (SelectedObject.transform.position - transform.position).magnitude < INTERACT_RANGE;
}
} }

View file

@ -48,17 +48,22 @@ public class InteractionPanelController : MonoBehaviour {
if (mainPanel.activeInHierarchy) if (mainPanel.activeInHierarchy)
return; return;
interactionsDropdown.ClearOptions(); interactionsDropdown.ClearOptions();
var optionsList = new List<Dropdown.OptionData>(); var optionsList = new List<Dropdown.OptionData>();
foreach (Interaction interaction in controller.SelectedObject.interactions) foreach (Interaction interaction in controller.SelectedObject.interactions)
{ {
var data = new InteractionData(interaction, false); var data = new InteractionData(interaction, false);
optionsList.Add(data); optionsList.Add(data);
} }
foreach (Interaction interaction in controller.SelectedObject.spyInteractions) if (controller.SelectedObject.CompareTag("Spy"))
{ {
var data = new InteractionData(interaction, true); foreach (Interaction interaction in controller.SelectedObject.spyInteractions)
optionsList.Add(data); {
var data = new InteractionData(interaction, true);
optionsList.Add(data);
}
} }
interactionsDropdown.AddOptions(optionsList); interactionsDropdown.AddOptions(optionsList);
_controller.SelectedInteraction = ((InteractionData)(interactionsDropdown.options[interactionsDropdown.value])).interaction; _controller.SelectedInteraction = ((InteractionData)(interactionsDropdown.options[interactionsDropdown.value])).interaction;
ActivePanel.mainPanel.SetActive(true); ActivePanel.mainPanel.SetActive(true);