12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class AvatarToggle : MonoBehaviour
- {
- public Toggle avatartoggle;
- public RawImage image;
- private Texture tex;
- private string avatar;
- private void Start()
- {
- avatartoggle.onValueChanged.AddListener(ValueChange);
- ToggleGroup toggleGroup = transform.parent.GetComponent<ToggleGroup>();
- if (toggleGroup)
- {
- avatartoggle.group = toggleGroup;
- }
- if (!string.IsNullOrEmpty(this.avatar))
- {
- if (UserInfo.avatar == this.avatar)
- {
- avatartoggle.isOn = true;
- }
- }
- }
- private void ValueChange(bool isOn)
- {
- if (isOn)
- {
- Debug.Log("PP");
- if (tex != null)
- {
- UserSystem.swithAvatarAction?.Invoke(tex);
- UserInfo.avatar = this.avatar;
- UserInfo.textIcon = this.tex;
- }
- }
- }
- public void Init(Texture tex)
- {
- if (tex != null)
- {
- image.texture = tex;
- this.tex = tex;
- }
- }
- public void Init(string avatar)
- {
- if (!string.IsNullOrEmpty(avatar))
- {
- this.avatar = avatar;
- }
- }
- }
|