1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| using UnityEngine;
using System.Collections;
using System.Linq;
// Sets up transformation matrices to scale&scroll water waves // for the case where graphics card does not support vertex programs.
[ExecuteInEditMode] public class WaterSimple : MonoBehaviour {
string DataPath ;
string NewDirectoryForExternalImage ;
string ExImagePath;
Material CurrentMaterial;
private void LoadImage(string ImagePath){
// Création du répertoire contenant les futures images à importer if (!System.IO.Directory.Exists (ExImagePath))
System.IO.Directory.CreateDirectory (ExImagePath);
// Copy de l'image
System.IO.File.Copy (ImagePath,System.IO.Path.Combine (ExImagePath,System.IO.Path.GetFileName (ImagePath)),true);
// Construction du chemin de l'image copiée
ImagePath = System.IO.Path.Combine (ExImagePath, System.IO.Path.GetFileName (ImagePath));
// Changement du protocole d'accès au fichier ( sans cette ligne là ça ne marche plus! )
ImagePath = @"file://" + ImagePath;
// Création d'un objet à partir de l'image
WWW www = new WWW(ImagePath);
// Affectation de la texture à la texture courante
CurrentMaterial.mainTexture= <a href="http://www.texture;" target="_blank">www.texture;</a>
}
void Update() {
DataPath = Application.dataPath;
NewDirectoryForExternalImage = "External Image";
ExImagePath = System.IO.Path.Combine (DataPath, NewDirectoryForExternalImage);
// Récupération du matériaux nommé toto dans 3ds max // Parcours les matériaux de l'objet courant
CurrentMaterial =gameObject.renderer.materials.Where ( t => t.name.Contains ("toto")).FirstOrDefault ();
if (Input.GetKeyDown (KeyCode.P)) { // Boite de sélection d'une image
string ImageToLoad=
UnityEditor.EditorUtility.OpenFilePanel ("Choose image to load into unity",@"C:\","jpg");
// Chargement de l'image
LoadImage(ImageToLoad);
} else if (Input.GetKeyDown (KeyCode.O)) {
CurrentMaterial.color = Color.red;
// Permet de récupérer tous les objets qui se trouvent dans la scène
// System.Collections.Generic.List<GameObject>
Tableaux =UnityEditor.Selection.gameObjects.Where (t => t.name.ToLower ().Contains ("NomDeLobjetDans3DS")).ToList ();
}
if( !renderer ) return;
Material mat = renderer.sharedMaterial;
if( !mat ) return;
} } |