using UnityEngine; #if UNITY_EDITOR using UnityEditor; #endif using System; using System.Collections; using System.Collections.Generic; [ExecuteInEditMode] [DisallowMultipleComponent] public class BakerySkyLight : MonoBehaviour { public string texName = "sky.dds"; public Color color = Color.white; public float intensity = 1.0f; public int samples = 32; public bool hemispherical = false; public int bitmask = 1; public bool bakeToIndirect = true; public float indirectIntensity = 1.0f; public bool tangentSH = false; public bool correctRotation = false; public Cubemap cubemap; public int UID; public static int lightsChanged = 0; // 1 = const, 2 = full #if UNITY_EDITOR void OnValidate() { if (lightsChanged == 0) lightsChanged = 1; } void OnEnable() { lightsChanged = 2; } void OnDisable() { lightsChanged = 2; } public void Start() { if (gameObject.GetComponent() != null || gameObject.GetComponent() != null || gameObject.GetComponent() != null) { EditorUtility.DisplayDialog("Bakery", "Can't have more than one Bakery light on one object", "OK"); DestroyImmediate(this); return; } if (EditorApplication.isPlayingOrWillChangePlaymode) return; if (UID == 0) UID = Guid.NewGuid().GetHashCode(); ftUniqueIDRegistry.Register(UID, gameObject.GetInstanceID()); } void OnDestroy() { if (UID == 0) return; if (EditorApplication.isPlayingOrWillChangePlaymode) return; ftUniqueIDRegistry.Deregister(UID); } void Update() { if (EditorApplication.isPlayingOrWillChangePlaymode) return; if (!ftUniqueIDRegistry.Mapping.ContainsKey(UID)) ftUniqueIDRegistry.Register(UID, gameObject.GetInstanceID()); if (gameObject.GetInstanceID() != ftUniqueIDRegistry.GetInstanceId(UID)) { UID = Guid.NewGuid().GetHashCode(); ftUniqueIDRegistry.Register(UID, gameObject.GetInstanceID()); } } void OnDrawGizmos() { Gizmos.color = new Color(49/255.0f, 91/255.0f, 191/255.0f); Gizmos.DrawSphere(transform.position, 0.1f); } void OnDrawGizmosSelected() { Gizmos.color = new Color(49/255.0f, 91/255.0f, 191/255.0f); Vector3 origin = transform.position; const int segments = 16; for(int i=0; i