Assets/_Scripts/Others/RevertAllPrefabs.cs
/// <summary>
/// This allows for both nested prefabs as well as simply going into object trees without having to expand the whole tree first.
/// </summary>
This allows for both nested prefabs as well as simply going into object trees without having to expand the whole tree first.
This allows for both nested prefabs as well as simply going into object trees without having to expand the whole tree first .
static void RecursiveRevertPrefabInstances( GameObject obj, ref int revertedCount, ref Dictionary<UnityEngine.Object, bool> prefabsAlreadyReverted )
    {
        if ( obj == null )
            return;
        if ( IsAPrefabNotYetReverted( obj, ref prefabsAlreadyReverted ) )
        {
            revertedCount++;
            PrefabUtility.RevertPrefabInstance( obj );
        }
        Transform trans = obj.transform;
        for ( int i = 0; i < trans.childCount; i++ )
            RecursiveRevertPrefabInstances( trans.GetChild( i ).gameObject, ref revertedCount, ref prefabsAlreadyReverted );
    }
static void RecursiveRevertPrefabInstances ( GameObject obj , ref int revertedCount , ref Dictionary < UnityEngine . Object , bool > prefabsAlreadyReverted ) { if ( obj == null ) return ; if ( IsAPrefabNotYetReverted ( obj , ref prefabsAlreadyReverted ) ) { revertedCount ++ ; PrefabUtility . RevertPrefabInstance ( obj ) ; } Transform trans = obj . transform ; for ( int i = 0 ; i < trans . childCount ; i ++ ) RecursiveRevertPrefabInstances ( trans . GetChild ( i ) . gameObject , ref revertedCount , ref prefabsAlreadyReverted ) ; }
This allows for both nested prefabs as well as simply going into object trees without having to expand the whole tree first.
This allows for both nested prefabs as well as simply going into object trees without having to expand the whole tree first .
obj
GameObject
int
ref
Dictionary<UnityEngine.Object, bool>
ref