duck

Unity 3D very simple auto lightprobe placer editor script

May 16th, 2013
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5.  
  6. public class PlaceLightProbes {
  7.  
  8.     [MenuItem ("GameObject/Place Light Probes")]
  9.     static void DoPlaceLightProbes () {
  10.        
  11.         Bounds bounds = new Bounds(Vector3.zero,Vector3.zero);
  12.        
  13.         foreach (Renderer r in GameObject.FindObjectsOfType(typeof(Renderer)))
  14.         {
  15.             if (GameObjectUtility.AreStaticEditorFlagsSet(r.gameObject, StaticEditorFlags.LightmapStatic))
  16.             {
  17.                 bounds.Encapsulate(r.bounds);
  18.             }
  19.            
  20.         }
  21.        
  22.         Debug.Log ("Lightprobe Area Bounds:"+bounds);
  23.        
  24.         LightProbeGroup probes = (LightProbeGroup)GameObject.FindObjectOfType(typeof(LightProbeGroup));
  25.        
  26.         List<Vector3> probePositions = new List<Vector3>();
  27.        
  28.         for (float x = bounds.min.x; x<bounds.max.x; x += 2)
  29.         for (float z = bounds.min.z; z<bounds.max.z; z += 2)
  30.         {
  31.             probePositions.Add(new Vector3(x,0.3f,z));
  32.             probePositions.Add(new Vector3(x,2.3f,z));
  33.         }
  34.        
  35.         probes.probePositions = probePositions.ToArray();
  36.        
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment