bool IsDirty(GameObject prefabAssetRoot) { if (prefabAssetRoot == null) { return(false); } if (EditorUtility.IsDirty(prefabAssetRoot)) { return(true); } // For Prefab Variant Asset we need to also check if the instance handle is dirty // since this happens when the list of removed component changes var instanceHandle = PrefabUtility.GetPrefabInstanceHandle(prefabAssetRoot); if (instanceHandle != null) { if (EditorUtility.IsDirty(instanceHandle)) { return(true); } } prefabAssetRoot.GetComponents(m_TempComponentsResults); foreach (var component in m_TempComponentsResults) { if (EditorUtility.IsDirty(component)) { return(true); } } return(false); }
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; }
bool IsDirty(GameObject prefabAssetRoot) { if (prefabAssetRoot == null) { return(false); } if (EditorUtility.IsDirty(prefabAssetRoot)) { return(true); } // For Prefab Variant Asset we need to also check if the instance handle is dirty // since this happens when the list of removed component changes var instanceHandle = PrefabUtility.GetPrefabInstanceHandle(prefabAssetRoot); if (instanceHandle != null) { if (EditorUtility.IsDirty(instanceHandle)) { return(true); } } prefabAssetRoot.GetComponents(m_TempComponentsResults); foreach (var component in m_TempComponentsResults) { if (EditorUtility.IsDirty(component)) { return(true); } if (component is Renderer) { Renderer r = component as Renderer; foreach (Material mat in r.sharedMaterials) { if (EditorUtility.IsDirty(mat) && AssetDatabase.IsSubAsset(mat)) { return(AssetDatabase.GetAssetPath(mat) == AssetDatabase.GetAssetPath(prefabAssetRoot)); } } } } return(false); }
internal static UInt64 GetOrGenerateFileIDHint(UnityEngine.Object obj) { UInt64 fileID = Unsupported.GetFileIDHint(obj); if (fileID == 0) { // GenerateFileIDHint only work on saved nested prefabs instances. var instanceHandle = PrefabUtility.GetPrefabInstanceHandle(obj); if (instanceHandle != null) { bool isPrefabInstanceSaved = Unsupported.GetFileIDHint(instanceHandle) != 0; if (isPrefabInstanceSaved && PrefabUtility.IsPartOfNonAssetPrefabInstance(obj) && PrefabUtility.GetPrefabAssetType(obj) != PrefabAssetType.MissingAsset) { fileID = Unsupported.GenerateFileIDHint(obj); } } } return(fileID); }
// TODO: Having an non-obsolete method that takes an obsolete enum types as parameter is no good. #pragma warning disable 0618 // Type or member is obsolete private static GameObject SavePrefab(GameObject inputObject, string path, ReplacePrefabOptions replaceOptions, PrefabCreationFlags creationFlags) { if (inputObject == null) { throw new ArgumentNullException("inputObject is null"); } if (String.IsNullOrEmpty(path)) { throw new ArgumentNullException("path is null or empty"); } if (!Paths.IsValidAssetPath(path, ".prefab")) { throw new ArgumentException("Given path is not valid: '" + path + "'"); } string directory = Path.GetDirectoryName(path); if (directory.Length > 0 && !Directory.Exists(directory)) { throw new ArgumentException("Given path does not exist: '" + path + "'"); } string prefabGUID = AssetDatabase.AssetPathToGUID(path); if (!VerifyNestingFromScript(new GameObject[] { inputObject }, prefabGUID, PrefabUtility.GetPrefabInstanceHandle(inputObject))) { throw new ArgumentException("Cyclic nesting detected"); } return(SavePrefab_Internal(inputObject, path, replaceOptions, creationFlags)); }
internal override bool OnOptimizedInspectorGUI(Rect contentRect) { m_SerializedObject.UpdateIfRequiredOrScript(); bool childrenAreExpanded = true; bool wasEnabled = GUI.enabled; var visibleRect = GUIClip.visibleRect; var contentOffset = contentRect.y; // In some specific cases (e.g. when the inspector field has a dropdown behavior - case 1335344) we need to // apply the padding values so it behaves properly. By checking that xMin is zero when we do the assignments, // we avoid applying the padding more than once (because this is called more than once in some cases and // can lead to wrong indentation - case 1114055). if (contentRect.xMin == 0) { contentRect.xMin = EditorStyles.kInspectorPaddingLeft; contentRect.xMax -= EditorStyles.kInspectorPaddingRight; } if (Event.current.type != EventType.Repaint) { visibleRect = m_LastVisibleRect; } // Release keyboard focus before scrolling so that the virtual scrolling focus wrong control. if (Event.current.type == EventType.ScrollWheel) { GUIUtility.keyboardControl = 0; } var behaviour = target as MonoBehaviour; var property = m_SerializedObject.GetIterator(); bool isInspectorModeNormal = inspectorMode == InspectorMode.Normal; bool isInPrefabInstance = PrefabUtility.GetPrefabInstanceHandle(behaviour) != null; bool isMultiSelection = m_SerializedObject.targetObjectsCount > 1; using (new LocalizationGroup(behaviour)) { while (property.NextVisible(childrenAreExpanded)) { var handler = ScriptAttributeUtility.GetHandler(property); var hasPropertyDrawer = handler.propertyDrawer != null; childrenAreExpanded = !hasPropertyDrawer && property.isExpanded && EditorGUI.HasVisibleChildFields(property); contentRect.height = handler.GetHeight(property, null, hasPropertyDrawer || PropertyHandler.UseReorderabelListControl(property)); if (contentRect.Overlaps(visibleRect)) { EditorGUI.indentLevel = property.depth; using (new EditorGUI.DisabledScope((isInspectorModeNormal || isInPrefabInstance || isMultiSelection) && string.Equals("m_Script", property.propertyPath, System.StringComparison.Ordinal))) childrenAreExpanded &= handler.OnGUI(contentRect, property, GetPropertyLabel(property), PropertyHandler.UseReorderabelListControl(property), visibleRect); } if (contentRect.height > 0) { contentRect.y += contentRect.height + EditorGUI.kControlVerticalSpacing; } } } // Fix new height if (Event.current.type == EventType.Repaint) { m_LastVisibleRect = visibleRect; var newHeight = contentRect.y - contentOffset; if (newHeight != m_LastHeight) { m_LastHeight = contentRect.y - contentOffset; Repaint(); } } GUI.enabled = wasEnabled; return(m_SerializedObject.ApplyModifiedProperties()); }