pathfinding_v4 #4
File diff suppressed because it is too large
Load Diff
78
Assets/Graphics/Materials/NodePath_Mat.mat
Normal file
78
Assets/Graphics/Materials/NodePath_Mat.mat
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
%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: NodePath_Mat
|
||||||
|
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
|
||||||
|
m_ShaderKeywords:
|
||||||
|
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
|
||||||
|
- _Cutoff: 0.5
|
||||||
|
- _DetailNormalMapScale: 1
|
||||||
|
- _DstBlend: 0
|
||||||
|
- _GlossMapScale: 1
|
||||||
|
- _Glossiness: 0.5
|
||||||
|
- _GlossyReflections: 1
|
||||||
|
- _Metallic: 0
|
||||||
|
- _Mode: 0
|
||||||
|
- _OcclusionStrength: 1
|
||||||
|
- _Parallax: 0.02
|
||||||
|
- _SmoothnessTextureChannel: 0
|
||||||
|
- _SpecularHighlights: 1
|
||||||
|
- _SrcBlend: 1
|
||||||
|
- _UVSec: 0
|
||||||
|
- _ZWrite: 1
|
||||||
|
m_Colors:
|
||||||
|
- _Color: {r: 0, g: 0.787421, b: 0.9339623, a: 1}
|
||||||
|
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||||
|
m_BuildTextureStacks: []
|
8
Assets/Graphics/Materials/NodePath_Mat.mat.meta
Normal file
8
Assets/Graphics/Materials/NodePath_Mat.mat.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1293cff8126771046a5a69f1aa772d65
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 2100000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -1,214 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Linq;
|
|
||||||
using Logic.Graph;
|
|
||||||
using Logic.Utils;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Logic.Agent
|
|
||||||
{
|
|
||||||
public class Agent : MonoBehaviour
|
|
||||||
{
|
|
||||||
public Node actualNode;
|
|
||||||
private Node _previousNode;
|
|
||||||
private bool _canMove = true; //temporary
|
|
||||||
|
|
||||||
void Update()
|
|
||||||
{
|
|
||||||
//temporary
|
|
||||||
if (!_canMove) return;
|
|
||||||
if (actualNode is Table table)
|
|
||||||
{
|
|
||||||
if (table is KitchenTable kitchenTable)
|
|
||||||
{
|
|
||||||
if (Input.GetKeyDown(KeyCode.Space))
|
|
||||||
{
|
|
||||||
kitchenTable.HandleSpace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (table is CustomerTable customerTable)
|
|
||||||
{
|
|
||||||
if (Input.GetKeyDown(KeyCode.Space))
|
|
||||||
{
|
|
||||||
customerTable.HandleSpaceClick();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Input.GetKeyDown(KeyCode.Escape) && _previousNode != null)
|
|
||||||
{
|
|
||||||
StartCoroutine(RunToAnotherNode(_previousNode));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Input.GetKeyDown(KeyCode.UpArrow))
|
|
||||||
{
|
|
||||||
if (transform.rotation.eulerAngles.y.IsEq(0,2))
|
|
||||||
{
|
|
||||||
var node = actualNode.neighbors.FirstOrDefault(x =>
|
|
||||||
x.transform.position.x.IsEq(actualNode.transform.position.x) &&
|
|
||||||
x.transform.position.z > actualNode.transform.position.z);
|
|
||||||
if (node != null) StartCoroutine(RunToAnotherNode(node));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (transform.rotation.eulerAngles.y.IsEq(180, 2))
|
|
||||||
{
|
|
||||||
var node = actualNode.neighbors.FirstOrDefault(x =>
|
|
||||||
x.transform.position.x.IsEq(actualNode.transform.position.x) &&
|
|
||||||
x.transform.position.z < actualNode.transform.position.z);
|
|
||||||
if (node != null) StartCoroutine(RunToAnotherNode(node));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (transform.rotation.eulerAngles.y.IsEq(90, 2))
|
|
||||||
{
|
|
||||||
var node = actualNode.neighbors.FirstOrDefault(x =>
|
|
||||||
x.transform.position.z.IsEq(actualNode.transform.position.z) &&
|
|
||||||
x.transform.position.x > actualNode.transform.position.x);
|
|
||||||
if (node != null) StartCoroutine(RunToAnotherNode(node));
|
|
||||||
}
|
|
||||||
if (transform.rotation.eulerAngles.y.IsEq(270, 2))
|
|
||||||
{
|
|
||||||
var node = actualNode.neighbors.FirstOrDefault(x =>
|
|
||||||
x.transform.position.z.IsEq(actualNode.transform.position.z) &&
|
|
||||||
x.transform.position.x < actualNode.transform.position.x);
|
|
||||||
if (node != null) StartCoroutine(RunToAnotherNode(node));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Input.GetKeyDown(KeyCode.DownArrow))
|
|
||||||
{
|
|
||||||
if (transform.rotation.eulerAngles.y.IsEq(0, 1))
|
|
||||||
{
|
|
||||||
var node = actualNode.neighbors.FirstOrDefault(x =>
|
|
||||||
x.transform.position.x.IsEq(actualNode.transform.position.x) &&
|
|
||||||
x.transform.position.z < actualNode.transform.position.z);
|
|
||||||
if (node != null) StartCoroutine(RunToAnotherNode(node));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (transform.rotation.eulerAngles.y.IsEq(180, 1))
|
|
||||||
{
|
|
||||||
var node = actualNode.neighbors.FirstOrDefault(x =>
|
|
||||||
x.transform.position.x.IsEq(actualNode.transform.position.x) &&
|
|
||||||
x.transform.position.z > actualNode.transform.position.z);
|
|
||||||
if (node != null) StartCoroutine(RunToAnotherNode(node));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (transform.rotation.eulerAngles.y.IsEq(90, 1))
|
|
||||||
{
|
|
||||||
var node = actualNode.neighbors.FirstOrDefault(x =>
|
|
||||||
x.transform.position.z.IsEq(actualNode.transform.position.z) &&
|
|
||||||
x.transform.position.x < actualNode.transform.position.x);
|
|
||||||
if (node != null) StartCoroutine(RunToAnotherNode(node));
|
|
||||||
}
|
|
||||||
if (transform.rotation.eulerAngles.y.IsEq(270, 1))
|
|
||||||
{
|
|
||||||
var node = actualNode.neighbors.FirstOrDefault(x =>
|
|
||||||
x.transform.position.z.IsEq(actualNode.transform.position.z) &&
|
|
||||||
x.transform.position.x > actualNode.transform.position.x);
|
|
||||||
if (node != null) StartCoroutine(RunToAnotherNode(node));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Input.GetKeyDown(KeyCode.RightArrow))
|
|
||||||
{
|
|
||||||
if (transform.rotation.eulerAngles.y.IsEq(0, 1))
|
|
||||||
{
|
|
||||||
var node = actualNode.neighbors.FirstOrDefault(x =>
|
|
||||||
x.transform.position.z.IsEq(actualNode.transform.position.z) &&
|
|
||||||
x.transform.position.x > actualNode.transform.position.x);
|
|
||||||
if (node != null) StartCoroutine(RunToAnotherNode(node));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (transform.rotation.eulerAngles.y.IsEq(180, 1))
|
|
||||||
{
|
|
||||||
var node = actualNode.neighbors.FirstOrDefault(x =>
|
|
||||||
x.transform.position.z.IsEq(actualNode.transform.position.z) &&
|
|
||||||
x.transform.position.x < actualNode.transform.position.x);
|
|
||||||
if (node != null) StartCoroutine(RunToAnotherNode(node));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (transform.rotation.eulerAngles.y.IsEq(90, 1))
|
|
||||||
{
|
|
||||||
var node = actualNode.neighbors.FirstOrDefault(x =>
|
|
||||||
x.transform.position.x.IsEq(actualNode.transform.position.x) &&
|
|
||||||
x.transform.position.z < actualNode.transform.position.z);
|
|
||||||
if (node != null) StartCoroutine(RunToAnotherNode(node));
|
|
||||||
}
|
|
||||||
if (transform.rotation.eulerAngles.y.IsEq(270, 1))
|
|
||||||
{
|
|
||||||
var node = actualNode.neighbors.FirstOrDefault(x =>
|
|
||||||
x.transform.position.x.IsEq(actualNode.transform.position.x) &&
|
|
||||||
x.transform.position.z > actualNode.transform.position.z);
|
|
||||||
if (node != null) StartCoroutine(RunToAnotherNode(node));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Input.GetKeyDown(KeyCode.LeftArrow))
|
|
||||||
{
|
|
||||||
if (transform.rotation.eulerAngles.y.IsEq(0, 1))
|
|
||||||
{
|
|
||||||
var node = actualNode.neighbors.FirstOrDefault(x =>
|
|
||||||
x.transform.position.z.IsEq(actualNode.transform.position.z) &&
|
|
||||||
x.transform.position.x < actualNode.transform.position.x);
|
|
||||||
if (node != null) StartCoroutine(RunToAnotherNode(node));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (transform.rotation.eulerAngles.y.IsEq(180, 1))
|
|
||||||
{
|
|
||||||
var node = actualNode.neighbors.FirstOrDefault(x =>
|
|
||||||
x.transform.position.z.IsEq(actualNode.transform.position.z) &&
|
|
||||||
x.transform.position.x > actualNode.transform.position.x);
|
|
||||||
if (node != null) StartCoroutine(RunToAnotherNode(node));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (transform.rotation.eulerAngles.y.IsEq(90, 1))
|
|
||||||
{
|
|
||||||
var node = actualNode.neighbors.FirstOrDefault(x =>
|
|
||||||
x.transform.position.x.IsEq(actualNode.transform.position.x) &&
|
|
||||||
x.transform.position.z > actualNode.transform.position.z);
|
|
||||||
if (node != null) StartCoroutine(RunToAnotherNode(node));
|
|
||||||
}
|
|
||||||
if (transform.rotation.eulerAngles.y.IsEq(270, 1))
|
|
||||||
{
|
|
||||||
var node = actualNode.neighbors.FirstOrDefault(x =>
|
|
||||||
x.transform.position.x.IsEq(actualNode.transform.position.x) &&
|
|
||||||
x.transform.position.z < actualNode.transform.position.z);
|
|
||||||
if (node != null) StartCoroutine(RunToAnotherNode(node));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private IEnumerator RunToAnotherNode(Node destination)
|
|
||||||
{
|
|
||||||
_canMove = false;
|
|
||||||
var location = destination.GetComponent<Transform>().position;
|
|
||||||
|
|
||||||
var targetPoint = new Vector3(location.x, transform.position.y, location.z) - transform.position;
|
|
||||||
var targetRotation = Quaternion.LookRotation(targetPoint, Vector3.up);
|
|
||||||
float i = 0;
|
|
||||||
while (targetRotation.eulerAngles != transform.rotation.eulerAngles && i <= 1)
|
|
||||||
{
|
|
||||||
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, i);
|
|
||||||
yield return new WaitForEndOfFrame();
|
|
||||||
i += Time.deltaTime;
|
|
||||||
}
|
|
||||||
i = 1;
|
|
||||||
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, i);
|
|
||||||
i = 0;
|
|
||||||
var y = transform.position.y;
|
|
||||||
while (i <= 1 && !(destination is Table) && transform.position != new Vector3(location.x, transform.position.y, location.z))
|
|
||||||
{
|
|
||||||
transform.position = Vector3.Slerp(transform.position,
|
|
||||||
new Vector3(location.x, y, location.z), i);
|
|
||||||
yield return new WaitForEndOfFrame();
|
|
||||||
i += Time.deltaTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(destination is Table table))
|
|
||||||
{
|
|
||||||
transform.position = new Vector3(location.x, transform.position.y, location.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
_previousNode = actualNode;
|
|
||||||
actualNode = destination;
|
|
||||||
_canMove = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
20
Assets/Logic/Agent/FringeNodes.cs
Normal file
20
Assets/Logic/Agent/FringeNodes.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Logic.Agent;
|
||||||
|
|
||||||
|
namespace Assets.Logic.Agent
|
||||||
|
{
|
||||||
|
public class FringeNodes
|
||||||
|
{
|
||||||
|
public FringeNodes(State state)
|
||||||
|
{
|
||||||
|
State = state;
|
||||||
|
}
|
||||||
|
public State State;
|
||||||
|
public FringeNodes Parent;
|
||||||
|
public AgentAction Action;
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Logic/Agent/FringeNodes.cs.meta
Normal file
11
Assets/Logic/Agent/FringeNodes.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 131def8de3119224f95c4fd65f00f3c9
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
120
Assets/Logic/Agent/PathFinder.cs
Normal file
120
Assets/Logic/Agent/PathFinder.cs
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Assets.Logic.Agent;
|
||||||
|
using Logic.Graph;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Logic.Agent
|
||||||
|
{
|
||||||
|
public class PathFinder : MonoBehaviour
|
||||||
|
{
|
||||||
|
public Stack<AgentAction> GraphSearch(Queue<FringeNodes> fringe, HashSet<FringeNodes> explored, State iState, State goalState)
|
||||||
|
{
|
||||||
|
Stack<AgentAction> stack = new Stack<AgentAction>();
|
||||||
|
fringe.Enqueue(new FringeNodes(iState));
|
||||||
|
while (fringe.Count != 0)
|
||||||
|
{
|
||||||
|
var elem = fringe.Dequeue();
|
||||||
|
|
||||||
|
if (goalTest(elem.State, goalState))
|
||||||
|
{
|
||||||
|
while (!elem.State.Equals(iState))
|
||||||
|
{
|
||||||
|
elem.State.AgentPosition.MarkAsPath();
|
||||||
|
stack.Push(elem.Action);
|
||||||
|
elem = elem.Parent;
|
||||||
|
}
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
explored.Add(elem);
|
||||||
|
foreach (var successor in Succ(elem.State))
|
||||||
|
{
|
||||||
|
if (fringe.Any(z =>
|
||||||
|
z.State.Equals(successor.Item1)) || explored.Any(z => z.State.Equals(successor.Item1)))
|
||||||
|
continue;
|
||||||
|
var x = new FringeNodes(successor.Item1) {Parent = elem, Action = successor.Item2};
|
||||||
|
fringe.Enqueue(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Tuple<State, AgentAction>> Succ(State currentState)
|
||||||
|
{
|
||||||
|
var tupleList = new List<Tuple<State, AgentAction>>();
|
||||||
|
|
||||||
|
//akcja obrot w lewo
|
||||||
|
if (!(currentState.AgentPosition is Table))
|
||||||
|
{
|
||||||
|
var stateLeft = new State();
|
||||||
|
stateLeft.AgentPosition = currentState.AgentPosition;
|
||||||
|
switch (currentState.AgentRotation)
|
||||||
|
{
|
||||||
|
case Rotation.Left:
|
||||||
|
stateLeft.AgentRotation = Rotation.Bottom;
|
||||||
|
break;
|
||||||
|
case Rotation.Right:
|
||||||
|
stateLeft.AgentRotation = Rotation.Top;
|
||||||
|
break;
|
||||||
|
case Rotation.Top:
|
||||||
|
stateLeft.AgentRotation = Rotation.Left;
|
||||||
|
break;
|
||||||
|
case Rotation.Bottom:
|
||||||
|
stateLeft.AgentRotation = Rotation.Right;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
tupleList.Add(new Tuple<State, AgentAction>(stateLeft, AgentAction.Left));
|
||||||
|
}
|
||||||
|
|
||||||
|
//akcja obrot w prawo
|
||||||
|
if (!(currentState.AgentPosition is Table))
|
||||||
|
{
|
||||||
|
var stateRight = new State();
|
||||||
|
stateRight.AgentPosition = currentState.AgentPosition;
|
||||||
|
switch (currentState.AgentRotation)
|
||||||
|
{
|
||||||
|
case Rotation.Left:
|
||||||
|
stateRight.AgentRotation = Rotation.Top;
|
||||||
|
break;
|
||||||
|
case Rotation.Right:
|
||||||
|
stateRight.AgentRotation = Rotation.Bottom;
|
||||||
|
break;
|
||||||
|
case Rotation.Top:
|
||||||
|
stateRight.AgentRotation = Rotation.Right;
|
||||||
|
break;
|
||||||
|
case Rotation.Bottom:
|
||||||
|
stateRight.AgentRotation = Rotation.Left;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
}
|
||||||
|
|
||||||
|
tupleList.Add(new Tuple<State, AgentAction>(stateRight, AgentAction.Right));
|
||||||
|
}
|
||||||
|
|
||||||
|
//akcja do przodu
|
||||||
|
var stateGoForward = new State();
|
||||||
|
stateGoForward.AgentRotation = currentState.AgentRotation;
|
||||||
|
var node = currentState.AgentPosition.FindNode(currentState.AgentRotation);
|
||||||
|
if (node != null)
|
||||||
|
{
|
||||||
|
stateGoForward.AgentPosition = node;
|
||||||
|
tupleList.Add(new Tuple<State, AgentAction>(stateGoForward, AgentAction.GoForward));
|
||||||
|
}
|
||||||
|
|
||||||
|
return tupleList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool goalTest(State actualState, State goalState)
|
||||||
|
{
|
||||||
|
return actualState.Equals(goalState);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
3
Assets/Logic/Agent/PathFinder.cs.meta
Normal file
3
Assets/Logic/Agent/PathFinder.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 99113b0d565845e1a532d3ba5e06bb90
|
||||||
|
timeCreated: 1618150132
|
25
Assets/Logic/Agent/State.cs
Normal file
25
Assets/Logic/Agent/State.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using Logic.Graph;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Assets.Logic.Agent
|
||||||
|
{
|
||||||
|
public enum Rotation
|
||||||
|
{
|
||||||
|
Left = 0,
|
||||||
|
Right = 1,
|
||||||
|
Top = 2,
|
||||||
|
Bottom = 3
|
||||||
|
}
|
||||||
|
public class State
|
||||||
|
{
|
||||||
|
public Rotation AgentRotation;
|
||||||
|
public Node AgentPosition;
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null) return false;
|
||||||
|
var state = (State) obj;
|
||||||
|
return AgentPosition == state.AgentPosition && AgentRotation == state.AgentRotation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Logic/Agent/State.cs.meta
Normal file
11
Assets/Logic/Agent/State.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 20173ce40dd948143bfc1ac9545f4e0b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
201
Assets/Logic/Agent/Waitress.cs
Normal file
201
Assets/Logic/Agent/Waitress.cs
Normal file
@ -0,0 +1,201 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using Assets.Logic.Agent;
|
||||||
|
using Logic.Graph;
|
||||||
|
using UnityEngine;
|
||||||
|
using Debug = UnityEngine.Debug;
|
||||||
|
|
||||||
|
namespace Logic.Agent
|
||||||
|
{
|
||||||
|
public enum AgentAction
|
||||||
|
{
|
||||||
|
Left = 0,
|
||||||
|
Right = 1,
|
||||||
|
GoForward = 2
|
||||||
|
}
|
||||||
|
public class Waitress : MonoBehaviour
|
||||||
|
{
|
||||||
|
//[SerializeField] private Node currentNode;
|
||||||
|
public Node StartNode;
|
||||||
|
[SerializeField] private bool isFollowingPath;
|
||||||
|
[SerializeField] private bool canMove = true;
|
||||||
|
//private Node _previousNode;
|
||||||
|
private State _currentState;
|
||||||
|
private State _previousState;
|
||||||
|
private PathFinder _pathFinder;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
_pathFinder = GetComponent<PathFinder>();
|
||||||
|
_currentState = new State();
|
||||||
|
_currentState.AgentPosition = StartNode;
|
||||||
|
_currentState.AgentRotation = Rotation.Top;
|
||||||
|
_previousState = new State();
|
||||||
|
_previousState.AgentPosition = StartNode;
|
||||||
|
_previousState.AgentRotation = Rotation.Top;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
if (!canMove) return;
|
||||||
|
if (_currentState.AgentPosition is Table table)
|
||||||
|
{
|
||||||
|
if (table is KitchenTable kitchenTable)
|
||||||
|
{
|
||||||
|
if (Input.GetKeyDown(KeyCode.Space))
|
||||||
|
{
|
||||||
|
kitchenTable.HandleSpaceClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (table is CustomerTable customerTable)
|
||||||
|
{
|
||||||
|
if (Input.GetKeyDown(KeyCode.Space))
|
||||||
|
{
|
||||||
|
customerTable.HandleSpaceClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GoToNode(Table table)
|
||||||
|
{
|
||||||
|
if (isFollowingPath) return;
|
||||||
|
|
||||||
|
isFollowingPath = true;
|
||||||
|
|
||||||
|
if (_currentState.AgentPosition is Table && _previousState != null)
|
||||||
|
{
|
||||||
|
_currentState.AgentPosition = _previousState.AgentPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
var goalState = new State();
|
||||||
|
goalState.AgentPosition = table;
|
||||||
|
goalState.AgentRotation = Rotation.Right;
|
||||||
|
|
||||||
|
Stack<AgentAction> actions = _pathFinder.GraphSearch(new Queue<FringeNodes>(), new HashSet<FringeNodes>(),
|
||||||
|
_currentState, goalState);
|
||||||
|
if (actions.Count > 0)
|
||||||
|
{
|
||||||
|
StartCoroutine(ExecuteActions(actions));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator ExecuteActions(Stack<AgentAction> actions)
|
||||||
|
{
|
||||||
|
|
||||||
|
while (actions.Count > 0)
|
||||||
|
{
|
||||||
|
if (canMove)
|
||||||
|
{
|
||||||
|
_currentState.AgentPosition.ClearPathMark();
|
||||||
|
var action = actions.Pop();
|
||||||
|
switch (action)
|
||||||
|
{
|
||||||
|
case AgentAction.Left:
|
||||||
|
StartCoroutine(RotateLeft());
|
||||||
|
_previousState.AgentRotation = _currentState.AgentRotation;
|
||||||
|
_currentState.AgentRotation = _currentState.AgentRotation == Rotation.Left
|
||||||
|
?
|
||||||
|
Rotation.Bottom
|
||||||
|
: _currentState.AgentRotation == Rotation.Bottom
|
||||||
|
? Rotation.Right
|
||||||
|
: _currentState.AgentRotation == Rotation.Right
|
||||||
|
? Rotation.Top
|
||||||
|
: Rotation.Left;
|
||||||
|
break;
|
||||||
|
case AgentAction.Right:
|
||||||
|
StartCoroutine(RotateRight());
|
||||||
|
_previousState.AgentRotation = _currentState.AgentRotation;
|
||||||
|
_currentState.AgentRotation = _currentState.AgentRotation == Rotation.Left
|
||||||
|
?
|
||||||
|
Rotation.Top
|
||||||
|
: _currentState.AgentRotation == Rotation.Top
|
||||||
|
? Rotation.Right
|
||||||
|
: _currentState.AgentRotation == Rotation.Right
|
||||||
|
? Rotation.Bottom
|
||||||
|
: Rotation.Left;
|
||||||
|
break;
|
||||||
|
case AgentAction.GoForward:
|
||||||
|
StartCoroutine(
|
||||||
|
RunToAnotherNode(_currentState.AgentPosition.FindNode(_currentState.AgentRotation)));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//node.Item2?.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
yield return new WaitForEndOfFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
isFollowingPath = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator RotateLeft()
|
||||||
|
{
|
||||||
|
canMove = false;
|
||||||
|
transform.Rotate(new Vector3(0, -90, 0), Space.World);
|
||||||
|
var targetRotation = transform.rotation;
|
||||||
|
transform.Rotate(new Vector3(0, 90, 0), Space.World);
|
||||||
|
var startRotation = transform.rotation;
|
||||||
|
float i = 0;
|
||||||
|
while (i <= 1)
|
||||||
|
{
|
||||||
|
transform.rotation = Quaternion.Slerp(startRotation, targetRotation, i);
|
||||||
|
yield return new WaitForEndOfFrame();
|
||||||
|
i += Time.deltaTime*3;
|
||||||
|
}
|
||||||
|
transform.rotation = targetRotation;
|
||||||
|
canMove = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator RotateRight()
|
||||||
|
{
|
||||||
|
canMove = false;
|
||||||
|
transform.Rotate(new Vector3(0, 90, 0), Space.World);
|
||||||
|
var targetRotation = transform.rotation;
|
||||||
|
transform.Rotate(new Vector3(0, -90, 0), Space.World);
|
||||||
|
var startRotation = transform.rotation;
|
||||||
|
float i = 0;
|
||||||
|
while (i <= 1)
|
||||||
|
{
|
||||||
|
Debug.Log(i);
|
||||||
|
transform.rotation = Quaternion.Slerp(startRotation, targetRotation, i);
|
||||||
|
yield return new WaitForEndOfFrame();
|
||||||
|
i += Time.deltaTime*3;
|
||||||
|
}
|
||||||
|
transform.rotation = targetRotation;
|
||||||
|
canMove = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator RunToAnotherNode(Node destination)
|
||||||
|
{
|
||||||
|
canMove = false;
|
||||||
|
if (destination is Table)
|
||||||
|
{
|
||||||
|
_previousState.AgentPosition = _currentState.AgentPosition;
|
||||||
|
_currentState.AgentPosition = destination;
|
||||||
|
canMove = true;
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
var location = destination.GetComponent<Transform>().position;
|
||||||
|
|
||||||
|
float i = 0;
|
||||||
|
var y = transform.position.y;
|
||||||
|
var startPosition = transform.position;
|
||||||
|
while (i <= 1 && transform.position != new Vector3(location.x, transform.position.y, location.z))
|
||||||
|
{
|
||||||
|
transform.position = Vector3.Slerp(startPosition,
|
||||||
|
new Vector3(location.x, y, location.z), i);
|
||||||
|
yield return new WaitForEndOfFrame();
|
||||||
|
i += Time.deltaTime*3;
|
||||||
|
}
|
||||||
|
|
||||||
|
transform.position = new Vector3(location.x, transform.position.y, location.z);
|
||||||
|
_previousState.AgentPosition = _currentState.AgentPosition;
|
||||||
|
_currentState.AgentPosition = destination;
|
||||||
|
canMove = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,20 +4,13 @@ using JetBrains.Annotations;
|
|||||||
using Logic.Data;
|
using Logic.Data;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Logic.Inventory
|
namespace Logic.Agent
|
||||||
{
|
{
|
||||||
public class WaitressInventory : MonoBehaviour
|
public class WaitressInventory : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
|
||||||
public static WaitressInventory Instance;
|
|
||||||
private void Awake()
|
|
||||||
{
|
|
||||||
Instance = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
[SerializeField] private List<Item> container = new List<Item>();
|
[SerializeField] private List<Item> container = new List<Item>();
|
||||||
private int maxSize = 4;
|
private int maxSize = 4;
|
||||||
|
|
||||||
|
|
||||||
public bool AddItem(Item item)
|
public bool AddItem(Item item)
|
||||||
{
|
{
|
46
Assets/Logic/AgentManager.cs
Normal file
46
Assets/Logic/AgentManager.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Logic.Agent;
|
||||||
|
using Logic.Data;
|
||||||
|
using Logic.Graph;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Logic
|
||||||
|
{
|
||||||
|
public class AgentManager: MonoBehaviour
|
||||||
|
{
|
||||||
|
public static AgentManager Instance;
|
||||||
|
[SerializeField] private Waitress waitress;
|
||||||
|
[SerializeField] private WaitressInventory inventory;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
Instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GoToNode(Table table)
|
||||||
|
{
|
||||||
|
waitress.GoToNode(table);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddItem(Item item)
|
||||||
|
{
|
||||||
|
return inventory.AddItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Recipe> GetRecipes()
|
||||||
|
{
|
||||||
|
return inventory.GetRecipes();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Food GETMealForTable(int tableId)
|
||||||
|
{
|
||||||
|
return inventory.GETMealForTable(tableId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveItem(Item item)
|
||||||
|
{
|
||||||
|
inventory.RemoveItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
3
Assets/Logic/AgentManager.cs.meta
Normal file
3
Assets/Logic/AgentManager.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5a350b5d1b5f426495bcc8ac7ccdd527
|
||||||
|
timeCreated: 1618169050
|
@ -1,4 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -34,8 +33,18 @@ namespace Logic
|
|||||||
{
|
{
|
||||||
StartCoroutine(HandleCustomerSpawn(customerSpawnTime));
|
StartCoroutine(HandleCustomerSpawn(customerSpawnTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CustomerTable GETTable(int index)
|
||||||
|
{
|
||||||
|
return customerTables[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
public Recipe GetRandomRecipe()
|
||||||
|
{
|
||||||
|
return availableRecipes[Random.Range(0, availableRecipes.Count)];
|
||||||
|
}
|
||||||
|
|
||||||
IEnumerator HandleCustomerSpawn(int secs)
|
private IEnumerator HandleCustomerSpawn(int secs)
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@ -52,10 +61,5 @@ namespace Logic
|
|||||||
yield return new WaitForSeconds(secs);
|
yield return new WaitForSeconds(secs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Recipe GetRandomRecipe()
|
|
||||||
{
|
|
||||||
return availableRecipes[Random.Range(0, availableRecipes.Count)];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,3 +1,11 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 876ae8b73336491a91f3c96adaf27140
|
guid: 876ae8b73336491a91f3c96adaf27140
|
||||||
timeCreated: 1616101991
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: a759d3ff90f0402b8c991e705f06c815
|
guid: a759d3ff90f0402b8c991e705f06c815
|
||||||
timeCreated: 1617124677
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using Logic.Agent;
|
||||||
using Logic.Data;
|
using Logic.Data;
|
||||||
using Logic.Inventory;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Logic.Graph
|
namespace Logic.Graph
|
||||||
@ -76,7 +76,7 @@ namespace Logic.Graph
|
|||||||
if (item == null) return;
|
if (item == null) return;
|
||||||
|
|
||||||
item.tableNumber = tableNumber;
|
item.tableNumber = tableNumber;
|
||||||
bool isSuccess = WaitressInventory.Instance.AddItem(item);
|
bool isSuccess = AgentManager.Instance.AddItem(item);
|
||||||
if (isSuccess)
|
if (isSuccess)
|
||||||
{
|
{
|
||||||
ClearItemObject();
|
ClearItemObject();
|
||||||
@ -90,12 +90,12 @@ namespace Logic.Graph
|
|||||||
|
|
||||||
private void HandleFoodDelivery()
|
private void HandleFoodDelivery()
|
||||||
{
|
{
|
||||||
Food food = WaitressInventory.Instance.GETMealForTable(tableNumber);
|
Food food = AgentManager.Instance.GETMealForTable(tableNumber);
|
||||||
if (food != null)
|
if (food != null)
|
||||||
{
|
{
|
||||||
CurrentItem = food;
|
CurrentItem = food;
|
||||||
Spawn();
|
Spawn();
|
||||||
WaitressInventory.Instance.RemoveItem(food);
|
AgentManager.Instance.RemoveItem(food);
|
||||||
_eatMealCoroutine = StartCoroutine(HandleEatMeal(3));
|
_eatMealCoroutine = StartCoroutine(HandleEatMeal(3));
|
||||||
state = TableState.Eating;
|
state = TableState.Eating;
|
||||||
UIManager.Instance.uiTableManager
|
UIManager.Instance.uiTableManager
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 682c70c355804410af55074b0d8c0a88
|
guid: 682c70c355804410af55074b0d8c0a88
|
||||||
timeCreated: 1616062130
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Logic.Agent;
|
||||||
using Logic.Data;
|
using Logic.Data;
|
||||||
using Logic.Inventory;
|
|
||||||
using Logic.UI;
|
using Logic.UI;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@ -18,9 +18,9 @@ namespace Logic.Graph
|
|||||||
StartCoroutine(PrepareMeal());
|
StartCoroutine(PrepareMeal());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleSpace()
|
public void HandleSpaceClick()
|
||||||
{
|
{
|
||||||
List<Recipe> recipes = WaitressInventory.Instance.GetRecipes();
|
List<Recipe> recipes = AgentManager.Instance.GetRecipes();
|
||||||
foreach (Recipe recipe in recipes)
|
foreach (Recipe recipe in recipes)
|
||||||
{
|
{
|
||||||
KitchenTableManager.Instance.AddToQueue(recipe, QueueType.ProgressQueue);
|
KitchenTableManager.Instance.AddToQueue(recipe, QueueType.ProgressQueue);
|
||||||
@ -28,7 +28,7 @@ namespace Logic.Graph
|
|||||||
|
|
||||||
if (IsFull)
|
if (IsFull)
|
||||||
{
|
{
|
||||||
bool isSuccess = WaitressInventory.Instance.AddItem(CurrentItem);
|
bool isSuccess = AgentManager.Instance.AddItem(CurrentItem);
|
||||||
if (isSuccess)
|
if (isSuccess)
|
||||||
{
|
{
|
||||||
ClearItemObject();
|
ClearItemObject();
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 4a99b5cdee244cf9bece4746cc23b43a
|
guid: 4a99b5cdee244cf9bece4746cc23b43a
|
||||||
timeCreated: 1616006887
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Assets.Logic.Agent;
|
||||||
|
using Logic.Utils;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Logic.Graph
|
namespace Logic.Graph
|
||||||
{
|
{
|
||||||
public class Node : MonoBehaviour
|
public class Node : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
public Material nodeMat;
|
||||||
|
public Material pathMat;
|
||||||
public List<Node> neighbors;
|
public List<Node> neighbors;
|
||||||
[SerializeField] private float maxRange = 0.5f;
|
[SerializeField] private float maxRange = 0.5f;
|
||||||
[SerializeField] private bool debug = false;
|
[SerializeField] private bool debug = false;
|
||||||
@ -14,9 +20,11 @@ namespace Logic.Graph
|
|||||||
private Vector3 _position;
|
private Vector3 _position;
|
||||||
private float _nodeRayMaxLength;
|
private float _nodeRayMaxLength;
|
||||||
private float _tableRayMaxLength;
|
private float _tableRayMaxLength;
|
||||||
|
private Renderer _renderer;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
|
_renderer = GetComponent<Renderer>();
|
||||||
InitializeNeighbours();
|
InitializeNeighbours();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,6 +41,22 @@ namespace Logic.Graph
|
|||||||
Debug.DrawRay(_position, Vector3.left + new Vector3(-_tableRayMaxLength, 0, 0), Color.yellow);
|
Debug.DrawRay(_position, Vector3.left + new Vector3(-_tableRayMaxLength, 0, 0), Color.yellow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void MarkAsPath()
|
||||||
|
{
|
||||||
|
if (!gameObject.CompareTag("Table"))
|
||||||
|
{
|
||||||
|
_renderer.material = pathMat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ClearPathMark()
|
||||||
|
{
|
||||||
|
if (!gameObject.CompareTag("Table"))
|
||||||
|
{
|
||||||
|
_renderer.material = nodeMat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void InitializeNeighbours()
|
private void InitializeNeighbours()
|
||||||
{
|
{
|
||||||
@ -90,6 +114,31 @@ namespace Logic.Graph
|
|||||||
neighbors.Add(kitchenTableCollider);
|
neighbors.Add(kitchenTableCollider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Node FindNode(Rotation agentRotation)
|
||||||
|
{
|
||||||
|
switch (agentRotation)
|
||||||
|
{
|
||||||
|
case Rotation.Left:
|
||||||
|
return neighbors.FirstOrDefault(x =>
|
||||||
|
x.transform.position.z.IsEq(transform.position.z) &&
|
||||||
|
x.transform.position.x.IsEq(transform.position.x - 1));
|
||||||
|
case Rotation.Right:
|
||||||
|
return neighbors.FirstOrDefault(x =>
|
||||||
|
x.transform.position.z.IsEq(transform.position.z) &&
|
||||||
|
x.transform.position.x.IsEq(transform.position.x + 1));
|
||||||
|
case Rotation.Top:
|
||||||
|
return neighbors.FirstOrDefault(x =>
|
||||||
|
x.transform.position.x.IsEq(transform.position.x) &&
|
||||||
|
x.transform.position.z.IsEq(transform.position.z + 1.25f));
|
||||||
|
case Rotation.Bottom:
|
||||||
|
return neighbors.FirstOrDefault(x =>
|
||||||
|
x.transform.position.x.IsEq(transform.position.x) &&
|
||||||
|
x.transform.position.z.IsEq(transform.position.z - 1.25f));
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 599c04d23a8d4c178acdbeaaba748caf
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -18,6 +18,11 @@ namespace Logic
|
|||||||
Instance = this;
|
Instance = this;
|
||||||
kitchenTable = GetComponentInChildren<KitchenTable>();
|
kitchenTable = GetComponentInChildren<KitchenTable>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public KitchenTable GETTable()
|
||||||
|
{
|
||||||
|
return kitchenTable;
|
||||||
|
}
|
||||||
|
|
||||||
public void AddToQueue(Item item, QueueType type)
|
public void AddToQueue(Item item, QueueType type)
|
||||||
{
|
{
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: c34fcf5236784d3096ec85dd3649ec66
|
guid: c34fcf5236784d3096ec85dd3649ec66
|
||||||
timeCreated: 1616102469
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
@ -9,7 +9,6 @@ namespace Logic
|
|||||||
public class SceneContext : MonoBehaviour
|
public class SceneContext : MonoBehaviour
|
||||||
{
|
{
|
||||||
public List<Node> map;
|
public List<Node> map;
|
||||||
public Agent.Agent waitressAgent;
|
|
||||||
public static SceneContext Instance;
|
public static SceneContext Instance;
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
@ -19,8 +18,6 @@ namespace Logic
|
|||||||
map = GetComponentsInChildren<Node>().ToList();
|
map = GetComponentsInChildren<Node>().ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Gizmos
|
|
||||||
|
|
||||||
private void DrawGizmosFrom(Node from, List<Node> without)
|
private void DrawGizmosFrom(Node from, List<Node> without)
|
||||||
{
|
{
|
||||||
foreach (var x in from.neighbors.Where(x=>!without.Contains(x)))
|
foreach (var x in from.neighbors.Where(x=>!without.Contains(x)))
|
||||||
@ -46,7 +43,5 @@ namespace Logic
|
|||||||
if(map.Count>0)
|
if(map.Count>0)
|
||||||
DrawGizmosFrom(map.First(), new List<Node>());
|
DrawGizmosFrom(map.First(), new List<Node>());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 156304b0be9c4c1f99356a96496e773a
|
guid: 156304b0be9c4c1f99356a96496e773a
|
||||||
timeCreated: 1616158580
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
@ -1,21 +1,38 @@
|
|||||||
using Logic.Data;
|
using Logic.Data;
|
||||||
|
using Logic.Graph;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace Logic.UI
|
namespace Logic.UI
|
||||||
{
|
{
|
||||||
public class UIQueue : MonoBehaviour
|
public class UIQueue : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private UIInventorySlot uiInventorySlot;
|
[SerializeField] private UIInventorySlot uiInventorySlot;
|
||||||
|
[SerializeField] private KitchenTable table;
|
||||||
|
|
||||||
public GameObject queueWrapper;
|
public GameObject queueWrapper;
|
||||||
|
|
||||||
|
|
||||||
|
// private void Start()
|
||||||
|
// {
|
||||||
|
// foreach (var child in queueWrapper.GetComponentsInChildren<UIInventorySlot>())
|
||||||
|
// {
|
||||||
|
// Destroy(child.gameObject);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
foreach (var child in queueWrapper.GetComponentsInChildren<UIInventorySlot>())
|
table = KitchenTableManager.Instance.GETTable();
|
||||||
{
|
var button = GetComponentInChildren<Button>();
|
||||||
Destroy(child.gameObject);
|
button.onClick.AddListener( ButtonClick );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ButtonClick()
|
||||||
|
{
|
||||||
|
AgentManager.Instance.GoToNode(table);
|
||||||
|
}
|
||||||
|
|
||||||
public void Add(Item item)
|
public void Add(Item item)
|
||||||
{
|
{
|
||||||
UIInventorySlot uiQueueSlot = Instantiate(uiInventorySlot, queueWrapper.transform, false);
|
UIInventorySlot uiQueueSlot = Instantiate(uiInventorySlot, queueWrapper.transform, false);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
using Logic.Graph;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
@ -8,5 +9,17 @@ namespace Logic.UI
|
|||||||
public Text tableValue;
|
public Text tableValue;
|
||||||
public Text statusValue;
|
public Text statusValue;
|
||||||
public UIInventorySlot inventorySlot;
|
public UIInventorySlot inventorySlot;
|
||||||
|
public CustomerTable table;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
var button = GetComponentInChildren<Button>();
|
||||||
|
button.onClick.AddListener( ButtonClick );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonClick()
|
||||||
|
{
|
||||||
|
AgentManager.Instance.GoToNode(table);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ namespace Logic.UI
|
|||||||
{
|
{
|
||||||
public class UITableManager : MonoBehaviour
|
public class UITableManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
private void Awake()
|
private void Start()
|
||||||
{
|
{
|
||||||
_tableUIComponents = gameObject.transform.GetComponentsInChildren<UITableComponent>().ToList();
|
_tableUIComponents = gameObject.transform.GetComponentsInChildren<UITableComponent>().ToList();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -16,6 +16,7 @@ namespace Logic.UI
|
|||||||
{
|
{
|
||||||
component.tableValue.text = i.ToString();
|
component.tableValue.text = i.ToString();
|
||||||
component.statusValue.text = TableState.Empty.ToString();
|
component.statusValue.text = TableState.Empty.ToString();
|
||||||
|
component.table = CustomerTableManager.Instance.GETTable(i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 05952562e4e64c67ad5046529a09fea7
|
guid: 05952562e4e64c67ad5046529a09fea7
|
||||||
timeCreated: 1617125590
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user