예제 #1
0
 void ClearGeneratedAssets()
 {
     //Application.dataPath = .../Assets
     WG_Helper.ClearFolder(Application.dataPath + assetMaterialPath);
     WG_Helper.ClearFolder(Application.dataPath + assetLocationPath);
     WG_Helper.ClearFolder(Application.dataPath + assetMeshPath);
     WG_Helper.ClearFolder(Application.dataPath + assetTexturePath);
     WG_Helper.ClearFolder(Application.dataPath + assetNavmeshPath);
     WG_Helper.ClearFolder(Application.dataPath + assetMinimapPath);
 }
        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
        }