Last active
January 31, 2017 02:21
-
-
Save tsubaki/a61d5827ec18160ac271 to your computer and use it in GitHub Desktop.
PrefabにLightmapを適応する
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 UnityEngine; | |
using System.Collections; | |
[ExecuteInEditMode] | |
public class LightmapPrefab : MonoBehaviour { | |
[System.Serializable] | |
class LightmapParameter | |
{ | |
public int lightmapIndex = -1; | |
public Vector4 scaleOffset = Vector4.zero; | |
public Renderer renderer; | |
public void UpdateLightmapUVs() | |
{ | |
renderer.lightmapScaleOffset = scaleOffset; | |
renderer.lightmapIndex = lightmapIndex; | |
} | |
} | |
void Start () | |
{ | |
foreach (var lightmapParameter in lightmapParameters) { | |
lightmapParameter.UpdateLightmapUVs(); | |
} | |
} | |
//[HideInInspector] | |
[SerializeField] | |
LightmapParameter[] lightmapParameters; | |
[ContextMenu("Setup")] | |
void Setup() | |
{ | |
var renderer = GetComponentsInChildren<Renderer> (); | |
lightmapParameters = new LightmapParameter[renderer.Length]; | |
for (int i=0; i<renderer.Length; i++) { | |
var currentRenderer = renderer[i]; | |
lightmapParameters[i] = new LightmapParameter(){ | |
lightmapIndex = currentRenderer.lightmapIndex, | |
scaleOffset = currentRenderer.lightmapScaleOffset, | |
renderer = currentRenderer, | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment