Ejemplo n.º 1
0
        private void UpdateMaterial(string materialPath)
        {
            var materialAssetPath = UpdaterHelper.GetAssetRelativePath(materialPath);
            var material          = AssetDatabase.LoadAssetAtPath <Material> (materialAssetPath);

            if (material == null)
            {
                return;
            }

            _logger.LogStart(materialAssetPath);
            _logger.LogOriginShader(material.shader.name);

            var shaderConfigData = _configData.GetShaderConfigData(material.shader.name);

            if (shaderConfigData == null)
            {
                _logger.LogEnd(UpdaterLogType.Skip);
                return;
            }

            UpdateMaterialContent(material, shaderConfigData);

            _logger.LogEnd(shaderConfigData.NeedCheck ? UpdaterLogType.NeedCheck : UpdaterLogType.Done);
        }
Ejemplo n.º 2
0
        private List <string> OnGUISelectMaterialPaths()
        {
            // select root directory
            _materialFullRootDirectory  = EditorUtility.OpenFolderPanel("Select Material Root Directory", _materialFullRootDirectory, "");
            _materialAssetRootDirectory = UpdaterHelper.GetAssetRelativePath(_materialFullRootDirectory);
            if (string.IsNullOrEmpty(_materialFullRootDirectory))
            {
                return(null);
            }

            // collect material paths
            var materialPaths = UpdaterHelper.CollectAllFiles(_materialFullRootDirectory, true, "*.mat", "*.MAT");

            // show confirm dialog
            var message = string.Format("There are about [({0})] materials will be updated in directory [\"{1}\"]. this process can NOT be undo.",
                                        materialPaths.Count, _materialAssetRootDirectory);

            if (!EditorUtility.DisplayDialog("Warning !!", message, "Cancel", "Still Continue"))
            {
                return(materialPaths);
            }

            Debug.LogWarning("Updating Cancelled !!");
            return(null);
        }
Ejemplo n.º 3
0
        private void OnGUIMaterial()
        {
            if (string.IsNullOrEmpty(_materialAssetRootDirectory))
            {
                UpdaterHelper.UpdateAssetPath(out _materialAssetRootDirectory, out _materialFullRootDirectory, "Assets");
            }

            var originalColor = GUI.contentColor;

            GUI.contentColor = Color.yellow;
            if (GUILayout.Button("Select Root Directory..."))
            {
                var materialPaths = OnGUISelectMaterialPaths();

                if (materialPaths != null && materialPaths.Count > 0)
                {
                    ResetLogMessage();
                    UpdateMaterials(materialPaths);
                    GenerateLogMessage();
                }
            }
            GUI.contentColor = originalColor;

            EditorGUILayout.LabelField("Material Root Directory:", _materialAssetRootDirectory);
        }
Ejemplo n.º 4
0
        private static void UpdateMaterialDecalLayer(Material material, ShaderConfigData shaderConfigData, Material originalMaterial)
        {
            var decalLayers = CollectOriginalMaterialDecalLayers(originalMaterial, shaderConfigData.DecalLayerType);

            if (!UpdaterHelper.EnableMaterialPropertyGroup(material, UpdaterHelper.DecalLayerPropertyGroupConfigData, decalLayers.Count, true))
            {
                return;
            }

            bool useUv2 = false;
            var  index  = 0;
            var  decalTextureConfigDatas = UpdaterHelper.DecalLayerTextureConfigDatas;

            foreach (var decalLayer in decalLayers)
            {
                if (index >= decalTextureConfigDatas.Count)
                {
                    break;
                }

                var decalTextureConfigData = decalTextureConfigDatas [index];
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialTexture, decalTextureConfigData.TexturePropertyName, decalLayer.Key);
                if (decalLayer.Value)
                {
                    material.SetFloat(decalTextureConfigData.UVPropertyName, 1);
                    material.EnableKeyword(decalTextureConfigData.UVKeyword);
                    useUv2 = true;
                }
                else
                {
                    material.SetFloat(decalTextureConfigData.UVPropertyName, 0);
                    material.DisableKeyword(decalTextureConfigData.UVKeyword);
                }

                index++;
            }


            if (index == 1)
            {
                _logger.LogFeature(UpdaterLogFeature.DecalLayer1);
            }
            else if (index == 2)
            {
                _logger.LogFeature(UpdaterLogFeature.DecalLayer2);
            }
            else if (index > 2)
            {
                _logger.LogFeature(UpdaterLogFeature.DecalLayer3);
            }
            if (useUv2)
            {
                _logger.LogFeature(UpdaterLogFeature.DecalLayerUv2);
            }
        }
