PrefabApply.cs 1.0 KB

12345678910111213141516171819202122232425262728
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace EnhancedHierarchy.Icons {
  4. public sealed class PrefabApply : IconBase {
  5. public override string Name { get { return "Apply Prefab"; } }
  6. public override IconPosition Side { get { return IconPosition.All; } }
  7. public override void DoGUI(Rect rect) {
  8. #if UNITY_2018_3_OR_NEWER
  9. var isPrefab = PrefabUtility.IsPartOfAnyPrefab(EnhancedHierarchy.CurrentGameObject);
  10. #else
  11. var isPrefab = PrefabUtility.GetPrefabType(EnhancedHierarchy.CurrentGameObject) == PrefabType.PrefabInstance;
  12. #endif
  13. using(new GUIContentColor(isPrefab ? Styles.backgroundColorEnabled : Styles.backgroundColorDisabled))
  14. if (GUI.Button(rect, Styles.prefabApplyContent, Styles.applyPrefabStyle)) {
  15. var objs = GetSelectedObjectsAndCurrent();
  16. foreach (var obj in objs)
  17. Utility.ApplyPrefabModifications(obj, objs.Count <= 1);
  18. }
  19. }
  20. }
  21. }