Gnimmel
September 7, 2015, 2:54am
1
I’m trying to select every object in the scene that has the lightmap static flag set. If this makes a difference, I am still using unity pro 4.
I have a export obj script which exports the selected objects with their lightmap UVs so I can paint over lightmaps in substance painter, but I’d like to find a way to get the selection automatically instead of manually selecting all my lightmapped objects.
Can anyone point me in the right direction?
SvSe
February 26, 2016, 10:39am
2
Any luck with this? I am trying to do something similar, but I could also work with all objects that are reflection probe static.
Gnimmel
February 26, 2016, 2:47pm
3
It ended up being easy enough to work out. Below is the script I ended up writing.
Just so you know, I am still using unity 4, so its never been tested on 5 yet.
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
public class SelectLightmapStatic : EditorWindow
{
[MenuItem("Custom/Select Lightmap Static")]
static void Init()
{
// Find all the lightmap static objects
Object[] All_GOs = FindObjectsOfType(typeof(GameObject));
GameObject[] GOArray;
GOArray = new GameObject[All_GOs.Length];
int ArrayPointer = 0;
foreach(GameObject EachGO in All_GOs)
{
StaticEditorFlags flags = GameObjectUtility.GetStaticEditorFlags( EachGO );
if ((flags & StaticEditorFlags.LightmapStatic)!=0)
{
if( EachGO.GetComponent<MeshFilter>() != null )
{
GOArray[ArrayPointer] = EachGO;
ArrayPointer += 1;
}
}
}
Selection.objects = GOArray;
}
}
3 Likes
Gnimmel:
It ended up being easy enough to work out. Below is the script I ended up writing.
Just so you know, I am still using unity 4, so its never been tested on 5 yet.
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
public class SelectLightmapStatic : EditorWindow
{
[MenuItem("Custom/Select Lightmap Static")]
static void Init()
{
// Find all the lightmap static objects
Object[] All_GOs = FindObjectsOfType(typeof(GameObject));
GameObject[] GOArray;
GOArray = new GameObject[All_GOs.Length];
int ArrayPointer = 0;
foreach(GameObject EachGO in All_GOs)
{
StaticEditorFlags flags = GameObjectUtility.GetStaticEditorFlags( EachGO );
if ((flags & StaticEditorFlags.LightmapStatic)!=0)
{
if( EachGO.GetComponent<MeshFilter>() != null )
{
GOArray[ArrayPointer] = EachGO;
ArrayPointer += 1;
}
}
}
Selection.objects = GOArray;
}
}
Works like a dream on Unity 5. Thanks!
I was trying to do something similar with Navigation Static objects when I found this post.
Thanks a lot @Gnimmel you saved me time here.
And to contribute to this, here’s my adapted version, using Linq, and the probably new GameObjectUtility.AreStaticEditorFlagsSet method.
using System.Linq;
static void SelectStaticsByFlags (StaticEditorFlags flagsFilter)
{
var allGameObjects = FindObjectsOfType<GameObject>();
var statics = (from item in allGameObjects
where GameObjectUtility.AreStaticEditorFlagsSet(item.gameObject, flagsFilter)
select item).ToArray();
Selection.objects = statics;
}
UnityCoach:
I was trying to do something similar with Navigation Static objects when I found this post.
Thanks a lot @Gnimmel you saved me time here.
And to contribute to this, here’s my adapted version, using Linq, and the probably new GameObjectUtility.AreStaticEditorFlagsSet method.
using System.Linq;
static void SelectStaticsByFlags (StaticEditorFlags flagsFilter)
{
var allGameObjects = FindObjectsOfType<GameObject>();
var statics = (from item in allGameObjects
where GameObjectUtility.AreStaticEditorFlagsSet(item.gameObject, flagsFilter)
select item).ToArray();
Selection.objects = statics;
}
Wow, this is a old thread but I’m glad it helped
1 Like