Add Client_controller and mug interaction
This commit is contained in:
parent
70024c7b6a
commit
80704e1ba3
6 changed files with 205 additions and 24 deletions
BIN
Assets/Arts/Temporaires/Sprites/beer.png
Normal file
BIN
Assets/Arts/Temporaires/Sprites/beer.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
106
Assets/Arts/Temporaires/Sprites/beer.png.meta
Normal file
106
Assets/Arts/Temporaires/Sprites/beer.png.meta
Normal 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:
|
39
Assets/Scripts/Client_controller.cs
Normal file
39
Assets/Scripts/Client_controller.cs
Normal 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()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/Client_controller.cs.meta
Normal file
11
Assets/Scripts/Client_controller.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2dfbc8fb0a162ab4da4ff5cb76650e03
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -2,15 +2,18 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
[RequireComponent(typeof(Collider2D))]
|
||||||
public class Mug : MonoBehaviour, IGrabable
|
public class Mug : MonoBehaviour, IGrabable
|
||||||
{
|
{
|
||||||
public int size = 1; //Size (1 or 2 hands) of the object
|
public int size = 1; //Size (1 or 2 hands) of the object
|
||||||
|
bool dirty = false;
|
||||||
|
int content = 1;
|
||||||
|
|
||||||
public void use()
|
public void use()
|
||||||
{
|
{
|
||||||
|
//Do nothing
|
||||||
}
|
}
|
||||||
public void take()
|
public void take() //Object taken
|
||||||
{
|
{
|
||||||
gameObject.SetActive(false);
|
gameObject.SetActive(false);
|
||||||
}
|
}
|
||||||
|
@ -20,10 +23,20 @@ public class Mug : MonoBehaviour, IGrabable
|
||||||
gameObject.transform.position = position;
|
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
|
// Start is called before the first frame update
|
||||||
void Start()
|
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
|
// Update is called once per frame
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
[RequireComponent(typeof(Rigidbody))]
|
||||||
|
[RequireComponent(typeof(Animator))]
|
||||||
public class Tavernkeeper_controller : MonoBehaviour
|
public class Tavernkeeper_controller : MonoBehaviour
|
||||||
{
|
{
|
||||||
public float mvt_speed = 5.0f; //Movement speed
|
public float mvt_speed = 5.0f; //Movement speed
|
||||||
|
@ -36,10 +38,10 @@ public class Tavernkeeper_controller : MonoBehaviour
|
||||||
//Read inputs
|
//Read inputs
|
||||||
horizontal = Input.GetAxis("Horizontal"); //See Edit/Project setting / Input Manager
|
horizontal = Input.GetAxis("Horizontal"); //See Edit/Project setting / Input Manager
|
||||||
vertical = Input.GetAxis("Vertical");
|
vertical = Input.GetAxis("Vertical");
|
||||||
// Debug.Log(horizontal);
|
hands = Input.GetAxis("Hand");
|
||||||
|
|
||||||
|
//Movement action
|
||||||
Vector2 move = new Vector2(horizontal, vertical);
|
Vector2 move = new Vector2(horizontal, vertical);
|
||||||
|
|
||||||
//Update animation direction
|
//Update animation direction
|
||||||
if(!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f)) //Movement requested ?
|
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("Look Y", lookDirection.y);
|
||||||
animator.SetFloat("Speed", move.magnitude);
|
animator.SetFloat("Speed", move.magnitude);
|
||||||
|
|
||||||
|
//Hands actions
|
||||||
hands = Input.GetAxis("Hand");
|
|
||||||
// Debug.Log(hands);
|
|
||||||
if(!Mathf.Approximately(hands, 0.0f))
|
if(!Mathf.Approximately(hands, 0.0f))
|
||||||
{
|
{
|
||||||
if(hands>0)
|
if(hands>0)
|
||||||
|
@ -79,6 +79,7 @@ public class Tavernkeeper_controller : MonoBehaviour
|
||||||
rigidbody2d.MovePosition(position); //Movement processed by the phyisc engine for Collision, etc.
|
rigidbody2d.MovePosition(position); //Movement processed by the phyisc engine for Collision, etc.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Handle action with hands
|
||||||
void handAction(string hand)
|
void handAction(string hand)
|
||||||
{
|
{
|
||||||
// Test collision of ray from tavernkeeper center (A verifier) at action_dist unit distance on Interactions layer
|
// 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)
|
if (hit.collider != null)
|
||||||
{
|
{
|
||||||
GameObject hit_object = hit.collider.gameObject;
|
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)
|
if (hit_object != null)
|
||||||
{
|
{
|
||||||
//Empty hand : try grab grabable object
|
if(hit_object.tag == "Mug")
|
||||||
if(hand_container[hand] is null)
|
|
||||||
{
|
{
|
||||||
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.SetParent(transform);
|
||||||
// hit_object.transform.localPosition = new Vector2(-0.2f,0.2f);
|
// hit_object.transform.localPosition = new Vector2(-0.2f,0.2f);
|
||||||
|
|
||||||
//Doit traiter différement chaque Grabable ...
|
|
||||||
Mug obj = hit_object.GetComponent<Mug>();
|
Mug obj = hit_object.GetComponent<Mug>();
|
||||||
// if (obj.size==1 || (obj.size==2 && ));
|
if(obj!=null && obj.size == 1) //Only take obj of size 1 hand
|
||||||
if(obj!=null)
|
|
||||||
{
|
{
|
||||||
obj.take();
|
obj.take();
|
||||||
hand_container[hand]=hit_object;
|
hand_container[hand]=hit_object;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Full hand : try give to client
|
else if(hit_object.tag == "Client")
|
||||||
else if(hit_object.tag == "Client") //by tag or with parent-name ?
|
|
||||||
{
|
{
|
||||||
Debug.Log("Give "+ hand_container[hand]+" to "+hit_object);
|
// Debug.Log("Give "+ hand_container[hand].name+" to "+hit_object.name);
|
||||||
Destroy(hand_container[hand]);
|
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]);
|
// Debug.Log("Hand full with "+ hand_container[hand]);
|
||||||
// hand_container[hand].transform.SetParent(null);
|
// hand_container[hand].transform.SetParent(null);
|
||||||
|
|
||||||
//Doit traiter différement chaque Grabable ...
|
if (hand_container[hand].tag == "Mug")
|
||||||
Mug obj = hand_container[hand].GetComponent<Mug>();
|
|
||||||
if(obj !=null)
|
|
||||||
{
|
{
|
||||||
obj.drop(rigidbody2d.position);
|
Mug obj = hand_container[hand].GetComponent<Mug>();
|
||||||
hand_container[hand]=null;
|
if(obj !=null)
|
||||||
|
{
|
||||||
|
obj.drop(rigidbody2d.position);
|
||||||
|
hand_container[hand]=null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Log(gameObject+" doesn't handle Hand full with "+ hand_container[hand]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue