Beispiel #1
0
        public static NodeMap FilterByGroup(this NodeMap @self, int group)
        {
            var groupDict = new NodeMap.GroupDict();

            NodeMap.Group(@self, out groupDict);
            var objs = groupDict.Where((obj) => obj.Value == group);
            var res  = new Dictionary <string, NodeMap.NodeData>();

            foreach (var obj in objs)
            {
                res[obj.Key] = @self.nodeMap[obj.Key];
            }

            @self.nodeMap = res;
            return(@self);
        }
Beispiel #2
0
        public static void CreateRoadByNodeMap(NodeMap nodeMap, Action <CreateRoadMeshScripts.MeshSet, string, string> createMeshGameObject)
        {
            var hash         = new HashSet <string>();
            var roadMeshSets = new List <CreateRoadMeshScripts.MeshSet>();
            var areaMeshSets = new List <CreateRoadMeshScripts.MeshSet>();
            var groupDict    = new NodeMap.GroupDict();

            NodeMap.Group(nodeMap, out groupDict);

            foreach (var entry in groupDict)
            {
                // FIXME: 1つ以上のグループが存在する場合の暫定対処, 警告だけ出して処理続行する.
                if (entry.Value != 0)
                {
                    Debug.LogWarningFormat("More than one Node groups exist.");
                    continue;
                }

                CreateRoadMeshFromNode(nodeMap.nodeMap, entry.Key, hash,
                                       CreateRoadMeshScripts.CreateAddToMeshSetListCallback(roadMeshSets)
                                       );
                CreateCrossRoadMeshFromNode(nodeMap.nodeMap, entry.Key,
                                            CreateRoadMeshScripts.CreateAddToMeshSetListCallback(areaMeshSets)
                                            );
            }

            roadMeshSets = CreateRoadMeshScripts.GetCombinedMesh(roadMeshSets);

            for (int i = 0; i < roadMeshSets.Count; i++)
            {
                createMeshGameObject(roadMeshSets[i], "Road" + i, "TileMaterial");
            }

            areaMeshSets = CreateRoadMeshScripts.GetCombinedMesh(areaMeshSets.ConvertAll(ConvertUvSetting));

            for (int i = 0; i < areaMeshSets.Count; i++)
            {
                createMeshGameObject(areaMeshSets[i], "CrossRoad" + i, "CrossTileMaterial");
            }
        }
Beispiel #3
0
        /// <summary>
        /// _transform にランダムな道を歩かせる.
        /// </summary>
        /// <param name="_transform">Transform.</param>
        public void Test(Transform _transform)
        {
            nextNode         = null;
            _targetTransForm = _transform;
            var groupDict  = new NodeMap.GroupDict();
            var groupCount = NodeMap.Group(nodeMap, out groupDict);

            groupDict.Dump();
            var sameGroup = groupDict.Where((obj) =>
            {
                return(obj.Value == 0);
            }).ToList();
            int start     = Random.Range(0, sameGroup.Count);
            int goal      = Random.Range(0, sameGroup.Count);
            var nodeNames = sameGroup.Select((arg) => arg.Key).ToArray();

            Debug.Log(sameGroup.Count);
            NodeMap.CostDict    keyValuePairs;
            LinkedList <string> route;
            var pathCount = NodeMap.GetShortestRoute(nodeMap, nodeNames[start], nodeNames[goal], 10000, out keyValuePairs, out route);

            Debug.Log(string.Format("道を探します : start : {0} {1}", nodeNames[start], nodeNames[goal]));

            if (route == null)
            {
                Debug.Log("道が遠すぎたため停止します");
                currentRoute = null;
                return;
            }

            foreach (var nodeName in route)
            {
                Debug.Log("route : " + nodeName + " : " + nodeMap.nodeMap[nodeName].Position);
            }

            currentRoute = route;
        }
Beispiel #4
0
        public static void CreateRoadByNodeMapNext(NodeMap nodeMap, Action <CreateRoadMeshScripts.MeshSet, string, string> createMeshGameObject)
        {
            var hash          = new Dictionary <string, BeefMeshUtility.IPlaneMeshSet>();
            var roadMeshSets  = new List <BeefMeshUtility.IPlaneMeshSet>();
            var curveMeshSets = new List <BeefMeshUtility.IPlaneMeshSet>();
            var areaMeshSets  = new List <BeefMeshUtility.IPlaneMeshSet>();
            var groupDict     = new NodeMap.GroupDict(nodeMap.nodeMap.Count);

            NodeMap.Group(nodeMap, out groupDict);

            foreach (var entry in groupDict)
            {
                // FIXME: 1つ以上のグループが存在する場合の暫定対処, 警告だけ出して処理続行する.
                if (entry.Value != 0)
                {
                    Debug.LogWarningFormat("More than one Node groups exist.");
                    continue;
                }

                CreateRoadMeshFromNodeLine(nodeMap.nodeMap, entry.Key, hash, roadMeshSets);
                var key1       = entry.Key;
                var centerNode = nodeMap.nodeMap[key1];

                if (1 < centerNode.Graph.Count)
                {
                    var connectedMeshSets = centerNode.Graph.ConvertAll((string key2) => key1 + ":" + key2).ConvertAll((string input) => hash[input]).ToList();
                    var meshSet           = BeefMeshUtility.GetFrameMeshSet(connectedMeshSets);

                    if (meshSet == null)
                    {
                        continue;
                    }

                    if (centerNode.Graph.Count == 2)
                    {
                        curveMeshSets.Add(meshSet);
                    }
                    else
                    {
                        areaMeshSets.Add(meshSet);
                    }
                }
            }

            var roadMeshSetsNeo = CreateRoadMeshScripts.GetCombinedMesh(roadMeshSets.ConvertAll((input) => input.GetMeshSet()));

            for (int i = 0; i < roadMeshSetsNeo.Count; i++)
            {
                createMeshGameObject(roadMeshSetsNeo[i], "Road" + i, "TileMaterial");
            }

            var curveMeshSetsNeo = CreateRoadMeshScripts.GetCombinedMesh(curveMeshSets.ConvertAll((input) => input.GetMeshSet()));

            for (int i = 0; i < curveMeshSetsNeo.Count; i++)
            {
                createMeshGameObject(curveMeshSetsNeo[i], "Curve" + i, "CurveTileMaterial");
            }

            var areaMeshSetsNeo = CreateRoadMeshScripts.GetCombinedMesh(areaMeshSets.ConvertAll((input) => input.GetMeshSet()));

            for (int i = 0; i < areaMeshSetsNeo.Count; i++)
            {
                createMeshGameObject(areaMeshSetsNeo[i], "CrossRoad" + i, "CrossTileMaterial");
            }
        }