private IEnumerator ApplyTexture(Transform target, OSLibTexture textureData, OSLib library) { while(_assetBundleIsOpen) yield return new WaitForEndOfFrame(); _assetBundleIsOpen = true; WWW www = WWW.LoadFromCacheOrDownload (library.GetAssetBundlePath (), library.GetVersion ()); yield return www; AssetBundle assets = www.assetBundle; Texture2D texture = assets.LoadAsset (textureData.GetFilePath (), typeof (Texture2D)) as Texture2D; Texture2D normalMap = null; if (textureData.GetNormalPath () != "") normalMap = assets.LoadAsset (textureData.GetNormalPath (), typeof (Texture2D)) as Texture2D; Texture2D hueMask = null; if (textureData.GetHueMaskPath () != "") hueMask = assets.LoadAsset (textureData.GetHueMaskPath (), typeof (Texture2D)) as Texture2D; Texture2D specularMask = null; if (textureData.GetSpecularMaskPath () != "") specularMask = assets.LoadAsset (textureData.GetSpecularMaskPath (), typeof (Texture2D)) as Texture2D; assets.Unload (false); target.GetComponent<Renderer>().material.mainTexture = texture; float scale = textureData.GetScale(); /*if (target.name.CompareTo("plage")==0) scale/=2.0f;*/ if (target.name.CompareTo("sol")==0) scale/=2.0f; if(target.GetComponent<Renderer>().material.shader.name == "Pointcube/StandardObjet") { target.GetComponent<Renderer>().material.SetTextureScale("_Diffuse",new Vector2(scale,scale)); target.GetComponent<Renderer> ().material.SetTexture ("_Normal", normalMap); target.GetComponent<Renderer> ().material.SetTexture ("_Diffuse", texture); target.GetComponent<Renderer> ().material.SetTexture ("_HueMask", hueMask); target.GetComponent<Renderer> ().material.SetTexture ("_SpecMask", specularMask); Dictionary<string,float> preset; if(target.name == "plage" || target.name == "Plage") { preset = GameObject.Find ("MainScene").GetComponent<LoadShaderPresets>().getConfigPlage(texture.name); } else if(target.name == "margelle" || target.name == "Margelle") { preset = GameObject.Find ("MainScene").GetComponent<LoadShaderPresets>().getConfigMargelle(texture.name); } else if(target.name == "muret" || target.name == "Muret") { preset = GameObject.Find ("MainScene").GetComponent<LoadShaderPresets>().getConfigMuret(texture.name); } else { preset = null; } if(preset != null) { string[] keys = preset.Keys.ToArray(); float red = 0; float green = 0; float blue = 0; foreach (string key in keys) { switch(key) { case "Normallevel ": target.GetComponent<Renderer> ().material.SetFloat("_Normallevel",preset[key]); break ; case "UVtranslation ": target.GetComponent<Renderer> ().material.SetFloat("_UVtranslation",preset[key]); break ; case "UVRotation ": target.GetComponent<AABBOutlineResizer>().setOffsetRotationUV(preset[key]); //target.GetComponent<Renderer> ().material.SetFloat("_UVRotation",preset[key]); break ; case "UVTile ": target.GetComponent<AABBOutlineResizer>().setOffsetTileUV(preset[key]); //target.GetComponent<Renderer> ().material.SetFloat("_UVTile",preset[key]); break ; case "Blur ": target.GetComponent<Renderer> ().material.SetFloat("_Blur",preset[key]); break ; case "gloss ": target.GetComponent<Renderer> ().material.SetFloat("_gloss",preset[key]); break ; case "Specularlevel ": target.GetComponent<Renderer> ().material.SetFloat("_Specularlevel",preset[key]); break ; case "Lightness ": target.GetComponent<Renderer> ().material.SetFloat("_Ligntness",preset[key]); break ; case "HueMaskIntensity ": target.GetComponent<Renderer> ().material.SetFloat("_HueMaskIntensity",preset[key]); break ; case "HuecolorR ": red = preset[key]; break ; case "HuecolorG ": green = preset[key]; break ; case "HuecolorB ": blue = preset[key]; break ; case "Huelevel ": target.GetComponent<AABBOutlineResizer>().setHueLevel(preset[key]);; break ; case "Saturation ": target.GetComponent<AABBOutlineResizer>().setSaturation(preset[key]); break ; case "Bulb ": target.GetComponent<Renderer> ().material.SetFloat("_Bulb",preset[key]); break ; case "Reflexion ": target.GetComponent<Renderer> ().material.SetFloat("_Reflexion",preset[key]); if(preset[key] !=0) { Cubemap temp = Resources.Load("shaders/configs/Chrome 1") as Cubemap; Debug.Log(temp.name + " Reflexion"); target.GetComponent<Renderer> ().material.SetTexture("_CubeMap",temp); } break ; case "Reflexionintensity ": target.GetComponent<Renderer> ().material.SetFloat("_Reflexionintensity",preset[key]); break ; case "ReflexionBlur ": target.GetComponent<Renderer> ().material.SetFloat("_ReflexionBlur",preset[key]); break ; } } Vector3 hue = new Vector3(red,green,blue); Color hueColor = new Color(red,green,blue,1.0f); if(target.name == "plage" || target.name == "Plage") { target.GetComponent<AABBOutlineResizer>().setColorPlage(hue); } else if(target.name == "margelle" || target.name == "Margelle") { target.GetComponent<AABBOutlineResizer>().setColorMargelle(hue); } else if(target.name == "muret" || target.name == "Muret") { target.GetComponent<AABBOutlineResizer>().setColorMuret(hue); } //target.GetComponent<Renderer> ().material.SetColor("_Huecolor",hue); picker.GetComponent<HSVPicker>().currentColor = hueColor; } } else { target.GetComponent<Renderer>().material.SetTextureScale("_MainTex",new Vector2(scale,scale)); target.GetComponent<Renderer> ().material.SetTexture ("_BumpMap", normalMap); } _assetBundleIsOpen=false; }
private IEnumerator ApplyTexture2(Transform target, OSLibTexture textureData, OSLib library) { while(_assetBundleIsOpen) yield return new WaitForEndOfFrame(); _assetBundleIsOpen = true; WWW www = WWW.LoadFromCacheOrDownload (library.GetAssetBundlePath (), library.GetVersion ()); yield return www; AssetBundle assets = www.assetBundle; Texture2D texture = assets.LoadAsset (textureData.GetFilePath2 (), typeof (Texture2D)) as Texture2D; assets.Unload (false); target.GetComponent<Renderer>().material.mainTexture = texture; _assetBundleIsOpen=false; }
//--------------COROUTINES----------------------------------- /* LoadConf() * Chargement de la configuration d'abri par défaut **/ private IEnumerator LoadConf() { _isBuilding = true; Montage.assetBundleLock = true; //Attend que le objdata soit configuré while(gameObject.GetComponent<ObjData>()==null) { yield return new WaitForEndOfFrame(); } while(gameObject.GetComponent<ObjData>().GetObjectModel() == null) { yield return new WaitForEndOfFrame(); } _lib = GetComponent<ObjData>().GetObjectModel().GetLibrary(); //Récupération de l'assetbundle // OSLib libObj = GetComponent<ObjData>().GetObjectModel().GetLibrary(); WWW www = WWW.LoadFromCacheOrDownload (_lib.GetAssetBundlePath (), _lib.GetVersion ()); yield return www; if (www.error != null) { Debug.Log ("AssetBundle ERROR" + www.error); } else { _assetBundle = www.assetBundle; if (_assetBundle != null) { //Chargement de la config TextAsset confXml = _assetBundle.LoadAsset (modelName+"_conf", typeof (TextAsset)) as TextAsset; if (confXml != null) { _dsMdl.ParseConfFile(confXml); } } _assetBundle.Unload (false); } www.Dispose(); //Création de l'abri par default ArrayList stConf= _dsMdl.GetdefaultConf(); _currentColor = _dsMdl.GetColor(_currentColorIndex); if(stConf.Count > 0) { // SaveTransform(); _hasFacadeInDefaultBegin = false; _hasFacadeInDefaultEnd = false; for(int i=0;i<stConf.Count;i=i+3) { ModuleType typ = ModuleType.bloc; switch ((string)stConf[i]) { case "facade": typ = ModuleType.facade; break; case "bloc": typ = ModuleType.bloc; if(IsAbrifixe()) { typ = ModuleType.multiBloc; } break; case "extremite": typ = ModuleType.extremite; break; case "multibloc": typ = ModuleType.multiBloc; break; } if((typ == ModuleType.facade) && (i==0)) { _hasFacadeInDefaultBegin = true; _saveTailleBegin = (int) stConf[i+1]; _saveStyleBegin = (string) stConf[i+2]; continue; } if((typ == ModuleType.facade) && (i>0)) { _hasFacadeInDefaultEnd = true; _saveTailleEnd = (int) stConf[i+1]; _saveStyleEnd = (string) stConf[i+2]; continue; } int t = (int) stConf[i+1]; string styl = (string) stConf[i+2]; _nextInsertion = true; _decalZ = 0.0f; yield return StartCoroutine(AddModule(t,styl,typ,/*_dsMdl.GetColor(0)*/_currentColor,true)); } _isBuilding = false; } if(!_hasFacadeInDefaultEnd) { _selectedIndex = 0; if(IsAbrifixe()) _selectedIndex = Mathf.Clamp(_selectedIndex,1,_modules.Count-2); } UpdateCurrentModule(); UpdateModules(); UpdateBoxCollider(); ChangeModuleColor(_currentColor); // www.Dispose(); Montage.assetBundleLock = false; enabled = false; if(_hasFacadeInDefaultEnd) { yield return StartCoroutine(AddModule(_saveTailleEnd,_saveStyleEnd,ModuleType.facade,_currentColor,true)); _hasFacadeInDefaultEnd = false; _selectedIndex = 0; if(IsAbrifixe()) _selectedIndex = Mathf.Clamp(_selectedIndex,1,_modules.Count-2); } if(_hasFacadeInDefaultBegin) { _selectedIndex = 0; UpdateCurrentModule(); _nextInsertion = false; yield return StartCoroutine(AddModule(_saveTailleBegin,_saveStyleBegin,ModuleType.facade,_currentColor,true)); _hasFacadeInDefaultBegin = false; if(IsAbrifixe()) _selectedIndex = Mathf.Clamp(_selectedIndex,1,_modules.Count-2); UpdateCurrentModule(); UpdateModules(); UpdateBoxCollider(); } //CenterDeployAndFeetLimit(); yield return null; }