/// <summary> /// Getting material from cache or instantiating new one. /// </summary> /// <returns></returns> public static Material GetOrCreateMaterial(Material baseMaterial, Texture2D texture, out MaterialKey materialKey) { if (baseMaterial == null || texture == null) { materialKey = null; return(null); } MaterialValue matValue; var key = materialKey = new MaterialKey(baseMaterial, texture); if (!MaterialMap.TryGetValue(key, out matValue)) { var mat = (Material)Instantiate(baseMaterial); mat.name = GeneratedMaterialName; mat.mainTexture = texture; MaterialMap[key] = matValue = new MaterialValue(mat, 1); } else { matValue.UsageCount++; } return(matValue.Material); }
/// <summary> /// Getting material from cache or instantiating new one. /// </summary> /// <returns></returns> public Material GetOrCreateMaterial() { TryReleaseMaterial(); if (Material == null || Sprite == null) { return(null); } MaterialValue matValue; var key = new MaterialKey(Material, Sprite.texture); if (!MaterialMap.TryGetValue(key, out matValue)) { var mat = (Material)Instantiate(Material); mat.name = GeneratedMaterialName; mat.mainTexture = Sprite.texture; MaterialMap[key] = matValue = new MaterialValue(mat, 1); } else { matValue.UsageCount++; } _oldMaterialKey = key; return(matValue.Material); }
/// <summary> /// Getting material from cache or instantiating new one. /// </summary> /// <returns></returns> public Material GetOrCreateMaterial() { TryReleaseMaterial(); if (material == null || sprite == null) { return(null); } MaterialValue matValue; MaterialKey key = new MaterialKey(material, sprite.texture); if (!materialMap.TryGetValue(key, out matValue)) { Material mat = Instantiate(material); mat.name = GeneratedMaterialName; mat.mainTexture = sprite.texture; materialMap[key] = matValue = new MaterialValue(mat, 1); } else { matValue.usageCount++; } _oldMaterialKey = key; return(matValue.material); }
public void SetObjectMaterialValue(GameObject gobject, MaterialValue materialValue) { Node node = SyncData.nodes[gobject.name]; Utils.SetMaterialValue(node.prefab, materialValue); Utils.SetMaterialValue(gobject, materialValue); InformModification(gobject); }
public static Material fromDynamic(dynamic json) { Material material = new Material(); material.materials = new List <MaterialValue>(); foreach (var data in json) { material.materials.Add(MaterialValue.fromDynamic(data)); } return(material); }
public static void CopyTo(this MaterialChannel srcChannel, ChannelBuilder dstChannel) { Guard.NotNull(srcChannel, nameof(srcChannel)); Guard.NotNull(dstChannel, nameof(dstChannel)); foreach (var srcProp in srcChannel.Parameters) { dstChannel.Parameters[srcProp.Name] = MaterialValue.CreateFrom(srcProp.Value); } if (srcChannel.Texture == null) { return; } if (dstChannel.Texture == null) { dstChannel.UseTexture(); } dstChannel.Texture.SetNameAndExtrasFrom(srcChannel.Texture); dstChannel.Texture.CoordinateSet = srcChannel.TextureCoordinate; if (srcChannel.TextureSampler != null) { dstChannel.Texture.MinFilter = srcChannel.TextureSampler.MinFilter; dstChannel.Texture.MagFilter = srcChannel.TextureSampler.MagFilter; dstChannel.Texture.WrapS = srcChannel.TextureSampler.WrapS; dstChannel.Texture.WrapT = srcChannel.TextureSampler.WrapT; } var srcXform = srcChannel.TextureTransform; if (srcXform != null) { dstChannel.Texture.WithTransform(srcXform.Offset, srcXform.Scale, srcXform.Rotation, srcXform.TextureCoordinateOverride); } ImageBuilder _convert(Image src) { if (src == null) { return(null); } return(ImageBuilder.From(src.Content, src.Name, src.Extras.DeepClone())); } dstChannel.Texture.PrimaryImage = _convert(srcChannel.Texture.PrimaryImage); dstChannel.Texture.FallbackImage = _convert(srcChannel.Texture.FallbackImage); }
// // Refreshes the list of presets. // public static void Initialize() { // Count the number of presets. int numPresets = 12; values = new MaterialValue[numPresets]; // Create all the built-in presets. values[0] = new MaterialValue(0.10f, 0.20f, 0.30f, 0.05f, 0.100f, 0.050f, 0.030f); values[1] = new MaterialValue(0.03f, 0.04f, 0.07f, 0.05f, 0.015f, 0.015f, 0.015f); values[2] = new MaterialValue(0.05f, 0.07f, 0.08f, 0.05f, 0.015f, 0.002f, 0.001f); values[3] = new MaterialValue(0.01f, 0.02f, 0.02f, 0.05f, 0.060f, 0.044f, 0.011f); values[4] = new MaterialValue(0.60f, 0.70f, 0.80f, 0.05f, 0.031f, 0.012f, 0.008f); values[5] = new MaterialValue(0.24f, 0.69f, 0.73f, 0.05f, 0.020f, 0.005f, 0.003f); values[6] = new MaterialValue(0.06f, 0.03f, 0.02f, 0.05f, 0.060f, 0.044f, 0.011f); values[7] = new MaterialValue(0.12f, 0.06f, 0.04f, 0.05f, 0.056f, 0.056f, 0.004f); values[8] = new MaterialValue(0.11f, 0.07f, 0.06f, 0.05f, 0.070f, 0.014f, 0.005f); values[9] = new MaterialValue(0.20f, 0.07f, 0.06f, 0.05f, 0.200f, 0.025f, 0.010f); values[10] = new MaterialValue(0.13f, 0.20f, 0.24f, 0.05f, 0.015f, 0.002f, 0.001f); values[11] = new MaterialValue(); }