private Material ReadMaterial(JSONObject matObject) { if (matObject["name"] != null) { string name = matObject["name"]; foreach (string dirEntry in ResourcesDirectory.dirList) { if (dirEntry.Length <= 2) { continue; } string newDirEntry = dirEntry.Substring(2); string checkFileName = Path.GetFileNameWithoutExtension(newDirEntry); if ((!editor) && checkFileName.StartsWith("$")) // special alternate materials for game { checkFileName = checkFileName.Substring(1); } if (checkFileName == name) { return(ResourcesDirectory.GetMaterial(newDirEntry)); } } warnings.Add("Unrecognized material: " + name); return(ReadWorldFile.missingMaterial); } 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); } }
public override void SetHighlight(Color c) { if (c == highlight) { return; } highlight = c; if (highlightMaterial == null) { highlightMaterial = ResourcesDirectory.MakeCustomMaterial(ColorMode.UNLIT, false); } 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); } }
public BallObject() { material = ResourcesDirectory.MakeCustomMaterial(ColorMode.MATTE, true); material.color = Color.red; }
private void ColorTab() { if (highlightMaterial == null || !ResourcesDirectory.IsCustomMaterial(highlightMaterial)) { highlightMaterial = ResourcesDirectory.MakeCustomMaterial(colorMode, allowAlpha); if (allowAlpha) { highlightMaterial.color = new Color(0, 0, 1, 0.25f); } else { highlightMaterial.color = Color.red; } if (handler != null) { handler(highlightMaterial); } } ColorMode newMode; if (colorModeSet == ColorModeSet.UNLIT_ONLY) { newMode = ColorMode.UNLIT; } else { string[] colorModes; if (colorModeSet == ColorModeSet.OBJECT) { colorModes = OBJECT_COLOR_MODES; } else if (allowAlpha) { colorModes = TRANSPARENT_COLOR_MODES; } else { colorModes = OPAQUE_COLOR_MODES; } // TODO: this is ugly int m = System.Array.IndexOf(colorModes, COLOR_MODE_NAMES[(int)colorMode]); m = GUILayout.SelectionGrid(m, colorModes, colorModes.Length, GUIStyleSet.instance.buttonTab); newMode = (ColorMode)System.Array.IndexOf(COLOR_MODE_NAMES, colorModes[m]); } if (newMode != colorMode) { Material newMat = ResourcesDirectory.MakeCustomMaterial(newMode, allowAlpha); newMat.color = highlightMaterial.color; highlightMaterial = newMat; colorMode = newMode; if (handler != null) { handler(highlightMaterial); } } if (colorPicker == null) { colorPicker = gameObject.AddComponent <ColorPickerGUI>(); colorPicker.enabled = false; colorPicker.SetColor(highlightMaterial.color); colorPicker.includeAlpha = allowAlpha; colorPicker.handler = (Color c) => { highlightMaterial.color = c; if (handler != null) { handler(highlightMaterial); } }; } colorPicker.WindowGUI(); }
// return warnings public List <string> Read(Transform cameraPivot, VoxelArray voxelArray, bool editor) { this.editor = editor; if (missingMaterial == null) { // allowTransparency is true in case the material is used for an overlay, so the alpha value can be adjusted missingMaterial = ResourcesDirectory.MakeCustomMaterial(ColorMode.UNLIT, true); missingMaterial.color = Color.magenta; } string jsonString; try { string filePath = WorldFiles.GetFilePath(fileName); using (FileStream fileStream = File.Open(filePath, FileMode.Open)) { using (var sr = new StreamReader(fileStream)) { jsonString = sr.ReadToEnd(); } } } catch (Exception e) { throw new MapReadException("An error occurred while reading the file", e); } JSONNode rootNode; try { rootNode = JSON.Parse(jsonString); } catch (Exception e) { throw new MapReadException("Invalid world file", e); } if (rootNode == null) { throw new MapReadException("Invalid world file"); } JSONObject root = rootNode.AsObject; if (root == null || root["writerVersion"] == null || root["minReaderVersion"] == null) { throw new MapReadException("Invalid world file"); } if (root["minReaderVersion"].AsInt > VERSION) { throw new MapReadException("This world file requires a newer version of the app"); } fileWriterVersion = root["writerVersion"].AsInt; EntityReference.ResetEntityIds(); try { if (editor && cameraPivot != null && root["camera"] != null) { ReadCamera(root["camera"].AsObject, cameraPivot); } if (root["world"] != null) { ReadWorld(root["world"].AsObject, voxelArray); } } catch (MapReadException e) { throw e; } catch (Exception e) { throw new MapReadException("Error reading world file", e); } EntityReference.DoneLoadingEntities(); return(warnings); }