예제 #1
0
        public static void GenerateConfig(Texture2DArrayConfig config)
        {
            var texs = config.Textures;

            if (texs == null || texs.Count == 0)
            {
                return;
            }

            var firstTex = config.FirstTexture();
            var format   = config.UseFirstTextureSettings ? firstTex.format : config.Format;
            var isLinear = config.UseFirstTextureSettings ? TextureHelper.IsLinearFormat(firstTex) : config.IsLinear;
            var texArray = new Texture2DArray(firstTex.width, firstTex.height, texs.Count, format,
                                              firstTex.mipmapCount, isLinear);

            for (int i = 0; i < texs.Count; i++)
            {
                var tex = texs[i];
                if (tex == null)
                {
                    continue;
                }

                TextureHelper.CopyToTexture2DArray(tex, texArray, i);
            }

            texArray.Apply(false);

            var configArr = config.TexArray;

            if (configArr == null)
            {
                configArr = AssetDatabase.LoadAssetAtPath <Texture2DArray>(GetTexture2DArrayPath(config));
            }

            if (configArr == null)
            {
                config.TexArray      = texArray;
                config.TexArray.name = config.name;
                AssetDatabase.CreateAsset(texArray, GetTexture2DArrayPath(config));
            }
            else
            {
                config.TexArray = configArr;
                EditorUtility.CopySerialized(texArray, config.TexArray);
            }

            EditorUtility.SetDirty(config);
            AssetDatabase.SaveAssets();
        }
예제 #2
0
        private static void FindOrCreateTextureConfigIfMissing(ref Texture2DArrayConfig config, string path)
        {
            if (config != null)
            {
                return;
            }

            config = AssetDatabase.LoadAssetAtPath <Texture2DArrayConfig>(path);

            if (config == null)
            {
                config = ScriptableObject.CreateInstance <Texture2DArrayConfig>();
                AssetDatabase.CreateAsset(config, path);
            }
        }
예제 #3
0
 private static void AddTextureToConfig(Texture2DArrayConfig config, Texture2D tex)
 {
     config.AddTexture(tex);
 }
예제 #4
0
        public static string GetTexture2DArrayPath(Texture2DArrayConfig config)
        {
            var path = AssetDatabase.GetAssetPath(config);

            return($"{Path.GetDirectoryName(path)}/{Path.GetFileNameWithoutExtension(path)}_array.asset");
        }