public override void OnInspectorGUI() { if (this.isNull == true) { EditorGUILayout.HelpBox("The associated script can not be loaded.\nPlease fix any compile errors\nand assign a valid script.", MessageType.Warning); if (this.isPrefab == true) { if (GUILayout.Button("Recover Missing Component") == true) { NGMissingScriptRecoveryWindow instance = EditorWindow.GetWindow <NGMissingScriptRecoveryWindow>(true, NGMissingScriptRecoveryWindow.NormalTitle); if (instance.IsRecovering == false) { instance.Diagnose(Selection.activeGameObject); instance.tab = NGMissingScriptRecoveryWindow.Tab.Selection; instance.Show(); } else { EditorUtility.DisplayDialog(NGMissingScriptRecoveryWindow.NormalTitle, "A recovery process is still running.", "OK"); } } } else { EditorGUILayout.HelpBox(NGMissingScriptRecoveryWindow.NormalTitle + " can only recover from prefabs.\nCreate a prefab of your broken asset and recover from it.", MessageType.Warning); } } else { base.OnInspectorGUI(); } }
private static void Diagnose(MenuCommand command) { // We assume that the context menu is opened from the active GameObject. PrefabType prefabType = PrefabUtility.GetPrefabType(Selection.activeGameObject); Object prefab = null; if (prefabType == PrefabType.Prefab) { prefab = Selection.activeGameObject; } else if (prefabType == PrefabType.PrefabInstance) { prefab = PrefabUtility.GetPrefabParent(Selection.activeGameObject); } else if (prefabType == PrefabType.DisconnectedPrefabInstance) { prefab = PrefabUtility.GetPrefabParent(Selection.activeGameObject); } if (prefab == null) { EditorUtility.DisplayDialog(NGMissingScriptRecoveryWindow.NormalTitle, "Recover a missing script is only possible on prefab.\n\nYou may temporary create a prefab, recover and then destroy the prefab.", "OK"); return; } NGMissingScriptRecoveryWindow instance = EditorWindow.GetWindow <NGMissingScriptRecoveryWindow>(true, NGMissingScriptRecoveryWindow.ShortTitle); if (instance.isRecovering == false) { instance.Diagnose(Selection.activeGameObject); instance.tab = Tab.Selection; instance.Show(); } else { EditorUtility.DisplayDialog(NGMissingScriptRecoveryWindow.NormalTitle, "A recovery process is still running.", "OK"); } }
public void Draw(NGMissingScriptRecoveryWindow window, bool force = false) { if (this.cachedFields == null) { StringBuilder buffer = Utility.GetBuffer(); for (int i = 0; i < this.fields.Count; i++) { buffer.AppendLine(this.fields[i]); } if (buffer.Length > 0) { buffer.Length -= Environment.NewLine.Length; } this.cachedFields = Utility.ReturnBuffer(buffer); } EditorGUI.BeginDisabledGroup(this.fields.Count <= 0); { Utility.content.text = this.name; Utility.content.image = Utility.GetIcon(this.asset ? this.asset.GetInstanceID() : 0); this.open = EditorGUILayout.Foldout(this.open, Utility.content) && this.fields.Count > 0 || force; Utility.content.image = null; } EditorGUI.EndDisabledGroup(); if (this.fields.Count == 0 && this.asset == null) { EditorGUILayout.HelpBox("Component seems to have absolutely no fields. Recovery can not proceed.", MessageType.Warning); } if (this.open == false) { return; } ++EditorGUI.indentLevel; this.fieldsOpen = EditorGUILayout.Foldout(this.fieldsOpen, "Fields found (" + this.fields.Count + ")"); if (this.fieldsOpen == true) { ++EditorGUI.indentLevel; Utility.content.text = this.cachedFields; float h = EditorStyles.label.CalcHeight(Utility.content, window.position.width - 60F); //float h = this.fields.Count * 15F; float totalH = h; if (h >= NGMissingScriptRecoveryWindow.MaxFieldsHeight) { h = NGMissingScriptRecoveryWindow.MaxFieldsHeight; } //Utility.content.text = this.cachedFields; //Rect viewRect = new Rect(); //Rect body = new Rect(4F, GUILayoutUtility.GetLastRect().yMax, window.position.width, 0F); //Rect r2 = GUILayoutUtility.GetRect(0F, h); //body.height = r2.height; //viewRect.height = EditorStyles.label.CalcSize(Utility.content).y; //EditorGUI.DrawRect(body, Color.blue); //this.scrollPositionFields = GUI.BeginScrollView(body, this.scrollPositionFields, viewRect); //{ // Rect selectableRect = body; // selectableRect.x = 0F; // selectableRect.y = 0F; // selectableRect.width = body.width - (viewRect.height > body.height ? 16F : 0F); // selectableRect.height = viewRect.height > body.height ? EditorStyles.label.CalcHeight(Utility.content, selectableRect.width) : viewRect.height; // EditorGUI.SelectableLabel(selectableRect, this.cachedFields, EditorStyles.label); //} //GUI.EndScrollView(); // TODO Fix bottom margin/padding? EditorGUI.HelpBox(new Rect(30F, GUILayoutUtility.GetLastRect().yMax, window.position.width - 60F, h + 10F), string.Empty, MessageType.None); //if (useScrollbar == true) this.scrollPositionFields = EditorGUILayout.BeginScrollView(this.scrollPositionFields, GUILayoutOptionPool.Height(h + 5F), GUILayoutOptionPool.Width(window.position.width - 30F)); //else //EditorGUI.HelpBox(new Rect(4F, GUILayoutUtility.GetLastRect().yMax, window.position.width, h), string.Empty, MessageType.None); { EditorGUILayout.SelectableLabel(this.cachedFields, EditorStyles.label, GUILayoutOptionPool.Height(totalH)); //for (int j = 0; j < this.fields.Count; j++) // EditorGUILayout.LabelField(this.fields[j]); } //if (useScrollbar == true) EditorGUILayout.EndScrollView(); --EditorGUI.indentLevel; } CachedLineFix lineFix = window.FindCachedComponentFixes(this.line); if (lineFix != null) { if (GUILayout.Button("Recover From Cache (" + lineFix.type + ")") == true) { this.FixLine(window, this.componentID, lineFix.type); window.Diagnose(window.Target); } } EditorGUILayout.LabelField("Potential types:"); ++EditorGUI.indentLevel; if (this.potentialTypes.Count == 0) { EditorGUILayout.LabelField("No type available."); } else { for (int l = 0; l < this.potentialTypes.Count; l++) { EditorGUILayout.BeginHorizontal(); { GUILayout.Space(30F); if (GUILayout.Button(this.potentialTypes[l].type.FullName, GUILayoutOptionPool.ExpandWidthFalse) == true) { this.FixMissingComponent(window, this.componentID, this.potentialTypes[l].type); window.Diagnose(window.Target); return; } if (this.potentialTypes[l].matchingFields == this.fields.Count && this.potentialTypes[l].fields.Length == this.fields.Count) { GUILayout.Label("(Perfect match)", GUILayoutOptionPool.ExpandWidthFalse); } else { int extraFields = this.potentialTypes[l].fields.Length == this.potentialTypes[l].matchingFields ? this.potentialTypes[l].matchingFields - this.fields.Count : this.potentialTypes[l].fields.Length - this.potentialTypes[l].matchingFields; GUILayout.Label("(Fields: " + this.potentialTypes[l].matchingFields + " matching" + (extraFields > 0 ? ", +" + extraFields + " extra" : (extraFields < 0 ? ", " + extraFields + " missing" : string.Empty)) + ")", GUILayoutOptionPool.ExpandWidthFalse); } if (Event.current.type == EventType.MouseMove) { Rect r = GUILayoutUtility.GetLastRect(); r.xMin = 0F; if (r.Contains(Event.current.mousePosition) == true) { if (this.hoverPopup != null) { if (this.hoverPopup.potentialType.type != this.potentialTypes[l].type) { if (this.hoverPopup.editorWindow != null) { this.hoverPopup.editorWindow.Close(); } this.hoverPopup = new HighlightMatchesPopup(this, this.potentialTypes[l]); r.x = 30F; r.y += 5F; PopupWindow.Show(r, this.hoverPopup); } } else { this.hoverPopup = new HighlightMatchesPopup(this, this.potentialTypes[l]); r.x = 30F; r.y += 5F; PopupWindow.Show(r, this.hoverPopup); } } else { if (this.hoverPopup != null && this.hoverPopup.potentialType.type == this.potentialTypes[l].type) { if (this.hoverPopup.editorWindow != null) { this.hoverPopup.editorWindow.Close(); } this.hoverPopup = null; } } } } EditorGUILayout.EndHorizontal(); } } --EditorGUI.indentLevel; --EditorGUI.indentLevel; }