Skip to content

Instantly share code, notes, and snippets.

@aobond2
Last active July 5, 2022 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aobond2/3951e4dceab70bbcbf7d01f59a38f220 to your computer and use it in GitHub Desktop.
Save aobond2/3951e4dceab70bbcbf7d01f59a38f220 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class GIDisabler : EditorWindow
{
static float volume = 0f;
static GameObject selectedGo;
static void show(string inText)
{
EditorWindow.GetWindow<SceneView>().ShowNotification(new GUIContent(inText));
}
public static string GetPrefabPath(Object asset)
{
string AssetPath = string.Empty;
Object targetObj = PrefabUtility.GetCorrespondingObjectFromSource<Object>(asset);
AssetPath = AssetDatabase.GetAssetPath(targetObj);
if (AssetPath == string.Empty)
Debug.LogWarning("Cound not find AssetPath : " + asset.ToString());
return AssetPath;
}
[MenuItem("DEBUG/GI Disabler")]
static void RunGIDisabler()
{
int GIDisabledcount = 0;
if (Selection.activeGameObject == null)
{
show("Need to select one GameObject");
return;
}
MeshRenderer currentRender = Selection.activeGameObject.GetComponent<MeshRenderer>();
if (currentRender == null)
{
show("Could not find MeshRenderer in the selected GameObject.");
return;
}
Vector3 dimension = currentRender.bounds.max - currentRender.bounds.min;
volume = currentRender.bounds.size.x * currentRender.bounds.size.y * currentRender.bounds.size.z;
show("Volume standard : " + volume.ToString() + " m³");
selectedGo = currentRender.gameObject;
MeshRenderer[] renders = Component.FindObjectsOfType<MeshRenderer>();
ArrayList exceptionalCase = new ArrayList();
exceptionalCase.Add("Assets/projects/City Bus/prefabs/city bus.prefab");
exceptionalCase.Add("Assets/projects/City Bus/prefabs/Lowpoly_CityBus_blue.prefab");
exceptionalCase.Add("Assets/projects/City Bus/prefabs/Lowpoly_CityBus_white.prefab");
exceptionalCase.Add("Assets/Vehicle - pro 3d models/Car1/Prefabs/Police.prefab");
exceptionalCase.Add("Assets/Vehicle - pro 3d models/Car1/Prefabs/Taxi.prefab");
exceptionalCase.Add("Assets/Art/Prefab/Vehicles/MiniVan_A/MiniVan_A.prefab");
exceptionalCase.Add("Assets/Art/Prefab/Vehicles/Scooter_A/Scooter_A.prefab");
foreach (MeshRenderer render in renders)
{
float currentVolume = render.bounds.size.x * render.bounds.size.y * render.bounds.size.z;
if (currentVolume <= volume)
{
render.gameObject.isStatic = false;
render.receiveGI = ReceiveGI.Lightmaps;
GIDisabledcount++;
}
else
{
string prefabPath = GetPrefabPath(render.gameObject);
if (exceptionalCase.Contains(prefabPath))
{
render.gameObject.isStatic = false;
GIDisabledcount++;
continue;
}
//render.gameObject.isStatic = true;
GameObjectUtility.SetStaticEditorFlags(render.gameObject, StaticEditorFlags.ContributeGI);
render.receiveGI = ReceiveGI.Lightmaps;
}
}
show("Disabled GI Count : " + GIDisabledcount.ToString() + " / " + renders.Length.ToString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment