public void addObj(OSLibObject o, int _selFab, int _selTyp, int _selObj) { m_object = o; safeDrop = true; selFab = _selFab; selTyp = _selTyp; selObj = _selObj; // mainScene.GetComponent<GUIMenuMain>().lpVisible = false; }
//Fonction de chargement des objets------------------------------------------- //Elle est ici car du fait des librairies onlines, la fonctions de chargement //doit etre une IEnumerator (s�quen�age et chargement d'assetBundle oblige) //(pas possible de la laisser dans ObjectsModel car pas Monobehaviour) // Attention, fonction longue et imbuvable ^^ //---------------------------------------------------------------------------- IEnumerator loadObjs(BinaryReader buf) { mainScene.GetComponent<PleaseWaitUI>().SetLoadingMode(true); mainScene.GetComponent<PleaseWaitUI>().SetDisplayIcon(true); if(!mainScene.GetComponent<PleaseWaitUI>().IsDisplayingIcon()) yield return new WaitForEndOfFrame (); if (buf == null) Debug.Log ("BUFFER NULL"); else Debug.Log ("BUFFER PLEIN"); bool cont = true; int nb=0; try { nb = buf.ReadInt32();// Nombre d'objet sauvegard� Debug.Log("nombre objet charg� " + nb); mainScene.GetComponent<GUIMenuMain>().flushObjects();// Enleve tout les objets de la scene courante } catch { Debug.Log("BIZARRE "); cont = false; } if (!cont) { yield return null; } for(int i=0;i<nb;i++) { int typeId, brandId, indexObj; Vector3 tmpPos; Quaternion tmpRot; Vector3 tmpScale; IDictionary conf; OSLibObject oslibObj; OSLibCategory catLvl1; bool lockability; #region chargement parametres objs //Chargement type/marque/objet brandId = -1; try{ brandId = buf.ReadInt32(); } catch { Debug.Log("ALERTE"); } typeId = buf.ReadInt32(); indexObj = buf.ReadInt32(); //correction du bug de la biblioth�que designer de piscine � laquelle on a retir� 2 mod�les if(brandId==4016 && indexObj>1) indexObj=0; /*if(indexObj>1) { indexObj = 0; }*/ Debug.Log("brand "+brandId+", type "+typeId+", and index "+indexObj+" loaded"); oslibObj = new OSLibObject(-1, "", "", "", null, null, null, null, false, false,-1); catLvl1 = null;// = om.getMainLib().GetCategoryList ()[typeId]; if(brandId != -1) { OSLibCategory catLvl2 = null; // int indexObjSearch=0; bool founded = false; foreach (OSLibCategory catLvl1NewSearch in om.getMainLib().GetCategoryList ()) { if(founded) break; // Debug.Log("--------------- Cat�gorie niveau 1 : "+catLvl1NewSearch.GetDefaultText()); foreach (OSLibCategory catLvl2NewSearch in catLvl1NewSearch.GetCategoryList ()) { if(founded) break; // Debug.Log("--------------- Cat�gorie niveau 2 : "+catLvl2NewSearch.GetDefaultText()); foreach (OSLibObject obj in catLvl2NewSearch.GetObjectList()) { if(founded) break; // Debug.Log("---------------- -------------- Objets : "+obj.GetDefaultText()+", cat 1 : "+obj.getCategory().GetParentCategory().GetId()+", cat2 : "+obj.getCategory().GetId()); if((obj.getCategory().GetParentCategory().GetId()==typeId) && (obj.getCategory().GetId()==brandId)) { //if (indexObjSearch==indexObj) if(indexObj == obj.GetId()) { catLvl1= catLvl1NewSearch; catLvl2= catLvl2NewSearch; oslibObj = obj; founded = true; break; } /* else { indexObjSearch++; } */ } } } } Debug.Log("osLib loaded founded "+founded); /* //if(catLvl1!=null) for(int lvl2 = 0;lvl2<catLvl1.GetCategoryList ().Count;lvl2++) { if(catLvl1.GetCategoryList ()[lvl2].GetId() == brandId) catLvl2 = catLvl1.GetCategoryList ()[lvl2]; } //if(catLvl2!=null) // if(catLvl2.GetObjectList().Count>=indexObj) oslibObj = catLvl2.GetObjectList () [indexObj]; */ } else { // if(catLvl1!=null) // if(catLvl1.GetObjectList().Count>=indexObj) Debug.Log("ELSE"); oslibObj = catLvl1.GetObjectList () [indexObj]; } //chargement du spatial //position tmpPos = new Vector3(0, 0, 0); tmpPos.x = buf.ReadSingle(); tmpPos.y = buf.ReadSingle(); tmpPos.z = buf.ReadSingle(); //rotation tmpRot = new Quaternion(0, 0, 0, 0); tmpRot.x = buf.ReadSingle(); tmpRot.y = buf.ReadSingle(); tmpRot.z = buf.ReadSingle(); tmpRot.w = buf.ReadSingle(); tmpScale = new Vector3(1, 1, 1); if(!LibraryLoader.numVersionInferieur(cdm.versionSave,"1.6.5")) { //scale tmpScale.x = buf.ReadSingle(); tmpScale.y = buf.ReadSingle(); tmpScale.z = buf.ReadSingle(); } Debug.Log("pos and rot laded"); //LockAbility lockability = buf.ReadBoolean(); Debug.Log("lockability loaded"); //Chargement Configuration textures/couleurs int confCount = buf.ReadInt32(); Debug.Log("confCount loaded"); conf = new SortedList(); for(int a=0;a<confCount;a++) { try { string objTx = buf.ReadString(); int txIdx = buf.ReadInt32(); if(!conf.Contains(objTx)) conf.Add(objTx,txIdx); } catch (EndOfStreamException e) { Debug.LogWarning("endofstream exception : "+e.Message); m_errorLoading = true; mainScene.GetComponent<PleaseWaitUI>().SetLoadingMode(false); buf.Close(); isLoading = false; canShow(); // mainScene.GetComponent<PleaseWaitUI>().SetDisplayIcon(false); Camera.main.GetComponent<ObjInteraction>().enabled = true; mainNode.transform.FindChild("_avatar").GetComponent<Avatar>().SetForceDisplay(false); GameObject.Find("mainCam").GetComponent<MainCamManager>().FitViewportToScreen(); mainScene.GetComponent<PleaseWaitUI>().SetDisplayIcon(false); break; } } if (m_errorLoading) { yield return true; } Debug.Log("config tex/color loaded"); #endregion // } /* catch (EndOfStreamException ue) { Debug.Log("error chargement param objs :" + ue.ToString()); break; }*/ #region instanciation Obj // ----------- d�but de cr�ation de l'objet ------------------ //Ouverture assetBundle //if(oslibObj!=null) { while (assetBundleLock) { yield return new WaitForEndOfFrame (); } OSLib objLib = oslibObj.GetLibrary (); if(objLib != null) { Montage.assetBundleLock = true; WWW www = WWW.LoadFromCacheOrDownload (objLib.GetAssetBundlePath (), objLib.GetVersion ()); yield return www; GameObject go; Transform newObj; AssetBundle assetBundle; ObjData data; try { assetBundle = www.assetBundle; //Chargement de l'objet(GameObject) UnityEngine.Object original = assetBundle.LoadAsset (oslibObj.GetModel ().GetPath (),typeof(GameObject)); //instanciation //Debug.Log(typeId+ " "+brandId+" "+indexObj+" "+original); go = (GameObject)Instantiate(original, tmpPos, tmpRot); go.transform.localScale = tmpScale; if(go.GetComponent<Rigidbody>()) go.GetComponent<Rigidbody>().isKinematic = true; newObj = go.transform; //Configuraton de lobjet newObj.parent = mainNode.transform; newObj.name = newObj.name + i; newObj.gameObject.AddComponent <ObjBehav>(); newObj.gameObject.AddComponent <ApplyShader>(); newObj.gameObject.layer = 9; data = (ObjData)newObj.gameObject.AddComponent<ObjData>(); } catch (UnityException ue) { Debug.Log("instanciation objs :" + ue.ToString()); break; } yield return new WaitForEndOfFrame(); // attend la fin du start du objData data.SetObjectModel (oslibObj, assetBundle); assetBundle.Unload (false); Montage.assetBundleLock = false; yield return new WaitForEndOfFrame(); // attend la fin du start de ObjBehav // data.loadConf(conf); yield return StartCoroutine(data.loadConfIE(conf)); try { float y = newObj.gameObject.GetComponent<ObjBehav>().init(); // > met a la bonne position en y newObj.gameObject.GetComponent<ObjBehav>().iAmLocked(lockability); newObj.transform.position = new Vector3(newObj.transform.position.x, newObj.transform.position.y+y, newObj.transform.position.z); string pref = newObj.GetComponent<ObjData> ().GetObjectModel ().GetObjectType (); //string pref = originalsNode.transform.GetChild(newObj.GetComponent<ObjData>().getTyp()).name; if(go.GetComponent<MeshCollider>())// <- ca aussi ca doit etre mis dans les libs { go.GetComponent<MeshCollider>().convex = true; go.transform.localRotation = tmpRot; // Correction du bug qui fait que la piscinne avec le canard est charg�e de travers } /*if (newObj.GetComponent<ObjData> ().GetObjectModel ().GetModules().FindModule("liner")!=null)//TODO Temporaire a enlever plus tard { newObj.FindChild("frise").gameObject.AddComponent<PoolFrise>(); }*/ mainScene.GetComponent<GUIMenuLeft>().updateSceneObj(); newObj.GetComponent<ObjBehav> ().SetHeighOff7(tmpPos.y); // -- Ajout du nouvel objet au mode2D si besoin -- OSLibObject obj = newObj.transform.GetComponent<ObjData>().GetObjectModel(); if(obj.GetObjectType() == "pool" || obj.GetObjectType() == "dynamicShelter" || obj.IsMode2D()) m_mode2D.AddObj(newObj.transform); // ----------- fin de cr�ation de l'objet ------------------ #endregion Debug.Log("instanciation obj loaded"); } catch (EndOfStreamException ue) { Debug.Log("instanciation objs :" + ue.ToString()); break; } #region chargement SpecFcn //Chargement des Fonctions Sp�cifiques try { int spcFcnNb = buf.ReadInt32(); //GameObject tmp = new GameObject(); for(int s=0;s<spcFcnNb;s++) { string type = buf.ReadString(); if(type == "Function_PergolaAutoFeet" && LibraryLoader.numVersionInferieur(cdm.versionSave,"1.2.95")) { type = "FunctionConf_PergolaAutoFeet"; } int id = buf.ReadInt32(); foreach(Component c in go.GetComponents<MonoBehaviour>()) { if(c.GetType().ToString().StartsWith("Function")) { if(((Function_OS3D)c).GetFunctionId() == id && c.GetType().ToString() == type) { ((Function_OS3D)c).load(buf); } } } /* if(go.GetComponent(type)) { ((Function_OS3D) go.GetComponent(type)).load(buf); } else { go.AddComponent(type); data.updateSpecFcns(); ((Function_OS3D) go.GetComponent(type)).load(buf); } */ } Debug.Log("spcfnc loaded"); } catch (EndOfStreamException ue) { Debug.Log("spec fcn:" + ue.ToString()); break; } //----------------------------------------------------- #endregion mainScene.GetComponent<PleaseWaitUI>().setAdditionalLoadingTxt(TextManager.GetText("Montage.LoadingObject")+" "+(i+1)+"/"+nb); } } } mainScene.GetComponent<PleaseWaitUI>().SetLoadingMode(false); mainScene.GetComponent<PleaseWaitUI>().SetDisplayIcon(false); // yield return new WaitForEndOfFrame(); // yield return Resources.UnloadUnusedAssets(); yield return null; }
public void SetObjectModel(OSLibObject obj, AssetBundle assets) { _objectModel = obj; _nbConfMats = _objectModel.GetModules().GetStandardModuleList().Count; // apply default materials foreach (OSLibModule mod in obj.GetModules ().GetStandardModuleList()) { Transform modTarget = transform.Find (mod.GetModuleType ()); Color colorText = new Color(0.78f,0.78f,0.78f,1.0f); if (modTarget != null) { if (mod.GetColorList ().Count > 0) { OSLibColor color = OSLibBuilderUtils. GetFirstColorOfType(mod, mod.GetModuleType ()); modTarget.GetComponent<Renderer>().material.color = color.GetColor (); if(modTarget.GetComponent<MeshRenderer>()) { modTarget.GetComponent<Renderer>().material.mainTexture = null; if((modTarget.GetComponent<Renderer>().material.HasProperty("_DecalTex")) && (usefullData.lowTechnologie)) { modTarget.GetComponent<Renderer>().material.mainTexture = modTarget.GetComponent<Renderer>().material.GetTexture("_DecalTex"); } } if(color.GetColorType2()!=null) { Transform modTarget2 = transform.Find (color.GetColorType2()); if (modTarget2 != null) { Color color2 = color.GetColor2(); modTarget2.GetComponent<Renderer>().material.mainTexture = null; modTarget2.GetComponent<Renderer>().material.color = color2; } } } else if (mod.GetTextureList ().Count > 0) { OSLibTexture textData = OSLibBuilderUtils. GetFirstTextureOfType (mod, mod.GetModuleType ()); Texture2D text = assets.LoadAsset (textData.GetFilePath (), typeof (Texture2D)) as Texture2D; if(modTarget.GetComponent<Renderer>().material.shader.name.Contains("Pointcube")) { Debug.Log(text.name + " TEXTURES"); modTarget.GetComponent<Renderer>().material.SetTexture("_Diffuse",text); /*modTarget.GetComponent<Renderer>().material.SetTexture("_Normal",text); modTarget.GetComponent<Renderer>().material.SetTexture("_HueMask",text); modTarget.GetComponent<Renderer>().material.SetTexture("_SpecMask",text);*/ modTarget.GetComponent<Renderer>().material.color = colorText; float scale = textData.GetScale(); if(textData.GetTextureType2()!=null) { Transform modTarget2 = transform.Find (textData.GetTextureType2()); if (modTarget2 != null) { Texture2D text2 = assets.LoadAsset (textData.GetFilePath2 (), typeof (Texture2D)) as Texture2D; modTarget2.GetComponent<Renderer>().material.mainTexture = text2; modTarget2.GetComponent<Renderer>().material.color = colorText; modTarget2.GetComponent<Renderer>().material.SetTextureScale("_MainTex",new Vector2(scale,scale)); } } } else{ modTarget.GetComponent<Renderer>().material.mainTexture = text; modTarget.GetComponent<Renderer>().material.color = colorText; float scale = textData.GetScale(); if (modTarget.name.CompareTo("plage")==0) scale/=2.0f; modTarget.GetComponent<Renderer>().material.SetTextureScale("_MainTex",new Vector2(scale,scale)); if(textData.GetTextureType2()!=null) { Transform modTarget2 = transform.Find (textData.GetTextureType2()); if (modTarget2 != null) { Texture2D text2 = assets.LoadAsset (textData.GetFilePath2 (), typeof (Texture2D)) as Texture2D; modTarget2.GetComponent<Renderer>().material.mainTexture = text2; modTarget2.GetComponent<Renderer>().material.color = colorText; modTarget2.GetComponent<Renderer>().material.SetTextureScale("_MainTex",new Vector2(scale,scale)); } } } } subObjects.Add(mod.GetModuleType(),0); } } }
// public void LoadConf(ArrayList conf) // { // int i=0; // foreach(Transform t in transform) // { // setSubId(t.name,(int)conf[i]); // i++; // } // canUpdateMaps = true; // // } // IEnumerator updateMaps()//TODO A modifier quand yaura les libs // { // foreach(Transform t in transform) // { // //Quand yaura les libs, au lieu de faire un Resources.Load, // //faire un truc du genre lib.getMaps(t.name) // tmpMaps = Resources.LoadAll("maps/"+t.name); // //Debug.Log(tmpMaps.Length+" MAPS FOR "+t.name); // if(tmpMaps.Length>0) // { // int id = (int)subObjects[t.name]; // t.renderer.material.mainTexture = (Texture2D)tmpMaps[id]; // } // // yield return new WaitForSeconds(Time.deltaTime); // } // tmpMaps = null; // yield return true; // } public void SetObjectModel(OSLibObject obj) { _objectModel = obj; }
// 2013-10 : l'instanciation d'objet passe par ici (pas swap ni copy) public IEnumerator cloneObject(OSLibObject oslObj, Vector3 position) { mainScene.GetComponent<PleaseWaitUI>().SetDisplayIcon(true); yield return new WaitForEndOfFrame(); Transform newObj; position.y = 100; OSLib objLib = oslObj.GetLibrary (); //Debug.Log("avant www"); Montage.assetBundleLock = true; WWW www = WWW.LoadFromCacheOrDownload (objLib.GetAssetBundlePath (), objLib.GetVersion ()); yield return www; AssetBundle assetBundle = www.assetBundle; //Debug.Log("Apres www"); Object original = assetBundle.LoadAsset (oslObj.GetModel ().GetPath (), typeof(GameObject)); Vector3 wordPos = new Vector3(); Ray ray=Camera.main.ScreenPointToRay(new Vector3(Screen.width/2,Screen.height-180.0f,1.0f)); RaycastHit hit; if(Physics.Raycast(ray,out hit,1000f)) wordPos = hit.point; Vector3 temp = Camera.main.ScreenToWorldPoint (new Vector3(Screen.width / 2, Screen.height - 100.0f, 200.0f)); //Debug.DrawLine (ray.origin, hit.point, Color.cyan,2000.0f); float temp_hauteur = SceneControl.m_hauteur; wordPos = Camera.main.transform.position + Camera.main.transform.forward * 100.0f*(0.0000005f*temp_hauteur+1.0f); position += Camera.main.transform.forward * (1f + SceneControl.m_hauteur * 0.2f)*10f; GameObject go = (GameObject) Instantiate (original, position, new Quaternion (0,0,0,0)); newObj = go.transform; newObj.name = newObj.name + ++iobjectNumber; newObj.parent = objectNode.transform; newObj.gameObject.layer = 9; newObj.gameObject.AddComponent <ObjBehav>(); newObj.gameObject.AddComponent<ApplyShader>(); ObjData data = (ObjData) newObj.gameObject.AddComponent <ObjData>(); yield return new WaitForEndOfFrame(); // attend la fin du start de ObjBehav data.SetObjectModel (oslObj, assetBundle); data.selFab = selFab; data.selTyp = selTyp; data.selObj = selObj; assetBundle.Unload (false); Montage.assetBundleLock = false; //yield return new WaitForEndOfFrame(); // attend la fin du start de ObjBehav // newObj.name = prefix+"_"+o.name; float y = newObj.gameObject.GetComponent<ObjBehav>().init(); // > met a la bonne position en y newObj.transform.position = new Vector3(newObj.transform.position.x, y, newObj.transform.position.z); // -- Si c'est un gros objet, le déplacer un peu vers le fond -- float s = Montage.sm.getCamData().m_s; if(newObj.GetComponent<Collider>().bounds.size.z > 1.4f*s) { Matrix4x4 m = Camera.main.cameraToWorldMatrix; float distance = (newObj.GetComponent<Collider>().bounds.size.z < 4*s ? 4*s : newObj.GetComponent<Collider>().bounds.size.z)*-1.25f; Vector3 p = m.MultiplyPoint(new Vector3(0f, 0f, distance)); Vector3 pos = newObj.transform.position; pos.Set(p.x, pos.y, p.z); newObj.transform.position = pos; } if(oslObj.GetModules().FindModule("sol")!=null) { position = Camera.main.transform.position + Camera.main.transform.forward * 5.0f * Mathf.Max(10,newObj.transform.localScale.x); position.y = y; newObj.transform.position = position; } // newObj.transform.Rotate (new Vector3 (0, 180, 0)); // TODO Ajouter un "si iOS" string pref = newObj.GetComponent<ObjData> ().GetObjectModel ().GetObjectType (); //string pref = originalsNode.transform.GetChild(newObj.GetComponent<ObjData>().getTyp()).name; /* if(pref != "piscines" && pref != "spas") // Pas d'ombres pour les piscines (très moches) { if(_iosShadows) { _iosShadows.GetComponent<IosShadowManager>().AddShadow(newObj.gameObject); } else Debug.LogWarning("Objet \"iosShadows\" introuvable. Les ombres pour iOS risquent de ne pas fonctionner."); } else { //newObj.gameObject.AddComponent ("PoolInitializer"); }*/ // -- Ajout de l'objet au mode2D si besoin -- OSLibObject obj = newObj.transform.GetComponent<ObjData>().GetObjectModel(); if (obj.GetObjectType () == "pool" || obj.GetObjectType () == "dynamicShelter" || obj.IsMode2D ()) { m_mode2D.AddObj (newObj.transform); } if (newObj.GetComponent<ObjData> ().GetObjectModel ().GetModules().FindModule("duck")!=null)//TODO Temporaire a enlever plus tard { // // // This is the parent node // Transform parent = (Transform) newObj.transform.Find("water"); // // This is the prefab // GameObject prefab = (GameObject)Resources.Load("animDuck"); // // Add the instance in the hierarchy // GameObject obj = (GameObject)Instantiate(prefab); // // // Find the instantiate prefab and asign the parent // // obj.transform.localScale = go.transform.localScale;//new Vector3 (8.0f,8.0f,8.0f);//TODO < remplacer 8.0f par le scale de la scene // obj.transform.parent = parent; // obj.transform.position = new Vector3(0,-0.1f,0); newObj.gameObject.AddComponent<Function_duck>(); data.updateSpecFcns(); if(go.GetComponent<MeshCollider>())// <- ca aussi ca doit etre mis dans les libs { go.GetComponent<MeshCollider>().convex = true; } } // if (newObj.GetComponent<ObjData> ().GetObjectModel ().GetModules().FindModule("liner")!=null)//TODO Temporaire a enlever plus tard // { // newObj.FindChild("frise").gameObject.AddComponent<PoolFrise>(); // } yield return new WaitForEndOfFrame(); mainScene.GetComponent<GUIMenuLeft>().updateSceneObj(); Camera.main.GetComponent<ObjInteraction>().setSelected(go); yield return new WaitForEndOfFrame(); m_obj2rotate = go; mainScene.GetComponent<PleaseWaitUI>().SetDisplayIcon(false); PC.ctxHlp.ShowCtxHelp(m_ctxPanelID); yield return true; }
// 2013-10 : le swap d'objet passe par ici public IEnumerator swap(Vector3 p, OSLibObject newO, GameObject oldO, int _selFab, int _selTyp, int _selObj) { mainScene.GetComponent<GUIMenuLeft>().canSwap = false; selFab = _selFab; selTyp = _selTyp; selObj = _selObj; mainScene.GetComponent<PleaseWaitUI>().SetDisplayIcon(true); yield return new WaitForEndOfFrame(); Quaternion tmpRotate = new Quaternion(0,0,0,0); tmpRotate.eulerAngles = oldO.transform.localRotation.eulerAngles + new Vector3(0,180,0); Transform newObj; //newObj = Instantiate (objToIns, p, tmpRotate) as Transform; OSLib objLib = newO.GetLibrary (); while (Montage.assetBundleLock) { yield return new WaitForEndOfFrame (); } Montage.assetBundleLock = true; WWW www = WWW.LoadFromCacheOrDownload (objLib.GetAssetBundlePath (), objLib.GetVersion ()); yield return www; yield return new WaitForEndOfFrame(); // attend la fin du start AssetBundle assetBundle = www.assetBundle; Object original = assetBundle.LoadAsset (newO.GetModel ().GetPath (), typeof(GameObject)); GameObject go = Instantiate (original/*, p, tmpRotate*/) as GameObject; yield return new WaitForEndOfFrame(); // attend la fin du start //TODO: to remove newObj = go.transform; newObj.name = newObj.name + ++iobjectNumber; newObj.position = p; newObj.rotation = tmpRotate; newObj.parent = objectNode.transform; if(!newO.IsBrandObject()) newObj.localScale = oldO.transform.localScale; newObj.gameObject.AddComponent <ObjBehav>(); newObj.GetComponent<ObjBehav>().iAmLocked(oldO.GetComponent<ObjBehav>().amILocked()); newObj.gameObject.layer = 9; float y = newObj.gameObject.GetComponent<ObjBehav> ().init (); newObj.Rotate (new Vector3 (0, 180, 0)); newObj.gameObject.AddComponent <ApplyShader>(); ObjData data = (ObjData) newObj.gameObject.AddComponent <ObjData>(); yield return new WaitForEndOfFrame(); // attend la fin du start de ObjBehav data.selFab = selFab; data.selTyp = selTyp; data.selObj = selObj; data.SetObjectModel (newO, assetBundle); assetBundle.Unload (false); Montage.assetBundleLock = false; yield return new WaitForEndOfFrame(); // attend la fin du start de ObjBehav yield return StartCoroutine(data.loadConfIE(oldO.GetComponent<ObjData>().getConfiguration())); // float y = newObj.gameObject.GetComponent<ObjBehav>().init(); newObj.position = new Vector3(newObj.position.x, newObj.position.y+y, newObj.position.z); newObj.GetComponent<ObjBehav>().SetHeighOff7(p.y); // -- Suppression de l'ancien objet si besoin -- OSLibObject oldObj = oldO.transform.GetComponent<ObjData>().GetObjectModel(); if(oldObj.GetObjectType() == "pool" || oldObj.IsMode2D()) m_mode2D.RemoveObj(oldO.transform); // -- Ajout du nouvel objet au mode2D si besoin -- OSLibObject obj = newObj.transform.GetComponent<ObjData>().GetObjectModel(); if(obj.GetObjectType() == "pool" || obj.GetObjectType() == "dynamicShelter" || obj.IsMode2D()) m_mode2D.AddObj(newObj.transform); // OSLibObject oldOModel = oldO.GetComponent<ObjData> ().GetObjectModel (); // foreach (OSLibModule mod in oldOModel.GetModules ().GetStandardModuleList ()) // { // Transform modTargetOld = oldO.transform.Find (mod.GetModuleType ()); // Transform modTargetNew = newObj.transform.Find (mod.GetModuleType ()); // // if (modTargetNew != null && modTargetOld != null) // { // modTargetNew.renderer.material.color = modTargetOld.renderer.material.color; // modTargetNew.renderer.material.mainTexture = modTargetOld.renderer.material.mainTexture; // } // } //Chargement de la configuration foreach(MonoBehaviour func in newObj.GetComponents<MonoBehaviour>()) { // Debug.Log("Passe la "+func.GetType()); if(func.GetType().GetInterface("Function_OS3D") != null) { /* if((Function_OS3D)oldO.GetComponent(func.GetType().ToString()) != null) { ArrayList conf = ((Function_OS3D)oldO.GetComponent(func.GetType().ToString())).getConfig(); ((Function_OS3D)func).setConfig(conf); } */ foreach (MonoBehaviour function in oldO.GetComponents<MonoBehaviour>()) { // MonoBehaviour function = (MonoBehaviour)function2; if(function.GetType().ToString().CompareTo(func.GetType().ToString())==0) { if( ((Function_OS3D)function).GetFunctionId()== ((Function_OS3D)func).GetFunctionId() ) { ArrayList conf = ((Function_OS3D)function).getConfig(); ((Function_OS3D)func).setConfig(conf); } } } } } //------------------------------ Camera.main.GetComponent<ObjInteraction>().swapObj(newObj.gameObject,oldO); // cest ici quon fait le delete if (newObj.GetComponent<ObjData> ().GetObjectModel ().GetModules().FindModule("duck")!=null) //TODO Deplacer ca ailleur { // // This is the parent node // Transform parent = (Transform) newObj.transform.Find("water"); // // This is the prefab // GameObject prefab = (GameObject)Resources.Load("animDuck"); // // Add the instance in the hierarchy // GameObject obj = (GameObject)Instantiate(prefab); // // // Find the instantiate prefab and asign the parent // obj.transform.localScale = newObj.transform.localScale;//new Vector3 (8.0f,8.0f,8.0f);//TODO < remplacer 8.0f par le scale de la scene // obj.transform.parent = parent; // obj.transform.position = new Vector3(0,-0.1f,0); newObj.gameObject.AddComponent<Function_duck>(); data.updateSpecFcns(); if(go.GetComponent<MeshCollider>())// <- ca aussi ca doit etre mis dans les libs { go.GetComponent<MeshCollider>().convex = true; } } // mainScene.GetComponent<GUIMenuLeft>().updateSceneObj(); mainScene.GetComponent<PleaseWaitUI>().SetDisplayIcon(false); yield return new WaitForEndOfFrame(); mainScene.GetComponent<GUIMenuLeft>().canSwap = true; yield return new WaitForEndOfFrame(); }
public void setSelected(GameObject g,bool justShow) { if(g == null) // plus d'objets sélectionné { if(selectedObj != null) { selectedObj.GetComponent<ObjBehav>().setAsUnselected(selectedObj); selectedObj.GetComponent<ObjBehav>().isActive = false; } selectedObj = null; if(!justShow) { mainScene.GetComponent<GUIMenuInteraction>().setVisibility(false); mainScene.GetComponent<GUIMenuLeft>().canDisplay(true); mainScene.GetComponent<GUIMenuRight>().setVisibility(false); mainScene.GetComponent<GUIMenuRight>().canDisplay(true); // hud.hideShowUD(false); hud.ActivateLineDisplay(false); } setColor(vert);//ADDED TO TEST v2CanSelectNext = false; } else //nouvel objet sélectionné { if(selectedObj != null && selectedObj != g) { selectedObj.GetComponent<ObjBehav>().setAsUnselected(selectedObj); selectedObj.GetComponent<ObjBehav>().isActive = false; setColor(vert);//ADDED TO TEST } selectedObj = g; if(selectedObj.transform.GetComponent<ObjData>()) m_selectedOSLibObj = selectedObj.transform.GetComponent<ObjData>().GetObjectModel(); else m_selectedOSLibObj = null;//cas Avatars selectedObj.GetComponent<ObjBehav>().isActive = true; selectedObj.GetComponent<ObjBehav>().setAsSelected(selectedObj); if(!justShow && selectedObj.name!="_avatar") { mainScene.GetComponent<GUIMenuInteraction>().setVisibility(true); mainScene.GetComponent<GUIMenuInteraction>().setLockability(selectedObj.GetComponent<ObjBehav>().amILocked()); mainScene.GetComponent<GUIMenuInteraction>().SetCustomizability(selectedObj.GetComponent<ObjData>().IsCustomizable()); if(selectedObj.GetComponent<ObjBehav>().amILocked()) { setColor(orange); //ADDED TO TEST } mainScene.GetComponent<GUIMenuLeft>().canDisplay(false); mainScene.GetComponent<GUIMenuRight>().canDisplay(false); // hud.hideShowUD(true); hud.ActivateLineDisplay(true,true); if(selectedObj != null) { if(selectedObj.GetComponent<ObjBehav>().amILocked()) { highlight.SetColor("_Color", orange); } else { highlight.SetColor("_Color", vert); } } } else if(selectedObj.name == "_avatar") { mainScene.GetComponent<GUIMenuInteraction>().setVisibility(false); mainScene.GetComponent<GUIMenuRight>().canDisplay(true); mainScene.GetComponent<GUIMenuRight>().ShowAvatarSettings(); hud.ActivateLineDisplay(true,true); } } }
//----------------------------------------------------- private bool CanAddObj(OSLibObject oslo) { bool b = true; if(usefullData.lowTechnologie) { if(mainNode.transform.GetChildCount() >18) { StartCoroutine(GetComponent<PleaseWaitUI>().showTempMsg(TextManager.GetText("GUIMenuLeft.WarningiPhone2Objects"),2)); b = false; } } return b; }
public IEnumerator SwapPool(int gizmoIndex, int stairIndex) { if (gizmoIndex >= _gizmos.Count) { yield return null; } ObjData objData = GetComponent<ObjData> (); OSLibObject objModel = objData.GetObjectModel (); Montage.assetBundleLock = true; OSLib objLib = objModel.GetLibrary (); WWW www = WWW.LoadFromCacheOrDownload (objLib.GetAssetBundlePath (), objLib.GetVersion ()); yield return www; AssetBundle assetBundle = www.assetBundle; int newStairIndex = stairIndex; string stairName = ""; string path = ""; int newGizmoIndex = gizmoIndex; if (stairIndex < 0) { newStairIndex = -1; path = objModel.GetModel ().GetBasePath (); } else { stairName = _stairList.GetStairList ()[stairIndex].GetStairType (); string baseModelPath = objModel.GetModel ().GetBasePath (); path = baseModelPath + "_" + stairName + "_" + (gizmoIndex + 1); bool exist = assetBundle.Contains (path); if (!exist) { newGizmoIndex = FindFirstGizmoAvailable (assetBundle, stairName); if (newGizmoIndex < 0) { path = baseModelPath; } else { path = baseModelPath + "_" + stairName + "_" + (newGizmoIndex + 1); } } } assetBundle.Unload (false); Montage.assetBundleLock = false; _selectedGizmoIndex = newGizmoIndex; _selectedStairIndex = newStairIndex; OSLibModel poolStairModel = new OSLibModel (path, objModel.GetModel ().GetBasePath ()); OSLibObject poolStairObject = new OSLibObject (objModel.GetId (), objModel.GetObjectType (), objModel.GetBrand (), objModel.GetThumbnailPath (), objModel.GetLibrary (), poolStairModel, objModel.GetModules (), objModel.getCategory (), objModel.IsMode2D (), objModel.IsAllowedToScale (), objModel.GetObjectScaleGenerale()); poolStairObject.SetLanguages (objModel); Camera.main.GetComponent<ObjInteraction>().setSelected (gameObject, true); ObjInstanciation instantiator = GameObject.Find("MainNode").GetComponent<ObjInstanciation> (); yield return StartCoroutine (instantiator.swap (transform.position, poolStairObject, gameObject, -1, -1, -1)); }