public static MaterialRestoreData GetRestoreData(Material material) { if (material == null || material.shader == null) { return(null); } if (!ShaderInfoDatabase.TypeData.TryGetValue(GetLastShaderName(material.shader.name), out var properties)) { Debug.LogWarningFormat( "Nova: Shader {0} is not in shader info database. The material will not be restored correctly.", material.shader.name); return(null); } var data = new MaterialRestoreData { isRestorableMaterial = material is RestorableMaterial, shaderName = material.shader.name }; foreach (var p in properties) { var name = p.Key; var type = p.Value; AddMaterialPropertyData(material, data, name, type); } return(data); }
public CompositeSpriteControllerBaseRestoreData(CompositeSpriteControllerBaseRestoreData baseData) { currentImageName = baseData.currentImageName; transformRestoreData = baseData.transformRestoreData; color = baseData.color; materialRestoreData = baseData.materialRestoreData; renderQueue = baseData.renderQueue; }
public CompositeSpriteControllerBaseRestoreData(string currentImageName, Transform transform, Color color, MaterialRestoreData materialRestoreData, int renderQueue) { this.currentImageName = currentImageName; transformRestoreData = new TransformRestoreData(transform); this.color = color; this.materialRestoreData = materialRestoreData; this.renderQueue = renderQueue; }
public static Material RestoreMaterialFromData(MaterialRestoreData data, MaterialFactory factory) { Assert.IsNotNull(factory); // no data supplied, return nothing if (data == null) { return(null); } // preserve data consistency of material factor var mat = data.isRestorableMaterial ? factory.GetRestorableMaterial(data.shaderName) : factory.Get(data.shaderName); foreach (var c in data.colorDatas) { mat.SetColor(c.Key, c.Value); } foreach (var v in data.vectorDatas) { mat.SetVector(v.Key, v.Value); } foreach (var f in data.floatDatas) { mat.SetFloat(f.Key, f.Value); } foreach (var so in data.textureScaleOffsets) { var name = so.Key; so.Value.Split(out var s, out var o); mat.SetTextureScale(name, s); mat.SetTextureOffset(name, o); } if (!data.isRestorableMaterial) { return(mat); } var res = mat as RestorableMaterial; Assert.IsNotNull(res); foreach (var t in data.textureNames) { res.SetTexturePath(t.Key, t.Value); } return(res); }
static int GetRestoreData(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); UnityEngine.Material arg0 = (UnityEngine.Material)ToLua.CheckObject <UnityEngine.Material>(L, 1); Nova.MaterialRestoreData o = Nova.RestorableMaterial.GetRestoreData(arg0); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int RestoreMaterialFromData(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); Nova.MaterialRestoreData arg0 = (Nova.MaterialRestoreData)ToLua.CheckObject <Nova.MaterialRestoreData>(L, 1); Nova.MaterialFactory arg1 = (Nova.MaterialFactory)ToLua.CheckObject(L, 2, typeof(Nova.MaterialFactory)); UnityEngine.Material o = Nova.RestorableMaterial.RestoreMaterialFromData(arg0, arg1); ToLua.Push(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
private static void AddMaterialPropertyData(Material mat, MaterialRestoreData data, string name, ShaderPropertyType type) { switch (type) { case ShaderPropertyType.Color: var c = mat.GetColor(name); data.colorDatas.Add(name, c); break; case ShaderPropertyType.Vector: var v = mat.GetVector(name); data.vectorDatas.Add(name, v); break; case ShaderPropertyType.Float: var f = mat.GetFloat(name); data.floatDatas.Add(name, f); break; case ShaderPropertyType.TexEnv: var offset = mat.GetTextureOffset(name); var scale = mat.GetTextureScale(name); data.textureScaleOffsets.Add(name, new Vector4Data(scale, offset)); var res = mat as RestorableMaterial; if (res == null) { break; } if (!res.textureNames.TryGetValue(name, out string tn)) { break; } data.textureNames.Add(name, tn); break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } }