protected void Functions_CustomCode(SWDataCode code) { if (!code.IsFunction()) { return; } Dictionary <SWDataType, string> dic = new Dictionary <SWDataType, string> (); dic.Add(SWDataType._Alpha, "float"); dic.Add(SWDataType._UV, "float2"); dic.Add(SWDataType._Color, "float4"); string param = ""; for (int i = 0; i < code.inputs.Count; i++) { var input = code.inputs [i]; if (i != 0) { param += ","; } param += string.Format(" {0} {1} ", dic [input.GetType()], input.name); } string content = "\t\t\t\t" + code.code; content = content.Replace("\n", "\n\t\t\t\t"); string str = string.Format("\t\t\t{0} {1}({2})\n\t\t\t{{\n{3}\n\t\t\t}}", dic [code.output.GetType()], code.name, param, content); StringAddLine(str); }
protected void Property_Code(SWNodeBase node, bool isField) { if (node is SWNodeCode) { var data = node.data; SWDataCode code = window.dataCode.CodeOfName(data.code); foreach (var paramUse in data.codeParams) { if (code.ContainParam(paramUse.n)) { var param = code.GetParam(paramUse.n); if (param != null && param.IsProperty()) { if (isField) { if (param.type == CodeParamType.Range) { StringAddLine(string.Format("\t\t{0}_{2} (\"{1}_{2}\", Range({4},{5})) = {3}", node.data.iName, node.data.name, paramUse.n, paramUse.fv.ToStringEX(), param.min.ToStringEX(), param.max.ToStringEX())); } else { StringAddLine(string.Format("\t\t{0}_{2} (\"{0}_{2}\", float) = {3}", node.data.iName, node.data.name, paramUse.n, paramUse.fv.ToStringEX())); } } else { StringAddLine(string.Format("\t\t\tfloat {0}_{1};", node.data.iName, paramUse.n)); } } } } } }
void Code_Add(SWDataCode code = null) { if (code == null) { code = new SWDataCode(NextCodeParam(), nodeCode.data.codeType); } dataCode.codes.Add(code); Code_Select(code.name); }
public SWDataCode Clone(string newName) { SWDataCode item = new SWDataCode(newName, output.type); item.name = newName; item.description = description; item.output = output.Clone(); foreach (var input in inputs) { item.inputs.Add(input.Clone()); } item.code = code; return(item); }
public static SWData_Codes Load(string swFolder) { string folder = CodeFolder(swFolder); SWData_Codes codes = new SWData_Codes(); DirectoryInfo d = new DirectoryInfo(folder); foreach (var item in d.GetFiles()) { if (item.FullName.EndsWith(".swcode")) { SWDataCode code = LoadSub(item.FullName); codes.codes.Add(code); } } return(codes); }
void Code_Duplicate(SWDataCode item) { string name = item.name; int index = -1; int number = 1; var cs = name.ToCharArray(); for (int i = cs.Length - 1; i >= 0; i--) { if (cs [i] >= '0' && cs [i] <= '9') { index = i; } else { break; } } if (index >= 0) { name = item.name.Substring(0, index); number = int.Parse(item.name.Substring(index)) + 1; } else { name = item.name; number = 1; } string newName = name + number; while (dataCode.CodeOfName(newName) != null) { number++; newName = name + number; } SWDataCode newItem = item.Clone(newName); Code_Add(newItem); }
private static void SaveSub(string path, SWDataCode data) { string txt = JsonUtility.ToJson(data); File.WriteAllText(path, txt); }