void Start()
        {
            if (instance != null)
                throw new Exception("Error: multiple LocationGraphs present");
            instance = this;

            locations = new List<Location>();

            Component[] components = this.gameObject.GetComponents(typeof(Edge));
            Edge[] edges = new Edge[components.Length];
            for (int i = 0; i < components.Length; i++) {
                edges[i] = (Edge) components[i];

                if (!locations.Contains(edges[i].one))
                    locations.Add(edges[i].one);
                if (!locations.Contains(edges[i].two))
                    locations.Add(edges[i].two);
            }

            graph = new bool[locations.Count, locations.Count];
            for (int i = 0; i < graph.GetLength(0); i++) {
                for (int j = 0; j < graph.GetLength(1); j++) {
                    graph[i,j] = inverse;
                }
            }

            foreach (Edge edge in edges) {
                int indexOne = locations.IndexOf(edge.one);
                int indexTwo = locations.IndexOf(edge.two);

                graph[indexOne, indexTwo] = !inverse;
                graph[indexTwo, indexOne] = !inverse;
            }
        }
Example #2
0
        void Start()
        {
            if (instance != null)
            {
                throw new Exception("Error: multiple LocationGraphs present");
            }
            instance = this;

            locations = new List <Location>();

            Component[] components = this.gameObject.GetComponents(typeof(Edge));
            Edge[]      edges      = new Edge[components.Length];
            for (int i = 0; i < components.Length; i++)
            {
                edges[i] = (Edge)components[i];

                if (!locations.Contains(edges[i].one))
                {
                    locations.Add(edges[i].one);
                }
                if (!locations.Contains(edges[i].two))
                {
                    locations.Add(edges[i].two);
                }
            }

            graph = new bool[locations.Count, locations.Count];
            for (int i = 0; i < graph.GetLength(0); i++)
            {
                for (int j = 0; j < graph.GetLength(1); j++)
                {
                    graph[i, j] = inverse;
                }
            }

            foreach (Edge edge in edges)
            {
                int indexOne = locations.IndexOf(edge.one);
                int indexTwo = locations.IndexOf(edge.two);

                graph[indexOne, indexTwo] = !inverse;
                graph[indexTwo, indexOne] = !inverse;
            }
        }