CinemachineSettings.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. #if !UNITY_2019_1_OR_NEWER
  2. #define CINEMACHINE_UGUI
  3. #endif
  4. using UnityEngine;
  5. using UnityEditor;
  6. using System;
  7. namespace Cinemachine.Editor
  8. {
  9. #if !UNITY_2021_2_OR_NEWER
  10. [InitializeOnLoad]
  11. internal sealed class CinemachineSettings
  12. #else
  13. internal sealed class CinemachineSettings : AssetPostprocessor
  14. #endif
  15. {
  16. #if UNITY_2021_2_OR_NEWER
  17. static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload)
  18. {
  19. if (didDomainReload)
  20. {
  21. EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyGUI;
  22. }
  23. }
  24. #endif
  25. public static class CinemachineCoreSettings
  26. {
  27. private static readonly string hShowInGameGuidesKey = "CNMCN_Core_ShowInGameGuides";
  28. public static bool ShowInGameGuides
  29. {
  30. get { return EditorPrefs.GetBool(hShowInGameGuidesKey, true); }
  31. set
  32. {
  33. if (ShowInGameGuides != value)
  34. {
  35. EditorPrefs.SetBool(hShowInGameGuidesKey, value);
  36. UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
  37. }
  38. }
  39. }
  40. static string kUseTimelneScrubbingCache = "CNMCN_Timeeline_UseTimelineScrubbingCache";
  41. public static bool UseTimelneScrubbingCache
  42. {
  43. get { return EditorPrefs.GetBool(kUseTimelneScrubbingCache, true); }
  44. set
  45. {
  46. if (UseTimelneScrubbingCache != value)
  47. EditorPrefs.SetBool(kUseTimelneScrubbingCache, value);
  48. }
  49. }
  50. private static readonly string kCoreActiveGizmoColourKey = "CNMCN_Core_Active_Gizmo_Colour";
  51. public static readonly Color kDefaultActiveColour = new Color32(255, 0, 0, 100);
  52. public static Color ActiveGizmoColour
  53. {
  54. get
  55. {
  56. string packedColour = EditorPrefs.GetString(kCoreActiveGizmoColourKey, PackColor(kDefaultActiveColour));
  57. return UnpackColour(packedColour);
  58. }
  59. set
  60. {
  61. if (ActiveGizmoColour != value)
  62. {
  63. string packedColour = PackColor(value);
  64. EditorPrefs.SetString(kCoreActiveGizmoColourKey, packedColour);
  65. }
  66. }
  67. }
  68. private static readonly string kCoreInactiveGizmoColourKey = "CNMCN_Core_Inactive_Gizmo_Colour";
  69. public static readonly Color kDefaultInactiveColour = new Color32(9, 54, 87, 100);
  70. public static Color InactiveGizmoColour
  71. {
  72. get
  73. {
  74. string packedColour = EditorPrefs.GetString(kCoreInactiveGizmoColourKey, PackColor(kDefaultInactiveColour));
  75. return UnpackColour(packedColour);
  76. }
  77. set
  78. {
  79. if (InactiveGizmoColour != value)
  80. {
  81. string packedColour = PackColor(value);
  82. EditorPrefs.SetString(kCoreInactiveGizmoColourKey, packedColour);
  83. }
  84. }
  85. }
  86. private static readonly string kCoreBoundaryObjectGizmoColorKey = "CNMCN_Core_BoundaryObject_Gizmo_Colour";
  87. public static readonly Color kDefaultBoundaryObjectColour = Color.yellow;
  88. public static Color BoundaryObjectGizmoColour
  89. {
  90. get
  91. {
  92. string packedColour = EditorPrefs.GetString(kCoreBoundaryObjectGizmoColorKey, PackColor(kDefaultBoundaryObjectColour));
  93. return UnpackColour(packedColour);
  94. }
  95. set
  96. {
  97. if (BoundaryObjectGizmoColour != value)
  98. {
  99. string packedColour = PackColor(value);
  100. EditorPrefs.SetString(kCoreBoundaryObjectGizmoColorKey, packedColour);
  101. }
  102. }
  103. }
  104. }
  105. public static class ComposerSettings
  106. {
  107. private static readonly string kOverlayOpacityKey = "CNMCN_Overlay_Opacity";
  108. private static readonly string kComposerHardBoundsColourKey = "CNMCN_Composer_HardBounds_Colour";
  109. private static readonly string kComposerSoftBoundsColourKey = "CNMCN_Composer_SoftBounds_Colour";
  110. private static readonly string kComposerTargetColourKey = "CNMCN_Composer_Target_Colour";
  111. private static readonly string kComposerTargetSizeKey = "CNMCN_Composer_Target_Size";
  112. public const float kDefaultOverlayOpacity = 0.15f;
  113. public static readonly Color kDefaultHardBoundsColour = new Color32(255, 0, 72, 255);
  114. public static readonly Color kDefaultSoftBoundsColour = new Color32(0, 194, 255, 255);
  115. public static readonly Color kDefaultTargetColour = new Color32(255, 254, 25, 255);
  116. public static float OverlayOpacity
  117. {
  118. get { return EditorPrefs.GetFloat(kOverlayOpacityKey, kDefaultOverlayOpacity); }
  119. set
  120. {
  121. if (value != OverlayOpacity)
  122. {
  123. EditorPrefs.SetFloat(kOverlayOpacityKey, value);
  124. }
  125. }
  126. }
  127. public static Color HardBoundsOverlayColour
  128. {
  129. get
  130. {
  131. string packedColour = EditorPrefs.GetString(kComposerHardBoundsColourKey, PackColor(kDefaultHardBoundsColour));
  132. return UnpackColour(packedColour);
  133. }
  134. set
  135. {
  136. if (HardBoundsOverlayColour != value)
  137. {
  138. string packedColour = PackColor(value);
  139. EditorPrefs.SetString(kComposerHardBoundsColourKey, packedColour);
  140. }
  141. }
  142. }
  143. public static Color SoftBoundsOverlayColour
  144. {
  145. get
  146. {
  147. string packedColour = EditorPrefs.GetString(kComposerSoftBoundsColourKey, PackColor(kDefaultSoftBoundsColour));
  148. return UnpackColour(packedColour);
  149. }
  150. set
  151. {
  152. if (SoftBoundsOverlayColour != value)
  153. {
  154. string packedColour = PackColor(value);
  155. EditorPrefs.SetString(kComposerSoftBoundsColourKey, packedColour);
  156. }
  157. }
  158. }
  159. public static Color TargetColour
  160. {
  161. get
  162. {
  163. string packedColour = EditorPrefs.GetString(kComposerTargetColourKey, PackColor(kDefaultTargetColour));
  164. return UnpackColour(packedColour);
  165. }
  166. set
  167. {
  168. if (TargetColour != value)
  169. {
  170. string packedColour = PackColor(value);
  171. EditorPrefs.SetString(kComposerTargetColourKey, packedColour);
  172. }
  173. }
  174. }
  175. public static float TargetSize
  176. {
  177. get
  178. {
  179. return EditorPrefs.GetFloat(kComposerTargetSizeKey, 5f);
  180. }
  181. set
  182. {
  183. if (TargetSize != value)
  184. {
  185. EditorPrefs.SetFloat(kComposerTargetSizeKey, value);
  186. }
  187. }
  188. }
  189. }
  190. private static bool ShowCoreSettings
  191. {
  192. get { return EditorPrefs.GetBool(kCoreSettingsFoldKey, false); }
  193. set
  194. {
  195. if (value != ShowCoreSettings)
  196. {
  197. EditorPrefs.SetBool(kCoreSettingsFoldKey, value);
  198. }
  199. }
  200. }
  201. private static bool ShowComposerSettings
  202. {
  203. get { return EditorPrefs.GetBool(kComposerSettingsFoldKey, false); }
  204. set
  205. {
  206. if (value != ShowComposerSettings)
  207. {
  208. EditorPrefs.SetBool(kComposerSettingsFoldKey, value);
  209. }
  210. }
  211. }
  212. private static Texture2D sCinemachineLogoTexture = null;
  213. internal static Texture2D CinemachineLogoTexture
  214. {
  215. get
  216. {
  217. if (sCinemachineLogoTexture == null)
  218. sCinemachineLogoTexture = AssetDatabase.LoadAssetAtPath<Texture2D>(
  219. ScriptableObjectUtility.CinemachineRealativeInstallPath
  220. + "/Editor/EditorResources/cm_logo_sm.png");
  221. if (sCinemachineLogoTexture != null)
  222. sCinemachineLogoTexture.hideFlags = HideFlags.DontSaveInEditor;
  223. return sCinemachineLogoTexture;
  224. }
  225. }
  226. private static Texture2D sCinemachineHeader = null;
  227. internal static Texture2D CinemachineHeader
  228. {
  229. get
  230. {
  231. if (sCinemachineHeader == null)
  232. sCinemachineHeader = AssetDatabase.LoadAssetAtPath<Texture2D>(
  233. ScriptableObjectUtility.CinemachineRealativeInstallPath
  234. + "/Editor/EditorResources/cinemachine_header.tif");
  235. ;
  236. if (sCinemachineHeader != null)
  237. sCinemachineHeader.hideFlags = HideFlags.DontSaveInEditor;
  238. return sCinemachineHeader;
  239. }
  240. }
  241. private static readonly string kCoreSettingsFoldKey = "CNMCN_Core_Folded";
  242. private static readonly string kComposerSettingsFoldKey = "CNMCN_Composer_Folded";
  243. internal static event Action AdditionalCategories = null;
  244. #if !UNITY_2021_2_OR_NEWER
  245. [InitializeOnLoadMethod]
  246. /// Ensures that CM Brain logo is added to the Main Camera
  247. /// after adding a virtual camera to the project for the first time
  248. static void OnPackageLoadedInEditor()
  249. {
  250. #if UNITY_2020_3_OR_NEWER
  251. // Nothing to load in the context of a secondary process.
  252. if ((int)UnityEditor.MPE.ProcessService.level == 2 /*UnityEditor.MPE.ProcessLevel.Secondary*/)
  253. return;
  254. #endif
  255. if (CinemachineLogoTexture == null)
  256. {
  257. // After adding the CM to a project, we need to wait for one update cycle for the assets to load
  258. EditorApplication.update -= OnPackageLoadedInEditor;
  259. EditorApplication.update += OnPackageLoadedInEditor;
  260. }
  261. else
  262. {
  263. EditorApplication.update -= OnPackageLoadedInEditor;
  264. EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyGUI; // Update hierarchy with CM Brain logo
  265. }
  266. }
  267. static CinemachineSettings()
  268. {
  269. if (CinemachineLogoTexture != null)
  270. {
  271. EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyGUI;
  272. }
  273. }
  274. #endif
  275. class Styles {
  276. //private static readonly GUIContent sCoreShowHiddenObjectsToggle = new GUIContent("Show Hidden Objects", "If checked, Cinemachine hidden objects will be shown in the inspector. This might be necessary to repair broken script mappings when upgrading from a pre-release version");
  277. public static readonly GUIContent sCoreActiveGizmosColour = new GUIContent("Active Virtual Camera", "The colour for the active virtual camera's gizmos");
  278. public static readonly GUIContent sCoreInactiveGizmosColour = new GUIContent("Inactive Virtual Camera", "The colour for all inactive virtual camera gizmos");
  279. public static readonly GUIContent sCoreBoundaryObjectGizmosColour = new GUIContent("Boundary Object", "The colour to indicate secondary objects like group boundaries and confiner shapes");
  280. public static readonly GUIContent sComposerOverlayOpacity = new GUIContent("Overlay Opacity", "The alpha of the composer's overlay when a virtual camera is selected with composer module enabled");
  281. public static readonly GUIContent sComposerHardBoundsOverlay = new GUIContent("Hard Bounds Overlay", "The colour of the composer overlay's hard bounds region");
  282. public static readonly GUIContent sComposerSoftBoundsOverlay = new GUIContent("Soft Bounds Overlay", "The colour of the composer overlay's soft bounds region");
  283. public static readonly GUIContent sComposerTargetOverlay = new GUIContent("Composer Target", "The colour of the composer overlay's target");
  284. public static readonly GUIContent sComposerTargetOverlayPixels = new GUIContent("Target Size (px)", "The size of the composer overlay's target box in pixels");
  285. }
  286. private static Vector2 sScrollPosition = Vector2.zero;
  287. static GUIContent sDraggableText = new GUIContent("Draggable Game Window Guides", "If checked, game window " +
  288. "guides are draggable in play mode. If false, game window guides are only for visualization");
  289. static GUIContent sGlobalMuteText = new GUIContent("Storyboard Global Mute", "If checked, all storyboards " +
  290. "are globally muted.");
  291. #if UNITY_2019_1_OR_NEWER
  292. [SettingsProvider]
  293. static SettingsProvider CreateProjectSettingsProvider()
  294. {
  295. var provider = new SettingsProvider("Preferences/Cinemachine",
  296. SettingsScope.User, SettingsProvider.GetSearchKeywordsFromGUIContentProperties<Styles>());
  297. provider.guiHandler = (sarchContext) => OnGUI();
  298. return provider;
  299. }
  300. #else
  301. [PreferenceItem("Cinemachine")]
  302. #endif
  303. private static void OnGUI()
  304. {
  305. if (CinemachineHeader != null)
  306. {
  307. const float kWidth = 350f;
  308. float aspectRatio = (float)CinemachineHeader.height / (float)CinemachineHeader.width;
  309. GUILayout.BeginScrollView(Vector2.zero, false, false, GUILayout.Width(kWidth), GUILayout.Height(kWidth * aspectRatio));
  310. Rect texRect = new Rect(0f, 0f, kWidth, kWidth * aspectRatio);
  311. GUILayout.BeginArea(texRect);
  312. GUI.DrawTexture(texRect, CinemachineHeader, ScaleMode.ScaleToFit);
  313. GUILayout.EndArea();
  314. GUILayout.EndScrollView();
  315. }
  316. // set label width, so text is not cut for Toggles
  317. float originalLabelWidth = EditorGUIUtility.labelWidth;
  318. EditorGUIUtility.labelWidth = GUI.skin.label.CalcSize(
  319. sGlobalMuteText.text.Length > sDraggableText.text.Length ? sGlobalMuteText : sDraggableText).x;
  320. {
  321. #if CINEMACHINE_UGUI
  322. CinemachineStoryboardMute.Enabled = EditorGUILayout.Toggle(
  323. sGlobalMuteText,
  324. CinemachineStoryboardMute.Enabled);
  325. #endif
  326. CinemachineScreenComposerGuidesGlobalDraggable.Enabled = EditorGUILayout.Toggle(
  327. sDraggableText,
  328. CinemachineScreenComposerGuidesGlobalDraggable.Enabled);
  329. }
  330. EditorGUIUtility.labelWidth = originalLabelWidth;
  331. sScrollPosition = GUILayout.BeginScrollView(sScrollPosition);
  332. //CinemachineCore.sShowHiddenObjects
  333. // = EditorGUILayout.Toggle("Show Hidden Objects", CinemachineCore.sShowHiddenObjects);
  334. ShowCoreSettings = EditorGUILayout.Foldout(ShowCoreSettings, "Runtime Settings", true);
  335. if (ShowCoreSettings)
  336. {
  337. EditorGUI.indentLevel++;
  338. EditorGUI.BeginChangeCheck();
  339. EditorGUILayout.BeginHorizontal();
  340. EditorGUI.BeginChangeCheck();
  341. Color newActiveGizmoColour = EditorGUILayout.ColorField(Styles.sCoreActiveGizmosColour, CinemachineCoreSettings.ActiveGizmoColour);
  342. if (EditorGUI.EndChangeCheck())
  343. {
  344. CinemachineCoreSettings.ActiveGizmoColour = newActiveGizmoColour;
  345. UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
  346. }
  347. if (GUILayout.Button("Reset"))
  348. {
  349. CinemachineCoreSettings.ActiveGizmoColour = CinemachineCoreSettings.kDefaultActiveColour;
  350. }
  351. EditorGUILayout.EndHorizontal();
  352. EditorGUILayout.BeginHorizontal();
  353. EditorGUI.BeginChangeCheck();
  354. Color newInactiveGizmoColour = EditorGUILayout.ColorField(Styles.sCoreInactiveGizmosColour, CinemachineCoreSettings.InactiveGizmoColour);
  355. if (EditorGUI.EndChangeCheck())
  356. {
  357. CinemachineCoreSettings.InactiveGizmoColour = newInactiveGizmoColour;
  358. UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
  359. }
  360. if (GUILayout.Button("Reset"))
  361. {
  362. CinemachineCoreSettings.InactiveGizmoColour = CinemachineCoreSettings.kDefaultInactiveColour;
  363. }
  364. EditorGUILayout.EndHorizontal();
  365. EditorGUILayout.BeginHorizontal();
  366. EditorGUI.BeginChangeCheck();
  367. Color newBoundaryObjectColor = EditorGUILayout.ColorField(Styles.sCoreBoundaryObjectGizmosColour, CinemachineCoreSettings.BoundaryObjectGizmoColour);
  368. if (EditorGUI.EndChangeCheck())
  369. {
  370. CinemachineCoreSettings.BoundaryObjectGizmoColour = newBoundaryObjectColor;
  371. UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
  372. }
  373. if (GUILayout.Button("Reset"))
  374. {
  375. CinemachineCoreSettings.BoundaryObjectGizmoColour = CinemachineCoreSettings.kDefaultBoundaryObjectColour;
  376. }
  377. EditorGUILayout.EndHorizontal();
  378. EditorGUI.indentLevel--;
  379. }
  380. ShowComposerSettings = EditorGUILayout.Foldout(ShowComposerSettings, "Composer Settings", true);
  381. if (ShowComposerSettings)
  382. {
  383. EditorGUI.indentLevel++;
  384. EditorGUILayout.BeginHorizontal();
  385. EditorGUI.BeginChangeCheck();
  386. float overlayOpacity = EditorGUILayout.Slider(Styles.sComposerOverlayOpacity, ComposerSettings.OverlayOpacity, 0f, 1f);
  387. if (EditorGUI.EndChangeCheck())
  388. {
  389. ComposerSettings.OverlayOpacity = overlayOpacity;
  390. }
  391. if (GUILayout.Button("Reset"))
  392. {
  393. ComposerSettings.OverlayOpacity = ComposerSettings.kDefaultOverlayOpacity;
  394. }
  395. EditorGUILayout.EndHorizontal();
  396. EditorGUILayout.BeginHorizontal();
  397. EditorGUI.BeginChangeCheck();
  398. Color newHardEdgeColor = EditorGUILayout.ColorField(Styles.sComposerHardBoundsOverlay, ComposerSettings.HardBoundsOverlayColour);
  399. if (EditorGUI.EndChangeCheck())
  400. {
  401. ComposerSettings.HardBoundsOverlayColour = newHardEdgeColor;
  402. }
  403. if (GUILayout.Button("Reset"))
  404. {
  405. ComposerSettings.HardBoundsOverlayColour = ComposerSettings.kDefaultHardBoundsColour;
  406. }
  407. EditorGUILayout.EndHorizontal();
  408. EditorGUILayout.BeginHorizontal();
  409. EditorGUI.BeginChangeCheck();
  410. Color newSoftEdgeColor = EditorGUILayout.ColorField(Styles.sComposerSoftBoundsOverlay, ComposerSettings.SoftBoundsOverlayColour);
  411. if (EditorGUI.EndChangeCheck())
  412. {
  413. ComposerSettings.SoftBoundsOverlayColour = newSoftEdgeColor;
  414. }
  415. if (GUILayout.Button("Reset"))
  416. {
  417. ComposerSettings.SoftBoundsOverlayColour = ComposerSettings.kDefaultSoftBoundsColour;
  418. }
  419. EditorGUILayout.EndHorizontal();
  420. EditorGUILayout.BeginHorizontal();
  421. EditorGUI.BeginChangeCheck();
  422. Color newTargetColour = EditorGUILayout.ColorField(Styles.sComposerTargetOverlay, ComposerSettings.TargetColour);
  423. if (EditorGUI.EndChangeCheck())
  424. {
  425. ComposerSettings.TargetColour = newTargetColour;
  426. }
  427. if (GUILayout.Button("Reset"))
  428. {
  429. ComposerSettings.TargetColour = ComposerSettings.kDefaultTargetColour;
  430. }
  431. EditorGUILayout.EndHorizontal();
  432. EditorGUI.BeginChangeCheck();
  433. float targetSide = EditorGUILayout.FloatField(Styles.sComposerTargetOverlayPixels, ComposerSettings.TargetSize);
  434. if (EditorGUI.EndChangeCheck())
  435. {
  436. ComposerSettings.TargetSize = targetSide;
  437. }
  438. EditorGUI.indentLevel--;
  439. }
  440. if (AdditionalCategories != null)
  441. {
  442. AdditionalCategories();
  443. }
  444. GUILayout.EndScrollView();
  445. }
  446. private static void OnHierarchyGUI(int instanceID, Rect selectionRect)
  447. {
  448. GameObject instance = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
  449. if (instance == null)
  450. {
  451. // Object in process of being deleted?
  452. return;
  453. }
  454. if (instance.TryGetComponent(out CinemachineBrain _))
  455. {
  456. var tex = CinemachineLogoTexture;
  457. if (tex != null)
  458. {
  459. var texRect = new Rect(selectionRect.xMax - selectionRect.height, selectionRect.yMin, selectionRect.height, selectionRect.height);
  460. GUI.DrawTexture(texRect, tex, ScaleMode.ScaleAndCrop);
  461. }
  462. }
  463. }
  464. internal static Color UnpackColour(string str)
  465. {
  466. if (!string.IsNullOrEmpty(str))
  467. {
  468. byte[] bytes = Base64Decode(str);
  469. if ((bytes != null) && bytes.Length == 16)
  470. {
  471. float r = BitConverter.ToSingle(bytes, 0);
  472. float g = BitConverter.ToSingle(bytes, 4);
  473. float b = BitConverter.ToSingle(bytes, 8);
  474. float a = BitConverter.ToSingle(bytes, 12);
  475. return new Color(r, g, b, a);
  476. }
  477. }
  478. return Color.white;
  479. }
  480. internal static string PackColor(Color col)
  481. {
  482. byte[] bytes = new byte[16];
  483. byte[] rBytes = BitConverter.GetBytes(col.r);
  484. byte[] gBytes = BitConverter.GetBytes(col.g);
  485. byte[] bBytes = BitConverter.GetBytes(col.b);
  486. byte[] aBytes = BitConverter.GetBytes(col.a);
  487. Buffer.BlockCopy(rBytes, 0, bytes, 0, 4);
  488. Buffer.BlockCopy(gBytes, 0, bytes, 4, 4);
  489. Buffer.BlockCopy(bBytes, 0, bytes, 8, 4);
  490. Buffer.BlockCopy(aBytes, 0, bytes, 12, 4);
  491. return Base64Encode(bytes);
  492. }
  493. private static string Base64Encode(byte[] data)
  494. {
  495. return Convert.ToBase64String(data);
  496. }
  497. private static byte[] Base64Decode(string base64EncodedData)
  498. {
  499. return Convert.FromBase64String(base64EncodedData);
  500. }
  501. }
  502. }