WitUpgrader.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) Meta Platforms, Inc. and affiliates.
  3. * All rights reserved.
  4. *
  5. * Licensed under the Oculus SDK License Agreement (the "License");
  6. * you may not use the Oculus SDK except in compliance with the License,
  7. * which is provided at the time of installation or download, or which
  8. * otherwise accompanies this software in either electronic or hard copy form.
  9. *
  10. * You may obtain a copy of the License at
  11. *
  12. * https://developer.oculus.com/licenses/oculussdk/
  13. *
  14. * Unless required by applicable law or agreed to in writing, the Oculus SDK
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. using Meta.WitAi;
  21. using UnityEditor;
  22. using UnityEngine;
  23. namespace Oculus.Voice.Upgrade
  24. {
  25. [CustomEditor(typeof(Wit), false)]
  26. public class WitUpgrader : Editor
  27. {
  28. class Styles
  29. {
  30. public static GUIContent upgrade = new GUIContent("Upgrade to App Voice Experience",
  31. "This will replace your Wit object with a comparable component from the Voice SDK.");
  32. }
  33. public override void OnInspectorGUI()
  34. {
  35. var wit = (Wit) target;
  36. if (!wit.GetComponent<AppVoiceExperience>())
  37. {
  38. base.OnInspectorGUI();
  39. if (!Application.isPlaying && GUILayout.Button(Styles.upgrade))
  40. {
  41. var voiceService = wit.gameObject.AddComponent<AppVoiceExperience>();
  42. voiceService.VoiceEvents = wit.VoiceEvents;
  43. voiceService.RuntimeConfiguration = wit.RuntimeConfiguration;
  44. var voiceServiceSerializedObject = new SerializedObject(voiceService);
  45. voiceServiceSerializedObject.ApplyModifiedProperties();
  46. DestroyImmediate(wit);
  47. }
  48. }
  49. }
  50. }
  51. }