public UnityEditor.MonoScript GetMonoScript() { var type = Type; return(type != null?FileUtility.FindScriptFile(type) : null); }
public void ResetToDefaults() { UndoHandler.RegisterUndoableAction(this, "Reset To Defaults"); #if UNITY_EDITOR // in UnityEditor use Presets or EditorJsonUtility #if UNITY_2018_1_OR_NEWER // Presets were introduced in Unity 2018.1 #if UNITY_2019_3_OR_NEWER // GetDefaultForObject became obsolete in Unity 2019.3 var presets = Preset.GetDefaultPresetsForObject(this); var preset = presets.Length > 0 ? presets[0] : null; #else var preset = Preset.GetDefaultForObject(this); #endif // if no default preset has been assigned for preferences asset, then try finding a preset // in the same directory with the preferences asset if (preset == null) { var preferencesPath = AssetDatabase.GetAssetPath(this); var directoryPath = FileUtility.GetParentDirectory(preferencesPath); var updateGuids = AssetDatabase.FindAssets("t:Preset", ArrayExtensions.TempStringArray(directoryPath)); for (int n = updateGuids.Length - 1; n >= 0; n--) { var path = AssetDatabase.GUIDToAssetPath(updateGuids[n]); preset = AssetDatabase.LoadAssetAtPath <Preset>(path); if (!string.Equals(preset.GetTargetFullTypeName(), typeof(InspectorPreferences).FullName, StringComparison.OrdinalIgnoreCase)) { preset = null; } else { break; } } } if (preset != null) { preset.ApplyTo(this); } else #endif { var freshInstance = CreateInstance <InspectorPreferences>(); var jsonString = EditorJsonUtility.ToJson(freshInstance); Platform.Active.Destroy(freshInstance); EditorJsonUtility.FromJsonOverwrite(jsonString, this); } #else // at runtime use JsonUtility to reset values to those of a freshly created instance var freshInstance = CreateInstance <InspectorPreferences>(); var jsonString = JsonUtility.ToJson(freshInstance); Platform.Active.Destroy(freshInstance); JsonUtility.FromJsonOverwrite(jsonString, this); #endif setupDone = false; isFirstOnValidate = true; if (Event.current != null) { Setup(); } Platform.Active.SetDirty(this); if (onSettingsChanged != null) { onSettingsChanged(this); } }