예제 #1
0
    public static bool BuildBundle(BuildTarget buildTarget, out string filepath, bool ignoreGraphCacheWarning)
    {
        filepath = "";

        Debug.ClearDeveloperConsole();
        Debug.Log("\n\n");
        Debug.Log("\n--- Building map ---");

        AssetBundleBuild build = new AssetBundleBuild();

        if (!AssetDatabase.IsValidFolder(PATH))
        {
            Debug.Log("No Export folder found, creating one.");
            AssetDatabase.CreateFolder("Assets", "Export");
        }

        try {
            EditorSceneManager.SaveOpenScenes();

            if (!SanityCheck.DoSanityCheck(ignoreGraphCacheWarning))
            {
                Debug.Log("Sanity check failed, aborting export!");
                return(false);
            }



            //Bundle graphcache if available.
            TextAsset graphCacheAsset           = CacheGenerator.GetGraphCacheFile();
            TextAsset graphCacheCoverPointAsset = CacheGenerator.GetGraphCacheCoverPointFile();

            if (graphCacheAsset != null && graphCacheCoverPointAsset != null)
            {
                Debug.Log("Graphcache was found, bundling!");
                SetupGraphCache(graphCacheAsset, graphCacheCoverPointAsset);
                EditorSceneManager.SaveOpenScenes();
            }
            else
            {
                Debug.Log("WARNING: Couldn't find graphcache.");
            }

            Scene currentScene = EditorSceneManager.GetSceneAt(0);

            build.assetBundleName = currentScene.name + ".rfl";

            List <string> assetNames = new List <string>();

            assetNames.Add(currentScene.path);


            build.assetNames = assetNames.ToArray();

            AssetBundleBuild[] buildMap = new AssetBundleBuild[] { build };

            BuildPipeline.BuildAssetBundles(PATH, buildMap, BuildAssetBundleOptions.None, buildTarget);
        }
        catch (System.Exception e) {
            EditorUtility.DisplayDialog("Could not export map", "Could not create the .rfl file.\n\nDetails: " + e.Message, "Ok");
            Debug.LogException(e);
            return(false);
        }

        Debug.Log("Successfully exported " + build.assetBundleName);

        if (Paths.HasExecutablePath())
        {
            string exportPath = Paths.ProjectPath() + PATH + "/" + build.assetBundleName;

            string levelDestinationPath = Paths.ExecutableToolsStagingPath() + "/" + build.assetBundleName;

            try {
                File.Copy(exportPath, levelDestinationPath, true);
            }
            catch (System.Exception e) {
                EditorUtility.DisplayDialog("Could not export map", "Could not copy map to the mod staging folder.\n\nDetails: " + e.Message, "Ok");
                Debug.LogException(e);
                return(false);
            }

            Debug.Log("Copied exported map to " + levelDestinationPath);
            filepath = levelDestinationPath;
            return(true);
        }

        return(false);
    }
