Added basic node system
This commit is contained in:
18
Assets/Scripts/Network/Connection.cs
Normal file
18
Assets/Scripts/Network/Connection.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Connection : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Network/Connection.cs.meta
Normal file
11
Assets/Scripts/Network/Connection.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f4fb1ff8b2de19418dabab0540c7338
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
41
Assets/Scripts/Network/Node.cs
Normal file
41
Assets/Scripts/Network/Node.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
public class Node : MonoBehaviour
|
||||
{
|
||||
public GameManager gameManager;
|
||||
public bool isActive = false;
|
||||
public enum Direction { Up, Down, Left, Right}
|
||||
public GameObject[] connections;
|
||||
public GameObject UI;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void SetActiveNode()
|
||||
{
|
||||
if (isActive) { return; }
|
||||
Debug.Log(string.Format("{0} became active node", gameObject.name));
|
||||
isActive = true;
|
||||
UI.SetActive(true);
|
||||
gameManager.networkCamera.transform.position = new Vector3(transform.position.x, gameManager.networkCamera.transform.position.y, transform.position.z);
|
||||
}
|
||||
|
||||
public void MoveToDirection(Direction dir)
|
||||
{
|
||||
connections[(int)dir].GetComponent<Node>().SetActiveNode();
|
||||
UI.SetActive(false);
|
||||
isActive = false;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Network/Node.cs.meta
Normal file
11
Assets/Scripts/Network/Node.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a9a9bc95ca8443547a959578e6da7425
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
Assets/Scripts/Network/NodeButton.cs
Normal file
43
Assets/Scripts/Network/NodeButton.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class NodeButton : MonoBehaviour
|
||||
{
|
||||
public Node node;
|
||||
public Node.Direction direction;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
if (node.connections[(int)direction] == null)
|
||||
{
|
||||
gameObject.GetComponent<Renderer>().material.color = Color.gray;
|
||||
gameObject.GetComponent<Collider>().enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
|
||||
if (Mouse.current.leftButton.wasPressedThisFrame)
|
||||
{
|
||||
Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue());
|
||||
RaycastHit hit;
|
||||
|
||||
if (Physics.Raycast(ray, out hit))
|
||||
{
|
||||
if (hit.transform == gameObject.transform)
|
||||
{
|
||||
Debug.Log(string.Format("Button down on {0}", direction));
|
||||
node.MoveToDirection(direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMouseOver()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Network/NodeButton.cs.meta
Normal file
11
Assets/Scripts/Network/NodeButton.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a64249c1002fb1440b328a6f24cc5319
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
49
Assets/Scripts/Network/Switch.cs
Normal file
49
Assets/Scripts/Network/Switch.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class Switch : MonoBehaviour
|
||||
{
|
||||
public GameManager gameManager;
|
||||
public float interactionDistance = 10;
|
||||
private Renderer renderer;
|
||||
|
||||
public Node debugNode;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
renderer = gameObject.GetComponent<Renderer>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
if (renderer.isVisible)
|
||||
{
|
||||
if (Vector3.Distance(transform.position, gameManager.player.transform.position) < interactionDistance) {
|
||||
//Debug.Log("Switch is visible and in range");
|
||||
if (Keyboard.current.eKey.wasPressedThisFrame)
|
||||
{
|
||||
gameManager.SetActiveCamera(1);
|
||||
debugNode.SetActiveNode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
// Gizmos.DrawSphere(transform.position, interactionDistance);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Network/Switch.cs.meta
Normal file
11
Assets/Scripts/Network/Switch.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b93509662707cb46a505705e8d49278
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user