예제 #1
0
 static public int initData(IntPtr l)
 {
     try {
         LightmapSwitcher self = (LightmapSwitcher)checkSelf(l);
         self.initData();
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #2
0
 static public int get_nightLightmaps(IntPtr l)
 {
     try {
         LightmapSwitcher self = (LightmapSwitcher)checkSelf(l);
         pushValue(l, self.nightLightmaps);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #3
0
 static public int set_dayLightmaps(IntPtr l)
 {
     try {
         LightmapSwitcher        self = (LightmapSwitcher)checkSelf(l);
         UnityEngine.Texture2D[] v;
         checkType(l, 2, out v);
         self.dayLightmaps = v;
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #4
0
 static public int set_allParams(IntPtr l)
 {
     try {
         LightmapSwitcher self = (LightmapSwitcher)checkSelf(l);
         LightmapParams[] v;
         checkType(l, 2, out v);
         self.allParams = v;
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #5
0
 static public int set_useNightLightmaps(IntPtr l)
 {
     try {
         LightmapSwitcher self = (LightmapSwitcher)checkSelf(l);
         System.Boolean   v;
         checkType(l, 2, out v);
         self.useNightLightmaps = v;
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #6
0
 private void Awake()
 {
     LEDlightmapSwitcher      = FindObjectOfType <LEDstripLightmapSwitcher>();
     timeOfDayManager         = FindObjectOfType <TimeOfDayManager>();
     dayNightLightmapSwitcher = FindObjectOfType <DayNightLightmapSwitcher>();
 }
예제 #7
0
    void CollectLightmapParams(bool isNight)
    {
        GameObject scenery = GameObject.Find("scenery");

        if (scenery == null)
        {
            RefreshEditorStateDisp();
            return;
        }

        GameObject models = GameObject.Find("scenery/models");

        if (models == null)
        {
            RefreshEditorStateDisp();
            return;
        }

        GameObject     dncc = null;
        DayNightConfig dnc  = scenery.GetComponentInChildren <DayNightConfig> ();

        if (dnc == null)
        {
            var prefabc = AssetDatabase.LoadAssetAtPath <GameObject> ("Assets/Models/Prefab/lightingCtrl/dayNightCycleCtrls.prefab");
            dncc = PrefabUtility.InstantiatePrefab(prefabc) as GameObject;
            dncc.transform.SetParent(scenery.transform, false);
        }
        else
        {
            dncc = dnc.gameObject;
        }

        GameObject       lsgo = null;
        LightmapSwitcher lss  = dncc.GetComponentInChildren <LightmapSwitcher> ();

        if (lss == null)
        {
            var prefabc = AssetDatabase.LoadAssetAtPath <GameObject> ("Assets/Models/Prefab/lightingCtrl/lightmapSwitcher.prefab");
            lsgo = PrefabUtility.InstantiatePrefab(prefabc) as GameObject;
            lsgo.transform.SetParent(dncc.transform, false);
            lss = lsgo.GetComponent <LightmapSwitcher> ();
        }
        else
        {
            lsgo = lss.gameObject;
        }

        List <LightmapParams> lps = new List <LightmapParams> ();

        Renderer[] renderers = models.GetComponentsInChildren <Renderer> ();
        foreach (Renderer r in renderers)
        {
            LightmapParams lp = r.gameObject.GetComponent <LightmapParams> ();
            if (lp == null)
            {
                lp = r.gameObject.AddComponent <LightmapParams> ();
            }
            lp.RefreshData();
            lp.SetData(isNight ? 1 : 0);
            lps.Add(lp);
        }

        lss.allParams = lps.ToArray();

        RefreshEditorStateDisp();
    }
예제 #8
0
 private void Awake()
 {
     lightMapSwitcher = FindObjectOfType <DayNightLightmapSwitcher>();
 }
예제 #9
0
    public void GenerateReflectionProbes()
    {
        DayNightConfig dnc    = GameObject.FindObjectOfType <DayNightConfig>();
        GameObject     parent = Selection.activeGameObject;

        if (dnc == null || parent == null)
        {
            return;
        }

        LightmapSwitcher ls = GameObject.FindObjectOfType <LightmapSwitcher>();

        if (ls != null)
        {
            ls.initData();
        }

        FogCtrl fc = GameObject.FindObjectOfType <FogCtrl>();

        IgnoreFarClip[] ifcs = Resources.FindObjectsOfTypeAll <IgnoreFarClip> ();

        EnterBusyState("正在烘焙ReflectionProbes,请别乱动!");
        curIndex = 0;

        string productionScenePath = EditorApplication.currentScene;
        string ppath           = Path.GetDirectoryName(productionScenePath) + "/";
        string pname           = Path.GetFileNameWithoutExtension(productionScenePath);
        string lightmapTgtPath = ppath + pname + "/";

        string[] wrps = Directory.GetFiles(lightmapTgtPath, "water_reflection_probe_*.exr");
        foreach (string wrpname in wrps)
        {
            FileUtil.DeleteFileOrDirectory(wrpname);
        }
        AssetDatabase.Refresh();

        actions.Clear();

        actions.Add(delegate(int a) {
            // disable all IgnoreFarClips
            for (int i = 0; i < ifcs.Length; ++i)
            {
                IgnoreFarClip ifc       = ifcs[i];
                ifc.gameObject.isStatic = true;
                Renderer rdr            = ifc.gameObject.GetComponent <Renderer>();
                if (rdr == null)
                {
                    continue;
                }

                foreach (Material m in rdr.sharedMaterials)
                {
                    m.SetInt("_ifc", 0);
                    m.DisableKeyword("IGNORE_FAR_CLIP");
                }
            }
        });

        for (int i = 0; i < weatherNames.Length; ++i)
        {
            // create gameobject and reflection probe
            actions.Add(delegate(int a) {
                string wname        = weatherNames[curIndex];
                string goname       = "water_reflection_probe_" + wname;
                Transform probTrans = parent.transform.Find(goname);
                if (probTrans == null)
                {
                    GameObject probGO = new GameObject();
                    probGO.name       = goname;
                    probGO.transform.SetParent(parent.transform, false);
                    probTrans = probGO.transform;
                }
                ReflectionProbe rp = probTrans.GetComponent <ReflectionProbe>();
                if (rp == null)
                {
                    rp = probTrans.gameObject.AddComponent <ReflectionProbe>();
                }

                rp.size          = new Vector3(400, 200, 400);
                rp.resolution    = 128;
                rp.nearClipPlane = 0.5f;
                rp.farClipPlane  = 3000.0f;
                rp.cullingMask   = ~0;
                rp.mode          = UnityEngine.Rendering.ReflectionProbeMode.Baked;
                curProbe         = rp;

//				FVWaterCubemapLoader cl = probTrans.GetComponent<FVWaterCubemapLoader>();
//				if (cl == null)
//				{
//					cl = probTrans.gameObject.AddComponent<FVWaterCubemapLoader>();
//				}
//				curLoader = cl;
            });

//			if (Application.isPlaying)
            {
                // switch weather
                actions.Add(delegate(int a) {
                    dnc.SetToWeather(curIndex);
                });

                actions.Add(delegate(int a) {
                    if (ls != null)
                    {
                        ls.DoRefresh();
                    }
                    if (fc != null)
                    {
                        fc.DoRefresh();
                    }
                });

                actions.Add(delegate(int a) {
                    string wname  = weatherNames[curIndex];
                    string goname = "water_reflection_probe_" + wname;
                    string path   = AssetDatabase.GenerateUniqueAssetPath(Path.Combine(lightmapTgtPath, goname + ".exr"));
                    Lightmapping.BakeReflectionProbe(curProbe, path);

                    curProbe.mode = UnityEngine.Rendering.ReflectionProbeMode.Custom;
                    curProbe.customBakedTexture = UnityEditor.AssetDatabase.LoadAssetAtPath <Texture>(path);

//					curLoader.texPath = path;
                });
            }

            actions.Add(delegate(int a) {
                ++curIndex;
            });
        }

        actions.Add(delegate(int a) {
            // disable all IgnoreFarClips
            for (int i = 0; i < ifcs.Length; ++i)
            {
                IgnoreFarClip ifc       = ifcs[i];
                ifc.gameObject.isStatic = false;
                Renderer rdr            = ifc.gameObject.GetComponent <Renderer>();
                if (rdr == null)
                {
                    continue;
                }

                foreach (Material m in rdr.sharedMaterials)
                {
                    m.SetInt("_ifc", 1);
                    m.EnableKeyword("IGNORE_FAR_CLIP");
                }
            }
        });

        actions.Add(delegate(int a) {
            dnc.SetToWeather(0);
        });

        actions.Add(delegate(int a) {
            if (ls != null)
            {
                ls.DoRefresh();
            }
            if (fc != null)
            {
                fc.DoRefresh();
            }
        });

        actions.Add(delegate(int a) {
            RefreshEditorStateDisp();
        });

        haltFrame = 0;
    }