pathfinding_v4 #4
@ -53,18 +53,20 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\Logic\UI\UIInventoryManager.cs" />
|
||||
<Compile Include="Assets\Logic\Agent\Agent.cs" />
|
||||
<Compile Include="Assets\Logic\Agent\Waitress.cs" />
|
||||
<Compile Include="Assets\Logic\Data\Ingredient.cs" />
|
||||
<Compile Include="Assets\Logic\Utils\FloatComparer.cs" />
|
||||
<Compile Include="Assets\Logic\UI\UITableComponent.cs" />
|
||||
<Compile Include="Assets\Logic\SceneContext.cs" />
|
||||
<Compile Include="Assets\Logic\Data\Money.cs" />
|
||||
<Compile Include="Assets\Logic\Data\Customer.cs" />
|
||||
<Compile Include="Assets\Logic\Agent\PathFinder.cs" />
|
||||
<Compile Include="Assets\Logic\UIManager.cs" />
|
||||
<Compile Include="Assets\Logic\Data\Food.cs" />
|
||||
<Compile Include="Assets\Logic\UI\UITableManager.cs" />
|
||||
<Compile Include="Assets\Logic\UI\UIInventorySlot.cs" />
|
||||
<Compile Include="Assets\Logic\Utils\Randomizer.cs" />
|
||||
<Compile Include="Assets\Logic\AgentManager.cs" />
|
||||
<Compile Include="Assets\Logic\KitchenTableManager.cs" />
|
||||
<Compile Include="Assets\Logic\UI\UIQueueManager.cs" />
|
||||
<Compile Include="Assets\Logic\UI\UIQueue.cs" />
|
||||
@ -73,7 +75,7 @@
|
||||
<Compile Include="Assets\Logic\Graph\Node.cs" />
|
||||
<Compile Include="Assets\Logic\Graph\CustomerTable.cs" />
|
||||
<Compile Include="Assets\Logic\CustomerTableManager.cs" />
|
||||
<Compile Include="Assets\Logic\Inventory\WaitressInventory.cs" />
|
||||
<Compile Include="Assets\Logic\Agent\WaitressInventory.cs" />
|
||||
<Compile Include="Assets\Logic\Graph\KitchenTable.cs" />
|
||||
<Compile Include="Assets\Logic\Data\Item.cs" />
|
||||
<None Include="Assets\Graphics\Shaders\Food.shader" />
|
||||
|
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:
|
@ -7,7 +7,7 @@ Material:
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Node_mat
|
||||
m_Name: Node_Mat
|
||||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_ShaderKeywords:
|
||||
m_LightmapFlags: 4
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
72
Assets/Logic/Agent/PathFinder.cs
Normal file
72
Assets/Logic/Agent/PathFinder.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using System.Collections.Generic;
|
||||
using Logic.Graph;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Logic.Agent
|
||||
{
|
||||
public class PathFinder : MonoBehaviour
|
||||
{
|
||||
|
||||
private readonly IDictionary<Node, Node> _nodeParents = new Dictionary<Node, Node>();
|
||||
|
||||
public Stack<Node> FindPath(Node startNode, Node endNode)
|
||||
{
|
||||
_nodeParents.Clear();
|
||||
List<Node> path = new List<Node>();
|
||||
Stack<Node> pathStack = new Stack<Node>();
|
||||
|
||||
var goal = Bfs(startNode, endNode);
|
||||
|
||||
if (goal == startNode || !_nodeParents.ContainsKey(_nodeParents[goal])) {
|
||||
print("Not found");
|
||||
return pathStack;
|
||||
}
|
||||
|
||||
Node curr = goal;
|
||||
|
||||
var parents = _nodeParents;
|
||||
while (curr != startNode) {
|
||||
path.Add (curr);
|
||||
curr = parents[curr];
|
||||
}
|
||||
path.Add(curr);
|
||||
|
||||
foreach (Node node in path)
|
||||
{
|
||||
pathStack.Push(node);
|
||||
node.MarkAsPath();
|
||||
}
|
||||
|
||||
return pathStack;
|
||||
}
|
||||
|
||||
private Node Bfs(Node startNode, Node endNode){
|
||||
|
||||
Queue<Node> queue = new Queue<Node> ();
|
||||
HashSet<Node> exploredNodes = new HashSet<Node> ();
|
||||
queue.Enqueue (startNode);
|
||||
|
||||
while (queue.Count != 0) {
|
||||
Node currentNode = queue.Dequeue ();
|
||||
|
||||
// Warunek spełnienia celu
|
||||
if (currentNode == endNode) {
|
||||
return currentNode;
|
||||
}
|
||||
|
||||
IList<Node> nodes = currentNode.neighbors;
|
||||
|
||||
foreach(Node node in nodes){
|
||||
if(!exploredNodes.Contains(node)) {
|
||||
exploredNodes.Add(node);
|
||||
_nodeParents.Add (node, currentNode);
|
||||
queue.Enqueue (node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return startNode;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
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
|
124
Assets/Logic/Agent/Waitress.cs
Normal file
124
Assets/Logic/Agent/Waitress.cs
Normal file
@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Logic.Graph;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Logic.Agent
|
||||
{
|
||||
public class Waitress : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Node currentNode;
|
||||
[SerializeField] private bool isFollowingPath = false;
|
||||
[SerializeField] private bool canMove = true; //temporary
|
||||
private Node _previousNode;
|
||||
private PathFinder _pathFinder;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_pathFinder = GetComponent<PathFinder>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!canMove) return;
|
||||
if (currentNode 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void GoToNode(Table table)
|
||||
{
|
||||
if (isFollowingPath) return;
|
||||
// Jużeli w stoliku to wyjdź ze stolika i znajdź ścieżkę
|
||||
if (currentNode is Table && _previousNode != null)
|
||||
{
|
||||
StartCoroutine(RunToAnotherNode(_previousNode, () => PrepareMove(table)));
|
||||
}
|
||||
else
|
||||
{
|
||||
PrepareMove(table);
|
||||
}
|
||||
}
|
||||
|
||||
private void PrepareMove(Table table)
|
||||
{
|
||||
isFollowingPath = true;
|
||||
Stack<Node> path = _pathFinder.FindPath(currentNode, table);
|
||||
if (path.Count > 0)
|
||||
{
|
||||
StartCoroutine(FollowPath(path));
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator FollowPath(Stack<Node> path)
|
||||
{
|
||||
|
||||
while (path.Count > 0)
|
||||
{
|
||||
if (canMove)
|
||||
{
|
||||
currentNode.ClearPathMark();
|
||||
var node = path.Pop();
|
||||
if (node != null) StartCoroutine(RunToAnotherNode(node, null));
|
||||
}
|
||||
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
|
||||
isFollowingPath = false;
|
||||
}
|
||||
|
||||
private IEnumerator RunToAnotherNode(Node destination, Action action)
|
||||
{
|
||||
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 = currentNode;
|
||||
currentNode = destination;
|
||||
canMove = true;
|
||||
|
||||
action?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
@ -4,20 +4,13 @@ using JetBrains.Annotations;
|
||||
using Logic.Data;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Logic.Inventory
|
||||
namespace Logic.Agent
|
||||
{
|
||||
public class WaitressInventory : MonoBehaviour
|
||||
{
|
||||
|
||||
public static WaitressInventory Instance;
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
[SerializeField] private List<Item> container = new List<Item>();
|
||||
private int maxSize = 4;
|
||||
|
||||
|
||||
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.Generic;
|
||||
using System.Linq;
|
||||
@ -34,8 +33,18 @@ namespace Logic
|
||||
{
|
||||
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)
|
||||
{
|
||||
@ -52,10 +61,5 @@ namespace Logic
|
||||
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
|
||||
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
|
||||
timeCreated: 1617124677
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
@ -1,6 +1,6 @@
|
||||
using System.Collections;
|
||||
using Logic.Agent;
|
||||
using Logic.Data;
|
||||
using Logic.Inventory;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Logic.Graph
|
||||
@ -76,7 +76,7 @@ namespace Logic.Graph
|
||||
if (item == null) return;
|
||||
|
||||
item.tableNumber = tableNumber;
|
||||
bool isSuccess = WaitressInventory.Instance.AddItem(item);
|
||||
bool isSuccess = AgentManager.Instance.AddItem(item);
|
||||
if (isSuccess)
|
||||
{
|
||||
ClearItemObject();
|
||||
@ -90,12 +90,12 @@ namespace Logic.Graph
|
||||
|
||||
private void HandleFoodDelivery()
|
||||
{
|
||||
Food food = WaitressInventory.Instance.GETMealForTable(tableNumber);
|
||||
Food food = AgentManager.Instance.GETMealForTable(tableNumber);
|
||||
if (food != null)
|
||||
{
|
||||
CurrentItem = food;
|
||||
Spawn();
|
||||
WaitressInventory.Instance.RemoveItem(food);
|
||||
AgentManager.Instance.RemoveItem(food);
|
||||
_eatMealCoroutine = StartCoroutine(HandleEatMeal(3));
|
||||
state = TableState.Eating;
|
||||
UIManager.Instance.uiTableManager
|
||||
|
@ -1,3 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
fileFormatVersion: 2
|
||||
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.Generic;
|
||||
using System.Linq;
|
||||
using Logic.Agent;
|
||||
using Logic.Data;
|
||||
using Logic.Inventory;
|
||||
using Logic.UI;
|
||||
using UnityEngine;
|
||||
|
||||
@ -20,7 +20,7 @@ namespace Logic.Graph
|
||||
|
||||
public void HandleSpace()
|
||||
{
|
||||
List<Recipe> recipes = WaitressInventory.Instance.GetRecipes();
|
||||
List<Recipe> recipes = AgentManager.Instance.GetRecipes();
|
||||
foreach (Recipe recipe in recipes)
|
||||
{
|
||||
KitchenTableManager.Instance.AddToQueue(recipe, QueueType.ProgressQueue);
|
||||
@ -28,7 +28,7 @@ namespace Logic.Graph
|
||||
|
||||
if (IsFull)
|
||||
{
|
||||
bool isSuccess = WaitressInventory.Instance.AddItem(CurrentItem);
|
||||
bool isSuccess = AgentManager.Instance.AddItem(CurrentItem);
|
||||
if (isSuccess)
|
||||
{
|
||||
ClearItemObject();
|
||||
|
@ -1,3 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
fileFormatVersion: 2
|
||||
guid: 4a99b5cdee244cf9bece4746cc23b43a
|
||||
timeCreated: 1616006887
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
@ -5,6 +5,8 @@ namespace Logic.Graph
|
||||
{
|
||||
public class Node : MonoBehaviour
|
||||
{
|
||||
public Material nodeMat;
|
||||
public Material pathMat;
|
||||
public List<Node> neighbors;
|
||||
[SerializeField] private float maxRange = 0.5f;
|
||||
[SerializeField] private bool debug = false;
|
||||
@ -14,9 +16,11 @@ namespace Logic.Graph
|
||||
private Vector3 _position;
|
||||
private float _nodeRayMaxLength;
|
||||
private float _tableRayMaxLength;
|
||||
private Renderer _renderer;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_renderer = GetComponent<Renderer>();
|
||||
InitializeNeighbours();
|
||||
}
|
||||
|
||||
@ -33,6 +37,22 @@ namespace Logic.Graph
|
||||
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()
|
||||
{
|
||||
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 599c04d23a8d4c178acdbeaaba748caf
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -18,6 +18,11 @@ namespace Logic
|
||||
Instance = this;
|
||||
kitchenTable = GetComponentInChildren<KitchenTable>();
|
||||
}
|
||||
|
||||
public KitchenTable GETTable()
|
||||
{
|
||||
return kitchenTable;
|
||||
}
|
||||
|
||||
public void AddToQueue(Item item, QueueType type)
|
||||
{
|
||||
|
@ -1,3 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
fileFormatVersion: 2
|
||||
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 List<Node> map;
|
||||
public Agent.Agent waitressAgent;
|
||||
public static SceneContext Instance;
|
||||
|
||||
void Start()
|
||||
@ -19,8 +18,6 @@ namespace Logic
|
||||
map = GetComponentsInChildren<Node>().ToList();
|
||||
}
|
||||
|
||||
#region Gizmos
|
||||
|
||||
private void DrawGizmosFrom(Node from, List<Node> without)
|
||||
{
|
||||
foreach (var x in from.neighbors.Where(x=>!without.Contains(x)))
|
||||
@ -46,7 +43,5 @@ namespace Logic
|
||||
if(map.Count>0)
|
||||
DrawGizmosFrom(map.First(), new List<Node>());
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
fileFormatVersion: 2
|
||||
guid: 156304b0be9c4c1f99356a96496e773a
|
||||
timeCreated: 1616158580
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
@ -1,21 +1,38 @@
|
||||
using Logic.Data;
|
||||
using Logic.Graph;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Logic.UI
|
||||
{
|
||||
public class UIQueue : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private UIInventorySlot uiInventorySlot;
|
||||
[SerializeField] private KitchenTable table;
|
||||
|
||||
public GameObject queueWrapper;
|
||||
|
||||
|
||||
// private void Start()
|
||||
// {
|
||||
// foreach (var child in queueWrapper.GetComponentsInChildren<UIInventorySlot>())
|
||||
// {
|
||||
// Destroy(child.gameObject);
|
||||
// }
|
||||
// }
|
||||
|
||||
private void Start()
|
||||
{
|
||||
foreach (var child in queueWrapper.GetComponentsInChildren<UIInventorySlot>())
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
table = KitchenTableManager.Instance.GETTable();
|
||||
var button = GetComponentInChildren<Button>();
|
||||
button.onClick.AddListener( ButtonClick );
|
||||
}
|
||||
|
||||
private void ButtonClick()
|
||||
{
|
||||
AgentManager.Instance.GoToNode(table);
|
||||
}
|
||||
|
||||
public void Add(Item item)
|
||||
{
|
||||
UIInventorySlot uiQueueSlot = Instantiate(uiInventorySlot, queueWrapper.transform, false);
|
||||
|
@ -1,3 +1,4 @@
|
||||
using Logic.Graph;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@ -8,5 +9,17 @@ namespace Logic.UI
|
||||
public Text tableValue;
|
||||
public Text statusValue;
|
||||
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
|
||||
{
|
||||
private void Awake()
|
||||
private void Start()
|
||||
{
|
||||
_tableUIComponents = gameObject.transform.GetComponentsInChildren<UITableComponent>().ToList();
|
||||
int i = 0;
|
||||
@ -16,6 +16,7 @@ namespace Logic.UI
|
||||
{
|
||||
component.tableValue.text = i.ToString();
|
||||
component.statusValue.text = TableState.Empty.ToString();
|
||||
component.table = CustomerTableManager.Instance.GETTable(i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
fileFormatVersion: 2
|
||||
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