BridgeMessage.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright (c) 2024 Vuplex Inc. All rights reserved.
  2. //
  3. // Licensed under the Vuplex Commercial Software Library License, you may
  4. // not use this file except in compliance with the License. You may obtain
  5. // a copy of the License at
  6. //
  7. // https://vuplex.com/commercial-library-license
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. using System;
  15. using UnityEngine;
  16. namespace Vuplex.WebView.Internal {
  17. /// <summary>
  18. /// A simple base class used for sending messages from
  19. /// C# to a WebView's JavaScript and vice versa as serialized JSON.
  20. /// </summary>
  21. [Serializable]
  22. public class BridgeMessage {
  23. public string type;
  24. public static string ParseType(string serializedMessage) {
  25. try {
  26. var message = JsonUtility.FromJson<BridgeMessage>(serializedMessage);
  27. return message.type;
  28. } catch (Exception) {
  29. return null;
  30. }
  31. }
  32. }
  33. }