public static void Save(string path, SWData data) { string s = JsonUtility.ToJson(data); s = "//" + SWGlobalSettings.ShaderID + s + "\n"; s += File.ReadAllText(path); File.WriteAllText(path, s); }
public static string DataToText(List <SWDataNode> nodes) { SWData data = new SWData(); data.nodes = nodes; string s = JsonUtility.ToJson(data); return(s); }
public static void FixParams(SWData data) { foreach (var item in data.nodes) { FixParam(data, ref item.effectData.t_Param); FixParam(data, ref item.effectData.r_Param); FixParam(data, ref item.effectData.s_Param); FixParam(data, ref item.effectData.pop_Param); FixParam(data, ref item.effectDataUV.param); FixParam(data, ref item.effectDataColor.param); } }
public static SWData Load(string path) { string jsonTxt = GetShaderJson(File.ReadAllLines(path)); if (!string.IsNullOrEmpty(jsonTxt)) { SWData e = JsonUtility.FromJson <SWData> (jsonTxt); VersionUpdate(e); return(e); } return(null); }
public static bool ParamIsPredefined(SWData data, string param) { if (param == "_Time.y") { return(true); } foreach (var item in data.paramList) { if (item.name == param) { return(true); } } return(false); }
public static void FixParam(SWData data, ref string param) { //1 _TimeAll->_Time _TimeMod->1 param = param.Replace("_TimeAll", "_Time"); param = param.Replace("_TimeMod", "1"); //_Time.y*2 ->(_Time.y*2) if (!ParamIsPredefined(data, param)) { if (param [0] != '(' || param [param.Length - 1] != ')') { param = string.Format("({0})", param); } } }
public static void VersionUpdate(SWData data) { if (data.version >= SWGlobalSettings.version) { return; } if (data.version < 120) { VersionUpdate_120(data); } if (data.version < 121) { VersionUpdate_121(data); } FixParams(data); data.version = SWGlobalSettings.version; }
public void SetMaterial(Material mat, SWData data, Sprite sp, float mulX, float mulY) { SWShaderType type = data.shaderType; for (int i = 0; i < objs.Count; i++) { objs [i].SetActive(false); } int index = (int)type; objs [index].SetActive(true); if (type == SWShaderType.normal) { rNormal.sharedMaterial = mat; } else if (type == SWShaderType.ui) { uiImage.material = mat; uiImage.sprite = sp; } else if (type == SWShaderType.uiFont) { uiText.material = mat; } else if (type == SWShaderType.sprite) { rSprite.sharedMaterial = mat; rSprite.sprite = sp; if (sp != null) { float xUnits = sp.rect.width / data.pixelPerUnit * mulX; float yUnits = sp.rect.height / data.pixelPerUnit * mulY; rSprite.transform.localScale = new Vector3(1 / xUnits, 1 / yUnits, 1); } } else if (type == SWShaderType.ngui_ui2dSprite) { uiImage.material = mat; uiImage.sprite = sp; } }
public void SetMaterial(Material mat, SWData data, Sprite sprite) { if (data.shaderType == SWShaderType.sprite) { int orginWidth = 0; int orginHeight = 0; if (sprite != null && SWCommon.TexureOriginSize(sprite.texture, out orginWidth, out orginHeight)) { Init(); material = mat; float mulX = (float)orginWidth / (float)sprite.texture.width; float mulY = (float)orginHeight / (float)sprite.texture.height; preview.SetMaterial(mat, data, sprite, mulX, mulY); } } else { Init(); material = mat; preview.SetMaterial(mat, data, sprite, 0, 0); } }
protected static void VersionUpdate_121(SWData data) { foreach (var node in data.nodes) { //color node now name as image node if (node.type == SWNodeType.color) { node.name = node.name.Replace("color", "image"); node.type = SWNodeType.image; } //new ports foreach (var item in node.parent) { node.parentPort.Add(0); } foreach (var item in node.children) { node.childrenPort.Add(0); } } }
protected static void VersionUpdate_130(SWData data) { List <SWDataNode> mixerNodes = new List <SWDataNode> (); foreach (var node in data.nodes) { node.dirty = true; if (node.type == SWNodeType.mixer) { mixerNodes.Add(node); } } foreach (var node in mixerNodes) { for (int i = 0; i < node.children.Count; i++) { node.childrenPort [i]++; } string s = JsonUtility.ToJson(node); var childNode = JsonUtility.FromJson <SWDataNode> (s); node.childPortNumber++; childNode.AssingNewID(); childNode.childPortNumber = 1; childNode.children.Clear(); childNode.childrenPort.Clear(); childNode.parent.Clear(); childNode.parentPort.Clear(); childNode.rect = new Rect(childNode.rect.x - 100, childNode.rect.y, childNode.rect.width, childNode.rect.height); childNode.name = "alpha" + NewGUID(); childNode.type = SWNodeType.alpha; AddConnection(childNode, 0, node, 0); data.nodes.Add(childNode); } }
public void SetMaterial(Material mat, SWData data, Sprite sprite) { Init(); material = mat; preview.SetMaterial(mat, data, sprite); }
public static List <SWDataNode> TextToData(string text) { SWData e = JsonUtility.FromJson <SWData> (text); return(e.nodes); }