/// <summary> /// 初始化头顶UI条 /// </summary> private void InitHeadBar() { if (RoleHeadBarRoot.Instance == null) { return; } if (CurrRoleInfo == null) { return; } if (m_HeadBarPos == null) { return; } //克隆预设 m_HeadBar = ResourcesMgr.Instance.Load(ResourcesMgr.ResourceType.UIOther, "RoleHeadBar"); m_HeadBar.transform.parent = RoleHeadBarRoot.Instance.gameObject.transform; m_HeadBar.transform.localScale = Vector3.one; m_HeadBar.transform.localPosition = Vector3.zero; roleHeadBarView = m_HeadBar.GetComponent <RoleHeadBarView>(); //给预设赋值 roleHeadBarView.Init(m_HeadBarPos, CurrRoleInfo.RoleNickName, isShowHPBar: (CurrRoleType == RoleType.MainPlayer ? false : true)); }
/// <summary> /// 克隆头顶UI的prefab,然后给prefab赋值 /// </summary> private void InitRoleHeadUI() { if (UIRoleHeadItems.Instance != null && currentRoleInfo != null && modelHeadPoint != null) { //克隆部分 modelHeadUI = ResourcesManager.Instance.Load(ResourcesManager.ResourceType.UIOTHER, "RoleHeadUGUI"); modelHeadUI.transform.parent = UIRoleHeadItems.Instance.gameObject.transform; modelHeadUI.transform.localScale = Vector3.one; modelHeadUI.transform.localPosition = Vector3.zero; headBar = modelHeadUI.GetComponent <RoleHeadBarView>(); //赋值部分,最后一个参数使用特别的写法,等同于使用一个变量经过判断赋值后传参 headBar.Init(modelHeadPoint, currentRoleInfo.RoleNickName, isShowHP: (currentRoleType == RoleType.PLAYER?false:true)); } }
/// <summary> 初始化头顶UI条 </summary> private void InitHeadBar() { if (RoleHeadBarRoot.Instance == null) { return; } if (CurrRoleInfo == null) { return; } //克隆预设 m_HeadBar = ResourcesManager.Instance.Load(ResourcesManager.ResourceType.UIOther, "RoleHeadBar"); m_HeadBar.transform.SetParent(RoleHeadBarRoot.Instance.gameObject.transform); m_HeadBar.transform.localScale = Vector3.one; m_RoleHeadBarView = m_HeadBar.GetComponent <RoleHeadBarView>(); //给预设赋值 m_RoleHeadBarView.Init(m_HeadBarTrans, CurrRoleInfo.NickName, isShowHPBar: (CurrRoleType == RoleType.MainPlayer ? false : true), sliderValue: CurrRoleInfo.CurrHP / (float)CurrRoleInfo.MaxHP); }