Example #1
0
 public TextureTypeUVsForMeshUVsAction(MeshDataReference mdr,
                                       TilesSetFilterReference tsf,
                                       LevelTextureConfig texConf)
 {
     m_meshData       = mdr;
     m_tilesSetFilter = tsf;
     m_texConfig      = texConf;
 }
Example #2
0
        // ReSharper disable once FlagArgument
        static Texture2D GenerateAtlas(LevelTextureConfig config, EAtlasType atlasType)
        {
            var textureCollections = config.LevelTextureCollections;
            var tileWidthAndHeight = 2 * config.HalfTileDimension;
            var atlasSize          = new Vector2Int(config.AtlasDimension, config.AtlasDimension);

            //int widthAndHeight = texWidthAndHeight + (repeatedPixels * 2);
            var outputTexture = new Texture2D(config.AtlasDimension, config.AtlasDimension, TextureFormat.ARGB32, false);

            config.UVInset    = (float)k_repeatedPixels / config.AtlasDimension;
            config.UVTileSize = (float)tileWidthAndHeight / atlasSize.x;

            var allTexData = GatherAllTextures(textureCollections, config);

            var data = new GenerateAtlasData()
            {
                AtlasType       = atlasType,
                OutputTexture   = outputTexture,
                CurrentDim      = Vector2Int.zero,
                AtlasSize       = atlasSize,
                TileWidthHeight = tileWidthAndHeight,
                CurrentRowYEnd  = -1,
                X = 0,
                Y = 0
            };
            //currentRowYStart = 0,
            //blockXStart = 0,
            //blockXEnd = -1,
            //blockX = 0,
            //blockY = 0;

            var progressIndex = 0;
            var initialCount  = allTexData.Count;

            while (allTexData.Count > 0)
            {
                EditorUtility.DisplayProgressBar("Generating Atlas", $"{progressIndex}/{initialCount}", (float)(progressIndex++) / initialCount);
                var current = allTexData[0];

                if (GenerateAtlasProcessTexture(current, ref data) == OperationResult.Error)
                {
                    break;
                }
                allTexData.RemoveAt(0);
            }

            EditorUtility.ClearProgressBar();
            return(outputTexture);
        }
Example #3
0
        public static void GenerateAtlas(LevelTextureConfig config, string materialPath, string textureDirectory)
        {
            EditorUtility.SetDirty(config);

            //AddMaskToAtlas(atlas, GroundTextureAtlasPath, target.MaskTextureCollections, out target.MaskUVInset, out target.MaskUVFactor, out target.MaskWrapValue);
            //var newAtlas =
            config.Material = LoadOrCreateMaterial(materialPath);

            for (var i = 0; i < (int)EAtlasType.Length; i++)
            {
                if (!config.ActiveMaps[i])
                {
                    continue;
                }
                var atType = (EAtlasType)i;
                var atlas  = GenerateAtlas(config, atType);
                EditorUtility.DisplayProgressBar("Generating Atlas", "Saving Atlas File", 1f);

                var atlasPath = TextureAtlasPath(config, textureDirectory, atType);
                ApplyAndWriteTextureToPath(atlas, atlasPath);
                Object.DestroyImmediate(atlas);
                config.Atlas[i] = AssetDatabase.LoadMainAssetAtPath(atlasPath) as Texture2D;
                UpdateMaterial(config.Material, config.Atlas[i], KTexNames[i]);
            }

            EditorUtility.ClearProgressBar();

            // todo validation stuff
            //int newHash = setting.GetHash();
            //if (setting.GeneratedWithHash!= newHash)
            //    _HashChanged = true;
            //setting.GeneratedWithHash = newHash;

            config.UsedTexturePixelHashes.Clear();
            GetTextureHashes(config.LevelTextureCollections, config.UsedTexturePixelHashes);

            //GetTextureHashes(target.MaskTextureCollections, target.UsedTexturePixelHashes);

            EditorGUIUtility.PingObject(config.Material);
        }
        public AddDefaultCustomFlagsAction(TilesSetListConfig config,
                                           TileTypeIdentifier floorNode, TileTypeIdentifier wallNode,
                                           LevelTextureConfig texTypeConfig,

                                           Vector3Reference pos,
                                           GridReference sourceGrid,
                                           GridReference targetGrid,
                                           TilesSetData hardEdgeSet,
                                           TilesSetData floorTexTypesSet,
                                           TilesSetData activeFloorNodesSet)
        {
            m_tilesSetListConfig = config;
            m_floorNode          = floorNode;
            m_wallNode           = wallNode;
            m_texTypeConfig      = texTypeConfig;

            m_pos        = pos;
            m_sourceGrid = sourceGrid;
            m_targetGrid = targetGrid;

            m_hardEdgeSet         = hardEdgeSet;
            m_floorTexTypesSet    = floorTexTypesSet;
            m_activeFloorNodesSet = activeFloorNodesSet;
        }
Example #5
0
        static List <TextureData> GatherAllTextures(IEnumerable <TextureCollection> textureCollections, LevelTextureConfig setting)
        {
            var allTexData = new List <TextureData>();

            foreach (var texCollection in textureCollections)
            {
                allTexData.AddRange(texCollection.FloorVariations);
                allTexData.AddRange(texCollection.WallVariations);
                if (texCollection.Edge.IsSet())
                {
                    allTexData.Add(texCollection.Edge);
                }
                if (texCollection.DiagEdge.IsSet())
                {
                    allTexData.Add(texCollection.DiagEdge);
                }
            }

            foreach (var trans in setting.Transitions)
            {
                allTexData.Add(trans);
            }

            allTexData.Sort(SortBiggestDimensionFirst);
            return(allTexData);
        }