// Finds a ScriptData object matching the given typed name static ScriptData FindScript(string name) { return(DllUpdate.GetInstance().CurrentData.FirstOrDefault( d => d.Status != ScriptStatus.Deleted && (d.Script.GetClass().FullName == name || d.Script.name == name))); }
/// <summary> /// Gets a DllUpdate instance /// </summary> /// <returns></returns> public static DllUpdate GetInstance() { instance = instance ?? Resources.FindObjectsOfTypeAll <DllUpdate>().FirstOrDefault() ?? CreateInstance <DllUpdate>(); return(instance); }
void Apply() { var replaceMap = new Dictionary <MonoScript, MonoScript>(); GenerateReplaceMap(replaceMap, removedScripts); GenerateReplaceMap(replaceMap, existingScripts); ScriptReplace.DoReplace(replaceMap); DllUpdate.GetInstance().SaveChanges(); }
/// <summary> /// Reloads script data /// </summary> public void RefreshData() { removedScripts.Clear(); var data = DllUpdate.GetInstance().CurrentData; removedScripts.AddRange( data.Where(d => d.Status == ScriptStatus.Deleted) .GroupBy(d => AssetDatabase.GetAssetPath(d.Script)) .Select(group => new ScriptGroup(group.Key, group.Select(d => new ScriptItem { oldScript = d })))); }
public static void OnPostprocessAllAssets( string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { var obj = DllUpdate.GetInstance(); obj.UpdateData(); if (obj.CheckData()) { DllUpdateWindow.Open().RefreshData(); } }
// Displays the given script category (removed, existing) void ShowScriptCategory(string categoryTitle, List <ScriptGroup> category) { EditorGUILayout.LabelField(categoryTitle, EditorStyles.boldLabel); if (category.Count == 0) { EditorGUILayout.LabelField("Nothing to display"); } foreach (var group in category) { group.foldout = EditorGUILayout.Foldout(group.foldout, group.dllPath); if (group.foldout) { EditorGUI.indentLevel++; foreach (var script in group.scripts) { GUILayout.Space(-EditorGUIUtility.standardVerticalSpacing); GUILayout.BeginHorizontal(); // Draw the text field EditorGUILayout.LabelField(script.oldScript.Name, GUILayout.Width(EditorGUIUtility.labelWidth - 15f)); GUI.color = GetColor(script); script.text = EditorGUILayout.TextField(script.text, GUILayout.ExpandWidth(true)); GUI.color = Color.white; // Draw the drop down for quick selection var buttonRect = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Width(25f), GUILayout.Height(EditorGUIUtility.singleLineHeight)); if (GUI.Button(buttonRect, "\u25bc")) { var data = DllUpdate.GetInstance().CurrentData; var items = data .Where(d => d.Status == ScriptStatus.New) .Where(d => script.oldScript.Type == ScriptType.Unknown || d.Type == script.oldScript.Type) .Select(d => new GUIContent((string.IsNullOrEmpty(d.Namespace) ? "" : (d.Namespace + ".")) + d.Name)); EditorUtility.DisplayCustomMenu(buttonRect, new [] { new GUIContent("Choose...") }.Concat(items).ToArray(), -1, SelectMenuItem, script); } GUILayout.EndHorizontal(); GUILayout.Space(2 * EditorGUIUtility.standardVerticalSpacing); script.newScript = FindScript(script.text); } EditorGUI.indentLevel--; } } EditorGUILayout.Space(); }
void Cancel() { DllUpdate.GetInstance().SaveChanges(); Close(); }
protected virtual void OnGUI() { switch (Event.current.commandName) { case "ObjectSelectorUpdated": var script = (MonoScript)EditorGUIUtility.GetObjectPickerObject(); objectPickerTarget.text = script == null ? "" : script.GetClass().FullName; EditorGUIUtility.editingTextField = false; Repaint(); break; case "ObjectSelectorClosed": objectPickerTarget = null; break; } const float buttonWidth = 60f; GUILayout.BeginArea(new Rect(margin, margin, position.width - 2 * margin, position.height - 2 * margin)); scrollPosition = GUILayout.BeginScrollView(scrollPosition); // 'Show older' button GUILayout.BeginHorizontal(); if (GUILayout.Button("Show older", GUILayout.Width(100f))) { DllUpdate.GetInstance().ShowOlder(); RefreshData(); } GUILayout.FlexibleSpace(); if (GUILayout.Button("Reload scripts", GUILayout.Width(100f))) { DllUpdate.GetInstance().UpdateData(); RefreshData(); } GUILayout.EndHorizontal(); // Script categories ShowScriptCategory("Removed scripts", removedScripts); ShowScriptCategory("Existing scripts", existingScripts); // Add existing script GUILayout.BeginHorizontal(); addScript = EditorGUILayout.TextField("Add existing script", addScript); var addScriptData = FindScript(addScript); EditorGUI.BeginDisabledGroup(addScriptData == null || addScriptData.Status == ScriptStatus.Deleted); if (GUILayout.Button("Add", GUILayout.Width(buttonWidth))) { AddToGroup(existingScripts, addScriptData); addScript = ""; } EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); GUILayout.EndScrollView(); // Control buttons GUILayout.BeginHorizontal(); if (GUILayout.Button("OK", GUILayout.Width(buttonWidth))) { Apply(); Close(); } if (GUILayout.Button("Apply", GUILayout.Width(buttonWidth))) { Apply(); DllUpdate.GetInstance().UpdateData(); RefreshData(); } GUILayout.FlexibleSpace(); if (GUILayout.Button("Cancel", GUILayout.Width(buttonWidth))) { Cancel(); } GUILayout.EndHorizontal(); GUILayout.EndArea(); }