Skip to content
Snippets Groups Projects
Commit 9baa9c32 authored by John Schihada's avatar John Schihada
Browse files

Added Task-Character

parent ccc88541
No related branches found
No related tags found
No related merge requests found
Showing
with 513 additions and 10 deletions
fileFormatVersion: 2 fileFormatVersion: 2
guid: b543d9677cbde534ab69c0a229bfdb06 guid: d04998951e922ab44afeb4969ab855d5
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using static TaskCharakterAnimation;
public class CharacterDialog : MonoBehaviour
{
public TextMeshPro textDisplay;
public TextMeshPro textHint;
public string[] sentences;
private int index;
//speed for typing the Text
public float typingSpeed;
//Only reset once after Player is out of range of the TaskCharacter
private bool textReseted = true;
//If pushoutSucceeded -> Disable Talking with TaskCharacter
private bool pushoutSucceeded = false;
// Start is called before the first frame update
void Start()
{
CommunicationEvents.PushoutFactEvent.AddListener(PushoutSucceededSentence);
//Type first sentence
StartCoroutine(Type());
}
private void Update()
{
if(!pushoutSucceeded && Input.GetKeyDown(KeyCode.Return) && TaskCharakterAnimation.getPlayerInTalkingZone())
{
//Type Next sentence if player is in the talkinZone around the TaskCharacter AND the player typed the return-Key
NextSentence();
}
else if (!pushoutSucceeded && !TaskCharakterAnimation.getPlayerInTalkingZone() && !textReseted)
{
//Reset Sentence if Player is out of range of the TaskCharacter and it's not already reseted
ResetSentence();
}
}
//Type a sentence slowly
IEnumerator Type() {
foreach (char letter in sentences[index].ToCharArray()) {
textDisplay.text += letter;
yield return new WaitForSeconds(typingSpeed);
}
}
public void NextSentence() {
//-2 because the last sentence is only for SucceededPushout-Purposes
if (index < sentences.Length - 2)
{
index++;
textDisplay.text = "";
StartCoroutine(Type());
textReseted = false;
}
else {
textDisplay.text = "";
}
}
public void ResetSentence() {
index = 0;
textDisplay.text = "";
//Type first sentence again
StartCoroutine(Type());
textReseted = true;
}
public void PushoutSucceededSentence(Fact startFact) {
textDisplay.text = "";
//Last Sentence is the Pushout-Sentence
index = sentences.Length - 1;
pushoutSucceeded = true;
//Disable Hint With Enter-Key for Talking
textHint.GetComponent<MeshRenderer>().enabled = false;
//Type final message
StartCoroutine(Type());
}
}
fileFormatVersion: 2
guid: e3fcfba3e8441b64582de85e4b5517e0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TaskCharakterAnimation : MonoBehaviour
{
public GameObject walkAroundObject;
public GameObject player;
public float radiusAroundObject;
private Animator anim;
private Transform currentTransform;
private float currentDistance;
private float walkingTime = 5;
private bool walking = true;
private float standingTime = 3;
private bool standing = false;
private float timer = 0;
private bool rotate = false;
private float nextRotation = 0;
private float rotationUnits = 0;
private float rotationTime = 2;
private bool happy = false;
private static bool playerInTalkingZone = false;
// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator>();
currentTransform = GetComponent<Transform>();
CommunicationEvents.PushoutFactEvent.AddListener(startHappy);
CommunicationEvents.PushoutFactEndEvent.AddListener(stopHappy);
}
// Update is called once per frame
void Update()
{
//Do nothing else than the animation if animationController is in happy-State
if (happy)
return;
RaycastHit hit;
Ray ray = new Ray(player.transform.position, player.transform.forward);
int layerMask = LayerMask.GetMask("TalkingZone"); //only hit TalkingZone
//If Player is in TalkingZone: TaskCharacter should look to the Player, stop walking and enable enter-key for talking
if (Physics.Raycast(ray, out hit, 5f, layerMask))
{
this.walking = false;
this.standing = true;
this.timer = 0;
//Change boolean for switching to Standing-State in AnimationController
anim.SetBool("standing", true);
//Enable enter-key for talking
setPlayerInTalkingZone(true);
//Face walkAroundObject to Player (but only on y-Axis, so ignore x-and z-axis)
currentTransform.LookAt(new Vector3(player.transform.position.x, currentTransform.position.y, player.transform.position.z));
return;
}
else {
//disable enter-key for talking
setPlayerInTalkingZone(false);
}
//Calculate distance from tree, so that the TaskCharacter only walks in a specific radius around the tree
//so that the player always knows where he is
currentDistance = (currentTransform.position - walkAroundObject.transform.position).magnitude;
//Turn on the radius-edges around the radiusAroundObject
if (currentDistance > radiusAroundObject)
{
//Change roation if TaskCharacter is at the edges of the radius
currentTransform.RotateAround(currentTransform.position, Vector3.up, 30 * Time.deltaTime);
//return, because at the radius-edges we only want to rotate without standing/walking
return;
}
this.timer += Time.deltaTime;
if (rotate)
{
if (this.timer <= rotationTime)
{
//Change to random direction after standing-state
currentTransform.RotateAround(currentTransform.position, Vector3.up, rotationUnits);
}
else {
//After rotating: Change to Walking-State
rotate = false;
this.timer = 0;
//Change boolean for switching to Walking-State in AnimationController
anim.SetBool("standing", false);
}
}
else
{
//If walking-time is over -> Change to standing-state
if (walking && !standing)
{
if (this.timer >= this.walkingTime)
{
this.walking = false;
this.standing = true;
this.timer = 0;
//Change boolean for switching to Standing-State in AnimationController
anim.SetBool("standing", true);
}
}
else
{
//If standingTime is over: Change to walking-state, but before set rotate=true for rotating before walking
if (this.timer >= this.standingTime)
{
this.standing = false;
this.walking = true;
this.timer = 0;
//Rotate Character randomly
nextRotation = Random.Range(0, 180);
int positive = (int)Random.Range(0, 2);
if (positive == 0)
nextRotation *= -1;
rotationUnits = nextRotation / (rotationTime/Time.deltaTime);
rotate = true;
}
}
}
}
public void startHappy(Fact startFact)
{
//Set Variable in animationController to change the state
anim.SetBool("solved", true);
happy = true;
}
public void stopHappy(Fact startFact) {
//Set Variable in animationController to change the state
anim.SetBool("solved", false);
happy = false;
}
//Static Method for CharacterDialog
public static bool getPlayerInTalkingZone() {
return playerInTalkingZone;
}
//Static Method for CharacterDialog
public static void setPlayerInTalkingZone(bool value) {
playerInTalkingZone = value;
}
}
fileFormatVersion: 2
guid: 1548220cdff39434da0c355ae7ade121
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -66,6 +66,7 @@ public class ShinyEvent : UnityEvent<Fact> { ...@@ -66,6 +66,7 @@ public class ShinyEvent : UnityEvent<Fact> {
//Event for stopping all previews -> Made When ToolMode is changed //Event for stopping all previews -> Made When ToolMode is changed
public static ShinyEvent StopPreviewsEvent = new ShinyEvent(); public static ShinyEvent StopPreviewsEvent = new ShinyEvent();
public static ShinyEvent PushoutFactEvent = new ShinyEvent(); public static ShinyEvent PushoutFactEvent = new ShinyEvent();
public static ShinyEvent PushoutFactEndEvent = new ShinyEvent();
public static ShinyEvent PushoutFactFailEvent = new ShinyEvent(); public static ShinyEvent PushoutFactFailEvent = new ShinyEvent();
......
...@@ -261,6 +261,9 @@ public void StopPushoutFactHighlighting() { ...@@ -261,6 +261,9 @@ public void StopPushoutFactHighlighting() {
GameObject.Destroy(this.extraHighlight); GameObject.Destroy(this.extraHighlight);
this.extraHighlight = null; this.extraHighlight = null;
//Event for the happy Task-Charakter
CommunicationEvents.PushoutFactEndEvent.Invoke(null);
} }
public void StartPushoutFactFailHighlighting(Fact startFact) public void StartPushoutFactFailHighlighting(Fact startFact)
......
...@@ -57,11 +57,9 @@ void Update() ...@@ -57,11 +57,9 @@ void Update()
{ {
Ray ray = Cam.ScreenPointToRay(Input.mousePosition); Ray ray = Cam.ScreenPointToRay(Input.mousePosition);
int layerMask = LayerMask.GetMask("Player", "TalkingZone");
int layerMask = 1 << LayerMask.NameToLayer("Player"); //only hit player //Ignore player and TalkingZone
layerMask = ~layerMask; //ignore Player layerMask = ~layerMask;
if(Physics.Raycast(ray, out Hit, 30f, layerMask)){ if(Physics.Raycast(ray, out Hit, 30f, layerMask)){
......
fileFormatVersion: 2 fileFormatVersion: 2
guid: d24faa9ba77ab91459039238ad17d83c guid: 8a28cccde2536794c97ec91954e34e90
NativeFormatImporter: NativeFormatImporter:
externalObjects: {} externalObjects: {}
mainObjectFileID: 0 mainObjectFileID: 0
......
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: TalkingZoneMaterial
m_Shader: {fileID: 4800000, guid: 2649b895a4c22d649852a0ca4c825c74, type: 3}
m_ShaderKeywords: _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _ColorMask: 15
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 0
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 0
- _SrcBlend: 1
- _Stencil: 0
- _StencilComp: 8
- _StencilOp: 0
- _StencilReadMask: 255
- _StencilWriteMask: 255
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 0.65882355, b: 0, a: 0.078431375}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
fileFormatVersion: 2
guid: d24faa9ba77ab91459039238ad17d83c
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:
...@@ -94,7 +94,7 @@ Material: ...@@ -94,7 +94,7 @@ Material:
m_Colors: m_Colors:
- _ClipRect: {r: -32767, g: -32767, b: 32767, a: 32767} - _ClipRect: {r: -32767, g: -32767, b: 32767, a: 32767}
- _EnvMatrixRotation: {r: 0, g: 0, b: 0, a: 0} - _EnvMatrixRotation: {r: 0, g: 0, b: 0, a: 0}
- _FaceColor: {r: 1, g: 1, b: 1, a: 1} - _FaceColor: {r: 1, g: 0.65038824, b: 0, a: 1}
- _GlowColor: {r: 0, g: 1, b: 0, a: 0.5} - _GlowColor: {r: 0, g: 1, b: 0, a: 0.5}
- _MaskCoord: {r: 0, g: 0, b: 32767, a: 32767} - _MaskCoord: {r: 0, g: 0, b: 32767, a: 32767}
- _OutlineColor: {r: 0, g: 0, b: 0, a: 1} - _OutlineColor: {r: 0, g: 0, b: 0, a: 1}
......
fileFormatVersion: 2
guid: dbd33989986f3d54f8490c447f51b585
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 5a9fa4b6d301dc14aa6250493dff5575
folderAsset: yes
timeCreated: 1523535136
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
File added
fileFormatVersion: 2
guid: 865fba1b2532b5c4ca3e99732bd0ff34
timeCreated: 1523629692
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: de6e676950f3759498883efd4debf43f
folderAsset: yes
timeCreated: 1523535308
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 1247529560651778}
m_IsPrefabParent: 1
--- !u!1 &1247529560651778
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4180241154466476}
- component: {fileID: 33349337866831054}
- component: {fileID: 23508224406823698}
- component: {fileID: 95778886811690964}
m_Layer: 0
m_Name: PT_Medieval_Club_01
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4180241154466476
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1247529560651778}
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: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!23 &23508224406823698
MeshRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1247529560651778}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 2100000, guid: f2c05d6ef5551fe488fd04bde00fe91e, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &33349337866831054
MeshFilter:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1247529560651778}
m_Mesh: {fileID: 4300000, guid: 6f2d9bc7eb21b33458adc797b065969b, type: 3}
--- !u!95 &95778886811690964
Animator:
serializedVersion: 3
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1247529560651778}
m_Enabled: 1
m_Avatar: {fileID: 9000000, guid: 6f2d9bc7eb21b33458adc797b065969b, type: 3}
m_Controller: {fileID: 0}
m_CullingMode: 0
m_UpdateMode: 0
m_ApplyRootMotion: 0
m_LinearVelocityBlending: 0
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
fileFormatVersion: 2
guid: 004a9151c34cdb34a895313a480b2d87
timeCreated: 1530679810
licenseType: Store
NativeFormatImporter:
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment