void SetPrefabModeButtonVisibility(GameObjectTreeViewItem item) { item.showPrefabModeButton = false; GameObject go = item.objectPPTR as GameObject; if (go == null) { return; } if (!PrefabUtility.IsPartOfAnyPrefab(go)) { return; } if (!PrefabUtility.IsAnyPrefabInstanceRoot(go)) { return; } // Don't show button if prefab asset is missing if (PrefabUtility.GetPrefabInstanceStatus(go) == PrefabInstanceStatus.Connected) { var source = PrefabUtility.GetOriginalSourceOrVariantRoot(go); if (source == null) { return; } // Don't show buttons for model prefabs but allow buttons for other immutables if (PrefabUtility.IsPartOfModelPrefab(source)) { return; } } else if (PrefabUtility.GetPrefabInstanceHandle(go) == null) { return; } else { var assetPath = PrefabUtility.GetAssetPathOfSourcePrefab(go); var broken = AssetDatabase.LoadMainAssetAtPath(assetPath) as BrokenPrefabAsset; if (broken == null || !broken.isPrefabFileValid) { return; } } item.showPrefabModeButton = true; }
public float PrefabModeButton(GameObjectTreeViewItem item, Rect selectionRect) { float contentRectRight = selectionRect.xMax; if (item.showPrefabModeButton) { float yOffset = (selectionRect.height - GameObjectStyles.rightArrow.fixedWidth) / 2; Rect buttonRect = new Rect( selectionRect.xMax - GameObjectStyles.rightArrow.fixedWidth - GameObjectStyles.rightArrow.margin.right, selectionRect.y + yOffset, GameObjectStyles.rightArrow.fixedWidth, GameObjectStyles.rightArrow.fixedHeight); int instanceID = item.id; GUIContent content = buttonRect.Contains(Event.current.mousePosition) ? PrefabStageUtility.GetPrefabButtonContent(instanceID) : GUIContent.none; if (GUI.Button(buttonRect, content, GameObjectStyles.rightArrow)) { GameObject go = EditorUtility.InstanceIDToObject(instanceID) as GameObject; string assetPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(go); if (string.IsNullOrWhiteSpace(assetPath)) //In case its a broken prefab { assetPath = PrefabUtility.GetAssetPathOfSourcePrefab(go); } Object originalSource = AssetDatabase.LoadMainAssetAtPath(assetPath); if (originalSource != null) { var prefabStageMode = PrefabStageUtility.GetPrefabStageModeFromModifierKeys(); PrefabStageUtility.OpenPrefab(assetPath, go, prefabStageMode, StageNavigationManager.Analytics.ChangeType.EnterViaInstanceHierarchyRightArrow); } } contentRectRight = buttonRect.xMin; } return(contentRectRight); }