/// <summary> /// Store a map of renderers and their materials into a dictionary /// </summary> /// <param name="targetObject">Game object to scan</param> /// <param name="materialsBackup">Dictionary used to map renderers to their materials</param> public static void BackupMaterials(GameObject targetObject, MaterialMap materialsBackup) { materialsBackup.Clear(); foreach (Renderer mr in targetObject.GetComponentsInChildren <Renderer>(true)) { materialsBackup.Add(mr, mr.sharedMaterial); } }
/// <summary> /// Replace the materials in a game object with a copy of each one of them. /// Both the original materials and the cloned materials are stored in the given dictionaries. /// </summary> /// <param name="targetObject">Game object to scan</param> /// <param name="originalMaterials">Dictionary that maps renderers to their original materials</param> /// <param name="newMaterials">Dictionary that maps renderers to their cloned materials</param> /// <remarks>The given dictionaries are cleaned before they are filled.</remarks> public static void CloneMaterials(GameObject targetObject, MaterialMap originalMaterials, MaterialMap newMaterials) { originalMaterials.Clear(); newMaterials.Clear(); foreach (Renderer mr in targetObject.GetComponentsInChildren <Renderer>(true)) { originalMaterials.Add(mr, mr.sharedMaterial); mr.sharedMaterial = Material.Instantiate(mr.sharedMaterial); newMaterials.Add(mr, mr.sharedMaterial); } }
/// <summary> /// Adds a new resource and its location to the manifest. /// </summary> /// <param name="resource"></param> /// <param name="path"></param> public bool AddResource(UnityEngine.Object resource, string path) { if (Application.isPlaying) { throw new UnityException("ResourceManifest should only have new resourceses added to it during edit-time."); } if (resource == null || path == null) { return(false); } Type resType = resource.GetType(); if (resType == null) { return(false); } InitMaps(); bool flag = false; //APPEND NEW TYPES HERE if (resType == typeof(AnimationClip)) { flag = AnimationClips.Add(resource, path); } else if (resType == typeof(AudioClip)) { flag = AudioClips.Add(resource, path); } else if (resType == typeof(RuntimeAnimatorController)) { flag = AnimatorControllers.Add(resource, path); } else if (resType.IsSubclassOf(typeof(RuntimeAnimatorController))) { flag = AnimatorControllers.Add(resource, path); } else if (resType == typeof(Font)) { flag = Fonts.Add(resource, path); } else if (resType == typeof(GameObject)) { flag = GameObjects.Add(resource, path); } else if (resType == typeof(Material)) { flag = Materials.Add(resource, path); } else if (resType == typeof(Mesh)) { flag = Meshes.Add(resource, path); } else if (resType == typeof(PhysicMaterial)) { flag = PhysicMaterials.Add(resource, path); } else if (resType == typeof(PhysicsMaterial2D)) { flag = PhysicsMaterial2Ds.Add(resource, path); } else if (resType == typeof(Shader)) { flag = Shaders.Add(resource, path); } else if (resType == typeof(Sprite)) { flag = Sprites.Add(resource, path); } else if (resType == typeof(Texture2D)) { flag = Texture2Ds.Add(resource, path); } else if (resType == typeof(Texture3D)) { flag = Texture3Ds.Add(resource, path); } else { return(false); } return(flag); }
protected void ParseMtlFile(string MtlPath) { var Lines = File.ReadAllLines(MtlPath); ObjMeshMaterial NewMaterial = null; foreach (var line in Lines) { var TrimmedLine = line.TrimStart(new char[] { ' ', '\t' }); if (TrimmedLine.StartsWith("newmtl")) { var Tokens = TrimmedLine.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (Tokens.Count() == 2) { NewMaterial = new ObjMeshMaterial(); NewMaterial.MaterialName = Tokens[1]; } } else if (TrimmedLine.StartsWith("map_Kd")) { var Tokens = TrimmedLine.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (Tokens.Count() == 2) { if (NewMaterial != null) { NewMaterial.DiffuseMap = Tokens[1]; } } } else if (TrimmedLine.StartsWith("map_bump")) { var tokens = TrimmedLine.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (tokens.Count() == 2) { if (NewMaterial != null) { NewMaterial.NormalMap = tokens[1]; } } } else if (TrimmedLine.StartsWith("map_Ka")) { var tokens = TrimmedLine.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (tokens.Count() == 2) { if (NewMaterial != null) { NewMaterial.SpecularMap = tokens[1]; } } } else if (TrimmedLine.StartsWith("map_Ns")) { var tokens = TrimmedLine.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (tokens.Count() == 2) { if (NewMaterial != null) { NewMaterial.RoughnessMap = tokens[1]; } } } else if (TrimmedLine.StartsWith("map_d")) { var tokens = TrimmedLine.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (tokens.Count() == 2) { if (NewMaterial != null) { NewMaterial.MaskMap = tokens[1]; } } } else if (TrimmedLine.Length == 0 && NewMaterial != null) { MaterialMap.Add(NewMaterial.MaterialName, NewMaterial); NewMaterial = null; } } if (NewMaterial != null) { MaterialMap.Add(NewMaterial.MaterialName, NewMaterial); NewMaterial = null; } }
public void AddMaterial(VoxMaterial butts) { mMaterials.Add(butts.Name, butts); }