using UnityEngine; using UnityEditor; using System.Collections;
public class ModelImportLights : AssetPostprocessor {
    void AddDirectionalLight(GameObject go) {         go.AddComponent("Light");         Light newLight = (Light)go.GetComponent(typeof(Light));         newLight.type = LightType.Directional;         Quaternion rot = new Quaternion();         rot.SetFromToRotation(Vector3.up, Vector3.forward);         go.transform.rotation = go.transform.rotation * rot;     }          void AddSpotLight(GameObject go) {         go.AddComponent("Light");         Light newLight = (Light)go.GetComponent(typeof(Light));         newLight.type = LightType.Spot;         Quaternion rot = new Quaternion();         rot.SetFromToRotation(Vector3.up, Vector3.forward);         go.transform.rotation = go.transform.rotation * rot;     }          void AddPointLight(GameObject go) {         go.AddComponent("Light");         Light newLight = (Light)go.GetComponent(typeof(Light));         newLight.type = LightType.Point;     }          void OnPostprocessGameObjectWithUserProperties( GameObject go, string[] names, object[] values) {         if(go.name.ToLower().Contains("directionallight"))             AddDirectionalLight(go);         else if(go.name.ToLower().Contains("spotlight"))             AddSpotLight(go);         else if(go.name.ToLower().Contains("pointlight"))             AddPointLight(go);
        for (int i = 0; i < names.Length; i++)         {             if(names[i].StartsWith("unityLight"))             {                 Light newLight = (Light)go.GetComponent(typeof(Light));                 if(names[i] == "unityLightColor")                 {                     Vector4 newColor = (Vector4)values[i];                     newColor[3] = 1.0f;                     newLight.color = (Color)newColor;                 }                 else if(names[i] == "unityLightIntensity")                 {                     newLight.intensity = (float)values[i];                     if(go.name.ToLower().Contains("spotlight") || go.name.ToLower().Contains("pointlight"))                     {                         newLight.range = Mathf.Sqrt(newLight.intensity) * 16;                     }                 }                 else if(names[i] == "unityLightConeAngle")                 {                     newLight.spotAngle = (float)values[i];                 }                 else if(names[i] == "unityLightError")                 {                     Debug.LogWarning(assetPath + ": " + go.name + " was not set to quadratic decay and might need to have its range set manually.", go);                 }             }         }      } }
|
|