Ejemplo n.º 5
0
        private static void UpdateMaterialSpecular(Material material, ShaderConfigData shaderConfigData, Material originalMaterial)
        {
            if (!UpdaterHelper.EnableMaterialPropertyGroup(material, UpdaterHelper.SpecularPropertyGroupConfigData, 1, shaderConfigData.IsSpecularEnabled))
            {
                return;
            }

            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialColor, TCShaderUtil.PROPERTY_SPEC_COLOR);
            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_SHININESS);

            _logger.LogFeature(UpdaterLogFeature.Specular);
        }
Ejemplo n.º 6
0
        private static void UpdateMaterialToonmap(Material material, ShaderConfigData shaderConfigData, Material originalMaterial)
        {
            var textureExists = ExistsMaterialTexture(material, TCShaderUtil.PROPERTY_TOONMAP_CUBE);

            if (!UpdaterHelper.EnableMaterialPropertyGroup(material, UpdaterHelper.ToonmapPropertyGroupConfigData, 1, shaderConfigData.IsToonmapEnabled && textureExists))
            {
                return;
            }

            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialTexture, TCShaderUtil.PROPERTY_TOONMAP_CUBE, "_ToonShade");

            _logger.LogFeature(UpdaterLogFeature.Toonmap);
        }
Ejemplo n.º 7
0
        private static void UpdateMaterialNormalmap(Material material, ShaderConfigData shaderConfigData, Material originalMaterial)
        {
            var textureExists = ExistsMaterialTexture(material, TCShaderUtil.PROPERTY_NORMAL_BUMP_MAP);

            if (!UpdaterHelper.EnableMaterialPropertyGroup(material, UpdaterHelper.NormalmapPropertyGroupConfigData, 1,
                                                           shaderConfigData.IsNormalmapEnabled && textureExists))
            {
                return;
            }

            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialTexture, TCShaderUtil.PROPERTY_NORMAL_BUMP_MAP);

            _logger.LogFeature(UpdaterLogFeature.Normalmap);
        }
Ejemplo n.º 8
0
        private static void UpdateMaterialRimWrap(Material material, ShaderConfigData shaderConfigData, Material originalMaterial)
        {
            if (!UpdaterHelper.EnableMaterialPropertyGroup(material, UpdaterHelper.RimWrapPropertyGroupConfigData, 1, shaderConfigData.IsRimWrapEnabled))
            {
                return;
            }

            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialColor, TCShaderUtil.PROPERTY_RIM_COLOR);
            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_RIM_POWER);
            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_WRAP_POWER);
            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_LIGHT_POWER);

            _logger.LogFeature(UpdaterLogFeature.RimWrap);
        }
Ejemplo n.º 9
0
        private static void UpdateMaterialReflection(Material material, ShaderConfigData shaderConfigData, Material originalMaterial)
        {
            if (!UpdaterHelper.EnableMaterialPropertyGroup(material, UpdaterHelper.ReflectionPropertyGroupConfigData, 1, shaderConfigData.IsReflectionEnabled))
            {
                return;
            }


            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialColor, TCShaderUtil.PROPERTY_REFLECT_COLOR);
            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialTexture, TCShaderUtil.PROPERTY_REFLECT_CUBE, "_Cube");

            _shouldUpdatePropertyFactor = true;

            _logger.LogFeature(UpdaterLogFeature.Reflection);
        }
