void ChangeSpecialType(object param) { EventMultiArgs args = (EventMultiArgs)param; ESpecialType specialType = args.GetArg <ESpecialType>("specialType"); ItemDepthConfig target = args.GetArg <ItemDepthConfig>("target"); target.SetSpecialType(specialType); if (specialType != ESpecialType.Auto) { target.SetIgnor(true); } else { target.SetIgnor(false); } AddItemConfig(target); }
private string GetSpecialTypeName(ESpecialType eType) { if (eType == ESpecialType.Auto) { return("Auto"); } else if (eType == ESpecialType.Depth0) { return("Depth-1"); } else if (eType == ESpecialType.Depth99) { return("Depth99"); } else if (eType == ESpecialType.Depth199) { return("Depth199"); } else if (eType == ESpecialType.Depth299) { return("Depth299"); } else if (eType == ESpecialType.Depth399) { return("Depth399"); } else if (eType == ESpecialType.Depth499) { return("Depth499"); } else if (eType == ESpecialType.Other) { return("Other"); } return("Auto"); }
//打印panel中的一个atlas的一个sprite void DrawOneItem(ref ItemDepthConfig depthConfig) { float height = 25f; GameObject PanelObj = depthConfig.panel; GameObject obj = depthConfig.target; bool bSelect = !depthConfig.bIgnor; int iDepth = depthConfig.idepth; string sSpecialType = depthConfig.specialType; ESpecialType eSpecial = depthConfig.eSpecial; GUILayout.BeginHorizontal(); GUILayout.Space(30f); bool bSelectNow = EditorGUILayout.Toggle("", bSelect, GUILayout.Width(25f)); if (bSelectNow != bSelect) { depthConfig.SetIgnor(!bSelectNow);//此数据是复制的,不能直接调 AddItemConfig(depthConfig); } bool bPush1 = GUILayout.Button(obj.transform.name, "AS TextArea", GUILayout.Width(120f)); bool bPush2 = GUILayout.Button(depthConfig.strContent, "AS TextArea", GUILayout.Width(200f)); if (bPush1 || bPush2) { GameObject[] objs = new GameObject[1]; objs[0] = obj; Selection.objects = objs; } if (eSpecial == ESpecialType.Other) { string sdepth = GUILayout.TextArea(iDepth.ToString(), GUILayout.Width(60f)); int int_depth = int.Parse(sdepth); if (int_depth != depthConfig.idepth) { depthConfig.SetDepth(int_depth); AddItemConfig(depthConfig); } } else { GUILayout.Box(iDepth.ToString(), GUILayout.Width(60f)); } //特殊处理下拉菜单 if (GUILayout.Button(GetSpecialTypeName(eSpecial), EditorStyles.layerMaskField, GUILayout.Width(250f), GUILayout.MinHeight(height))) { bool isSelect = false; GenericMenu menu = new GenericMenu(); EventMultiArgs args = new EventMultiArgs(); args.AddArg("target", depthConfig); args.AddArg("specialType", ESpecialType.Auto); if (sSpecialType == "Auto") { isSelect = true; } menu.AddItem(new GUIContent("Auto"), isSelect, ChangeSpecialType, args); isSelect = false; if (sSpecialType == "Depth-1") { isSelect = true; } EventMultiArgs args2 = new EventMultiArgs(); args2.AddArg("target", depthConfig); args2.AddArg("specialType", ESpecialType.Depth0); menu.AddItem(new GUIContent("-1:最底"), isSelect, ChangeSpecialType, args2); isSelect = false; if (sSpecialType == "Depth99") { isSelect = true; } EventMultiArgs args3 = new EventMultiArgs(); args3.AddArg("target", depthConfig); args3.AddArg("specialType", ESpecialType.Depth99); menu.AddItem(new GUIContent("99:Common_1顶层"), isSelect, ChangeSpecialType, args3); isSelect = false; if (sSpecialType == "Depth199") { isSelect = true; } EventMultiArgs args4 = new EventMultiArgs(); args4.AddArg("target", depthConfig); args4.AddArg("specialType", ESpecialType.Depth199); menu.AddItem(new GUIContent("199:界面图集顶层"), isSelect, ChangeSpecialType, args4); isSelect = false; if (sSpecialType == "Depth299") { isSelect = true; } EventMultiArgs args5 = new EventMultiArgs(); args5.AddArg("target", depthConfig); args5.AddArg("specialType", ESpecialType.Depth299); menu.AddItem(new GUIContent("299:Common_2顶层"), isSelect, ChangeSpecialType, args5); isSelect = false; if (sSpecialType == "Depth399") { isSelect = true; } EventMultiArgs args6 = new EventMultiArgs(); args6.AddArg("target", depthConfig); args6.AddArg("specialType", ESpecialType.Depth399); menu.AddItem(new GUIContent("399:图标图集顶层"), isSelect, ChangeSpecialType, args6); isSelect = false; if (sSpecialType == "Depth499") { isSelect = true; } EventMultiArgs args7 = new EventMultiArgs(); args7.AddArg("target", depthConfig); args7.AddArg("specialType", ESpecialType.Depth499); menu.AddItem(new GUIContent("499:Common_3顶层"), isSelect, ChangeSpecialType, args7); isSelect = false; if (sSpecialType == "Other") { isSelect = true; } EventMultiArgs args8 = new EventMultiArgs(); args8.AddArg("target", depthConfig); args8.AddArg("specialType", ESpecialType.Other); menu.AddItem(new GUIContent("Other"), isSelect, ChangeSpecialType, args8); menu.ShowAsContext(); } GUILayout.Space(30f); GUILayout.EndHorizontal(); }
/// <summary> /// /// </summary> /// <param name="target">处理该目标下的孩子</param> /// <param name="atlasLayers">指定要处理的哪些层</param> /// <param name="bAutoSet">是否开启自动设置depth</param> /// <param name="bReadDepth">是否记录当前的depth</param> private static void EachChildrenDepth(GameObject uiPanel, GameObject target, int atlasLayers, bool bAutoSet = true, bool bReadDepth = false) { int iCommon_1 = atlasLayers & (1 << (int)EAtlasLayers.Common_1); int iDepth199 = atlasLayers & (1 << (int)EAtlasLayers.Depth199); int iCommon_2 = atlasLayers & (1 << (int)EAtlasLayers.Common_2); int iDepth399 = atlasLayers & (1 << (int)EAtlasLayers.Depth399); int iCommon_3 = atlasLayers & (1 << (int)EAtlasLayers.Common_3); int iOtherAtlas = atlasLayers & (1 << (int)EAtlasLayers.OtherAtlas); int iLabelText = atlasLayers & (1 << (int)EAtlasLayers.LabelText); int iCount = target.transform.childCount; int curDepth = 0; int tempDepth = 10000000; EAtlasLayers tempType = EAtlasLayers.OtherAtlas; ItemDepthConfig tempConfig; string tempContent; bool isAtlas; UIPanel panel; UISprite sprite; UILabel label; UITexture texture; for (int i = 0; i < iCount; i++) { GameObject objChild = target.transform.GetChild(i).gameObject; panel = objChild.GetComponent <UIPanel>(); if (panel != null) { continue; //该孩子为uipanel时跳过 } tempConfig = GetItemConfig(objChild); sprite = objChild.GetComponent <UISprite>(); curDepth = 0; tempDepth = 10000000; tempType = tempConfig.belongTo; isAtlas = false; tempContent = tempConfig.strContent; if (sprite != null && sprite.atlas != null) //如果是sprite { // tempConfig = new ItemDepthConfig(); // tempConfig.bIgnor = false; isAtlas = true; curDepth = sprite.depth; string atlasName = sprite.atlas.name; if (IsIconAtlas(atlasName)) { atlasName = "SOME_ICON_ATLAS"; } if (atlasName != "" && atlasName == UIATLAS_NAME) { atlasName = "CURRENT_UI_ATLAS"; } if (atlasName == COMMON_1) { if (iCommon_1 != 0) { tempDepth = count_common1; count_common1++; tempType = EAtlasLayers.Common_1; tempContent = "sprite:" + sprite.spriteName; } } else if (atlasName == "CURRENT_UI_ATLAS") { if (iDepth199 != 0) { tempDepth = 100 + count_uiatlas; count_uiatlas++; tempType = EAtlasLayers.Depth199; tempContent = "sprite:" + sprite.spriteName; } } else if (atlasName == COMMON_2) { if (iCommon_2 != 0) { tempDepth = 200 + count_common2; count_common2++; tempType = EAtlasLayers.Common_2; tempContent = "sprite:" + sprite.spriteName; } } else if (atlasName == "SOME_ICON_ATLAS") { if (iDepth399 != 0) { tempDepth = 301; tempType = EAtlasLayers.Depth399; tempContent = "sprite:" + sprite.spriteName; } } else if (atlasName == COMMON_3) { if (iCommon_3 != 0) { tempDepth = 400 + count_common3; count_common3++; tempType = EAtlasLayers.Common_3; tempContent = "sprite:" + sprite.spriteName; } } else if (iOtherAtlas != 0) { int index = GetIndexInOtherAtlas(atlasName); tempDepth = 500 + index * 10 + 1; tempType = EAtlasLayers.OtherAtlas; tempContent = "Atlas:" + sprite.atlas.name + ", sprite:" + sprite.spriteName; } if (tempDepth != 10000000 && bAutoSet && !tempConfig.bIgnor)//有适配到值 { sprite.depth = tempDepth; curDepth = tempDepth; if (objChild.CompareTag("OtherDepth")) { objChild.tag = ""; } } } label = objChild.GetComponent <UILabel>(); if (label != null && iLabelText != 0) //如果是label { // tempConfig = new ItemDepthConfig(); // tempConfig.bIgnor = false; isAtlas = true; curDepth = label.depth; tempType = EAtlasLayers.LabelText; tempContent = "text:" + label.text; if (bAutoSet && !tempConfig.bIgnor) { label.depth = 901; curDepth = label.depth; if (objChild.CompareTag("OtherDepth")) { objChild.tag = ""; } } } texture = objChild.GetComponent <UITexture>(); if (texture != null && iOtherAtlas != 0) //如果是uitexture { // tempConfig = new ItemDepthConfig(); // tempConfig.bIgnor = false; isAtlas = true; curDepth = texture.depth; tempType = EAtlasLayers.OtherAtlas; tempContent = "texture:" + texture.name; if (bAutoSet && !tempConfig.bIgnor) { int index = GetIndexInOtherAtlas(texture.name); texture.depth = 500 + index * 10 + 1; curDepth = texture.depth; if (objChild.CompareTag("OtherDepth")) { objChild.tag = ""; } } } if (isAtlas && bReadDepth) { ESpecialType eType = GetSpecialDepth(curDepth); if (objChild.CompareTag("OtherDepth")) { eType = ESpecialType.Other; } tempConfig.belongTo = tempType; if (!tempConfig.bIgnor) { tempConfig.bIgnor = (eType != ESpecialType.Auto); } tempConfig.target = objChild; tempConfig.specialType = ""; tempConfig.eSpecial = eType; tempConfig.panel = uiPanel; tempConfig.idepth = curDepth; tempConfig.strContent = tempContent; AddItemConfig(tempConfig); } EachChildrenDepth(uiPanel, objChild, atlasLayers, bAutoSet, bReadDepth); } }