public void SetSky(Material sky) { // instantiating material allows modifying the Rotation property without modifying asset var skyInstance = ResourcesDirectory.InstantiateMaterial(sky); skyInstance.name = sky.name; // sky will be saved correctly RenderSettings.skybox = skyInstance; UpdateSky(); }
public static Material MissingMaterial(bool overlay) { if (missingMaterial == null) { missingMaterial = ResourcesDirectory.InstantiateMaterial( ResourcesDirectory.FindMaterial("MISSING", true)); missingOverlay = ResourcesDirectory.InstantiateMaterial( ResourcesDirectory.FindMaterial("MISSING_overlay", true)); } return(overlay ? missingOverlay : missingMaterial); }
private Material ReadMaterial(JSONObject matObject) { string name; Color color = Color.white; bool setColor = false; if (matObject["name"] != null) { name = matObject["name"]; } else if (matObject["mode"] != null) { name = matObject["mode"]; if (matObject["color"] != null) { color = ReadColor(matObject["color"].AsArray); setColor = true; bool overlay = color.a != 1; if (matObject["alpha"] != null) { overlay = matObject["alpha"].AsBool; // new with version 4 } if (overlay) { name += "_overlay"; } } } else { warnings.Add("Error reading material"); return(ReadWorldFile.MissingMaterial(false)); } Material mat = ResourcesDirectory.FindMaterial(name, editor); if (mat == null) { warnings.Add("Unrecognized material: " + name); return(ReadWorldFile.MissingMaterial(false)); } if (setColor) { string colorProp = ResourcesDirectory.MaterialColorProperty(mat); if (colorProp != null) { mat = ResourcesDirectory.InstantiateMaterial(mat); mat.SetColor(colorProp, color); } } return(mat); }
public override void SetHighlight(Color c) { if (c == highlight) { return; } highlight = c; if (highlightMaterial == null) { highlightMaterial = ResourcesDirectory.InstantiateMaterial(VoxelComponent.highlightMaterials[15]); } highlightMaterial.color = highlight; foreach (Voxel v in voxels) { v.UpdateVoxel(); } }
public override void SetHighlight(Color c) { if (c == highlight) { return; } highlight = c; if (highlightMaterial == null) { highlightMaterial = ResourcesDirectory.InstantiateMaterial( ResourcesDirectory.FindMaterial("UNLIT", true)); } highlightMaterial.color = highlight; if (marker != null) { marker.UpdateMarker(); } }
private Material ReadMaterial(MessagePackObjectDictionary matDict, bool forceOverlay, Dictionary <string, Material> customTextureNames) { string name; if (matDict.ContainsKey(FileKeys.MATERIAL_NAME)) { name = matDict[FileKeys.MATERIAL_NAME].AsString(); } else if (matDict.ContainsKey(FileKeys.MATERIAL_MODE)) // version 9 and earlier { name = matDict[FileKeys.MATERIAL_MODE].AsString(); // ignore MATERIAL_ALPHA key, it's usually wrong if (matDict.ContainsKey(FileKeys.MATERIAL_COLOR)) { if (ReadColor(matDict[FileKeys.MATERIAL_COLOR]).a < 1) { forceOverlay = true; } } if (forceOverlay) { name += "_overlay"; } } else { warnings.Add("Error reading material"); return(ReadWorldFile.MissingMaterial(forceOverlay)); } Material mat; bool isCustom = customTextureNames != null && customTextureNames.ContainsKey(name); if (isCustom) { mat = customTextureNames[name]; } else { mat = ResourcesDirectory.FindMaterial(name, editor); } if (mat == null) { warnings.Add("Unrecognized material: " + name); return(ReadWorldFile.MissingMaterial(forceOverlay)); } if (!isCustom && matDict.ContainsKey(FileKeys.MATERIAL_COLOR)) { // custom textures can't have colors string colorProp = ResourcesDirectory.MaterialColorProperty(mat); if (colorProp != null) { Color color = ReadColor(matDict[FileKeys.MATERIAL_COLOR]); bool setColor = color != mat.GetColor(colorProp); var colorStyle = ResourcesDirectory.ColorStyle.TINT; if (matDict.ContainsKey(FileKeys.MATERIAL_COLOR_STYLE)) { Enum.TryParse(matDict[FileKeys.MATERIAL_COLOR_STYLE].AsString(), out colorStyle); } bool setStyle = colorStyle == ResourcesDirectory.ColorStyle.PAINT && ResourcesDirectory.GetMaterialColorStyle(mat) != ResourcesDirectory.ColorStyle.PAINT; if (setColor || setStyle) { mat = ResourcesDirectory.InstantiateMaterial(mat); } if (setColor) { mat.SetColor(colorProp, color); } if (setStyle) { ResourcesDirectory.SetMaterialColorStyle(mat, colorStyle); } } } return(mat); }