Ejemplo n.º 10
0
        private void LoadConfig()
        {
            if (!_isConfigChanged)
            {
                return;
            }

            _isConfigChanged = false;

            if (!File.Exists(_configDataFullPath))
            {
                return;
            }

            _configData = UpdaterHelper.LoadFromJsonFile <UpdaterConfigData> (_configDataFullPath);
        }
Ejemplo n.º 11
0
        private static void UpdateMaterialBottomLayer(Material material, ShaderConfigData shaderConfigData, Material originalMaterial)
        {
            var textureExists = ExistsMaterialTexture(material, TCShaderUtil.PROPERTY_BOTTOM_TEX);

            if (!UpdaterHelper.EnableMaterialPropertyGroup(material, UpdaterHelper.BottomLayerPropertyGroupConfigData, 1,
                                                           shaderConfigData.IsBottomLayerEnabled && textureExists))
            {
                return;
            }

            UpdateMaterialProperty(material, originalMaterial, UpdateMaterialTexture, TCShaderUtil.PROPERTY_BOTTOM_TEX);

            _shouldUpdatePropertyFactor = true;

            _logger.LogFeature(UpdaterLogFeature.BottomLayer);
        }
Ejemplo n.º 12
0
        private static void UpdateMaterialDiscolor(Material material, ShaderConfigData shaderConfigData, Material originalMaterial)
        {
            var shouldEnabled           = true;
            var originalHuePropertyName = "_Hue";

            // check hue alpha
            if (shaderConfigData.DiscolorMode == TCShaderDiscolorMode.HueReplace)
            {
                var originalHuePropertyId = UnityEngine.Shader.PropertyToID(originalHuePropertyName);
                if (originalMaterial.HasProperty(originalHuePropertyId))
                {
                    var hueColor = originalMaterial.GetColor(originalHuePropertyId);
                    shouldEnabled = hueColor.a > 0.01f;
                }
            }

            if (!UpdaterHelper.EnableMaterialPropertyGroup(material, UpdaterHelper.DiscolorPropertyGroupConfigData, (int)shaderConfigData.DiscolorMode, shouldEnabled))
            {
                return;
            }

            switch (shaderConfigData.DiscolorMode)
            {
            case TCShaderDiscolorMode.HslBlend:
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_HUE);
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_SATURATION);
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_LIGHTNESS);
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_MIXING_FACTOR);

                _logger.LogFeature(UpdaterLogFeature.HslBlend);
                break;

            case TCShaderDiscolorMode.HueReplace:
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialColor, TCShaderUtil.PROPERTY_HUE_COLOR, originalHuePropertyName);
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_SATUR_MIN);
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_SATUR_RATIO);
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_SATUR_ADD);
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_LIGHT_MAX);
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_LIGHT_RATIO);
                UpdateMaterialProperty(material, originalMaterial, UpdateMaterialFloat, TCShaderUtil.PROPERTY_LIGHT_ADD);

                _logger.LogFeature(UpdaterLogFeature.HueReplace);
                break;
            }
        }
Ejemplo n.º 13
0
        private void OnGUIConfig()
        {
            if (string.IsNullOrEmpty(_configDataAssetPath))
            {
                UpdaterHelper.UpdateAssetPath(out _configDataAssetPath, out _configDataFullPath, CONFIG_DEFAULT_ASSET_PATH);
                _isConfigChanged = true;
            }

            var originalColor = GUI.contentColor;

            GUI.contentColor = Color.green;
            if (GUILayout.Button("Select Config Path..."))
            {
                _configDataFullPath  = EditorUtility.OpenFilePanel("Config File Path", _configDataFullPath, "json");
                _configDataAssetPath = UpdaterHelper.GetAssetRelativePath(_configDataFullPath);
                _isConfigChanged     = true;
            }
            GUI.contentColor = originalColor;

            EditorGUILayout.LabelField("Config File Path: ", _configDataAssetPath);

            LoadConfig();
        }