VXUtils.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 System.Linq;
  16. using UnityEngine;
  17. using UnityEngine.Rendering;
  18. namespace Vuplex.WebView.Internal {
  19. /// <summary>
  20. /// Static utility methods used internally by 3D WebView.
  21. /// </summary>
  22. /// <remarks>
  23. /// This class used to be named Utils, but since Utils is a common class name,
  24. /// if the user's project contained a class named Utils in the global namespace,
  25. /// it would break the 3D WebView classes that use this class.
  26. /// Similarly, the XR-related methods used to be in a class named XRUtils, but Unity added
  27. /// an XRUtils class to the UnityEngine.Rendering namespace, which led to ambiguous references.
  28. /// </remarks>
  29. public static class VXUtils {
  30. public static Material CreateDefaultMaterial() {
  31. // Construct a new material, because Resources.Load<T>() returns a singleton.
  32. return new Material(Resources.Load<Material>("DefaultWebMaterial"));
  33. }
  34. public static string GetGraphicsApiErrorMessage(GraphicsDeviceType activeGraphicsApi, GraphicsDeviceType[] acceptableGraphicsApis) {
  35. var isValid = Array.IndexOf(acceptableGraphicsApis, activeGraphicsApi) != -1;
  36. if (isValid) {
  37. return null;
  38. }
  39. var acceptableApiStrings = acceptableGraphicsApis.ToList().Select(api => api.ToString());
  40. var acceptableApisList = String.Join(" or ", acceptableApiStrings.ToArray());
  41. return $"Unsupported graphics API: Vuplex 3D WebView requires {acceptableApisList} for this platform, but the selected graphics API is {activeGraphicsApi}. Please go to Player Settings and set \"Graphics APIs\" to {acceptableApisList}.";
  42. }
  43. public static void LogNative2DModeWarning(string methodName, string effect = "will be ignored") {
  44. WebViewLogger.LogWarning($"{methodName}() was called but {effect} because it is not supported in Native 2D Mode.");
  45. }
  46. }
  47. }