// merge multiple librairies into one to fit the interface public static OSLib MergeLibraries(ICollection<OSLib> libraries) { OSLib mergedLibrary = new OSLib (-1, -1, "", "Merge", ""); foreach (OSLib library in libraries) { foreach (OSLibCategory catLvl1 in library.GetCategoryList ()) { _searchedId = catLvl1.GetBrandId(); if(_searchedId==-1) _searchedId = catLvl1.GetId (); OSLibCategory libraryCatLvl1 = mergedLibrary.GetCategoryList ().Find (IsCategoryWithId); if (libraryCatLvl1 == null) { libraryCatLvl1 = new OSLibCategory (catLvl1.GetId (), null, catLvl1, catLvl1.GetBrandId()); mergedLibrary.AddCategory (libraryCatLvl1); } foreach (OSLibCategory catLvl2 in catLvl1.GetCategoryList ()) { _searchedId = catLvl2.GetBrandId(); if(_searchedId==-1) _searchedId = catLvl2.GetId (); OSLibCategory libraryCatLvl2 = libraryCatLvl1.GetCategoryList ().Find (IsCategoryWithId); if (libraryCatLvl2 == null) { libraryCatLvl2 = new OSLibCategory (catLvl2.GetId (), libraryCatLvl1, catLvl2, catLvl2.GetBrandId()); libraryCatLvl1.AddChildCategory (libraryCatLvl2); } foreach (OSLibObject obj in catLvl2.GetObjectList ()) { libraryCatLvl2.AddObject (obj); } } foreach (OSLibObject obj in catLvl1.GetObjectList ()) { libraryCatLvl1.AddObject (obj); } } foreach (OSLibStairs stairs in library.GetStairsList ()) { _searchedId = stairs.GetId (); OSLibStairs mergedStairs = mergedLibrary.GetStairsList ().Find (IsStairsWithId); if (mergedStairs == null) { mergedStairs = new OSLibStairs (stairs.GetId (), stairs.GetDependency ()); mergedLibrary.AddStairs (mergedStairs); } foreach (OSLibStair stair in stairs.GetStairList ()) { _searchedId = stair.GetId (); OSLibStair mergedStair = mergedStairs.GetStairList ().Find (IsStairWithId); if (mergedStair == null) { mergedStair = new OSLibStair (stair.GetId (), stair.GetStairType (), stair.GetBrand (), stair.GetThumbnailPath ()); mergedStairs.AddStair (mergedStair); } } } } /* //Debug foreach (OSLibCategory catLvl1 in mergedLibrary.GetCategoryList ()) { Debug.Log("Catégorie niveau 1 : "+catLvl1.GetDefaultText()+" id "+catLvl1.GetId()+" brandid "+catLvl1.GetBrandId()); foreach (OSLibCategory catLvl2 in catLvl1.GetCategoryList ()) { Debug.Log("--------------- Catégorie niveau 2 : "+catLvl2.GetDefaultText()+" id "+catLvl2.GetId()+" brandid "+catLvl2.GetBrandId()); foreach (OSLibObject obj in catLvl2.GetObjectList()) { Debug.Log("---------------- -------------- Objets : "+obj.GetDefaultText()+", cat 1 : "+obj.getCategory().GetParentCategory().GetId()+", cat2 : "+obj.getCategory().GetId()); } } }*/ OSLib mergedAndOrderedLibrary = new OSLib (-1, -1, "", "mergedAndOrdered", ""); //Debug foreach (OSLibCategory catLvl1 in mergedLibrary.GetCategoryList ()) { //OSLibCategory catLvl1Ordered = catLvl1; OSLibCategory catLvl1Ordered = new OSLibCategory( catLvl1.GetId(), catLvl1.GetParentCategory(), catLvl1.isPrimaryType(), catLvl1.GetBrandId()); catLvl1Ordered.SetLanguagesDictionary(catLvl1.GetLanguagesDictionary()); catLvl1Ordered.SetDefaultLanguage(catLvl1.GetDefaultLanguage()); foreach (OSLibCategory catLvl2 in catLvl1.GetCategoryList ()) { //catLvl1Ordered.AddChildCategory(catLvl2); if(catLvl1Ordered.GetCategoryList().Count==0) catLvl1Ordered.AddChildCategory(catLvl2); else { bool max = true; for (int countCat=0; countCat < catLvl1Ordered.GetCategoryList().Count; countCat++) { OSLibCategory catLvl2ReOrdered = catLvl1Ordered.GetCategoryList()[countCat]; if(catLvl2ReOrdered.GetBrandId()>catLvl2.GetBrandId()) { catLvl1Ordered.AddChildCategoryAtPosition(catLvl2,countCat); max = false; break; } } if(max) { catLvl1Ordered.AddChildCategory(catLvl2); } } } if(mergedAndOrderedLibrary.GetCategoryList().Count==0) mergedAndOrderedLibrary.AddCategory (catLvl1Ordered); else { bool max = true; for (int countCat=0; countCat<mergedAndOrderedLibrary.GetCategoryList().Count;countCat++) { OSLibCategory catLvl1ReOrdered = mergedAndOrderedLibrary.GetCategoryList()[countCat]; if(catLvl1ReOrdered.GetBrandId()>catLvl1Ordered.GetBrandId()) { mergedAndOrderedLibrary.AddCategoryAtPosition(catLvl1Ordered,countCat); max = false; break; } } if(max) { mergedAndOrderedLibrary.AddCategory(catLvl1Ordered); } } } /* //Debug Debug.Log("----------------------------------------------------------"); Debug.Log("----------------------------------------------------------"); foreach (OSLibCategory catLvl1 in mergedAndOrderedLibrary.GetCategoryList ()) { Debug.Log("Catégorie niveau 1 : "+catLvl1.GetDefaultText()+" id "+catLvl1.GetId()+" brandid "+catLvl1.GetBrandId()); foreach (OSLibCategory catLvl2 in catLvl1.GetCategoryList ()) { Debug.Log("--------------- Catégorie niveau 2 : "+catLvl2.GetDefaultText()+" id "+catLvl2.GetId()+" brandid "+catLvl2.GetBrandId()); foreach (OSLibObject obj in catLvl2.GetObjectList()) { Debug.Log("---------------- -------------- Objets : "+obj.GetDefaultText()+" isMode 2D : "+obj.IsMode2D().ToString()+", cat 1 : "+obj.getCategory().GetParentCategory().GetId()+", cat2 : "+obj.getCategory().GetId()); } } } */ return mergedAndOrderedLibrary; // return mergedLibrary; }
public void CreateMenu(OSLib library) { _library = library; Montage.om.setLibrary(library); // < temporaire, mettre cette ligne ailleur //Menu ajout objets //GUIItemV2 originalsObj = new GUIItemV2(0,0,TextManager.GetText("GUIMenuLeft.Add"),"menuAddOn","menuAddOff",this); int x = 0; foreach(OSLibCategory catLvl1 in library.GetCategoryList ()) { if (catLvl1.GetCategoryList ().Count > 0) { GUIItemV2 typToAdd; if(catLvl1.GetText (PlayerPrefs.GetString("language")) == "OneShot 3d") { typToAdd = new GUIItemV2(0,x, catLvl1.GetText (PlayerPrefs.GetString("language")), "menuOSOn", "menuOSOff", this); } else { typToAdd = new GUIItemV2(0,x, catLvl1.GetText (PlayerPrefs.GetString("language")), "menuAddOn", "menuAddOff", this); } _firstCategory[catLvl1.GetBrandId()]=x; x++; int y = 0; foreach(OSLibCategory catLvl2 in catLvl1.GetCategoryList ()) { _secondCategory[catLvl2.GetBrandId()]=y; GUIUpperList fabToAdd = null; string szparentCategory = catLvl2.GetText (PlayerPrefs.GetString("language") + "_parent"); if(szparentCategory != "") { foreach(GUIItemV2 guiItemV2 in listParentCategory) { if(szparentCategory == guiItemV2.m_text) { fabToAdd = new GUIUpperList(1,/*guiItemV2.getSubItemsCount()*/y, catLvl2.GetText (PlayerPrefs.GetString("language")), "sousMenuOn2", "sousMenuOff2", this); guiItemV2.addSubItem(fabToAdd); break; } } if(fabToAdd == null) { GUIItemV2 parent = new GUIItemV2(1,listParentCategory.Count, szparentCategory, "sousMenuOn", "sousMenuOff", this); fabToAdd = new GUIUpperList(1,y, catLvl2.GetText (PlayerPrefs.GetString("language")), "sousMenuOn2", "sousMenuOff2", this); parent.addSubItem(fabToAdd); typToAdd.addSubItem(parent); listParentCategory.Add(parent); } } else { fabToAdd = new GUIUpperList(1,y, catLvl2.GetText (PlayerPrefs.GetString("language")), "sousMenuOn2", "sousMenuOff2", this); typToAdd.addSubItem(fabToAdd); } y++; int size = catLvl2.GetObjectList ().Count; int numberPerPage = 24; //Screen.currentResolution; #if UNITY_IPHONE numberPerPage = 9; #else if(Screen.currentResolution.width/Screen.currentResolution.height == 1.25f) numberPerPage = 25; else if(Screen.currentResolution.width/Screen.currentResolution.height == 1.6f) numberPerPage = 24; else numberPerPage = 24; #endif if( size % numberPerPage != 0) { size = (catLvl2.GetObjectList ().Count/numberPerPage)*numberPerPage + numberPerPage; } Texture2D[] tmpTexs = new Texture2D[size]; string[] tmpTexts = new string[size]; bool[] tmpCustomizables = new bool[size]; bool[] tmpBrands = new bool[size]; int i = 0; foreach(OSLibObject obj in catLvl2.GetObjectList ()) { // load texture Texture2D tmp = obj.GetThumbnail ();//Resources.Load (obj.GetThumbnailPath ()); if(tmp == null) tmp = Resources.Load ("thumbnails/noThumbs", typeof(Texture2D)) as Texture2D; if(obj==null) Debug.Log("Obj null"); if (obj.GetDefaultText ()==null) Debug.Log("Obj null"); // tmp.name = obj.GetDefaultText (); tmpTexts[i] = obj.GetText(PlayerPrefs.GetString("language")); tmpTexs[i] = tmp; tmpCustomizables[i] = obj.GetModules().GetStandardModuleList().Count > 0; tmpBrands[i] = obj.IsBrandObject(); //print (tmpTexts[i]); ++i; } fabToAdd.m_ctxPanelConfig = m_ctxPanelID_1; fabToAdd.m_ctxPanelBrand = m_ctxPanelID_2; fabToAdd.setImgContent(tmpTexs,tmpTexts, tmpCustomizables, tmpBrands); } Root.addSubItem(typToAdd); } if (catLvl1.GetObjectList ().Count > 0) { GUIUpperList fabToAdd = new GUIUpperList(0,x, catLvl1.GetDefaultText (), "sousMenuOn", "sousMenuOff", this); x++; Texture2D[] tmpTexs = new Texture2D[catLvl1.GetObjectList ().Count]; int i = 0; foreach(OSLibObject obj in catLvl1.GetObjectList ()) { // load texture Texture2D tmp = obj.GetThumbnail (); if(tmp == null) tmp = Resources.Load ("thumbnails/noThumbs",typeof(Texture2D)) as Texture2D; tmp.name = obj.GetText(PlayerPrefs.GetString("language"));// obj.GetDefaultText (); tmpTexs[i] = (Texture2D)tmp; ++i; } fabToAdd.setImgContent(tmpTexs); Root.addSubItem(fabToAdd); } } //Root.addSubItem(originalsObj); //print (x); if(usefullData._edition != usefullData.OSedition.Lite) { //Menu objets present dans la scene (sauf en édition lite) sceneObjs = new GUIItemV2(0,++x,TextManager.GetText("GUIMenuLeft.Select"),"menuSceneOn","menuSceneOff",this); Root.addSubItem(sceneObjs); } sceneObjs.SetEnableUI(GameObject.Find("MainNode").GetComponent<ObjBehavGlobal>().getNumberObjects() > 0); ResetMenu(); }