Esempio n. 1
0
 /// <summary>
 /// True if the provided information does not match the current scene or is not
 /// available.
 /// </summary>
 /// <param name="info">The build information to check. (Null is valid.)</param>
 /// <returns>True if the provided information does not match the current scene.</returns>
 public static bool SceneMismatch(NavmeshBuildInfo info)
 {
     return !(info == null
         || info.inputScene == EditorApplication.currentScene
         || info.inputScene == null
         || info.inputScene.Length == 0);
 }
Esempio n. 2
0
        /// <summary>
        /// The standard scene display name for the information.
        /// </summary>
        /// <param name="info">The build information to check. (Null is valid.)</param>
        /// <returns>The standard scene display name for the information.</returns>
        public static string SceneDisplayName(NavmeshBuildInfo info)
        {
            if (info == null || info.inputScene == null || info.inputScene.Length == 0)
                return "Unknown";

            string result = System.IO.Path.GetFileName(info.inputScene);

            return result.Substring(0, result.LastIndexOf("."));
        }
        internal static NavmeshBuildInfo GetConfig(NavmeshBuild build)
        {
            if (!build)
                return null;

            NMGenParams config = build.Config.GetConfig();

            NavmeshBuildInfo result = new NavmeshBuildInfo();

            result.tileSize = config.TileSize;
            result.walkableHeight = config.WalkableHeight;
            result.walkableRadius = config.WalkableRadius;
            result.walkableStep = config.WalkableStep;
            result.xzCellSize = config.XZCellSize;
            result.yCellSize = config.YCellSize;
            result.borderSize = config.BorderSize;
            result.inputScene = EditorApplication.currentScene;

            return result;
        }
    /// <summary>
    /// Load a navigation mesh from data created from the <see cref="Navmesh.GetSerializedMesh"/> 
    /// method.
    /// </summary>
    /// <param name="serializedMesh">The serialized mesh.</param>
    /// <param name="buildConfig">The build information. (Optional)</param>
    /// <returns>The <see cref="NavStatus"/> flags for the operation.</returns>
    public NavStatus Load(byte[] serializedMesh, NavmeshBuildInfo buildConfig)
    {
        if (serializedMesh == null)
            return NavStatus.Failure | NavStatus.InvalidParam;

        // This roundabout method is used for validation.

        Navmesh navmesh;
        NavStatus status = Navmesh.Create(serializedMesh, out navmesh);

        if ((status & NavStatus.Sucess) == 0)
            return status;

        mDataPack = navmesh.GetSerializedMesh();

        if (mDataPack == null)
            return NavStatus.Failure;

        mBuildInfo = buildConfig;

        mVersion++;

        return NavStatus.Sucess;
    }
    /// <summary>
    /// Loads a navigation mesh.
    /// </summary>
    /// <param name="config">The mesh configuration.</param>
    /// <param name="tiles">The tiles to add to the mesh.</param>
    /// <param name="buildConfig">The build information. (Optional)</param>
    /// <returns>The <see cref="NavStatus"/> flags for the operation.</returns>
    public NavStatus Load(NavmeshParams config
        , NavmeshTileData[] tiles
        , NavmeshBuildInfo buildConfig)
    {
        if (config == null || tiles == null || tiles.Length > config.maxTiles)
            return NavStatus.Failure | NavStatus.InvalidParam;

        Navmesh navmesh;
        NavStatus status = Navmesh.Create(config, out navmesh);

        if ((status & NavStatus.Sucess) == 0)
            return status;

        foreach (NavmeshTileData tile in tiles)
        {
            if (tile == null)
                continue;

            uint trash;
            status = navmesh.AddTile(tile, Navmesh.NullTile, out trash);

            if ((status & NavStatus.Sucess) == 0)
                return status | NavStatus.InvalidParam;
        }

        mDataPack = navmesh.GetSerializedMesh();

        if (mDataPack == null)
            return NavStatus.Failure;

        mBuildInfo = buildConfig;

        mVersion++;

        return NavStatus.Sucess;
    }
    /// <summary>
    /// Loads a single-tile navigation mesh from the provided data.
    /// </summary>
    /// <param name="buildData">The tile build data.</param>
    /// <param name="buildConfig">The build information. (Optional)</param>
    /// <returns>The <see cref="NavStatus"/> flags for the operation.</returns>
    public NavStatus Load(NavmeshTileBuildData buildData, NavmeshBuildInfo buildConfig)
    {
        if (buildData == null || buildData.IsDisposed)
            return NavStatus.Failure | NavStatus.InvalidParam;

        Navmesh navmesh;
        NavStatus status = Navmesh.Create(buildData, out navmesh);

        if ((status & NavStatus.Sucess) == 0)
            return status;

        mDataPack = navmesh.GetSerializedMesh();

        if (mDataPack == null)
            return NavStatus.Failure;

        mBuildInfo = buildConfig;

        mVersion++;

        return NavStatus.Sucess;
    }