public void Init(string[] names, Material[] presets, ShaderEditor shaderEditor) { this.shaderEditor = shaderEditor; this.beforePreset = shaderEditor.materials.Select(m => new Material(m)).ToArray(); mainStruct = new PresetStruct(""); backgroundTextrure = new Texture2D(1, 1); if (EditorGUIUtility.isProSkin) { backgroundTextrure.SetPixel(0, 0, new Color(0.18f, 0.18f, 0.18f, 1)); } else { backgroundTextrure.SetPixel(0, 0, new Color(0.9f, 0.9f, 0.9f, 1)); } backgroundTextrure.Apply(); for (int i = 1; i < names.Length; i++) { string[] path = names[i].Split('/'); PresetStruct addUnder = mainStruct; for (int j = 0; j < path.Length; j++) { addUnder = addUnder.GetSubStruct(path[j]); } addUnder.SetPreset(presets[i - 1]); } }
public void Apply(ShaderEditor editor) { Shader originShader = Shader.Find(OriginShader); Shader targetShader = Shader.Find(TargetShader); SerializedObject serializedMaterial = new SerializedObject(editor.Materials[0]); foreach (PropertyTranslation trans in PropertyTranslations) { if (editor.PropertyDictionary.ContainsKey(trans.Target)) { SerializedProperty p; switch (editor.PropertyDictionary[trans.Target].MaterialProperty.type) { case MaterialProperty.PropType.Float: case MaterialProperty.PropType.Range: p = GetProperty(serializedMaterial, "m_SavedProperties.m_Floats", trans.Origin); if (p != null) { float f = p.FindPropertyRelative("second").floatValue; if (trans.Math.Length > 0) { f = Helper.SolveMath(trans.Math, f); } editor.PropertyDictionary[trans.Target].MaterialProperty.floatValue = f; } break; case MaterialProperty.PropType.Vector: p = GetProperty(serializedMaterial, "m_SavedProperties.m_Colors", trans.Origin); if (p != null) { editor.PropertyDictionary[trans.Target].MaterialProperty.vectorValue = p.FindPropertyRelative("second").vector4Value; } break; case MaterialProperty.PropType.Color: p = GetProperty(serializedMaterial, "m_SavedProperties.m_Colors", trans.Origin); if (p != null) { editor.PropertyDictionary[trans.Target].MaterialProperty.colorValue = p.FindPropertyRelative("second").colorValue; } break; case MaterialProperty.PropType.Texture: p = GetProperty(serializedMaterial, "m_SavedProperties.m_TexEnvs", trans.Origin); if (p != null) { SerializedProperty values = p.FindPropertyRelative("second"); editor.PropertyDictionary[trans.Target].MaterialProperty.textureValue = values.FindPropertyRelative("m_Texture").objectReferenceValue as Texture; Vector2 scale = values.FindPropertyRelative("m_Scale").vector2Value; Vector2 offset = values.FindPropertyRelative("m_Offset").vector2Value; editor.PropertyDictionary[trans.Target].MaterialProperty.textureScaleAndOffset = new Vector4(scale.x, scale.y, offset.x, offset.y); } break; } } } }
public static void TranslationSelectionGUI(ShaderEditor editor) { Rect r; if (GuiHelper.ButtonWithCursor(Styles.icon_style_shaders, "Shader Translation", 25, 25, out r)) { EditorUtility.DisplayCustomMenu(r, TranslationDefinitions.Select(t => new GUIContent(t.Name)).ToArray(), -1, ConfirmTranslationSelection, editor); } }
public static void SuggestedTranslationButtonGUI(ShaderEditor editor) { if (editor.SuggestedTranslationDefinition != null) { if (GUILayout.Button("Apply " + editor.SuggestedTranslationDefinition.Name + " shader translation.")) { editor.SuggestedTranslationDefinition.Apply(editor); } } }
public override void OnClick(TreeView treeview) { ShaderEditor editor = (ShaderEditor)LibraryGUI.GetActiveContent(typeof(ShaderEditor)); if (editor == null) { editor = new ShaderEditor(); LibraryGUI.LoadEditor(editor); } editor.Text = Text; editor.Dock = DockStyle.Fill; editor.FillEditor(this, ((SHARCFB)Parent.Parent).header); }
private void Menu_Save(object sender, RoutedEventArgs e) { ShaderEditor.SaveFile(); D3DContext.UpdateShader(); }