Skip to content

Instantly share code, notes, and snippets.

@michaelbartnett
Created April 18, 2014 02:49
Show Gist options
  • Save michaelbartnett/11022346 to your computer and use it in GitHub Desktop.
Save michaelbartnett/11022346 to your computer and use it in GitHub Desktop.
helper class for showing changes properties in a prefab instance, needs a StringListWindow helper that just prints a bunch of strings to an editor window
using System;
using System.Linq;
using UnityEngine;
using UnityEditor;
public class ListPrefabChanges : EditorWindow
{
[MenuItem("Tools/List Prefab Changes")]
private static void Command()
{
var propertyMods = from pm in PrefabUtility.GetPropertyModifications(Selection.activeGameObject)
where !(pm.propertyPath.StartsWith("m_LocalRotation") || pm.propertyPath.StartsWith("m_LocalPosition"))
select pm;
var propertyStrings = propertyMods.Select<PropertyModification, string>(ConstructPropertyString);
StringListWindow.ShowStringList("Prefab Changes", propertyStrings);
}
private static string ConstructPropertyString(PropertyModification pm)
{
var comp = pm.target as Component;
var gob = pm.target as GameObject;
if (comp != null) {
return comp.transform.GetHierarchyPath() + ": " + comp.GetType().Name + "." + pm.propertyPath + " " + pm.value;
} else if (gob != null) {
return gob.transform.GetHierarchyPath() + "." + pm.propertyPath + " " + pm.value;
}
return "Unknown target type: " + pm.target.GetType().Name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment