GesFPS.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Net.Mime;
  2. namespace Rokid.UXR.Utility {
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. using UnityEngine;
  16. using UnityEngine.UI;
  17. using Rokid.UXR.Interaction;
  18. [RequireComponent(typeof(Text))]
  19. public class GesFPS : MonoBehaviour
  20. {
  21. private Text textField;
  22. private float fps = 60;
  23. void Start()
  24. {
  25. textField = GetComponent<Text>();
  26. GesEventInput.OnGesDataUpdate += OnGesDataUpdate;
  27. }
  28. private void OnDestroy()
  29. {
  30. GesEventInput.OnGesDataUpdate -= OnGesDataUpdate;
  31. }
  32. void OnGesDataUpdate(float delta)
  33. {
  34. string text = "GesFPS: ";
  35. float interp = delta / (0.5f + delta);
  36. float currentFPS = 1.0f / delta;
  37. fps = Mathf.Lerp(fps, currentFPS, interp);
  38. text += Mathf.RoundToInt(fps);
  39. textField.text = text;
  40. // RKLog.Info("GesFPS:" + text);
  41. }
  42. }
  43. }