예제 #2
0
    public static bool DoSanityCheck(bool ignoreGraphCacheWarning)
    {
        Debug.Log("Running map sanity check");

        ClearLog();

        SpawnPoint[] spawnPoints            = GameObject.FindObjectsOfType <SpawnPoint>();
        SpawnPointNeighborManager neighbors = GameObject.FindObjectOfType <SpawnPointNeighborManager>();

        Camera[]         cameras          = GameObject.FindObjectsOfType <Camera>();
        PathfindingBox[] pathfindingBoxes = GameObject.FindObjectsOfType <PathfindingBox>();

        bool ok = true;

        for (int i = 0; i < requiredTypes.Length; i++)
        {
            if (GameObject.FindObjectOfType(requiredTypes[i]) == null)
            {
                Log("No " + requiredTypes[i] + " found in scene, you should place a " + prefabs[i] + " from the \"Prefabs/Map Elements/Must Haves\" folder!");
                ok = false;
            }
        }

        bool blueTeamSpawn = false;
        bool redTeamSpawn  = false;

        foreach (SpawnPoint spawnPoint in spawnPoints)
        {
            if (spawnPoint.defaultOwner == SpawnPoint.Team.Blue)
            {
                blueTeamSpawn = true;
            }
            else if (spawnPoint.defaultOwner == SpawnPoint.Team.Red)
            {
                redTeamSpawn = true;
            }
        }

        if (!blueTeamSpawn || !redTeamSpawn)
        {
            Log("Not all teams have spawn points. Make sure both teams is the default owner of at least one spawn point!");
            ok = false;
        }

        if (neighbors != null && neighbors.neighbors.Length == 0)
        {
            Log("There are no neighbors set up in the Neighbor Manager.");
            ok = false;
        }

        if (!ok)
        {
            Log("All these issues must be fixed before the map can be exported.");
            DisplayFatalLog();
            return(false);
        }



        // WARNINGS

        foreach (Camera camera in cameras)
        {
            if (camera.enabled && !CameraHasSupportedScript(camera))
            {
                Log("The camera " + camera.gameObject.name + " doesn't have a game script on it, and is likely unintetionally placed. Consider deleting it!");
            }
        }

        foreach (PathfindingBox box in pathfindingBoxes)
        {
            /*int cellNumber = Mathf.RoundToInt((box.transform.localScale.x/box.cellSize)*(box.transform.localScale.z/box.cellSize));
             * if(cellNumber > PathfindingBox.RECOMMENDED_MAX_CELLS) {
             *
             * }*/

            if (box.characterRadius < box.cellSize * 2)
            {
                Log("Character radius of PathfindingBox " + box.gameObject.name + " is less than double the cell size. You should increase the character radius to something larger than " + box.cellSize * 2 + "!");
            }
        }

        Camera minimapCamera = GameObject.FindObjectOfType <MinimapCamera>().GetComponent <Camera>();

        foreach (SpawnPoint spawn in spawnPoints)
        {
            Vector3 viewportPoint = minimapCamera.WorldToViewportPoint(spawn.transform.position);
            if (viewportPoint.x < 0 || viewportPoint.x > 11f || viewportPoint.y < 0 || viewportPoint.y > 1f)
            {
                Log("Spawnpoint " + spawn.gameObject.name + " is outside of the minimap camera, move the minimap or increase the minimap camera's field of view to solve this.");
            }
        }


        if (EditorSceneManager.GetSceneAt(0).name == "ExampleScene")
        {
            Log("You are working in the ExampleScene, you should save it as your own scene so it doesn't get accidentally overwritten if you update the Ravenfield Tools.");
        }

        if (RenderSettings.ambientMode != UnityEngine.Rendering.AmbientMode.Trilight)
        {
            Log("Environment Lighting Source is not set to Gradient, consider changing this (in Window -> Lighting -> Settings)!");
        }

        if (neighbors.neighbors.Length > spawnPoints.Length * RECOMMENDED_MAX_NEIGHBORS_PER_FLAG)
        {
            Log("You have a very large number of neighbor elements, consider simplifying the neighbor connections!");
        }

        if (UnityEditor.Lightmapping.bakedGI)
        {
            Log("Your scene is set up to use Baked Global Illumination. This is not required for Ravenfield, consider disabling it (in Window -> Lighting -> Settings)!");
        }
        if (UnityEditor.Lightmapping.realtimeGI)
        {
            Log("Your scene is set up to use Realtime Global Illumination. This is not required for Ravenfield, consider disabling it (in Window -> Lighting -> Settings)!");
        }

        if (!ignoreGraphCacheWarning && !CacheGenerator.GraphCacheSceneObjectExists() && (CacheGenerator.GetGraphCacheFile() == null || CacheGenerator.GetGraphCacheCoverPointFile() == null))
        {
            Log("You haven't generated a navmesh graph cache for your scene. You can generate one by running Ravenfield Tools -> Scan Pathfinding. This will significantly speed up load times!");
        }

        if (!string.IsNullOrEmpty(log))
        {
            DisplayWarningLog();
        }

        return(ok);
    }