Beispiel #1
0
        /// <summary>
        /// Preload the stencils for ALL groups
        /// </summary>
        public void PreloadStencilData()
        {
            isStencilLayerFiltersToApply = new bool[numActiveGroups];

            for (int i = 0; i < numActiveGroups; i++)
            {
                // Are there any Stencil Layer filters for this group?
                isStencilLayerFiltersToApply[i] = LBFilter.Contains(activeGroupList[i].filterList, LBFilter.FilterType.StencilLayer);
                if (isStencilLayerFiltersToApply[i])
                {
                    // Preload the stencil data
                    if (activeGroupList[i].filterList != null)
                    {
                        foreach (LBFilter lbFilter in activeGroupList[i].filterList)
                        {
                            if (lbFilter != null)
                            {
                                // Currently all stencil filters are AND
                                // Is this a valid Stencil Filter?
                                if (lbFilter.filterType == LBFilter.FilterType.StencilLayer && !string.IsNullOrEmpty(lbFilter.lbStencilGUID) && !string.IsNullOrEmpty(lbFilter.lbStencilLayerGUID))
                                {
                                    // If the temporary class instance isn't defined, look it up and validate it is in the current landscape
                                    if (lbFilter.lbStencil == null)
                                    {
                                        lbFilter.lbStencil = LBStencil.GetStencilInLandscape(lbGroupParams.landscape, lbFilter.lbStencilGUID, lbGroupParams.showErrors);
                                    }

                                    if (lbFilter.lbStencil != null)
                                    {
                                        // Find the Stencil Layer for this Layer Filter and populate the temporary class instance
                                        lbFilter.lbStencilLayer = lbFilter.lbStencil.GetStencilLayerByGUID(lbFilter.lbStencilLayerGUID);

                                        // Load the USHORT data
                                        if (lbFilter.lbStencilLayer != null)
                                        {
                                            if (lbFilter.lbStencilLayer.layerArray == null)
                                            {
                                                lbFilter.lbStencilLayer.AllocLayerArray();
                                                lbFilter.lbStencilLayer.UnCompressToUShort();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Stencil LBLayerFilter temp variables
            stencilLayerPosN = new Vector2();
        }
        /// <summary>
        /// Update the landscape to the current version
        /// v2.0.2 Upgrades the Texture, Grass, and Tree list to include any missing GUIDs.
        /// v2.1.5 Updates Groups to include any missing GUIDs
        /// v2.3.2 Update Texture Filters for Grass and Trees to NOT cutOff value of 0.1
        /// </summary>
        /// <param name="OldVersion"></param>
        /// <param name="NewVersion"></param>
        /// <param name="landscapeToUpdate"></param>
        /// <param name="isSilentUpdate"></param>
        /// <returns></returns>
        public static bool LandscapeUpdate(string OldVersion, string NewVersion, ref LBLandscape landscapeToUpdate, bool isSilentUpdate = false)
        {
            bool isSuccessful = false;

            if (landscapeToUpdate == null)
            {
#if UNITY_EDITOR
                if (!isSilentUpdate)
                {
                    Debug.LogError("LBUpdate LandscapeUpdate - no landscape to update");
                }
#endif
            }
            else
            {
                //Debug.Log("LBUpdate LandscapeUpdate - upgrading " + landscapeToUpdate.gameObject.name + " from version " + OldVersion + " to " + NewVersion);
                landscapeToUpdate.LastUpdatedVersion = NewVersion;

                int majorVersion = landscapeToUpdate.GetLastUpdateMajorVersion;
                int minorVersion = landscapeToUpdate.GetLastUpdateMinorVersion;
                int patchVersion = landscapeToUpdate.GetLastUpdatePatchVersion;

                // Before a Landscape is imported, it doesn't have a grass list, so check first.
                if (landscapeToUpdate.terrainGrassList != null)
                {
                    // Update any Grass types that don't have a GUID
                    List <LBTerrainGrass> updateableGrassList = landscapeToUpdate.terrainGrassList.FindAll(grs => string.IsNullOrEmpty(grs.GUID));

                    int numGrassToUpdate = updateableGrassList == null ? 0 : updateableGrassList.Count;

                    for (int gIdx = 0; gIdx < numGrassToUpdate; gIdx++)
                    {
                        updateableGrassList[gIdx].GUID = System.Guid.NewGuid().ToString();
                    }

                    // Has landscape been created before 2.3.2?
                    // For Texture NOT filters, reset cutOff to default of 0.1 to mimic pre-2.3.2 behaviour.
                    // Fix Texture filter GUIDs
                    if (majorVersion == 1 || (majorVersion == 2 && minorVersion <= 3 && (minorVersion < 3 || patchVersion < 2)))
                    {
                        numGrassToUpdate = landscapeToUpdate.terrainGrassList == null ? 0 : landscapeToUpdate.terrainGrassList.Count;

                        for (int gIdx = 0; gIdx < numGrassToUpdate; gIdx++)
                        {
                            if (LBFilter.Contains(landscapeToUpdate.terrainGrassList[gIdx].filterList, LBFilter.FilterType.Texture))
                            {
                                LBFilter.UpdateTextures(landscapeToUpdate.terrainGrassList[gIdx].filterList, landscapeToUpdate.terrainTexturesList, !isSilentUpdate);

                                foreach (LBFilter lbFilter in landscapeToUpdate.terrainGrassList[gIdx].filterList)
                                {
                                    if (lbFilter != null && lbFilter.filterType == LBFilter.FilterType.Texture && lbFilter.filterMode == LBFilter.FilterMode.NOT && lbFilter.cutOff == 0.5f)
                                    {
                                        lbFilter.cutOff = 0.1f;
                                    }
                                }
                            }
                        }
                    }
                }

                // Before a Landscape is imported, it doesn't have a texture list, so check first.
                if (landscapeToUpdate.terrainTexturesList != null)
                {
                    // Update any Texture types that don't have a GUID
                    List <LBTerrainTexture> updateableTextureList = landscapeToUpdate.terrainTexturesList.FindAll(tx => string.IsNullOrEmpty(tx.GUID));

                    int numTexturesToUpdate = (updateableTextureList == null ? 0 : updateableTextureList.Count);

                    for (int txIdx = 0; txIdx < numTexturesToUpdate; txIdx++)
                    {
                        updateableTextureList[txIdx].GUID = System.Guid.NewGuid().ToString();
                    }
                }

                // Before a Landscape is imported, it doesn't have a tree list, so check first.
                if (landscapeToUpdate.terrainTreesList != null)
                {
                    // Update any Tree types that don't have a GUID
                    List <LBTerrainTree> updateableTreeList = landscapeToUpdate.terrainTreesList.FindAll(tr => string.IsNullOrEmpty(tr.GUID));

                    int numTreesToUpdate = updateableTreeList == null ? 0 : updateableTreeList.Count;

                    for (int trIdx = 0; trIdx < numTreesToUpdate; trIdx++)
                    {
                        updateableTreeList[trIdx].GUID = System.Guid.NewGuid().ToString();
                    }

                    // Has landscape been created before 2.3.2?
                    // For Texture NOT filters, reset cutOff to default of 0.1 to mimic pre-2.3.2 behaviour.
                    if (majorVersion == 1 || (majorVersion == 2 && minorVersion <= 3 && (minorVersion < 3 || patchVersion < 2)))
                    {
                        numTreesToUpdate = landscapeToUpdate.terrainTreesList == null ? 0 : landscapeToUpdate.terrainTreesList.Count;

                        for (int trIdx = 0; trIdx < numTreesToUpdate; trIdx++)
                        {
                            if (LBFilter.Contains(landscapeToUpdate.terrainTreesList[trIdx].filterList, LBFilter.FilterType.Texture))
                            {
                                LBFilter.UpdateTextures(landscapeToUpdate.terrainTreesList[trIdx].filterList, landscapeToUpdate.terrainTexturesList, !isSilentUpdate);

                                foreach (LBFilter lbFilter in landscapeToUpdate.terrainTreesList[trIdx].filterList)
                                {
                                    if (lbFilter != null && lbFilter.filterType == LBFilter.FilterType.Texture && lbFilter.filterMode == LBFilter.FilterMode.NOT && lbFilter.cutOff == 0.5f)
                                    {
                                        lbFilter.cutOff = 0.1f;
                                    }
                                }
                            }
                        }
                    }
                }

                // To use SubGroups, Groups need to have a unique identifier
                if (landscapeToUpdate.lbGroupList != null)
                {
                    // Update any Groups that don't have a GUID
                    List <LBGroup> updateableGroupList = landscapeToUpdate.lbGroupList.FindAll(grp => string.IsNullOrEmpty(grp.GUID));

                    int numGroupsToUpdate = updateableGroupList == null ? 0 : updateableGroupList.Count;

                    for (int gpIdx = 0; gpIdx < numGroupsToUpdate; gpIdx++)
                    {
                        updateableGroupList[gpIdx].GUID = System.Guid.NewGuid().ToString();
                    }
                }

                #if UNITY_EDITOR
                if (!isSilentUpdate)
                {
                    Debug.Log("LBUpdate LandscapeUpdate - upgraded " + landscapeToUpdate.gameObject.name + " from version " + OldVersion + " to " + NewVersion);
                }
                #endif

                isSuccessful = true;
            }

            return(isSuccessful);
        }