Created
April 13, 2017 01:07
-
-
Save twobob/90fb93504b4c7076818a5de393773fdb to your computer and use it in GitHub Desktop.
For clearing down the blank mesh renderers from ProDrawCall - Works on Selected items + children
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEditor; | |
using System.Linq; | |
// Select some Gameobjects in the scene view to use this | |
public class RipOrphanRenderers { | |
[MenuItem("Window/Remove Orphaned Disabled Renderers")] | |
static void RipOrphans() | |
{ | |
var objs = Selection.gameObjects; | |
foreach (var go in objs) { | |
foreach(Transform child in go.transform) | |
{ | |
if ( child.gameObject.name.Contains ("LOD")) { | |
MeshRenderer mr = child.gameObject.GetComponent<MeshRenderer> (); | |
if (mr != null) { | |
if (!mr.enabled) { | |
SafeDestroy ( child.gameObject); | |
} | |
} | |
} | |
} | |
} | |
} | |
public static T SafeDestroy<T>(T obj) where T : Object | |
{ | |
if (Application.isEditor) | |
Object.DestroyImmediate(obj); | |
else | |
Object.Destroy(obj); | |
return null; | |
} | |
public static T SafeDestroyGameObject<T>(T component) where T : Component | |
{ | |
if (component != null) | |
SafeDestroy(component.gameObject); | |
return null; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment