Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save neon-izm/29643d5206d9b9a497ea77a72938775c to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace UnityChan
{
public class CopyMaterialParameter : EditorWindow
{
[SerializeField]
static Material source;
Material target;
static EditorWindow window;
[MenuItem("CONTEXT/Material/Copy Material Parameter")]
static void Init (MenuCommand command)
{
source = (Material) command.context;
window = EditorWindow.GetWindow<CopyMaterialParameter> (true, "Copy Material Parameter : Select Materials", true);
window.Show ();
}
void OnGUI ()
{
source = (Material)EditorGUILayout.ObjectField ("Source material", source, typeof(Material),true);
target = (Material)EditorGUILayout.ObjectField ("Target material", target, typeof(Material),true);
EditorGUILayout.Space();
if (GUILayout.Button ("Copy Sorce ⇒ Target")) {
CopyMaterial (source, target);
window.Close();
}
if (GUILayout.Button ("Switch Sorce/Target")) {
var tmp = target;
target = source;
source = tmp;
}
}
void CopyMaterial (Material source, Material target)
{
target.shader = source.shader;
target.CopyPropertiesFromMaterial (source);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment