void CreateClassFile(GUIGenerator_Elem_Base class_elem) { class_elem.className = GUIGenerator_Macros.text_classPrefix + canvasName + class_elem.nameMain; class_elem.classInstanceName = GUIGenerator_Macros.text_classPrefix.ToLower() + class_elem.nameMain; class_elem.classButtonListenerFunction = GUIGenerator_Macros.text_function_OnButtonCallback_Prefix.Replace(GUIGenerator_Macros.replacement_name, class_elem.nameMain); class_elem.classToggleListenerFunction = GUIGenerator_Macros.text_function_OnToggleCallback_Prefix.Replace(GUIGenerator_Macros.replacement_name, class_elem.nameMain); string classContent = ""; classContent += GUIGenerator_Macros.text_includes; classContent += GUIGenerator_Macros.text_classDeclaration.Replace(GUIGenerator_Macros.replacement_name, class_elem.className); classContent += GUIGenerator_Macros.text_function_InitializeValues_Method_Comment. Replace(GUIGenerator_Macros.replacement_variable, class_elem.nameMain.ToUpper()); classContent += GUIGenerator_Macros.text_variableDeclaration. Replace(GUIGenerator_Macros.replacement_type, GUIGenerator_Macros.typeFormated_gameObject). Replace(GUIGenerator_Macros.replacement_name, class_elem.variableName_obj); if (class_elem.type == GUIGenerator_Elem_Base.TYPE.OTHER) { } else { classContent += GUIGenerator_Macros.text_variableDeclaration. Replace(GUIGenerator_Macros.replacement_type, class_elem.classTypeFormated). Replace(GUIGenerator_Macros.replacement_name, class_elem.variableName); } classContent += "\n\n"; for (int i = 0; i < class_elem.children.Count; ++i) { classContent += GUIGenerator_Macros.text_function_InitializeValues_Method_Comment. Replace(GUIGenerator_Macros.replacement_variable, class_elem.children[i].nameMain.ToUpper()); CreateVariablesNames(class_elem.children[i], ref classContent); classContent += "\n"; } classContent += "\n\n"; classContent += GUIGenerator_Macros.text_function_UpdateValues_Header; CreateFunctionUpdateValues(class_elem, ref classContent); classContent = classContent.Substring(0, classContent.Length - 1); classContent += GUIGenerator_Macros.text_function_End; classContent += GUIGenerator_Macros.text_classEnd; File.WriteAllText(directory_GUIGeneratorScripts + class_elem.className + GUIGenerator_Macros.file_end, classContent); }
void CreateVariablesNames(GUIGenerator_Elem_Base elem, ref string str) { str += GUIGenerator_Macros.text_variableDeclaration.Replace(GUIGenerator_Macros.replacement_type, GUIGenerator_Macros.typeFormated_gameObject). Replace(GUIGenerator_Macros.replacement_name, elem.variableName_obj); if (elem.type == GUIGenerator_Elem_Base.TYPE.OTHER) { } else { str += GUIGenerator_Macros.text_variableDeclaration.Replace(GUIGenerator_Macros.replacement_type, elem.classTypeFormated). Replace(GUIGenerator_Macros.replacement_name, elem.variableName); } for (int i = 0; i < elem.children.Count; ++i) { str += "\n"; CreateVariablesNames(elem.children[i], ref str); } }
void GetAllComponents(GameObject obj, ref List <GUIGenerator_Elem_Base> list, GUIGenerator_Elem_Base parent_elem = null) { for (int i = 0; i < obj.transform.childCount; ++i) { GUIGenerator_Elem_Base elem = new GUIGenerator_Elem_Base(); elem.parent = parent_elem; elem.GenerateInfo(obj.transform.GetChild(i).gameObject); if (elem.parent == null) { list.Add(elem); } else { elem.parent.children.Add(elem); } GetAllComponents(elem.obj, ref list, elem); } }
void FindAndResolveRepeatedElements(List <GUIGenerator_Elem_Base> list) { for (int k = 0; k < list.Count; ++k) { List <GUIGenerator_Elem_Base> full_list = new List <GUIGenerator_Elem_Base>(); if (list[k].children.Count > 0) { GetAllElements(list[k].children, ref full_list); int ac = 1; for (int i = 0; i < full_list.Count; ++i) { GUIGenerator_Elem_Base elem1 = full_list[i]; for (int j = 0; j < full_list.Count; ++j) { if (i != j) { GUIGenerator_Elem_Base elem2 = full_list[j]; if (elem1.variableName == elem2.variableName) { elem1.obj.name += "_" + ac; elem1.nameMain += "_" + ac; elem1.UpdateVariableNames(); ac++; elem2.obj.name += "_" + ac; elem2.nameMain += "_" + ac; elem2.UpdateVariableNames(); ac++; } } } } } } }
void CreateFunctionUpdateValues(GUIGenerator_Elem_Base class_elem, ref string str) { string parent = ""; if (class_elem.parent == null) { parent = GUIGenerator_Macros.text_function_UpdateValues_ReplacementParent; str += GUIGenerator_Macros.text_function_UpdateValues_GetGameObjectParent. Replace(GUIGenerator_Macros.replacement_variable, class_elem.variableName_obj). Replace(GUIGenerator_Macros.replacement_variableParent, parent); } else { parent = class_elem.parent.variableName_obj; str += GUIGenerator_Macros.text_function_UpdateValues_GetGameObject. Replace(GUIGenerator_Macros.replacement_variable, class_elem.variableName_obj). Replace(GUIGenerator_Macros.replacement_variableParent, parent). Replace(GUIGenerator_Macros.replacement_name, class_elem.nameOrig); } if (class_elem.type != GUIGenerator_Elem_Base.TYPE.OTHER) { str += GUIGenerator_Macros.text_function_UpdateValues_GetComponent. Replace(GUIGenerator_Macros.replacement_variable, class_elem.variableName). Replace(GUIGenerator_Macros.replacement_variableParent, class_elem.variableName_obj). Replace(GUIGenerator_Macros.replacement_name, class_elem.nameOrig). Replace(GUIGenerator_Macros.replacement_type, class_elem.classType); } str += "\n"; for (int i = 0; i < class_elem.children.Count; ++i) { CreateFunctionUpdateValues(class_elem.children[i], ref str); } }
void GetAllComponents(GameObject obj, ref List<GUIGenerator_Elem_Base> list, GUIGenerator_Elem_Base parent_elem = null) { for(int i = 0 ; i < obj.transform.childCount ; ++i){ GUIGenerator_Elem_Base elem = new GUIGenerator_Elem_Base(); elem.parent = parent_elem; elem.GenerateInfo(obj.transform.GetChild(i).gameObject); if(elem.parent == null){ list.Add(elem); } else{ elem.parent.children.Add(elem); } GetAllComponents(elem.obj, ref list, elem); } }
void CreateVariablesNames(GUIGenerator_Elem_Base elem, ref string str) { str += GUIGenerator_Macros.text_variableDeclaration.Replace(GUIGenerator_Macros.replacement_type, GUIGenerator_Macros.typeFormated_gameObject). Replace(GUIGenerator_Macros.replacement_name, elem.variableName_obj); if(elem.type == GUIGenerator_Elem_Base.TYPE.OTHER){ } else{ str += GUIGenerator_Macros.text_variableDeclaration.Replace(GUIGenerator_Macros.replacement_type, elem.classTypeFormated). Replace(GUIGenerator_Macros.replacement_name, elem.variableName); } for(int i = 0 ; i < elem.children.Count ; ++i){ str += "\n"; CreateVariablesNames(elem.children[i], ref str); } }
void CreateFunctionUpdateValues(GUIGenerator_Elem_Base class_elem, ref string str) { string parent = ""; if(class_elem.parent == null){ parent = GUIGenerator_Macros.text_function_UpdateValues_ReplacementParent; str += GUIGenerator_Macros.text_function_UpdateValues_GetGameObjectParent. Replace(GUIGenerator_Macros.replacement_variable,class_elem.variableName_obj). Replace(GUIGenerator_Macros.replacement_variableParent,parent); } else{ parent = class_elem.parent.variableName_obj; str += GUIGenerator_Macros.text_function_UpdateValues_GetGameObject. Replace(GUIGenerator_Macros.replacement_variable,class_elem.variableName_obj). Replace(GUIGenerator_Macros.replacement_variableParent,parent). Replace(GUIGenerator_Macros.replacement_name,class_elem.nameOrig); } if(class_elem.type != GUIGenerator_Elem_Base.TYPE.OTHER){ str += GUIGenerator_Macros.text_function_UpdateValues_GetComponent. Replace(GUIGenerator_Macros.replacement_variable,class_elem.variableName). Replace(GUIGenerator_Macros.replacement_variableParent,class_elem.variableName_obj). Replace(GUIGenerator_Macros.replacement_name,class_elem.nameOrig). Replace(GUIGenerator_Macros.replacement_type,class_elem.classType); } str += "\n"; for(int i = 0 ; i < class_elem.children.Count ; ++i){ CreateFunctionUpdateValues(class_elem.children[i], ref str); } }
void CreateClassFile(GUIGenerator_Elem_Base class_elem) { class_elem.className = GUIGenerator_Macros.text_classPrefix + canvasName + class_elem.name; class_elem.classInstanceName = GUIGenerator_Macros.text_classPrefix.ToLower() + class_elem.name; class_elem.classButtonListenerFunction = GUIGenerator_Macros.text_function_OnButtonCallback_Prefix.Replace(GUIGenerator_Macros.replacement_name,class_elem.name); class_elem.classToggleListenerFunction = GUIGenerator_Macros.text_function_OnToggleCallback_Prefix.Replace(GUIGenerator_Macros.replacement_name,class_elem.name); string classContent = ""; classContent += GUIGenerator_Macros.text_includes; classContent += GUIGenerator_Macros.text_classDeclaration.Replace(GUIGenerator_Macros.replacement_name,class_elem.className); classContent += GUIGenerator_Macros.text_function_InitializeValues_Method_Comment. Replace(GUIGenerator_Macros.replacement_variable, class_elem.name.ToUpper()); classContent += GUIGenerator_Macros.text_variableDeclaration. Replace(GUIGenerator_Macros.replacement_type, GUIGenerator_Macros.typeFormated_gameObject). Replace(GUIGenerator_Macros.replacement_name, class_elem.variableName_obj); if(class_elem.type == GUIGenerator_Elem_Base.TYPE.OTHER){ } else{ classContent += GUIGenerator_Macros.text_variableDeclaration. Replace(GUIGenerator_Macros.replacement_type, class_elem.classTypeFormated). Replace(GUIGenerator_Macros.replacement_name, class_elem.variableName); } classContent += "\n\n"; for(int i = 0 ; i < class_elem.children.Count ; ++i){ classContent += GUIGenerator_Macros.text_function_InitializeValues_Method_Comment. Replace(GUIGenerator_Macros.replacement_variable, class_elem.children[i].name.ToUpper()); CreateVariablesNames(class_elem.children[i], ref classContent); classContent += "\n"; } classContent += "\n\n"; classContent += GUIGenerator_Macros.text_function_UpdateValues_Header; CreateFunctionUpdateValues(class_elem, ref classContent); classContent = classContent.Substring(0, classContent.Length-1); classContent += GUIGenerator_Macros.text_function_End; classContent += GUIGenerator_Macros.text_classEnd; File.WriteAllText(directory_GUIGeneratorScripts + class_elem.className + GUIGenerator_Macros.file_end, classContent); }
bool HasToggleRecursive(GUIGenerator_Elem_Base elem) { if(elem.type == TYPE.TOGGLE) return true; if(elem.children.Count > 0){ for(int i = 0 ; i < elem.children.Count ; ++i){ if(HasToggleRecursive(elem.children[i])){ return true; } } return false; } else return false; }