/// <summary> /// 设置头像 avatar 到目标对象 /// 目标对象应当是一个 UI 元素 /// 注意:如果头像加载失败并且未指定性别,头像将显示空白 /// </summary> /// <param name="o">要显示头像的目标对象</param> /// <param name="avatar">头像</param> /// <param name="useNativeSize">是否使用原始头像大小</param> /// <param name="gender">性别 可选,主要用于头像加载失败时确定男性还是女性默认头像</param> public static void SetAvatar(GameObject o, string avatar, bool useNativeSize = false, int gender = -1) { if (!o) { return; } if (string.IsNullOrEmpty(avatar)) { var dt = gender < 0 ? null : gender == 0 ? defaultFemale : defaultMale; AtlasHelper.SetAvatar(o, dt); return; } var cached = m_cachedAvatars.Get(avatar); if (cached) { UIDynamicImage.LoadImageCreated(o, avatar, cached, useNativeSize); return; } var fp = LocalFilePath.AVATAR + "/" + avatar + ".avatar"; cached = Util.LoadImage(fp); if (cached) { m_cachedAvatars.Set(avatar, cached); UIDynamicImage.LoadImageCreated(o, avatar, cached, useNativeSize); return; } var url = URLs.avatar + avatar + ".png"; UIDynamicImage.LoadImage(o, url, (di, t) => { if (!t) { if (di && gender > -1) { AtlasHelper.SetAvatar(di.gameObject, gender == 0 ? defaultFemale : defaultMale); } return; } m_cachedAvatars.Set(avatar, t); var data = UIDynamicImage.RemoveCache(url, false); if (data != null) { var hash = data.GetMD5(); if ((fp = Util.SaveFile(fp, data)) != null) { HashListFile.ReplaceHashListFile(hashFileName, avatar, hash); } } }, useNativeSize); }
private void RefreshInfo() { AssertInit(); Util.SetText(npcName, _source.NpcInfo.name); Util.SetText(endurance, $"{_source.NpcInfo.bodyPower}/{_source.NpcInfo.maxBodyPower}"); Util.SetText(goodFeelingValue, $"+{_source.addPoint}"); AtlasHelper.SetAvatar(icon, _source.NpcInfo.icon); }
/// <summary> /// 设置玩家自己的橘色头像到目标对象 /// 目标对象应当是一个 UI 元素 /// </summary> /// <param name="o">要显示头像的目标对象</param> /// <param name="useNativeSize">是否使用原始头像大小</param> public static void SetPlayerAvatar(GameObject o, bool useNativeSize = false) { if (!o) { return; } var a = Module_Player.instance.classAvatar ?? string.Empty; AtlasHelper.SetAvatar(o, a, null, useNativeSize); }
private void SetItemData(Transform node, Module_Npc.NpcMessage data) { if (data == null) { return; } PropItemInfo pinfo = new PropItemInfo(); pinfo.ID = data.npcId; BaseRestrain.SetRestrainData(node.gameObject, pinfo, 0, 0); node.name = data.npcId.ToString(); Text textName = node.Find("Text").GetComponent <Text>(); Image imgRelationShip = node.Find("dateLevelBg/fill").GetComponent <Image>(); Text textTel = node.Find("phoneNumberBg/phoneNumber").GetComponent <Text>(); Text textDesc = node.Find("intro").GetComponent <Text>(); Text textLabel = node.Find("labelBg/label").GetComponent <Text>(); Image icon = node.Find("avatar_back/mask/head_icon").GetComponent <Image>(); Image pledge = node.Find("pledgeState").GetComponent <Image>();//誓约状态 Text textFetterStage = node.Find("goodfeelingLevel").GetComponent <Text>(); Toggle toggle = node.GetComponent <Toggle>(); toggle.group = m_togGroup; //名字 Util.SetText(textName, data.name); //设置关系 SetRelationShip(imgRelationShip, data); //设置Npc标签 Util.SetText(textLabel, data.npcInfo.labelMark); //电话 SetTel(textTel, data); //描述 SetDesc(textDesc, data); //头像 AtlasHelper.SetAvatar(icon, data.icon); //AtlasHelper.SetNpcDateInfo(icon, data.npcInfo.datingAvatar); //誓约状态 pledge.SafeSetActive(data.fetterStage == data.maxFetterStage); //羁绊等级名称 Util.SetText(textFetterStage, data.curStageName); int togIndex = toggle.transform.GetSiblingIndex(); if (m_itemDataDic.ContainsKey(togIndex)) { m_itemDataDic.Remove(togIndex); } m_itemDataDic.Add(togIndex, data); }
private void CreateNpc() { _npcDict.Clear(); for (var i = NpcTypeID.None + 1; i < NpcTypeID.StoryNpc; i++) { var t = _root.AddNewChild(_templete); t.SafeSetActive(true); t.name = i.ToString(); var npcInfo = ConfigManager.Get <NpcInfo>((int)i); AtlasHelper.SetAvatar(t.GetComponent <Transform>("head_icon"), npcInfo?.icon); var npc = moduleNpc.GetTargetNpc(i); t.GetComponent <Transform>("avatar_topbg_img").SafeSetActive(npc.maxFetterLv == npc.fetterLv); _npcDict.Add(i, t.GetComponent <Toggle>()); } }
/// <summary> /// 设置指定角色职业头像到目标对象 /// 目标对象应当是一个 UI 元素 /// </summary> /// <param name="o">要显示头像的目标对象</param> /// <param name="c">要显示头像的角色</param> /// <param name="useNativeSize">是否使用原始头像大小</param> public static void SetClassAvatar(GameObject o, Creature c, bool useNativeSize = false) { if (!o) { return; } if (c && (c.isMonster || c.avatar.StartsWith(npcAvatarPrefix))) { AtlasHelper.SetAvatar(o, c.avatar); return; } SetClassAvatar(o, c ? c.roleProto : 0, useNativeSize, c ? c.gender : -1); }
public override bool Initialize(params object[] p) { if (!base.Initialize(p)) { if (_npcId == (NpcTypeID)p[0]) { return(false); } } else { _excuteButton?.onClick.AddListener(OnExcuteClick); } _npcId = (NpcTypeID)p[0]; var npcInfo = moduleNpc.GetTargetNpc(_npcId); if (_icon) { AtlasHelper.SetAvatar(_icon.gameObject, npcInfo.icon); } Util.SetText(_npcName, npcInfo.name); if (npcInfo.fetterLv == npcInfo.maxFetterLv) { Util.SetText(_exp, ConfigText.GetDefalutString(TextForMatType.NpcAwakeUI, 9)); if (_slider) { _slider.fillAmount = 1; } } else { Util.SetText(_exp, $"{npcInfo.nowFetterValue}/{npcInfo.toFetterValue}"); Util.SetText(_level, npcInfo.fetterLv.ToString()); if (_slider) { _slider.fillAmount = npcInfo.fetterProgress; } } Util.SetText(_level, npcInfo.fetterLv.ToString()); RefreshAttribute(); RefreshExcuteButton(); _lock.SafeSetActive(!npcInfo.isUnlockEngagement); return(true); }
/// <summary> /// 设置职业头像到目标对象 /// 目标对象应当是一个 UI 元素 /// 注意:如果头像加载失败并且未指定性别,头像将显示空白 /// </summary> /// <param name="o">要显示头像的目标对象</param> /// <param name="_class">职业</param> /// <param name="useNativeSize">是否使用原始头像大小</param> /// <param name="gender">性别 可选,主要用于头像加载失败时确定男性还是女性默认头像</param> public static void SetClassAvatar(GameObject o, int _class, bool useNativeSize = false, int gender = -1) { if (!o) { return; } if (_class <= 0) { var dt = gender < 0 ? null : gender == 0 ? defaultFemale : defaultMale; AtlasHelper.SetAvatar(o, dt); return; } AtlasHelper.SetAvatar(o, Creature.GetClassAvatarName(_class), null, useNativeSize); }
/// <summary> /// 设置指定角色头像到目标对象 /// 目标对象应当是一个 UI 元素 /// </summary> /// <param name="o">要显示头像的目标对象</param> /// <param name="c">要显示头像的角色</param> /// <param name="useNativeSize">是否使用原始头像大小</param> public static void SetAvatar(GameObject o, Creature c, bool useNativeSize = false) { if (!o) { return; } if (c && (c.isMonster || c.avatar.StartsWith(npcAvatarPrefix))) { AtlasHelper.SetAvatar(o, c.avatar); return; } var a = c ? c.avatar : null; var g = c ? c.gender : -1; SetAvatar(o, a, useNativeSize, g); }
public override bool Initialize(params object[] p) { var watcher = TimeWatcher.Watch("star panel init"); if (!base.Initialize(p)) { return(false); } _npcId = (NpcTypeID)p[0]; _npc = moduleNpc.GetTargetNpc(_npcId); AtlasHelper.SetAvatar(_headIcon, _npc?.icon); watcher.See("111"); excuteButton?.onClick.AddListener(OnExcute); RefreshUI(); watcher.See("222"); return(true); }
private void Refresh() { Module_NPCDatingSettlement.SettlementData data = moduleNPCDatingSettlement.datingSettlement; if (data == null) { return; } AtlasHelper.SetNpcDateInfo(m_imgDatingLevel, data.lvIconName); Util.SetText(m_textMoodValue, Util.Format("×{0}", data.moodValue.ToString())); Module_Npc.NpcMessage npcInfo = moduleNpc.GetTargetNpc((NpcTypeID)moduleNPCDating.curDatingNpc.npcId); if (npcInfo != null) { AtlasHelper.SetAvatar(m_npcIcon, npcInfo.icon); Util.SetText(m_textNpcName, npcInfo.name); RefreshLastFetter(npcInfo); } string preStr = data.addGoodFeelValue == 0 ? "" : "+"; Util.SetText(m_textAddGoodFeelValue, preStr + data.addGoodFeelValue.ToString()); //刷新事件列表 List <string> sourcedataList = new List <string>(); if (data.finishedEventIds != null) { for (int i = 0; i < data.finishedEventIds.Length; i++) { sourcedataList.Add(Util.GetString(data.finishedEventIds[i])); } sourcedataList.Distinct();//去除相同元素的值 } m_dataSource.SetItems(sourcedataList); CreateNpcModel(npcInfo.npcId); //显示约会完成标记 m_tfDatingFinishedMark.SafeSetActive(true); }