AvatarToggle.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using rtc;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. public class AvatarToggle : MonoBehaviour
  8. {
  9. public Toggle avatartoggle;
  10. public RawImage image;
  11. private Texture tex;
  12. private string avatar;
  13. private void Start()
  14. {
  15. avatartoggle.onValueChanged.AddListener(ValueChange);
  16. ToggleGroup toggleGroup = transform.parent.GetComponent<ToggleGroup>();
  17. if (toggleGroup)
  18. {
  19. avatartoggle.group = toggleGroup;
  20. }
  21. if (!string.IsNullOrEmpty(this.avatar))
  22. {
  23. if (UserInfo.avatar == this.avatar)
  24. {
  25. avatartoggle.isOn = true;
  26. }
  27. }
  28. }
  29. private void ValueChange(bool isOn)
  30. {
  31. if (isOn)
  32. {
  33. Debug.Log("PP");
  34. if (tex != null)
  35. {
  36. UserSystem.swithAvatarAction?.Invoke(tex);
  37. UserInfo.avatar = this.avatar;
  38. UserInfo.textIcon = this.tex;
  39. }
  40. }
  41. }
  42. public void Init(Texture tex)
  43. {
  44. if (tex != null)
  45. {
  46. image.texture = tex;
  47. this.tex = tex;
  48. }
  49. }
  50. public void Init(string avatar)
  51. {
  52. if (!string.IsNullOrEmpty(avatar))
  53. {
  54. this.avatar = avatar;
  55. }
  56. }
  57. }