Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEditor;
- public class Node : MonoBehaviour
- {
- public GameObject[] neighbors;
- public float range = 5.0f;
- private void OnDrawGizmosSelected()
- {
- Gizmos.color = Color.red;
- Gizmos.DrawWireSphere(gameObject.transform.position, range);
- }
- public void RecalcNeighbors()
- {
- GameObject[] allNodes = GameObject.FindGameObjectsWithTag("node");
- List<GameObject> result = new List<GameObject>();
- foreach (GameObject o in allNodes)
- {
- if(Vector3.Distance(o.transform.position, gameObject.transform.position) < range)
- {
- result.Add(o);
- }
- }
- neighbors = result.ToArray();
- }
- }
- [CustomEditor(typeof(Node))]
- public class NodeInspector : Editor
- {
- Node node;
- private void OnEnable()
- {
- node = (Node)target;
- }
- public override void OnInspectorGUI()
- {
- DrawDefaultInspector();
- if(GUILayout.Button("Recalc Neighbors"))
- {
- node.RecalcNeighbors();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement