| | |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | using vnxbqy.UI; |
| | | |
| | | public class AvatarCell : MonoBehaviour |
| | |
|
| | | namespace vnxbqy.UI
|
| | | {
|
| | | public float scale = 1.0f;
|
| | |
|
| | | ImageEx m_BgImage;
|
| | | public ImageEx bgImage
|
| | | public class AvatarCell : MonoBehaviour
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_BgImage == null)
|
| | | {
|
| | | LoadPrefab();
|
| | | m_BgImage = this.GetComponent<ImageEx>("AvatarCell/Img_BG");
|
| | | }
|
| | | return m_BgImage;
|
| | | }
|
| | | }
|
| | | public float scale = 1.0f;
|
| | |
|
| | | ImageEx m_AvatarImage;
|
| | | public ImageEx avatarImage
|
| | | {
|
| | | get
|
| | | ImageEx m_BgImage;
|
| | | public ImageEx bgImage
|
| | | {
|
| | | if (m_AvatarImage == null)
|
| | | get
|
| | | {
|
| | | LoadPrefab();
|
| | | m_AvatarImage = this.GetComponent<ImageEx>("AvatarCell/Img_Avatar");
|
| | | }
|
| | | return m_AvatarImage;
|
| | | }
|
| | | } |
| | | |
| | | ImageEx m_AvatarFrameImage;
|
| | | public ImageEx avatarFrameImage
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_AvatarFrameImage == null)
|
| | | {
|
| | | LoadPrefab();
|
| | | m_AvatarFrameImage = this.GetComponent<ImageEx>("AvatarCell/Img_AvatarFrame");
|
| | | }
|
| | | return m_AvatarFrameImage;
|
| | | }
|
| | | }
|
| | | |
| | | ButtonEx m_button;
|
| | | public ButtonEx button
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_button == null)
|
| | | {
|
| | | LoadPrefab();
|
| | | m_button = this.GetComponent<ButtonEx>("AvatarCell/Img_AvatarFrame");
|
| | | }
|
| | | return m_button;
|
| | | }
|
| | | }
|
| | |
|
| | | UIFrame m_AvatarUIFrame; |
| | | public UIFrame avatarUIFrame
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_AvatarUIFrame == null)
|
| | | {
|
| | | LoadPrefab();
|
| | | m_AvatarUIFrame = this.GetComponent<UIFrame>("AvatarCell/Img_Avatar");
|
| | | }
|
| | | return m_AvatarUIFrame;
|
| | | }
|
| | | } |
| | | |
| | | UIFrame m_AvatarFrameUIFrame; |
| | | public UIFrame avatarFrameUIFrame
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_AvatarFrameUIFrame == null)
|
| | | {
|
| | | LoadPrefab();
|
| | | m_AvatarFrameUIFrame = this.GetComponent<UIFrame>("AvatarCell/Img_AvatarFrame");
|
| | | }
|
| | | return m_AvatarFrameUIFrame;
|
| | | }
|
| | | } |
| | | |
| | | UIEffect m_AvatarUIEffect; |
| | | public UIEffect avatarUIEffect
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_AvatarUIEffect == null)
|
| | | {
|
| | | LoadPrefab();
|
| | | m_AvatarUIEffect = this.GetComponent<UIEffect>("AvatarCell/Img_Avatar");
|
| | | }
|
| | | return m_AvatarUIEffect;
|
| | | }
|
| | | }
|
| | |
|
| | | UIEffect m_AvatarFrameUIEffect; |
| | | public UIEffect avatarFrameUIEffect
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_AvatarFrameUIEffect == null)
|
| | | {
|
| | | LoadPrefab();
|
| | | m_AvatarFrameUIEffect = this.GetComponent<UIEffect>("AvatarCell/Img_AvatarFrame");
|
| | | }
|
| | | return m_AvatarFrameUIEffect;
|
| | | }
|
| | | }
|
| | |
|
| | | GameObject prefab;
|
| | | PhantasmPavilionModel model { get { return ModelCenter.Instance.GetModel<PhantasmPavilionModel>(); } }
|
| | |
|
| | | protected void LoadPrefab()
|
| | | {
|
| | | var tmp = transform.Find("AvatarCell");
|
| | |
|
| | | if (tmp != null)
|
| | | {
|
| | | prefab = tmp.gameObject;
|
| | | return;
|
| | | }
|
| | | if (prefab == null)
|
| | | {
|
| | | prefab = UIUtility.CreateWidget("AvatarCell", "AvatarCell");
|
| | |
|
| | | if (prefab != null)
|
| | | {
|
| | | prefab.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one);
|
| | | prefab.transform.SetAsFirstSibling();
|
| | |
|
| | | RectTransform prefabRect = prefab.GetComponent<RectTransform>();
|
| | | RectTransform parentRect = GetComponent<RectTransform>();
|
| | | if (prefabRect != null && parentRect != null)
|
| | | if (m_BgImage == null)
|
| | | {
|
| | | prefabRect.anchorMin = new Vector2(0.5f, 0.5f);
|
| | | prefabRect.anchorMax = new Vector2(0.5f, 0.5f);
|
| | | prefabRect.sizeDelta = new Vector2(parentRect.rect.width, parentRect.rect.height);
|
| | | prefabRect.localScale = new Vector3(scale, scale, scale);
|
| | | LoadPrefab();
|
| | | m_BgImage = this.GetComponent<ImageEx>("AvatarCell/Img_BG");
|
| | | }
|
| | | return m_BgImage;
|
| | | }
|
| | | }
|
| | |
|
| | | ImageEx m_AvatarImage;
|
| | | public ImageEx avatarImage
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_AvatarImage == null)
|
| | | {
|
| | | LoadPrefab();
|
| | | m_AvatarImage = this.GetComponent<ImageEx>("AvatarCell/Img_Avatar");
|
| | | }
|
| | | return m_AvatarImage;
|
| | | }
|
| | | }
|
| | |
|
| | | ImageEx m_AvatarFrameImage;
|
| | | public ImageEx avatarFrameImage
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_AvatarFrameImage == null)
|
| | | {
|
| | | LoadPrefab();
|
| | | m_AvatarFrameImage = this.GetComponent<ImageEx>("AvatarCell/Img_AvatarFrame");
|
| | | }
|
| | | return m_AvatarFrameImage;
|
| | | }
|
| | | }
|
| | |
|
| | | ButtonEx m_button;
|
| | | public ButtonEx button
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_button == null)
|
| | | {
|
| | | LoadPrefab();
|
| | | m_button = this.GetComponent<ButtonEx>("AvatarCell/Img_AvatarFrame");
|
| | | }
|
| | | return m_button;
|
| | | }
|
| | | }
|
| | |
|
| | | UIFrame m_AvatarUIFrame;
|
| | | public UIFrame avatarUIFrame
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_AvatarUIFrame == null)
|
| | | {
|
| | | LoadPrefab();
|
| | | m_AvatarUIFrame = this.GetComponent<UIFrame>("AvatarCell/Img_Avatar");
|
| | | }
|
| | | return m_AvatarUIFrame;
|
| | | }
|
| | | }
|
| | |
|
| | | UIFrame m_AvatarFrameUIFrame;
|
| | | public UIFrame avatarFrameUIFrame
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_AvatarFrameUIFrame == null)
|
| | | {
|
| | | LoadPrefab();
|
| | | m_AvatarFrameUIFrame = this.GetComponent<UIFrame>("AvatarCell/Img_AvatarFrame");
|
| | | }
|
| | | return m_AvatarFrameUIFrame;
|
| | | }
|
| | | }
|
| | |
|
| | | UIEffect m_AvatarUIEffect;
|
| | | public UIEffect avatarUIEffect
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_AvatarUIEffect == null)
|
| | | {
|
| | | LoadPrefab();
|
| | | m_AvatarUIEffect = this.GetComponent<UIEffect>("AvatarCell/Img_Avatar");
|
| | | }
|
| | | return m_AvatarUIEffect;
|
| | | }
|
| | | }
|
| | |
|
| | | UIEffect m_AvatarFrameUIEffect;
|
| | | public UIEffect avatarFrameUIEffect
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_AvatarFrameUIEffect == null)
|
| | | {
|
| | | LoadPrefab();
|
| | | m_AvatarFrameUIEffect = this.GetComponent<UIEffect>("AvatarCell/Img_AvatarFrame");
|
| | | }
|
| | | return m_AvatarFrameUIEffect;
|
| | | }
|
| | | }
|
| | |
|
| | | GameObject prefab;
|
| | | PhantasmPavilionModel model { get { return ModelCenter.Instance.GetModel<PhantasmPavilionModel>(); } }
|
| | |
|
| | | protected void LoadPrefab()
|
| | | {
|
| | | var tmp = transform.Find("AvatarCell");
|
| | |
|
| | | if (tmp != null)
|
| | | {
|
| | | prefab = tmp.gameObject;
|
| | | return;
|
| | | }
|
| | | if (prefab == null)
|
| | | {
|
| | | prefab = UIUtility.CreateWidget("AvatarCell", "AvatarCell");
|
| | |
|
| | | if (prefab != null)
|
| | | {
|
| | | prefab.transform.SetParentEx(this.transform, Vector3.zero, Quaternion.identity, Vector3.one);
|
| | | prefab.transform.SetAsFirstSibling();
|
| | |
|
| | | RectTransform prefabRect = prefab.GetComponent<RectTransform>();
|
| | | RectTransform parentRect = GetComponent<RectTransform>();
|
| | | if (prefabRect != null && parentRect != null)
|
| | | {
|
| | | prefabRect.anchorMin = new Vector2(0.5f, 0.5f);
|
| | | prefabRect.anchorMax = new Vector2(0.5f, 0.5f);
|
| | | prefabRect.sizeDelta = new Vector2(parentRect.rect.width, parentRect.rect.height);
|
| | | prefabRect.localScale = new Vector3(scale, scale, scale);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | public void InitUI(AvatarModel model)
|
| | | {
|
| | | if (model == null)
|
| | | return;
|
| | | string img = AvatarHelper.GetAvatarBgColorStr(model.avatarID);
|
| | | bgImage.SetSprite(img);
|
| | | InitUI(model.avatarID, model.avatarUIEffectID, model.avatarFrameID, model.avatarFrameUIEffectID);
|
| | | }
|
| | |
|
| | | private void InitUI(int avatarID, int avatarUIEffectID, int avatarFrameID, int avatarFrameUIEffectID)
|
| | | {
|
| | | InitAvatarUI(avatarID, avatarUIEffectID);
|
| | | InitAvatarFrameUI(avatarFrameID, avatarFrameUIEffectID);
|
| | | }
|
| | |
|
| | | private void InitAvatarUI(int avatarID, int avatarUIEffectID)
|
| | | {
|
| | | avatarUIEffect.Stop();
|
| | | if (!PlayerFaceConfig.Has(avatarID))
|
| | | return;
|
| | |
|
| | | PlayerFaceConfig config = PlayerFaceConfig.Get(avatarID);
|
| | | string imgStr = config.Image;
|
| | | if (UIFrameMgr.Inst.ContainsDynamicImage(imgStr))
|
| | | {
|
| | | avatarUIFrame.ResetFrame(imgStr);
|
| | |
|
| | | List<UnityEngine.Sprite> spriteList = UIFrameMgr.Inst.GetDynamicImage(imgStr);
|
| | | if (!spriteList.IsNullOrEmpty())
|
| | | {
|
| | | avatarImage.rectTransform.sizeDelta = new Vector2(spriteList[0].rect.width, spriteList[0].rect.height);
|
| | | }
|
| | |
|
| | | avatarUIFrame.enabled = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | avatarImage.SetSprite(imgStr);
|
| | | avatarImage.SetNativeSize();
|
| | | avatarUIFrame.enabled = false;
|
| | | }
|
| | |
|
| | | if (!EffectConfig.Has(avatarUIEffectID))
|
| | | return;
|
| | | avatarUIEffect.effect = avatarUIEffectID;
|
| | | avatarUIEffect.loop = true;
|
| | | avatarUIEffect.Play();
|
| | | }
|
| | |
|
| | | private void InitAvatarFrameUI(int avatarFrameID, int avatarFrameUIEffectID)
|
| | | {
|
| | | avatarFrameUIEffect.Stop();
|
| | | if (!PlayerFacePicConfig.Has(avatarFrameID))
|
| | | return;
|
| | |
|
| | | PlayerFacePicConfig config = PlayerFacePicConfig.Get(avatarFrameID);
|
| | | string imgStr = config.Image;
|
| | | if (UIFrameMgr.Inst.ContainsDynamicImage(imgStr))
|
| | | {
|
| | | avatarFrameUIFrame.ResetFrame(imgStr);
|
| | |
|
| | | List<UnityEngine.Sprite> spriteList = UIFrameMgr.Inst.GetDynamicImage(imgStr);
|
| | | if (!spriteList.IsNullOrEmpty())
|
| | | {
|
| | | avatarFrameImage.rectTransform.sizeDelta = new Vector2(spriteList[0].rect.width, spriteList[0].rect.height);
|
| | | }
|
| | |
|
| | | avatarFrameUIFrame.enabled = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | avatarFrameImage.SetSprite(imgStr);
|
| | | avatarFrameImage.SetNativeSize();
|
| | | avatarFrameUIFrame.enabled = false;
|
| | | }
|
| | |
|
| | | if (!EffectConfig.Has(avatarFrameUIEffectID))
|
| | | return;
|
| | | avatarUIEffect.effect = avatarFrameUIEffectID;
|
| | | avatarUIEffect.loop = true;
|
| | | avatarUIEffect.Play();
|
| | | }
|
| | | }
|
| | |
|
| | | public void InitUI(AvatarModel model)
|
| | | public class AvatarModel
|
| | | {
|
| | | if (model == null)
|
| | | return;
|
| | | string img = AvatarHelper.GetAvatarBgColorStr(model.avatarID);
|
| | | bgImage.SetSprite(img);
|
| | | InitUI(model.avatarID, model.avatarUIEffectID, model.avatarFrameID, model.avatarFrameUIEffectID);
|
| | | } |
| | | |
| | | private void InitUI(int avatarID, int avatarUIEffectID, int avatarFrameID, int avatarFrameUIEffectID)
|
| | | {
|
| | | InitAvatarUI(avatarID, avatarUIEffectID);
|
| | | InitAvatarFrameUI(avatarFrameID, avatarFrameUIEffectID);
|
| | | } |
| | | |
| | | private void InitAvatarUI(int avatarID, int avatarUIEffectID)
|
| | | {
|
| | | avatarUIEffect.Stop();
|
| | | if (!PlayerFaceConfig.Has(avatarID))
|
| | | return;
|
| | | public int avatarID { get; private set; }
|
| | | public int avatarFrameID { get; private set; }
|
| | | public int avatarUIEffectID { get; private set; }
|
| | | public int avatarFrameUIEffectID { get; private set; }
|
| | | public float scale { get; private set; }
|
| | |
|
| | | PlayerFaceConfig config = PlayerFaceConfig.Get(avatarID);
|
| | | string imgStr = config.Image;
|
| | | if (UIFrameMgr.Inst.ContainsDynamicImage(imgStr))
|
| | | public AvatarModel(int avatarID, int avatarFrameID, int avatarUIEffectID = 0, int avatarFrameUIEffectID = 0)
|
| | | {
|
| | | avatarUIFrame.ResetFrame(imgStr);
|
| | |
|
| | | List<UnityEngine.Sprite> spriteList = UIFrameMgr.Inst.GetDynamicImage(imgStr);
|
| | | if (!spriteList.IsNullOrEmpty())
|
| | | {
|
| | | avatarImage.rectTransform.sizeDelta = new Vector2(spriteList[0].rect.width, spriteList[0].rect.height);
|
| | | }
|
| | |
|
| | | avatarUIFrame.enabled = true;
|
| | | this.avatarID = avatarID;
|
| | | this.avatarFrameID = avatarFrameID;
|
| | | this.avatarUIEffectID = avatarUIEffectID;
|
| | | this.avatarFrameUIEffectID = avatarFrameUIEffectID;
|
| | | }
|
| | | else
|
| | | {
|
| | | avatarImage.SetSprite(imgStr);
|
| | | avatarImage.SetNativeSize();
|
| | | avatarUIFrame.enabled = false;
|
| | | }
|
| | |
|
| | | if (!EffectConfig.Has(avatarUIEffectID))
|
| | | return;
|
| | | avatarUIEffect.effect = avatarUIEffectID;
|
| | | avatarUIEffect.loop = true;
|
| | | avatarUIEffect.Play();
|
| | | } |
| | | |
| | | private void InitAvatarFrameUI(int avatarFrameID, int avatarFrameUIEffectID)
|
| | | {
|
| | | avatarFrameUIEffect.Stop();
|
| | | if (!PlayerFacePicConfig.Has(avatarFrameID))
|
| | | return;
|
| | |
|
| | | PlayerFacePicConfig config = PlayerFacePicConfig.Get(avatarFrameID);
|
| | | string imgStr = config.Image;
|
| | | if (UIFrameMgr.Inst.ContainsDynamicImage(imgStr))
|
| | | {
|
| | | avatarFrameUIFrame.ResetFrame(imgStr);
|
| | |
|
| | | List<UnityEngine.Sprite> spriteList = UIFrameMgr.Inst.GetDynamicImage(imgStr);
|
| | | if (!spriteList.IsNullOrEmpty())
|
| | | {
|
| | | avatarFrameImage.rectTransform.sizeDelta = new Vector2(spriteList[0].rect.width, spriteList[0].rect.height);
|
| | | }
|
| | |
|
| | | avatarFrameUIFrame.enabled = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | avatarFrameImage.SetSprite(imgStr);
|
| | | avatarFrameImage.SetNativeSize();
|
| | | avatarFrameUIFrame.enabled = false;
|
| | | }
|
| | |
|
| | | if (!EffectConfig.Has(avatarFrameUIEffectID))
|
| | | return;
|
| | | avatarUIEffect.effect = avatarFrameUIEffectID;
|
| | | avatarUIEffect.loop = true;
|
| | | avatarUIEffect.Play();
|
| | | } |
| | | }
|
| | |
|
| | | public class AvatarModel
|
| | | {
|
| | | public int avatarID { get; private set; }
|
| | | public int avatarFrameID { get; private set; }
|
| | | public int avatarUIEffectID { get; private set; }
|
| | | public int avatarFrameUIEffectID { get; private set; }
|
| | | public float scale { get; private set; }
|
| | |
|
| | | public AvatarModel(int avatarID, int avatarFrameID, int avatarUIEffectID = 0, int avatarFrameUIEffectID = 0)
|
| | | {
|
| | | this.avatarID = avatarID;
|
| | | this.avatarFrameID = avatarFrameID;
|
| | | this.avatarUIEffectID = avatarUIEffectID;
|
| | | this.avatarFrameUIEffectID = avatarFrameUIEffectID;
|
| | | }
|
| | | } |