public virtual void Populate(TestCaseMetadaProvider metadataProvider) { _testCase.SourceFile.Copy(_directory); if (_testCase.HasLinkXmlFile) { _testCase.LinkXmlFile.Copy(InputDirectory); } CopyToInputAndExpectations(GetExpectationsAssemblyPath()); foreach (var dep in metadataProvider.AdditionalFilesToSandbox()) { dep.Source.FileMustExist().Copy(_directory.Combine(dep.DestinationFileName)); } foreach (var res in metadataProvider.GetResources()) { res.Source.FileMustExist().Copy(ResourcesDirectory.Combine(res.DestinationFileName)); } foreach (var compileRefInfo in metadataProvider.GetSetupCompileAssembliesBefore()) { var destination = BeforeReferenceSourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists(); compileRefInfo.SourceFiles.Copy(destination); } foreach (var compileRefInfo in metadataProvider.GetSetupCompileAssembliesAfter()) { var destination = AfterReferenceSourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists(); compileRefInfo.SourceFiles.Copy(destination); } }
public void TutorialShowSky() { scrollVelocity = new Vector2(0, 3000); selectedLayer = 0; paint.material = ResourcesDirectory.GetMaterial("Materials/Sky"); handler(paint); UpdateMaterialSelector(); }
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); }
void UpdateMaterialDirectory() { materialSubDirectories = new List <string>(); if (materialDirectory != rootDirectory) { materialSubDirectories.Add(BACK_BUTTON); } materials = new List <Material>(); foreach (string dirEntry in ResourcesDirectory.dirList) { if (dirEntry.Length <= 2) { continue; } string newDirEntry = dirEntry.Substring(2); int slash = newDirEntry.LastIndexOf("/"); if (slash != -1) { if (newDirEntry.Substring(0, slash) != materialDirectory) { continue; } } else { if (materialDirectory != "") { continue; } } string fileName = newDirEntry.Substring(slash + 1); if (fileName.StartsWith("$")) { continue; // special alternate materials for game } if (!fileName.Contains(".")) { materialSubDirectories.Add(fileName); } else if (fileName.EndsWith(".mat")) { if (fileName.EndsWith(PREVIEW_SUFFIX_EXT)) { materials.RemoveAt(materials.Count - 1); // special preview material which replaces the previous } materials.Add(ResourcesDirectory.GetMaterial(newDirEntry)); } } AssetManager.UnusedAssets(); }
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); }
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); } }
private Material ReadMaterial(MessagePackObjectDictionary matDict, bool alpha) { if (matDict.ContainsKey(FileKeys.MATERIAL_NAME)) { string name = matDict[FileKeys.MATERIAL_NAME].AsString(); 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 (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 virtual void Populate(TestCaseMetadaProvider metadataProvider) { _testCase.SourceFile.Copy(_directory); if (_testCase.HasLinkXmlFile) { _testCase.LinkXmlFile.Copy(InputDirectory); } CopyToInputAndExpectations(GetExpectationsAssemblyPath()); foreach (var dep in metadataProvider.AdditionalFilesToSandbox()) { var destination = _directory.Combine(dep.DestinationFileName); dep.Source.FileMustExist().Copy(destination); // In a few niche tests we need to copy pre-built assemblies directly into the input directory. // When this is done, we also need to copy them into the expectations directory so that if they are used // as references we can still compile the expectations version of the assemblies if (destination.Parent == InputDirectory) { dep.Source.Copy(ExpectationsDirectory.Combine(destination.RelativeTo(InputDirectory))); } } foreach (var res in metadataProvider.GetResources()) { res.Source.FileMustExist().Copy(ResourcesDirectory.Combine(res.DestinationFileName)); } foreach (var compileRefInfo in metadataProvider.GetSetupCompileAssembliesBefore()) { var destination = BeforeReferenceSourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists(); compileRefInfo.SourceFiles.Copy(destination); destination = BeforeReferenceResourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists(); compileRefInfo.Resources?.Copy(destination); } foreach (var compileRefInfo in metadataProvider.GetSetupCompileAssembliesAfter()) { var destination = AfterReferenceSourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists(); compileRefInfo.SourceFiles.Copy(destination); destination = AfterReferenceResourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists(); compileRefInfo.Resources?.Copy(destination); } }
private JSONObject WriteMaterial(Material material) { JSONObject materialObject = new JSONObject(); if (ResourcesDirectory.IsCustomMaterial(material)) { materialObject["mode"] = ResourcesDirectory.GetCustomMaterialColorMode(material).ToString(); materialObject["color"] = WriteColor(material.color); materialObject["alpha"] = ResourcesDirectory.GetCustomMaterialIsTransparent(material); } else { materialObject["name"] = material.name; } return(materialObject); }
private static MessagePackObjectDictionary WriteMaterial(Material material) { var materialDict = new MessagePackObjectDictionary(); materialDict[FileKeys.MATERIAL_NAME] = material.name; string colorProp = CustomTexture.IsCustomTexture(material) ? null : ResourcesDirectory.MaterialColorProperty(material); if (colorProp != null) { materialDict[FileKeys.MATERIAL_COLOR] = WriteColor(material.GetColor(colorProp)); materialDict[FileKeys.MATERIAL_COLOR_STYLE] = ResourcesDirectory.GetMaterialColorStyle(material).ToString(); } return(materialDict); }
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(); } }
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 Write(WritingContext context) { var writer = context.Writer; writer.WriteUInt32(Cb); writer.WriteUInt16(MajorRuntimeVersion); writer.WriteUInt16(MinorRuntimeVersion); MetadataDirectory.Write(context); writer.WriteUInt32((uint)Flags); writer.WriteUInt32(EntryPointToken); ResourcesDirectory.Write(context); StrongNameSignatureDirectory.Write(context); CodeManagerTableDirectory.Write(context); VTableFixupsDirectory.Write(context); ExportAddressTableJumpsDirectory.Write(context); ManagedNativeHeaderDirectory.Write(context); }
private void MaterialSelected(Material material) { highlightMaterial = material; if (handler != null) { if (material != null && material.name.EndsWith(PREVIEW_SUFFIX)) { string newPath = materialDirectory + "/" + material.name.Substring(0, material.name.Length - PREVIEW_SUFFIX.Length); material = ResourcesDirectory.GetMaterial(newPath); } handler(material); } if (closeOnSelect) { Destroy(this); } }
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 static MessagePackObjectDictionary WriteMaterial(Material material, bool specifyAlphaMode) { var materialDict = new MessagePackObjectDictionary(); if (ResourcesDirectory.IsCustomMaterial(material)) { materialDict[FileKeys.MATERIAL_MODE] = ResourcesDirectory.GetCustomMaterialColorMode(material).ToString(); materialDict[FileKeys.MATERIAL_COLOR] = WriteColor(material.color); if (specifyAlphaMode) { materialDict[FileKeys.MATERIAL_ALPHA] = ResourcesDirectory.GetCustomMaterialIsTransparent(material); } } else { materialDict[FileKeys.MATERIAL_NAME] = material.name; } return(materialDict); }
void UpdateMaterialDirectory() { materialSubDirectories = new List <string>(); if (materialDirectory != rootDirectory) { materialSubDirectories.Add(BACK_BUTTON); } materials = new List <Material>(); foreach (string dirEntry in ResourcesDirectory.dirList) { if (dirEntry.Length <= 2) { continue; } string newDirEntry = dirEntry.Substring(2); string fileName = Path.GetFileName(newDirEntry); string extension = Path.GetExtension(newDirEntry); string directory = Path.GetDirectoryName(newDirEntry); if (fileName.StartsWith("$")) { continue; // special alternate materials for game } if (directory != materialDirectory) { continue; } if (extension == "") { materialSubDirectories.Add(fileName); } else if (extension == ".mat") { if (fileName.EndsWith(PREVIEW_SUFFIX_EXT)) { materials.RemoveAt(materials.Count - 1); // special preview material which replaces the previous } materials.Add(ResourcesDirectory.GetMaterial(newDirEntry)); } } AssetManager.UnusedAssets(); }
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 static List <string> BuildWorld(WorldFileReader reader, Transform cameraPivot, VoxelArray voxelArray, bool 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; } try { return(reader.BuildWorld(cameraPivot, voxelArray, editor)); } catch (MapReadException e) { throw e; } catch (Exception e) { throw new MapReadException("An error occurred while reading the file", e); } }
public void Start() { if (colorModeSet == ColorModeSet.UNLIT_ONLY) { colorMode = ColorMode.UNLIT; } else { colorMode = ColorMode.MATTE; } materialDirectory = rootDirectory; UpdateMaterialDirectory(); if (highlightMaterial != null && ResourcesDirectory.IsCustomMaterial(highlightMaterial)) { highlightMaterial = Instantiate(highlightMaterial); tab = 0; colorMode = ResourcesDirectory.GetCustomMaterialColorMode(highlightMaterial); } else { tab = 1; } }
public virtual void Populate(TestCaseCompilationMetadataProvider metadataProvider) { _testCase.SourceFile.Copy(_directory); if (_testCase.HasLinkXmlFile) { _testCase.LinkXmlFile.Copy(InputDirectory); } CopyToInputAndExpectations(GetExpectationsAssemblyPath()); foreach (var dep in metadataProvider.AdditionalFilesToSandbox()) { var destination = _directory.Combine(dep.DestinationFileName); dep.Source.FileMustExist().Copy(destination); // In a few niche tests we need to copy pre-built assemblies directly into the input directory. // When this is done, we also need to copy them into the expectations directory so that if they are used // as references we can still compile the expectations version of the assemblies if (destination.Parent == InputDirectory) { dep.Source.Copy(ExpectationsDirectory.Combine(destination.RelativeTo(InputDirectory))); } } // Copy non class library dependencies to the sandbox foreach (var fileName in metadataProvider.GetReferenceValues()) { if (!fileName.StartsWith("System.", StringComparison.Ordinal) && !fileName.StartsWith("Mono.", StringComparison.Ordinal) && !fileName.StartsWith("Microsoft.", StringComparison.Ordinal)) { CopyToInputAndExpectations(_testCase.SourceFile.Parent.Combine(fileName.ToNPath())); } } foreach (var referenceDependency in metadataProvider.GetReferenceDependencies()) { CopyToInputAndExpectations(_testCase.SourceFile.Parent.Combine(referenceDependency.ToNPath())); } foreach (var res in metadataProvider.GetResources()) { res.Source.FileMustExist().Copy(ResourcesDirectory.Combine(res.DestinationFileName)); } foreach (var compileRefInfo in metadataProvider.GetSetupCompileAssembliesBefore()) { var destination = BeforeReferenceSourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists(); compileRefInfo.SourceFiles.Copy(destination); destination = BeforeReferenceResourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists(); if (compileRefInfo.Resources == null) { continue; } foreach (var res in compileRefInfo.Resources) { res.Source.FileMustExist().Copy(destination.Combine(res.DestinationFileName)); } } foreach (var compileRefInfo in metadataProvider.GetSetupCompileAssembliesAfter()) { var destination = AfterReferenceSourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists(); compileRefInfo.SourceFiles.Copy(destination); destination = AfterReferenceResourceDirectoryFor(compileRefInfo.OutputName).EnsureDirectoryExists(); if (compileRefInfo.Resources == null) { continue; } foreach (var res in compileRefInfo.Resources) { res.Source.FileMustExist().Copy(destination.Combine(res.DestinationFileName)); } } }
// 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); }
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(); }
public BallObject() { material = ResourcesDirectory.MakeCustomMaterial(ColorMode.MATTE, true); material.color = Color.red; }
/// sphere cast down just beyond the bottom of the capsule to see if the capsule is colliding round the bottom private void GroundCheck() { previouslyGrounded = grounded; if (disableGroundCheck) { disableGroundCheck = false; grounded = false; jumping = true; } RaycastHit hitInfo; if (Physics.SphereCast(transform.position, capsule.radius * (1.0f - shellOffset), Vector3.down, out hitInfo, ((capsule.height / 2f) - capsule.radius) + groundCheckDistance, Physics.AllLayers, QueryTriggerInteraction.Ignore)) { grounded = true; groundContactNormal = hitInfo.normal; // move with moving object Vector3 move = Vector3.zero; foreach (MotionComponent motionComponent in hitInfo.transform.GetComponents <MotionComponent>()) { if (motionComponent.enabled) { move += motionComponent.GetTranslateFixed(); Vector3 relPos = transform.position - motionComponent.transform.position; move += (motionComponent.GetRotateFixed() * relPos) - relPos; } } move.y = 0; if (move != Vector3.zero) { rigidBody.MovePosition(rigidBody.position + move); } // determine footstep sound if (hitInfo.collider.gameObject.tag == "Voxel") { var voxelComponent = hitInfo.collider.GetComponent <VoxelComponent>(); Voxel voxel; int faceI; if (voxelComponent.GetSubstance() != null) { // substances use convex hulls which don't have submeshes // so just use the top face of the voxel voxel = voxelComponent.GetSingleBlock(); faceI = 3; } else { int hitVertexI = TouchListener.GetRaycastHitVertexIndex(hitInfo); voxelComponent.GetVoxelFaceForVertex(hitVertexI, out voxel, out faceI); } footstepSound = voxel.faces[faceI].GetSound(); } else { Renderer hitRender = hitInfo.collider.GetComponent <Renderer>(); if (hitRender != null) { // regular .material has (Instance) suffix footstepSound = ResourcesDirectory.GetMaterialSound(hitRender.sharedMaterial); } else { footstepSound = MaterialSound.GENERIC; } } } else { grounded = false; groundContactNormal = Vector3.up; } if (!previouslyGrounded && grounded && jumping) { jumping = false; } }
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); }