示例#1
0
        void PrepareScene(Transform locationRoot, Dictionary <string, string> savedStandardMeshes, Dictionary <string, string> savedObjectMeshes)
        {
            for (int i = 0; i < locationRoot.childCount; i++)
            {
                Transform             loc           = locationRoot.GetChild(i);
                WG_LocationController locController = loc.GetComponent <WG_LocationController>();
                if (locController != null)
                {
                    locController.PrepareLocation("Assets" + assetMeshPath,
                                                  "Assets" + assetMaterialPath,
                                                  "Assets" + assetTexturePath,
                                                  "Assets" + assetMinimapPath,
                                                  lightMapShader,
                                                  minimapSize, minimapCamera, minimapCameraHeight, exportLightmapHDR,
                                                  savedStandardMeshes, savedObjectMeshes);
                }
            }

            //prepare navmesh
            WG_TerrainBuilder builderComponent = builder.gameObject.GetComponent <WG_TerrainBuilder>();
            NavMeshData       data             = builderComponent.GetNavmeshData();

            if (data != null)
            {
                SaveNavmeshAsset(data);
                localNavMesh = data;
            }
        }
示例#2
0
        public List <WG_LocationController> GenerateLocationSegments(WG_TerrainBuilder builder, float segmentSize, float meshSquareSize, int meshSquaresCount, int segmentMinX, int segmentMaxX, int segmentMinY, int segmenMaxY, GameObject rootObject, Material floorMaterial, Material heightMaterial, Material wallsMaterial, bool[,] map, float height, bool bakeNavMesh, NavMeshModifierVolume navMeshCutter, float uvPadding)
        {
            List <WG_LocationController> locations = new List <WG_LocationController>();

            for (int u = segmentMinX; u < segmentMaxX + 1; u++)
            {
                for (int v = segmentMinY; v < segmenMaxY + 1; v++)
                {
                    bool[,] segmentMap = new bool[meshSquaresCount + 1, meshSquaresCount + 1];
                    //fill data for one segment
                    for (int x = 0; x < meshSquaresCount + 1; x++)
                    {
                        for (int y = 0; y < meshSquaresCount + 1; y++)
                        {
                            segmentMap[x, y] = map[(u - segmentMinX) * (meshSquaresCount) + x, (v - segmentMinY) * (meshSquaresCount) + y];
                        }
                    }
                    locations.Add(EmitSegment(u, v, segmentSize, meshSquareSize, rootObject.transform, segmentMap, floorMaterial, wallsMaterial, height, uvPadding));
                }
            }

            navMeshCutter.center = new Vector3((segmentMinX + segmentMaxX) * segmentSize / 2.0f, height, (segmentMinY + segmenMaxY) * segmentSize / 2.0f);
            navMeshCutter.size   = new Vector3((segmentMaxX - segmentMinX + 1) * segmentSize, 1, (segmenMaxY - segmentMinY + 1) * segmentSize);
            BuilNavMesh(builder, locations, bakeNavMesh);

            return(locations);
        }
        void SaveTowerPositions(WG_TerrainBuilder builderComponent)
        {
            NumberFormatInfo nfi = new NumberFormatInfo();

            nfi.NumberDecimalSeparator = ".";

            WG_Tower[] positions = WG_Helper.FindObjectsOfTypeAll <WG_Tower>().ToArray();// FindObjectsOfType<WG_Tower>();
            string     path      = serverPath + "Towers.txt";

            using (StreamWriter sw = File.CreateText(path))
            {
                for (int i = 0; i < positions.Length; i++)
                {
                    Vector3 p   = positions[i].transform.position;
                    IntPair loc = WG_Helper.GetLocationCoordinates(p, builderComponent.segmentSize);
                    if (loc.u >= builderComponent.segmentsMinX && loc.u <= builderComponent.segmenstMaxX && loc.v >= builderComponent.segmentsMinY && loc.v <= builderComponent.segmenstMaxY)
                    {
                        sw.Write(positions[i].towerType);
                        sw.Write(",");
                        sw.Write(p.x.ToString("0.000", nfi));
                        sw.Write(",");
                        sw.Write(p.z.ToString("0.000", nfi));
                        sw.Write(",");
                        sw.Write(positions[i].towerName);
                        if (i < positions.Length - 1)
                        {
                            sw.Write("|");
                        }
                    }
                }
            }
        }
        public override void OnInspectorGUI()
        {
            WG_TerrainBuilder wgBuilder = (WG_TerrainBuilder)target;

            DrawDefaultInspector();

            if (GUILayout.Button("Update Map"))
            {
                wgBuilder.UpdateMap();
            }

            if (GUILayout.Button("Build navmesh only"))
            {
                wgBuilder.BuildNavmeshOnly();
            }

            if (GUILayout.Button("1. Build Scene"))
            {
                wgBuilder.BuildMesh();
            }

            if (GUILayout.Button("1.5. Combine"))
            {
                wgBuilder.CombineCommand();
            }
        }
        public void PrepareNavmesh()
        {
            //prepare navmesh
            WG_TerrainBuilder builderComponent = builder.gameObject.GetComponent <WG_TerrainBuilder>();
            NavMeshData       data             = builderComponent.GetNavmeshData();

            if (data != null)
            {
                SaveNavmeshAsset(data);
                localNavMesh = data;
            }
        }
示例#6
0
        void BuilNavMesh(WG_TerrainBuilder builder, List <WG_LocationController> locations, bool bakeNavMesh)
        {
            for (int i = 0; i < locations.Count; i++)
            {
                GameObject     ground  = locations[i].groundGO;
                NavMeshSurface surface = ground.AddComponent <NavMeshSurface>();
            }

            if (bakeNavMesh)
            {
                //call bake from the first location
                if (locations.Count > 0)
                {
                    NavMeshSurface       navSurface = locations[0].groundGO.GetComponent <NavMeshSurface>();
                    NavMeshBuildSettings settings   = navSurface.GetBuildSettings();

                    builder.SaveNavMeshData(navSurface.navMeshData);
                }
            }
        }
示例#7
0
        void ExportScene(Transform locationRoot)
        {
            for (int i = 0; i < locationRoot.childCount; i++)
            {
                Transform             loc           = locationRoot.GetChild(i);
                WG_LocationController locController = loc.GetComponent <WG_LocationController>();

                if (locController != null)
                {
                    locController.ExportLocation("Assets" + assetLocationPath, minimapSize, minimapCamera, minimapCameraHeight, "Assets" + assetMinimapPath);
                }
            }

            //export navmesh
#if UNITY_EDITOR
            WG_TerrainBuilder builderComponent = builder.gameObject.GetComponent <WG_TerrainBuilder>();
            NavMeshData       data             = builderComponent.GetNavmeshData();
            string            navmeshAssetPath = "";
            if (data != null)
            {
                navmeshAssetPath = "navmeshes/" + data.name;
                AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(data)).SetAssetBundleNameAndVariant(navmeshAssetPath, "");
            }
            else
            {
                if (localNavMesh == null)
                {
                    Debug.Log("Navmesh data is null, can't export it.");
                }
                else
                {
                    Debug.Log("Use local version of the navmesh data object.");
                    data             = localNavMesh;
                    navmeshAssetPath = "navmeshes/" + localNavMesh.name;
                    AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(localNavMesh)).SetAssetBundleNameAndVariant(navmeshAssetPath, "");
                }
            }

            //create xml with navmeshlink and starting points
            GlobalLocation globalLocation = new GlobalLocation();
            if (navmeshAssetPath.Length > 0 && data != null)
            {
                globalLocation.navmeshData = new NavmeshData()
                {
                    link = navmeshAssetPath, name = data.name
                };
                if (exportPlayerPositionsInLocations)
                {
                    globalLocation.positions = new List <PositionData>();
                    WG_Position[] positions = FindObjectsOfType <WG_Position>();
                    for (int i = 0; i < positions.Length; i++)
                    {
                        Vector3 pos = positions[i].gameObject.transform.position;
                        globalLocation.positions.Add(new PositionData()
                        {
                            positionX = pos.x, positionY = pos.y, positionZ = pos.z
                        });
                    }

                    if (globalLocation.positions.Count == 0)
                    {
                        Debug.Log("No start positions on the scene. Add default position (0, 0, 0).");
                        globalLocation.positions.Add(new PositionData()
                        {
                            positionX = 0.0f, positionY = 0.0f, positionZ = 0.0f
                        });
                    }
                }


                globalLocation.bounds = new LocationsBounds()
                {
                    minU = builderComponent.segmentsMinX,
                    maxU = builderComponent.segmenstMaxX,
                    minV = builderComponent.segmentsMinY,
                    maxV = builderComponent.segmenstMaxY
                };

                globalLocation.locationSize = new LocationSize()
                {
                    value = builderComponent.segmentSize
                };

                string globalLocationName      = "global_location";
                string globalLocationAssetPath = "Assets" + assetLocationPath + globalLocationName + ".xml";
                globalLocation.Save(globalLocationAssetPath);
                AssetDatabase.ImportAsset(globalLocationAssetPath, ImportAssetOptions.ForceUpdate);
                AssetImporter.GetAtPath(globalLocationAssetPath).SetAssetBundleNameAndVariant("locations/" + globalLocationName, "");

                //export server data
                SavePlayerPositions();
                //SaveCollisionMap(data);
                SaveCollisionMap(serverPath);
                SaveTowerPositions();
            }
#endif
        }
        void ExportScene(Transform locationRoot)
        {
            WG_Helper.ClearFolder(Application.dataPath + assetLocationSOPath);

            for (int i = 0; i < locationRoot.childCount; i++)
            {
                Transform             loc           = locationRoot.GetChild(i);
                WG_LocationController locController = loc.GetComponent <WG_LocationController>();

                if (locController != null)
                {
                    locController.ExportLocation("Assets" + assetLocationXMLPath, "Assets" + assetLocationSOPath, minimapSize, minimapCamera, minimapCameraHeight, "Assets" + assetMinimapPath);
                }
            }

#if UNITY_EDITOR
            //export navmesh
            WG_TerrainBuilder builderComponent = builder.gameObject.GetComponent <WG_TerrainBuilder>();
            NavMeshData       data             = builderComponent.GetNavmeshData();
            string            navmeshAssetPath = "";
            if (data != null)
            {
                navmeshAssetPath = "navmeshes/" + data.name;
                AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(data)).SetAssetBundleNameAndVariant(navmeshAssetPath, "");
            }
            else
            {
                if (localNavMesh == null)
                {
                    Debug.Log("Navmesh data is null, can't export it.");
                }
                else
                {
                    Debug.Log("Use local version of the navmesh data object.");
                    data             = localNavMesh;
                    navmeshAssetPath = "navmeshes/" + localNavMesh.name;
                    AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(localNavMesh)).SetAssetBundleNameAndVariant(navmeshAssetPath, "");
                }
            }

            //create xml with navmeshlink and starting points
            GlobalLocation globalLocation = new GlobalLocation();
            if (navmeshAssetPath.Length > 0 && data != null)
            {
                globalLocation.navmeshData = new NavmeshData()
                {
                    link = navmeshAssetPath, name = data.name
                };
                if (exportPlayerPositionsInLocations)
                {
                    globalLocation.positions = new List <PositionData>();
                    WG_Position[] positions = WG_Helper.FindObjectsOfTypeAll <WG_Position>().ToArray();// FindObjectsOfType<WG_Position>();
                    for (int i = 0; i < positions.Length; i++)
                    {
                        Vector3 pos = positions[i].gameObject.transform.position;
                        IntPair loc = WG_Helper.GetLocationCoordinates(pos, builderComponent.segmentSize);
                        if (loc.u >= builderComponent.segmentsMinX && loc.u <= builderComponent.segmenstMaxX && loc.v >= builderComponent.segmentsMinY && loc.v <= builderComponent.segmenstMaxY)
                        {
                            globalLocation.positions.Add(new PositionData()
                            {
                                positionX = pos.x, positionY = pos.y, positionZ = pos.z
                            });
                        }
                    }

                    if (globalLocation.positions.Count == 0)
                    {
                        Debug.Log("No start positions on the scene. Add default position (0, 0, 0).");
                        globalLocation.positions.Add(new PositionData()
                        {
                            positionX = 0.0f, positionY = 0.0f, positionZ = 0.0f
                        });
                    }
                }


                globalLocation.bounds = new LocationsBounds()
                {
                    minU = builderComponent.segmentsMinX,
                    maxU = builderComponent.segmenstMaxX,
                    minV = builderComponent.segmentsMinY,
                    maxV = builderComponent.segmenstMaxY
                };

                globalLocation.locationSize = new LocationSize()
                {
                    value = builderComponent.segmentSize
                };

                string globalLocationName      = "global_location";
                string globalLocationAssetPath = "Assets" + assetLocationXMLPath + globalLocationName + ".xml";
                globalLocation.Save(globalLocationAssetPath);
                AssetDatabase.ImportAsset(globalLocationAssetPath, ImportAssetOptions.ForceUpdate);
                AssetImporter.GetAtPath(globalLocationAssetPath).SetAssetBundleNameAndVariant("locations/" + globalLocationName, "");

                //export server data
                SavePlayerPositions(builderComponent);
                SaveCollisionMap(serverPath);
                SaveTowerPositions(builderComponent);

                //also export locations data to SO
                GlobalLocationDataSO globalSO = ScriptableObjectUtility.CreateAsset <GlobalLocationDataSO>("Assets" + assetLocationSOPath, globalLocationName);
                globalSO.minU = builderComponent.segmentsMinX;
                globalSO.maxU = builderComponent.segmenstMaxX;
                globalSO.minV = builderComponent.segmentsMinY;
                globalSO.maxV = builderComponent.segmenstMaxY;

                globalSO.size = builderComponent.segmentSize;

                globalSO.navmeshName = data.name;
                globalSO.navmeshLink = navmeshAssetPath;

                if (exportPlayerPositionsInLocations)
                {
                    globalSO.startPositions = new List <Vector3>();
                    for (int pi = 0; pi < globalLocation.positions.Count; pi++)
                    {
                        globalSO.startPositions.Add(new Vector3(globalLocation.positions[pi].positionX, globalLocation.positions[pi].positionY, globalLocation.positions[pi].positionZ));
                    }
                }

                EditorUtility.SetDirty(globalSO);
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
                AssetImporter.GetAtPath("Assets" + assetLocationSOPath + globalLocationName + ".asset").SetAssetBundleNameAndVariant("locations_so/" + globalLocationName, "");
            }
#endif
        }