public void ShowUI(string uiName, params object[] allParams) { Jyx2_UIBase uibase; if (m_uiDic.ContainsKey(uiName)) { uibase = m_uiDic[uiName]; if (uibase.IsOnly)//如果这个层唯一存在 那么先关闭其他 { PopAllUI(uibase.Layer); } PushUI(uibase); uibase.Show(allParams); } else { if (_loadingUIParams.ContainsKey(uiName)) //如果正在加载这个UI 那么覆盖参数 { _loadingUIParams[uiName] = allParams; return; } _loadingUIParams[uiName] = allParams; string uiPath = string.Format(GameConst.UI_PREFAB_PATH, uiName); Jyx2ResourceHelper.SpawnPrefab(uiPath, OnUILoaded); } }
/// <summary> /// 挂载武器 /// </summary> /// <param name="weaponStr"></param> void DOMountWeapon(string weaponStr) { if (!IsInBattle) { return; } UnMountCurrentWeapon(); if (string.IsNullOrEmpty(weaponStr)) { return; } var paras = weaponStr.Split('|'); int index = 0; string prefab = paras[index++]; string bindObj = paras[index++]; float scale = float.Parse(paras[index++]); Vector3 pos = UnityTools.StringToVector3(paras[index++], ','); Vector3 rot = UnityTools.StringToVector3(paras[index++], ','); Jyx2ResourceHelper.SpawnPrefab(prefab, weaponObj => { m_CurrentWeapon = weaponObj; var parent = UnityTools.DeepFindChild(transform, bindObj); if (parent != null) { weaponObj.transform.SetParent(parent.transform); weaponObj.transform.localScale = new Vector3(scale, scale, scale); weaponObj.transform.localPosition = pos; weaponObj.transform.localRotation = Quaternion.Euler(rot); } else { Debug.LogError("武器挂载到了不存在的节点:" + bindObj); } }); }
public void OnChange(Action callback = null) { if (Application.isPlaying) { //销毁所有的孩子 HSUnityTools.DestroyChildren(transform); } else { int childCount = transform.childCount; for (int i = childCount - 1; i >= 0; --i) { var go = transform.GetChild(i).gameObject; go.SetActive(false); DestroyImmediate(go); } transform.DetachChildren(); //适应老的代码。。清理残留的合并Mesh var oldMesh = GetComponent <SkinnedMeshRenderer>(); if (oldMesh != null) { DestroyImmediate(oldMesh); } } string path = ""; if (m_ModelId.StartsWith("@")) { path = m_ModelId.TrimStart('@'); } else { var roleModelSet = RoleModelSetObj.GetByName(m_ModelId); if (roleModelSet == null) { Debug.LogError("找不到模型:" + m_ModelId); return; } var modelPath = roleModelSet.FilePath; path = modelPath.TrimStart('@') + ".prefab"; } Jyx2ResourceHelper.SpawnPrefab(path, (res) => { if (res == null) { Debug.LogError("找不到模型资源:" + path); return; } if (res != null) { res.transform.SetParent(gameObject.transform, false); res.transform.localPosition = Vector3.zero; } var animator = GetComponent <Animator>(); if (animator != null) { animator.enabled = false; } if (callback != null) { callback(); } }); }