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); } } }
// 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; }