/// <summary> /// 创建UI /// </summary> /// <typeparam name="T"></typeparam> /// <param name="uiName"></param> /// <returns></returns> public T CreateUI <T>(string uiName, int layer = -1) where T : BaseUIComponent { //GameObject uiModel = LoadAssetUtil.SyncLoadAsset<GameObject>("ui/ui", uiName); BaseUIComponent uiModel = LoadResourcesUtil.SyncLoadData <BaseUIComponent>($"UI/{uiName}"); if (uiModel) { Transform tfContainer = GetUITypeContainer(UITypeEnum.UIBase); GameObject objUIComponent = Instantiate(tfContainer.gameObject, uiModel.gameObject); objUIComponent.SetActive(false); objUIComponent.name = objUIComponent.name.Replace("(Clone)", ""); if (layer >= 0) { //设置层级 objUIComponent.transform.SetSiblingIndex(layer); } T uiComponent = objUIComponent.GetComponent <T>(); uiList.Add(uiComponent); return(uiComponent); } else { LogUtil.LogError("没有找到指定UI:" + "UI/" + uiName); return(null); } }
/// <summary> /// 通过UI开启UI并关闭其他UI /// </summary> /// <param name="uiName"></param> public void OpenUIAndCloseOther(BaseUIComponent uiComponent, Action <BaseUIComponent> actionBeforeOpen = null, int layer = -1) { if (manager.uiList == null || uiComponent == null) { return; } for (int i = 0; i < manager.uiList.Count; i++) { BaseUIComponent itemUI = manager.uiList[i]; if (!itemUI == uiComponent) { itemUI.CloseUI(); } } for (int i = 0; i < manager.uiList.Count; i++) { BaseUIComponent itemUI = manager.uiList[i]; if (itemUI == uiComponent) { //设置层级 if (layer >= 0) { itemUI.transform.SetSiblingIndex(layer); } actionBeforeOpen?.Invoke(itemUI); itemUI.OpenUI(); } } }
/// <summary> /// 通过UI的名字开启UI /// </summary> /// <param name="uiName"></param> public T OpenUI <T>(string uiName, Action <T> actionBeforeOpen = null, int layer = -1) where T : BaseUIComponent { if (uiName.IsNull()) { return(null); } for (int i = 0; i < manager.uiList.Count; i++) { BaseUIComponent itemUI = manager.uiList[i]; if (itemUI.name.Equals(uiName)) { //设置层级 if (layer >= 0) { itemUI.transform.SetSiblingIndex(layer); } actionBeforeOpen?.Invoke(itemUI as T); itemUI.OpenUI(); return(itemUI as T); } } T uiComponent = manager.CreateUI <T>(uiName, layer); if (uiComponent) { actionBeforeOpen?.Invoke(uiComponent as T); uiComponent.OpenUI(); return(uiComponent); } return(null); }
/// <summary> /// 通过UI的名字开启UI /// </summary> /// <param name="uiName"></param> public BaseUIComponent OpenUIByName(string uiName) { BaseUIComponent uiComponent = null; if (uiList == null || CheckUtil.StringIsNull(uiName)) { return(uiComponent); } bool hasData = false; for (int i = 0; i < uiList.Count; i++) { BaseUIComponent itemUI = uiList[i]; if (itemUI.name.Contains(uiName)) { itemUI.OpenUI(); hasData = true; } } if (!hasData) { BaseUIComponent uiModel = LoadResourcesUtil.SyncLoadData <BaseUIComponent>("UI/" + uiName); if (uiModel) { GameObject objUIComponent = Instantiate(objUIContainer, uiModel.gameObject); uiComponent = objUIComponent.GetComponent <BaseUIComponent>(); uiList.Add(uiComponent); } else { LogUtil.LogError("没有找到指定UI:" + "Resources/UI/" + uiName); } } return(uiComponent); }
/// <summary> /// 根据UI的名字获取UI /// </summary> /// <param name="uiName"></param> /// <returns></returns> public T GetUI <T>(string uiName, int layer = -1) where T : BaseUIComponent { if (manager.uiList == null || uiName.IsNull()) { return(null); } for (int i = 0; i < manager.uiList.Count; i++) { BaseUIComponent itemUI = manager.uiList[i]; if (itemUI.name.Equals(uiName)) { //设置层级 if (layer >= 0) { itemUI.transform.SetSiblingIndex(layer); } return(itemUI as T); } } T uiComponent = manager.CreateUI <T>(uiName, layer); if (uiComponent) { return(uiComponent as T); } return(null); }
public override void InteractiveDetection(CharacterInteractiveCpt characterInt) { //如果当前页面不是即将要打开的页面 并且当前页面是主界面 if (Input.GetButtonDown(InputInfo.Interactive_E)) { BaseUIComponent baseUIComponent = UIHandler.Instance.manager.GetUI <BaseUIComponent>(uiType); BaseUIComponent currentUIComponent = UIHandler.Instance.manager.GetOpenUI(); if (baseUIComponent != null) { if (currentUIComponent == baseUIComponent) { } else { baseUIComponent = UIHandler.Instance.manager.OpenUIAndCloseOther <BaseUIComponent>(uiType); if (!CheckUtil.StringIsNull(remarkData)) { baseUIComponent.SetRemarkData(remarkData); } } } else { baseUIComponent = UIHandler.Instance.manager.OpenUIAndCloseOther <BaseUIComponent>(uiType); if (!CheckUtil.StringIsNull(remarkData)) { baseUIComponent.SetRemarkData(remarkData); } } } }
/// <summary> /// 点击-开始合成 /// </summary> public void OnClickForStartSynthesis() { //当前选中的合成道具 ItemsSynthesisBean itemsSynthesis = listSynthesisData[indexSelect]; //检测当前道具是否能合成 bool canSynthesis = itemsSynthesis.CheckSynthesis(); if (!canSynthesis) { //素材不足 无法合成 UIHandler.Instance.ToastHint <ToastView>(TextHandler.Instance.GetTextById(30002)); return; } //首先消耗素材 BaseUIComponent currentUI = UIHandler.Instance.GetOpenUI(); //获取素材 List <ItemsSynthesisMaterialsBean> listMaterials = itemsSynthesis.GetSynthesisMaterials(); UserDataBean userData = GameDataHandler.Instance.manager.GetUserData(); //扣除素材 for (int i = 0; i < listMaterials.Count; i++) { ItemsSynthesisMaterialsBean itemMaterials = listMaterials[i]; for (int f = 0; f < itemMaterials.itemIds.Length; f++) { //只要扣除其中一项素材就行 long itemMaterialId = itemMaterials.itemIds[f]; if (userData.HasEnoughItem(itemMaterialId, itemMaterials.itemNumber)) { userData.RemoveItem(itemMaterialId, itemMaterials.itemNumber); break; } else { continue; } } } //添加道具 itemsSynthesis.GetSynthesisResult(out long itemsId, out int itemNum); int moreNum = userData.AddItems(itemsId, itemNum, null); //如果还有多余的道具 则丢出来 if (moreNum > 0) { Player player = GameHandler.Instance.manager.player; ItemsHandler.Instance.CreateItemCptDrop(itemsId, moreNum, null, player.transform.position + Vector3.up, ItemDropStateEnum.DropNoPick); } UIViewBackpackList backpackUI = currentUI.GetComponentInChildren <UIViewBackpackList>(); backpackUI.RefreshUI(); UIViewShortcuts shortcutsUI = currentUI.GetComponentInChildren <UIViewShortcuts>(); shortcutsUI.RefreshUI(); RefreshUI(); }
/// <summary> /// 关闭所有UI /// </summary> public void CloseAllUI() { for (int i = 0; i < manager.uiList.Count; i++) { BaseUIComponent itemUI = manager.uiList[i]; if (itemUI.gameObject.activeSelf) { itemUI.CloseUI(); } } }
/// <summary> /// 获取打开的UI /// </summary> /// <returns></returns> public BaseUIComponent GetOpenUI() { for (int i = 0; i < uiList.Count; i++) { BaseUIComponent itemUI = uiList[i]; if (itemUI.gameObject.activeSelf) { return(itemUI); } } return(null); }
/// <summary> /// 刷新UI /// </summary> public void RefreshAllUI() { if (manager.uiList == null) { return; } for (int i = 0; i < manager.uiList.Count; i++) { BaseUIComponent itemUI = manager.uiList[i]; itemUI.RefreshUI(); } }
/// <summary> /// 获取打开UI的名字 /// </summary> /// <returns></returns> public string GetOpenUIName() { for (int i = 0; i < manager.uiList.Count; i++) { BaseUIComponent itemUI = manager.uiList[i]; if (itemUI.gameObject.activeSelf) { return(itemUI.name); } } return(null); }
/// <summary> /// 视窗改变 /// </summary> private static void OnHierarchyChanged() { if (!EditorUtil.CheckIsPrefabMode(out var prefabStage)) { return; } dicSelectObj.Clear(); baseUIComponent = null; baseUIView = null; GameObject root = prefabStage.prefabContentsRoot; baseUIComponent = root.GetComponent <BaseUIComponent>(); baseUIView = root.GetComponent <BaseUIView>(); if (baseUIComponent == null && baseUIView == null) { return; } //设置初始化数据 Dictionary <string, Type> dicData = null; if (baseUIComponent != null) { dicData = ReflexUtil.GetAllNameAndType(baseUIComponent); } if (baseUIView != null) { dicData = ReflexUtil.GetAllNameAndType(baseUIView); } foreach (var itemData in dicData) { string itemKey = itemData.Key; Type itemValue = itemData.Value; if (itemKey.Contains("ui_")) { string componentName = itemKey.Replace("ui_", ""); if (itemValue != null) { Component[] listRootComponent = root.GetComponentsInChildren(itemValue); foreach (Component itemRootComponent in listRootComponent) { if (itemRootComponent.name.Equals(componentName)) { dicSelectObj.Add(componentName, itemRootComponent); } } } } } return; }
/// <summary> /// 初始化所有UI /// </summary> public void InitListUI() { uiList = new List <BaseUIComponent>(); for (int i = 0; i < transform.childCount; i++) { Transform tfChild = transform.GetChild(i); BaseUIComponent childUI = tfChild.GetComponent <BaseUIComponent>(); if (childUI) { childUI.uiManager = this; uiList.Add(childUI); } } }
/// <summary> /// 到达卵子 /// </summary> public void ArriveEgg(MiniGameBirthSpermBean spermData) { //获取家族数据 GameDataBean gameData = GameDataHandler.Instance.manager.GetGameData(); FamilyDataBean familyData = gameData.GetFamilyData(); //增加怀孕进度 familyData.addBirthPro(miniGameData.addBirthPro); DestroySperm(spermData); //刷新UI BaseUIComponent ui = UIHandler.Instance.manager.GetOpenUI(); ui.RefreshUI(); }
/// <summary> /// 根据名字刷新UI /// </summary> /// <param name="uiName"></param> public void RefreshUIByName(string uiName) { if (uiList == null || CheckUtil.StringIsNull(uiName)) { return; } for (int i = 0; i < uiList.Count; i++) { BaseUIComponent itemUI = uiList[i]; if (itemUI.name.Equals(uiName)) { itemUI.RefreshUI(); } } }
/// <summary> /// 根据UI的名字获取UI /// </summary> /// <param name="uiName"></param> /// <returns></returns> public T GetUIByName <T>(string uiName) where T : BaseUIComponent { if (uiList == null || CheckUtil.StringIsNull(uiName)) { return(null); } for (int i = 0; i < uiList.Count; i++) { BaseUIComponent itemUI = uiList[i]; if (itemUI.name.Contains(uiName)) { return(itemUI as T); } } return(null); }
/// <summary> /// 获取打开的UI /// </summary> /// <returns></returns> public BaseUIComponent GetOpenUI(int layer = -1) { for (int i = 0; i < manager.uiList.Count; i++) { BaseUIComponent itemUI = manager.uiList[i]; if (itemUI.gameObject.activeSelf) { //设置层级 if (layer >= 0) { itemUI.transform.SetSiblingIndex(layer); } return(itemUI); } } return(null); }
/// <summary> /// 根据UI的名字获取UI列表 /// </summary> /// <param name="uiName"></param> /// <returns></returns> public List <BaseUIComponent> GetUIList(string uiName) { if (manager.uiList == null || uiName.IsNull()) { return(null); } List <BaseUIComponent> tempuiList = new List <BaseUIComponent>(); for (int i = 0; i < manager.uiList.Count; i++) { BaseUIComponent itemUI = manager.uiList[i]; if (itemUI.name.Equals(uiName)) { tempuiList.Add(itemUI); } } return(tempuiList); }
/// <summary> /// 根据UI的名字获取UI列表 /// </summary> /// <param name="uiName"></param> /// <returns></returns> public List <BaseUIComponent> GetUIListByName(string uiName) { if (uiList == null || CheckUtil.StringIsNull(uiName)) { return(null); } List <BaseUIComponent> tempUIList = new List <BaseUIComponent>(); for (int i = 0; i < uiList.Count; i++) { BaseUIComponent itemUI = uiList[i]; if (itemUI.name.Equals(uiName)) { tempUIList.Add(itemUI); } } return(tempUIList); }
/// <summary> /// 根据名字刷新UI /// </summary> /// <param name="uiName"></param> public void RefreshUI(string uiName, int layer = -1) { if (manager.uiList == null || uiName.IsNull()) { return; } for (int i = 0; i < manager.uiList.Count; i++) { BaseUIComponent itemUI = manager.uiList[i]; if (itemUI.name.Equals(uiName)) { //设置层级 if (layer >= 0) { itemUI.transform.SetSiblingIndex(layer); } itemUI.RefreshUI(); } } }
/// <summary> /// 通过UI的名字开启UI并关闭其他UI /// </summary> /// <param name="uiName"></param> public T OpenUIAndCloseOther <T>(string uiName, Action <T> actionBeforeOpen = null, int layer = -1) where T : BaseUIComponent { if (manager.uiList == null || uiName.IsNull()) { return(null); } //首先关闭其他UI for (int i = 0; i < manager.uiList.Count; i++) { BaseUIComponent itemUI = manager.uiList[i]; if (!itemUI.name.Equals(uiName)) { if (itemUI.gameObject.activeSelf) { itemUI.CloseUI(); } } } return(OpenUI <T>(uiName, actionBeforeOpen, layer)); }
/// <summary> /// 通过UI的名字开启UI并关闭其他UI /// </summary> /// <param name="uiName"></param> public T OpenUIAndCloseOtherByName <T>(string uiName) where T : BaseUIComponent { if (uiList == null || CheckUtil.StringIsNull(uiName)) { return(null); } //首先关闭其他UI for (int i = 0; i < uiList.Count; i++) { BaseUIComponent itemUI = uiList[i]; if (!itemUI.name.Equals(uiName)) { if (itemUI.gameObject.activeSelf) { itemUI.CloseUI(); } } } return(OpenUIByName <T>(uiName)); }
/// <summary> /// 通过UI的名字开启UI /// </summary> /// <param name="uiName"></param> public T OpenUIByName <T>(string uiName) where T : BaseUIComponent { BaseUIComponent uiComponent = null; if (CheckUtil.StringIsNull(uiName)) { return(uiComponent as T); } bool hasData = false; for (int i = 0; i < uiList.Count; i++) { BaseUIComponent itemUI = uiList[i]; if (itemUI.name.Contains(uiName)) { uiComponent = itemUI; itemUI.OpenUI(); hasData = true; } } if (!hasData) { GameObject uiModel = LoadAssetUtil.SyncLoadAsset <GameObject>("ui/ui", uiName); //BaseUIComponent uiModel = LoadResourcesUtil.SyncLoadData<BaseUIComponent>("UI/"+ uiName); if (uiModel) { GameObject objUIComponent = Instantiate(gameObject, uiModel.gameObject); uiComponent = objUIComponent.GetComponent <BaseUIComponent>(); uiComponent.OpenUI(); uiList.Add(uiComponent); } else { LogUtil.LogError("没有找到指定UI:" + "ui/ui " + uiName); } } return(uiComponent as T); }
/// <summary> /// 通过UI开启UI并关闭其他UI /// </summary> /// <param name="uiName"></param> public void OpenUIAndCloseOtherByName(BaseUIComponent uiComponent) { if (uiList == null || uiComponent == null) { return; } for (int i = 0; i < uiList.Count; i++) { BaseUIComponent itemUI = uiList[i]; if (!itemUI == uiComponent) { itemUI.CloseUI(); } } for (int i = 0; i < uiList.Count; i++) { BaseUIComponent itemUI = uiList[i]; if (itemUI == uiComponent) { itemUI.OpenUI(); } } }
/// <summary> /// 通过UI的名字开启UI /// </summary> /// <param name="uiName"></param> public T OpenUIByName <T>(string uiName) where T : BaseUIComponent { if (CheckUtil.StringIsNull(uiName)) { return(null); } for (int i = 0; i < uiList.Count; i++) { BaseUIComponent itemUI = uiList[i]; if (itemUI.name.Equals(uiName)) { itemUI.OpenUI(); return(itemUI as T); } } T uiComponent = CreateUI <T>(uiName); if (uiComponent) { uiComponent.OpenUI(); return(uiComponent); } return(null); }
/// <summary> /// 点击 /// </summary> /// <param name="eventData"></param> public void OnPointerClick(PointerEventData eventData) { float isFastClick = inputActionShiftClick.ReadValue <float>(); //LogUtil.Log($"OnPointerClick dragging:{eventData.dragging} pointerDrag:{eventData.pointerDrag.name} eligibleForClick:{eventData.eligibleForClick} isFastClick:{isFastClick}"); //如果是快速选择 if (isFastClick == 1) { BaseUIComponent currentUI = UIHandler.Instance.GetOpenUI(); UIViewBoxList boxList; UIViewBackpackList backpackUI; UIViewShortcuts shortcutsUI; switch (originalParent.containerType) { //如果是快捷栏 case UIViewItemContainer.ContainerType.Shortcuts: //首先检测是否有箱子 优先放进箱子 boxList = currentUI.GetComponentInChildren <UIViewBoxList>(); if (boxList != null) { if (boxList.AddItems(this)) { return; } } backpackUI = currentUI.GetComponentInChildren <UIViewBackpackList>(); if (backpackUI != null) { if (backpackUI.AddItems(this)) { return; } } break; //如果是背包或者上帝模式 case UIViewItemContainer.ContainerType.Backpack: case UIViewItemContainer.ContainerType.God: //首先检测是否有箱子 优先放进箱子 boxList = currentUI.GetComponentInChildren <UIViewBoxList>(); if (boxList != null) { if (boxList.AddItems(this)) { return; } } //获取快捷栏 shortcutsUI = currentUI.GetComponentInChildren <UIViewShortcuts>(); if (shortcutsUI != null) { for (int i = 0; i < shortcutsUI.listShortcut.Count; i++) { UIViewItemContainer itemContainer = shortcutsUI.listShortcut[i]; //如果有容器VIEW 并且里面没有东西 if (itemContainer != null && itemContainer.GetViewItem() == null) { //如果是上帝模式则需要在原位置复制一个 if (originalParent.containerType == UIViewItemContainer.ContainerType.God) { CopyItemInOriginal(); } ExchangeItemForContainer(itemContainer); return; } } } break; //如果是箱子里的东西 case UIViewItemContainer.ContainerType.Box: //首先放进快捷栏 shortcutsUI = currentUI.GetComponentInChildren <UIViewShortcuts>(); if (shortcutsUI != null) { for (int i = 0; i < shortcutsUI.listShortcut.Count; i++) { UIViewItemContainer itemContainer = shortcutsUI.listShortcut[i]; //如果有容器VIEW 并且里面没有东西 if (itemContainer != null && itemContainer.GetViewItem() == null) { ExchangeItemForContainer(itemContainer); return; } } } //如果没有成功再放进背包 backpackUI = currentUI.GetComponentInChildren <UIViewBackpackList>(); if (backpackUI != null) { if (backpackUI.AddItems(this)) { return; } } break; } } }
/// <summary> /// 视窗元素 /// </summary> /// <param name="instanceid"></param> /// <param name="selectionrect"></param> private static void OnHierarchyShowSelect(int instanceid, Rect selectionrect) { //如果不是编辑模式则不进行操作 if (!EditorUtil.CheckIsPrefabMode(out var prefabStage)) { return; } //如果不是UI也不进行操作 if (baseUIComponent == null && baseUIView == null) { return; } //获取当前obj var go = EditorUtility.InstanceIDToObject(instanceid) as GameObject; if (go == null) { return; } if (baseUIComponent == null) { baseUIComponent = go.GetComponent <BaseUIComponent>(); } if (baseUIView == null) { baseUIView = go.GetComponent <BaseUIView>(); } //控制开关 var selectBox = new Rect(selectionrect); selectBox.x = selectBox.xMax - 30; selectBox.width = 10; //检测是否选中 bool hasGo = false; Component selectComonent = null; if (dicSelectObj.TryGetValue(go.name, out selectComonent)) { hasGo = true; } hasGo = GUI.Toggle(selectBox, hasGo, string.Empty); if (hasGo) { if (!dicSelectObj.ContainsKey(go.name)) { dicSelectObj.Add(go.name, null); } } else { if (dicSelectObj.ContainsKey(go.name)) { dicSelectObj.Remove(go.name); } } //如果选中了 if (hasGo) { //下拉选择 var selectType = new Rect(selectionrect); selectType.x = selectBox.xMax - 160; selectType.width = 150; //获取该obj下所拥有的所有comnponent Component[] componentList = go.GetComponents <Component>(); string[] listData = new string[componentList.Length]; int selectComonentIndex = 0; //初始化所有可选component; for (int i = 0; i < componentList.Length; i++) { listData[i] = componentList[i].GetType().Name; if (selectComonent != null && selectComonent.GetType().Name.Equals(listData[i])) { selectComonentIndex = i; } } //默认选择 if (selectComonent == null) { //如果有设置控件 if (listData.Length > 2) { selectComonentIndex = componentList.Length - 1; } dicSelectObj[go.name] = componentList[selectComonentIndex]; } //设置下拉数据 使用此方法需要连续点2次 //int newSelectComonentIndex = EditorGUI.Popup(selectType,selectComonentIndex, listData); //int newSelectComonentIndex = GUI.Toolbar(selectType, selectComonentIndex, listData); //如果下拉数据改变 //dicSelectObj[go.name] = componentList[selectComonentIndex]; //自定义弹窗 if (GUI.Button(selectType, listData[selectComonentIndex])) { Rect popupRect = GUILayoutUtility.GetLastRect(); popupRect.x = selectType.x; popupRect.y = selectType.y + selectType.height; PopupWindow.Show(popupRect, new HierarchySelectPopupSelect((popupSelectIndex) => { dicSelectObj[go.name] = componentList[popupSelectIndex]; }, listData)); } } }
/// <summary> /// 刷新打开的UI /// </summary> public void RefreshUI() { BaseUIComponent itemUI = GetOpenUI(); itemUI.RefreshUI(); }