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( ResourcesDirectory.FindMaterial("UNLIT", true)); } highlightMaterial.color = highlight; if (marker != null) { marker.UpdateMarker(); } }
private Material ReadMaterial(JSONObject matObject) { if (matObject["name"] != null) { string name = matObject["name"]; Material mat = ResourcesDirectory.FindMaterial(name, editor); if (mat == null) { warnings.Add("Unrecognized material: " + name); return(ReadWorldFile.missingMaterial); } return(mat); } else if (matObject["mode"] != null) { ColorMode mode = (ColorMode)System.Enum.Parse(typeof(ColorMode), matObject["mode"]); if (matObject["color"] != null) { Color color = ReadColor(matObject["color"].AsArray); bool alpha = color.a != 1; if (matObject["alpha"] != null) { alpha = matObject["alpha"].AsBool; // new with version 4 } Material mat = ResourcesDirectory.MakeCustomMaterial(mode, alpha); mat.color = color; return(mat); } else { return(ResourcesDirectory.MakeCustomMaterial(mode)); } } else { warnings.Add("Error reading material"); return(ReadWorldFile.missingMaterial); } }
private Material ReadMaterial(MessagePackObjectDictionary matDict, bool alpha) { if (matDict.ContainsKey(FileKeys.MATERIAL_NAME)) { string name = matDict[FileKeys.MATERIAL_NAME].AsString(); Material mat = ResourcesDirectory.FindMaterial(name, editor); if (mat == null) { warnings.Add("Unrecognized material: " + name); return(ReadWorldFile.missingMaterial); } return(mat); } else if (matDict.ContainsKey(FileKeys.MATERIAL_MODE)) { ColorMode mode = (ColorMode)System.Enum.Parse(typeof(ColorMode), matDict[FileKeys.MATERIAL_MODE].AsString()); if (matDict.ContainsKey(FileKeys.MATERIAL_COLOR)) { Color color = ReadColor(matDict[FileKeys.MATERIAL_COLOR]); if (matDict.ContainsKey(FileKeys.MATERIAL_ALPHA)) { alpha = matDict[FileKeys.MATERIAL_ALPHA].AsBoolean(); } Material mat = ResourcesDirectory.MakeCustomMaterial(mode, alpha); mat.color = color; return(mat); } else { return(ResourcesDirectory.MakeCustomMaterial(mode)); } } else { warnings.Add("Error reading material"); return(ReadWorldFile.missingMaterial); } }
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); }