Add Client_controller and mug interaction

This commit is contained in:
Antoine H 2020-12-04 13:12:01 +01:00
parent 70024c7b6a
commit 80704e1ba3
6 changed files with 205 additions and 24 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View file

@ -0,0 +1,106 @@
fileFormatVersion: 2
guid: 17d59b2d4d882c04480a40119a442279
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: 4096
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
- serializedVersion: 3
buildTarget: Standalone
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

@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Collider2D))]
public class Client_controller : MonoBehaviour
{
public float consumeTime = 3.0f; //Time to consume currentMug
public float waitingTime = 10.0f; //Patience after ordering
GameObject currentMug;
public bool use(GameObject new_mug)
{
if(new_mug != null && new_mug.tag=="Mug")
{
Debug.Log(gameObject.name+" take "+new_mug.name);
currentMug = new_mug;
return true; //Object taken from tavernkeeper
}
else
{
Debug.Log("Display order (or something else) of "+gameObject.name);
return false; //Object not taken from tavernkeeper
}
}
// Start is called before the first frame update
void Start()
{
//Needs to be on Interactions layer and have the Client tag to work properly
gameObject.tag = "Client"; //Force gameobject tag
}
// Update is called once per frame
void Update()
{
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2dfbc8fb0a162ab4da4ff5cb76650e03
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -2,15 +2,18 @@
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Collider2D))]
public class Mug : MonoBehaviour, IGrabable
{
public int size = 1; //Size (1 or 2 hands) of the object
bool dirty = false;
int content = 1;
public void use()
{
//Do nothing
}
public void take()
public void take() //Object taken
{
gameObject.SetActive(false);
}
@ -20,10 +23,20 @@ public class Mug : MonoBehaviour, IGrabable
gameObject.transform.position = position;
}
public void fill(int new_content)
{
content = new_content;
}
public void consume()
{
content=0;
}
// Start is called before the first frame update
void Start()
{
//Needs to be on Interactions layer and have the Mug tag to work properly
gameObject.tag = "Mug"; //Force gameobject tag
}
// Update is called once per frame

View file

@ -2,6 +2,8 @@
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(Animator))]
public class Tavernkeeper_controller : MonoBehaviour
{
public float mvt_speed = 5.0f; //Movement speed
@ -36,10 +38,10 @@ public class Tavernkeeper_controller : MonoBehaviour
//Read inputs
horizontal = Input.GetAxis("Horizontal"); //See Edit/Project setting / Input Manager
vertical = Input.GetAxis("Vertical");
// Debug.Log(horizontal);
hands = Input.GetAxis("Hand");
//Movement action
Vector2 move = new Vector2(horizontal, vertical);
//Update animation direction
if(!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f)) //Movement requested ?
{
@ -50,9 +52,7 @@ public class Tavernkeeper_controller : MonoBehaviour
animator.SetFloat("Look Y", lookDirection.y);
animator.SetFloat("Speed", move.magnitude);
hands = Input.GetAxis("Hand");
// Debug.Log(hands);
//Hands actions
if(!Mathf.Approximately(hands, 0.0f))
{
if(hands>0)
@ -79,6 +79,7 @@ public class Tavernkeeper_controller : MonoBehaviour
rigidbody2d.MovePosition(position); //Movement processed by the phyisc engine for Collision, etc.
}
//Handle action with hands
void handAction(string hand)
{
// Test collision of ray from tavernkeeper center (A verifier) at action_dist unit distance on Interactions layer
@ -86,32 +87,37 @@ public class Tavernkeeper_controller : MonoBehaviour
if (hit.collider != null)
{
GameObject hit_object = hit.collider.gameObject;
// Debug.Log("Raycast has hit the object " + hit_object+ hit_object.tag);
// Debug.Log("Raycast has hit the object " + hit_object.name+ hit_object.tag);
if (hit_object != null)
{
//Empty hand : try grab grabable object
if(hand_container[hand] is null)
if(hit_object.tag == "Mug")
{
if(hit_object.tag == "Grabable") //by tag, layer-mask or with parent-name ?
if(hand_container[hand] is null) //Empty hand : try grab mug
{
// hit_object.transform.SetParent(transform);
// hit_object.transform.localPosition = new Vector2(-0.2f,0.2f);
//Doit traiter différement chaque Grabable ...
Mug obj = hit_object.GetComponent<Mug>();
// if (obj.size==1 || (obj.size==2 && ));
if(obj!=null)
if(obj!=null && obj.size == 1) //Only take obj of size 1 hand
{
obj.take();
hand_container[hand]=hit_object;
}
}
}
//Full hand : try give to client
else if(hit_object.tag == "Client") //by tag or with parent-name ?
else if(hit_object.tag == "Client")
{
Debug.Log("Give "+ hand_container[hand]+" to "+hit_object);
Destroy(hand_container[hand]);
// Debug.Log("Give "+ hand_container[hand].name+" to "+hit_object.name);
Client_controller client = hit_object.GetComponent<Client_controller>();
if(client!=null)
{
if(client.use(hand_container[hand])) //Interactions w/ object in hands
{
//Object taken by client
// Destroy(hand_container[hand]);
hand_container[hand]=null;
}
}
}
}
}
@ -121,12 +127,18 @@ public class Tavernkeeper_controller : MonoBehaviour
// Debug.Log("Hand full with "+ hand_container[hand]);
// hand_container[hand].transform.SetParent(null);
//Doit traiter différement chaque Grabable ...
Mug obj = hand_container[hand].GetComponent<Mug>();
if(obj !=null)
if (hand_container[hand].tag == "Mug")
{
obj.drop(rigidbody2d.position);
hand_container[hand]=null;
Mug obj = hand_container[hand].GetComponent<Mug>();
if(obj !=null)
{
obj.drop(rigidbody2d.position);
hand_container[hand]=null;
}
}
else
{
Debug.Log(gameObject+" doesn't handle Hand full with "+ hand_container[hand]);
}
}
}