Handle HardObstacle solving by player

This commit is contained in:
Antoine H 2021-01-28 15:34:58 +01:00
parent 377916ffb2
commit 3bc7c9c7ee
6 changed files with 470 additions and 11 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View file

@ -0,0 +1,94 @@
fileFormatVersion: 2
guid: c6735ddd8c4ff4d4fabb39f6570e8749
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

View file

@ -14,9 +14,9 @@ GameObject:
- component: {fileID: 1835648757843523848}
- component: {fileID: 1725399312431511591}
- component: {fileID: 3189895248152533610}
m_Layer: 0
m_Layer: 8
m_Name: HardObstacle
m_TagString: Untagged
m_TagString: Usable
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
@ -31,7 +31,8 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -2.6143043, y: -0.40863657, z: -1.5327958}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Children:
- {fileID: 6358083401863030547}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -80,7 +81,7 @@ SpriteRenderer:
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_Size: {x: 0.23333333, y: 0.31666666}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 0
@ -122,8 +123,8 @@ BoxCollider2D:
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 1.28, y: 1.28}
newSize: {x: 1.28, y: 1.28}
oldSize: {x: 0.23333333, y: 0.31666666}
newSize: {x: 0.23333333, y: 0.31666666}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
@ -161,3 +162,278 @@ MonoBehaviour:
m_EditorClassIdentifier:
lifeTime: 20
waitTime: 30
UIStopTimer: {fileID: 5206273763756246576}
stopTime: 5
interactionSmoothing: 0
--- !u!1 &6665066355047754899
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6358083401863030547}
- component: {fileID: 8689076781086164286}
- component: {fileID: 694351900976302520}
- component: {fileID: 5793357273915132216}
m_Layer: 8
m_Name: Canvas
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &6358083401863030547
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6665066355047754899}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.01, y: 0.01, z: 1}
m_Children:
- {fileID: 5206273763756246577}
m_Father: {fileID: 2607014449971772197}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 38.83052, y: 39.35086}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!223 &8689076781086164286
Canvas:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6665066355047754899}
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 2
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 0
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!114 &694351900976302520
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6665066355047754899}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
--- !u!114 &5793357273915132216
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6665066355047754899}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreReversedGraphics: 1
m_BlockingObjects: 0
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295
--- !u!1001 &22301672846964402
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 6358083401863030547}
m_Modifications:
- target: {fileID: 1800030824761736103, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_Sprite
value:
objectReference: {fileID: 21300000, guid: c6735ddd8c4ff4d4fabb39f6570e8749,
type: 3}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_Pivot.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_AnchorMax.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909068, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_Icon
value:
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909068, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_Name
value: CircleTimer
objectReference: {fileID: 0}
- target: {fileID: 5192471320214909068, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_Layer
value: 8
objectReference: {fileID: 0}
- target: {fileID: 5192471320581481922, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -0.05999756
objectReference: {fileID: 0}
- target: {fileID: 5192471320581481923, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_Layer
value: 8
objectReference: {fileID: 0}
- target: {fileID: 7027467526786473816, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0.01914978
objectReference: {fileID: 0}
- target: {fileID: 7859106207142621937, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
propertyPath: m_Layer
value: 8
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 887fdd182800875449ec5ddf381bcf87, type: 3}
--- !u!224 &5206273763756246577 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 5192471320214909059, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
m_PrefabInstance: {fileID: 22301672846964402}
m_PrefabAsset: {fileID: 0}
--- !u!114 &5206273763756246576 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 5192471320214909058, guid: 887fdd182800875449ec5ddf381bcf87,
type: 3}
m_PrefabInstance: {fileID: 22301672846964402}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: da748f5c6c44f274786e0947a0c6bbf8, type: 3}
m_Name:
m_EditorClassIdentifier:

View file

@ -4,6 +4,7 @@ using UnityEngine;
using UnityEngine.AI;
//Define the behavior of a client
[RequireComponent(typeof(SpriteRenderer))]
[RequireComponent(typeof(Animator))]
[RequireComponent(typeof(Rigidbody2D))]
[RequireComponent(typeof(Collider2D))]

View file

@ -7,12 +7,26 @@ using UnityEngine.AI;
[RequireComponent(typeof(Animator))]
[RequireComponent(typeof(Collider2D))]
[RequireComponent(typeof(NavMeshObstacle))]
public class HardObstacle : MonoBehaviour
public class HardObstacle : MonoBehaviour, IUsable
{
[SerializeField]
float lifeTime= -1.0f, waitTime= 30.0f; //Time active/waiting before self-destruct (Negative value to prevent self-destruct)
float lifeTimer;
[SerializeField]
UITimer UIStopTimer = null; //Script of the UI display
[SerializeField]
float stopTime=1.0f; //Time to stop fight by tavernkeeper
float stopTimer=0.0f;
bool playerInteracting = false; //Wether the player is interacting w/ the workshop
float interactionCd = 0.0f; //Time to consider the interaction stopped
[SerializeField]
float interactionSmoothing = 0.0f; //% of action_cd added to the interaction CD for smooth continued interaction
protected float cdTimer = 0.0f;
SpriteRenderer user_renderer = null; //Sprite renderer of the user (to turn insvisible)
List<Client_controller> angryClients = new List<Client_controller>(); //Clients in the fight
Collider2D ObsCollider;
@ -20,11 +34,53 @@ public class HardObstacle : MonoBehaviour
// SpriteRenderer ObsRenderer;
Animator animator;
bool gameRunning = true;
bool gameRunning = true; //Wehter the game is running (for clean-up purpose)
//Handle objects interactions w/ obstacle
//Return wether the object is taken from tavernkeeper
public bool use(GameObject userObject)
{
//Handle continuous interaction w/ tavernkeeper
if(userObject.tag=="Player")
{
if(stopTimer<stopTime) //Continue to stop fight
{
Debug.Log(gameObject.name+" still used by "+userObject.name);
if(interactionCd<0.01f) //No interaction CD ?
{
user_renderer = userObject.GetComponent<SpriteRenderer>(); //Renderer for visual effects
//Reset interaction CD
Tavernkeeper_controller player = userObject.GetComponent<Tavernkeeper_controller>();
if(player != null)
interactionCd=player.action_cd*(1.0f+interactionSmoothing); //=action_cd+ interactionSmoothing(%) action_cd (for smooth continued interaction)
else
Debug.LogWarning(userObject.name+" cannot have a continuous interaction on "+gameObject.name);
}
playerInteracting = true; //Set interaction indicator
cdTimer = interactionCd; //Reset Interaction CD
//Visual effect (user disappear)
if(user_renderer != null)
user_renderer.color=Color.clear;
}
else //Fight stopped
Destroy(gameObject);
}
return false; //No object taken
}
// Start is called before the first frame update
void Start()
{
if(gameObject.layer != LayerMask.NameToLayer("Interactions"))
Debug.LogWarning(gameObject.name+" layer should be set to 'Interactions' to work properly");
if(gameObject.tag != "Usable")
Debug.LogWarning(gameObject.name+" tag should be set to 'Usable' to work properly");
if(UIStopTimer is null)
Debug.LogWarning(gameObject.name+" doesn't have a UIStopTimer set");
lifeTimer=waitTime; //Start by waiting client
ObsCollider = GetComponent<Collider2D>();
@ -39,10 +95,34 @@ public class HardObstacle : MonoBehaviour
// Update is called once per frame
void Update()
{
//Life time update
lifeTimer -= Time.deltaTime;
if(lifeTimer<0)
Destroy(gameObject);
//Player interactions update
if(user_renderer != null && !playerInteracting)
user_renderer.color=Color.white; //User reappear if there's one
if(playerInteracting)
{
//Continue stopping fight
if(stopTimer<stopTime)
stopTimer+=Time.deltaTime;
//Update interaction CD
cdTimer-=Time.deltaTime;
if (cdTimer<0)
playerInteracting=false; //Reset interaction indicator
}
else if(stopTimer>0) //Decrease fight stopping jauge if not interacting
stopTimer-=Time.deltaTime*0.5f;
//UI update
if(UIStopTimer != null)
{
UIStopTimer.SetValue(stopTimer/stopTime);
UIStopTimer.gameObject.SetActive(stopTimer>0); //Set active if timer>0
}
}
void OnTriggerEnter2D(Collider2D other)
@ -76,12 +156,17 @@ public class HardObstacle : MonoBehaviour
void OnDestroy()
{
if(gameRunning) //Only apply if game is still running
{
foreach(Client_controller client in angryClients) //Clients return to their previous behavior
{
client.gameObject.SetActive(true);
client.assignToEvent(); //Restore previous behavior
}
if(user_renderer != null) //User reappear if there's one
user_renderer.color=Color.white;
}
EventManager.Instance.removeEvent(gameObject);
}

View file

@ -9,12 +9,15 @@ public abstract class Workshop : MonoBehaviour, IUsable
{
protected GameObject currentMug = null; //Mug currently stocked in workshop
public float prepTime = 2.0f; //Time for preparation of product
[SerializeField]
protected float prepTime = 2.0f; //Time for preparation of product
protected float prepTimer= 0.0f;
public UITimer UIPrepTimer = null; //Script of the UI display
[SerializeField]
protected UITimer UIPrepTimer = null; //Script of the UI display
protected bool playerInteracting = false; //Wether the player is interacting w/ the workshop
protected float interactionCd = 0.0f; //Time to consider the interaction stopped
public float interactionSmoothing = 0.0f; //% of action_cd added to the interaction CD for smooth continued interaction
[SerializeField]
protected float interactionSmoothing = 0.0f; //% of action_cd added to the interaction CD for smooth continued interaction
protected float cdTimer = 0.0f;
//Handle objects interactions w/ Workshop