public static void CleanUpProperties(CleanUpParameter param) { Undo.RecordObjects(param.materials, "WF cleanup materials"); foreach (Material material in param.materials) { if (material == null) { continue; } var props = ShaderSerializedProperty.AsList(material); // 無効になってる機能のプレフィックスを集める var delPrefix = new List <string>(); foreach (var p in props) { string label, name; WFCommonUtility.FormatPropName(p.name, out label, out name); if (label != null && name.ToLower() == "enable" && p.FloatValue == 0) { delPrefix.Add(label); } } var del_props = new HashSet <ShaderSerializedProperty>(); // プレフィックスに合致する設定値を消去 Predicate <ShaderSerializedProperty> predPrefix = p => { string label = WFCommonUtility.GetPrefixFromPropName(p.name); return(label != null && delPrefix.Contains(label)); }; props.FindAll(predPrefix) // ただしEnableToggle自体は初期化しない .Where(p => !WFCommonUtility.IsEnableToggleFromPropName(p.name)).ToList().ForEach(p => del_props.Add(p)); // 未使用の値を削除 Predicate <ShaderSerializedProperty> predUnused = p => param.resetUnused && !p.HasPropertyInShader; props.FindAll(predUnused).ForEach(p => del_props.Add(p)); // 削除実行 DeleteProperties(del_props); // キーワードクリア if (param.resetKeywords) { foreach (var so in ShaderSerializedProperty.GetUniqueSerialObject(props)) { DeleteShaderKeyword(so); } } // キーワードを整理する WFCommonUtility.SetupShaderKeyword(material); // 反映 EditorUtility.SetDirty(material); } }
private void OnEnable() { minSize = new Vector2(480, 640); param = ScriptableObject.CreateInstance <CleanUpParameter>(); if (0 < arguments.Count) { param.materials = arguments.ToArray(); } styleTitle = new GUIStyle(EditorStyles.boldLabel) { fontSize = 18, fontStyle = FontStyle.Bold, fixedHeight = 32, }; styleBigText = new GUIStyle(EditorStyles.boldLabel) { fontSize = 16, fontStyle = FontStyle.Bold, fixedHeight = 32, }; }
private void OnEnable() { minSize = new Vector2(480, 640); param = CleanUpParameter.Create(); ToolCommon.GetSelectedMaterials(ref param.materials); }