Created
July 3, 2021 09:13
-
-
Save watapj/678d957397a4373ea683f34bbfe7302c to your computer and use it in GitHub Desktop.
テクスチャをひたすらマテリアルにアタッチするスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
#if UNITY_EDITOR | |
using UnityEditor; | |
using System.IO; | |
using System; | |
using UnityEditor.Events; | |
using UnityEditor.Animations; | |
#endif | |
public class SetLightmapsMaterials : MonoBehaviour { | |
public Texture2D[] texs = new Texture2D[2]; | |
public Material[] materials; | |
public float _Mix0; | |
public float _Mix1; | |
#if UNITY_EDITOR | |
private void Generate() { | |
for(int i=0; i<materials.Length; i++){ | |
materials[i].SetTexture("_LightMap1", texs[0]); | |
materials[i].SetTexture("_LightMap2", texs[1]); | |
materials[i].SetFloat("_Mix1", _Mix0); | |
materials[i].SetFloat("_Mix2", _Mix1); | |
} | |
Debug.Log("Set Texture End"); | |
} | |
[CustomEditor(typeof(SetLightmapsMaterials))] | |
public class TextureGeneratorEditor : Editor { | |
public override void OnInspectorGUI() { | |
var t = target as SetLightmapsMaterials; | |
drawArrayProperty("materials"); | |
t.texs[0] = (Texture2D)EditorGUILayout.ObjectField("LightMap Texture 1", t.texs[0], typeof(Texture2D), t.texs[0]); | |
t.texs[1] = (Texture2D)EditorGUILayout.ObjectField("LightMap Texture 2", t.texs[1], typeof(Texture2D), t.texs[1]); | |
t._Mix1 = EditorGUILayout.FloatField( "Mix0", t._Mix0 ); | |
t._Mix2 = EditorGUILayout.FloatField( "Mix1", t._Mix1 ); | |
if (GUILayout.Button("Set Lightmap Textures")) { | |
t.Generate(); | |
} | |
} | |
//https://gist.github.com/Suzeep/7257058 | |
private void drawArrayProperty( string prop_name ){ | |
EditorGUIUtility.LookLikeInspector(); //Legacy | |
SerializedProperty prop = this.serializedObject.FindProperty( prop_name ); | |
EditorGUI.BeginChangeCheck(); | |
EditorGUILayout.PropertyField( prop, true ); | |
if( EditorGUI.EndChangeCheck() ){ | |
this.serializedObject.ApplyModifiedProperties(); | |
} | |
} | |
} | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment