-
-
Save NeatWolf/8f7428381de75758e04bfd14ae49f649 to your computer and use it in GitHub Desktop.
Simple Utility script for Unity3D that allows access for "IsDirty" method for gameobjects.
This file contains 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 UnityEditor; | |
using System.Reflection; | |
using System; | |
//Special thanks to Shamanim for solution | |
//https://forum.unity.com/threads/sorta-solved-check-if-gameobject-is-dirty.504894/#post-3967810 | |
public class IsDirtyUtility | |
{ | |
//Cached Value | |
private static Func<int, bool> _isDirtyCallback; | |
private static Func<int, bool> IsDirtyCallback | |
{ | |
get | |
{ | |
if(_isDirtyCallback == null) | |
{ | |
//Reflection | |
MethodInfo isDirtyMethod = typeof(EditorUtility).GetMethod("IsDirty", BindingFlags.NonPublic | BindingFlags.Static); | |
_isDirtyCallback = (Func<int, bool>)Delegate.CreateDelegate(typeof(Func<int, bool>), null, isDirtyMethod); | |
} | |
return _isDirtyCallback; | |
} | |
} | |
public static bool IsDirty(int instanceID) | |
{ | |
return IsDirtyCallback(instanceID); | |
} | |
public static bool IsDirty(GameObject gameObject) | |
{ | |
return IsDirtyCallback(gameObject.GetInstanceID()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment