private static void Generate(string pathToData, bool recompile, bool minimalScriptsSize, System.Func <FD.FlowWindow, bool> predicate) { var filename = Path.GetFileName(pathToData); if (string.IsNullOrEmpty(pathToData) == true) { throw new Exception(string.Format("`pathToData` is wrong: {0}. Filename: {1}", pathToData, filename)); } var directory = pathToData.Replace(filename, string.Empty); CompilerSystem.currentProject = Path.GetFileNameWithoutExtension(pathToData); CompilerSystem.currentProjectDirectory = directory; var basePath = directory + CompilerSystem.currentProject; IO.CreateDirectory(basePath, string.Empty); IO.CreateDirectory(basePath, FlowDatabase.OTHER_NAME); predicate = predicate ?? delegate { return(true); }; AssetDatabase.StartAssetEditing(); { try { var windows = FlowSystem.GetContainersAndWindows().Where(w => w.CanCompiled() && predicate(w)); //var windows = FlowSystem.GetContainers().Where(w => w.CanCompiled() && predicate(w)); foreach (var each in windows) { var relativePath = IO.GetRelativePath(each, "/"); CompilerSystem.GenerateWindow(string.Format("{0}{1}/", basePath, relativePath), each, recompile, minimalScriptsSize); } // Generate Base Files var newInfo = new Tpl.Info(CompilerSystem.currentNamespace, "Container", "ContainerBase", "LayoutWindowType", basePath); var baseClassTemplate = TemplateGenerator.GenerateWindowLayoutContainerBaseClass(newInfo.baseClassname, newInfo.baseNamespace, newInfo.containerClassName); var derivedClassTemplate = TemplateGenerator.GenerateWindowLayoutDerivedClass(newInfo.classname, newInfo.baseClassname, newInfo.baseNamespace); IO.CreateFile(basePath, newInfo.baseClassnameFile, baseClassTemplate, rewrite: true); IO.CreateFile(basePath, newInfo.classnameFile, derivedClassTemplate, rewrite: false); } catch (Exception e) { if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) { UnityEngine.Debug.LogException(e); } } } AssetDatabase.StopAssetEditing(); AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); FlowSystem.SetDirty(); FlowSystem.Save(); }
public static string ReplaceText(string text, Info oldInfo, Info newInfo) { return(TemplateGenerator.ReplaceText(text, oldInfo, newInfo)); }
public static string GenerateTransitionMethods(FD.FlowWindow window) { var flowData = FlowSystem.GetData(); var result = string.Empty; var transitions = new List <FlowWindow>(); if (window.IsContainer() == true) { foreach (var attachItem in window.attachItems) { var attachWindow = flowData.GetWindow(attachItem.targetId); if (attachWindow.IsContainer() == true) { continue; } var items = attachWindow.attachItems.Where(x => { var w = flowData.GetWindow(x.targetId); return(w.IsContainer() == false); }).Select(x => flowData.GetWindow(x.targetId)); foreach (var item in items) { if (transitions.Any(x => x.id == item.id) == false) { transitions.Add(item); } } } } else { transitions = flowData.windowAssets.Where(w => window.attachItems.Any((item) => item.targetId == w.id) && !w.IsContainer()).ToList(); } if (transitions == null) { return(result); } foreach (var each in transitions) { var className = each.directory; var classNameWithNamespace = Tpl.GetNamespace(each) + "." + Tpl.GetDerivedClassName(each); if (each.IsShowDefault() == true) { // Collect all default windows foreach (var defaultWindowId in FlowSystem.GetDefaultWindows()) { var defaultWindow = FlowSystem.GetWindow(defaultWindowId); className = defaultWindow.directory; classNameWithNamespace = Tpl.GetNamespace(defaultWindow) + "." + Tpl.GetDerivedClassName(defaultWindow); result += TemplateGenerator.GenerateWindowLayoutTransitionMethod(window, each, className, classNameWithNamespace); FlowEditorUtilities.CollectCallVariations(each.GetScreen().Load <WindowBase>(), (listTypes, listNames) => { result += TemplateGenerator.GenerateWindowLayoutTransitionTypedMethod(window, each, className, classNameWithNamespace, listTypes, listNames); }); } continue; } else { if (each.CanCompiled() == false) { continue; } } result += TemplateGenerator.GenerateWindowLayoutTransitionMethod(window, each, className, classNameWithNamespace); FlowEditorUtilities.CollectCallVariations(each.GetScreen().Load <WindowBase>(), (listTypes, listNames) => { result += TemplateGenerator.GenerateWindowLayoutTransitionTypedMethod(window, each, className, classNameWithNamespace, listTypes, listNames); }); } var c = 0; var everyPlatformHasUniqueName = false; foreach (var attachItem in window.attachItems) { var attachId = attachItem.targetId; var attachedWindow = FlowSystem.GetWindow(attachId); var tmp = UnityEditor.UI.Windows.Plugins.Flow.Flow.IsCompilerTransitionAttachedGeneration(window, attachedWindow); if (tmp == true) { ++c; } } everyPlatformHasUniqueName = c > 1; foreach (var attachItem in window.attachItems) { var attachId = attachItem.targetId; var attachedWindow = FlowSystem.GetWindow(attachId); if (attachedWindow.IsShowDefault() == true) { // Collect all default windows foreach (var defaultWindowId in FlowSystem.GetDefaultWindows()) { var defaultWindow = FlowSystem.GetWindow(defaultWindowId); result += UnityEditor.UI.Windows.Plugins.Flow.Flow.OnCompilerTransitionAttachedGeneration(window, defaultWindow, everyPlatformHasUniqueName); FlowEditorUtilities.CollectCallVariations(attachedWindow.GetScreen().Load <WindowBase>(), (listTypes, listNames) => { result += UnityEditor.UI.Windows.Plugins.Flow.Flow.OnCompilerTransitionTypedAttachedGeneration(window, defaultWindow, everyPlatformHasUniqueName, listTypes, listNames); }); } result += TemplateGenerator.GenerateWindowLayoutTransitionMethodDefault(); } /*if (withFunctionRoot == true) { * * var functionId = attachedWindow.GetFunctionId(); * var functionContainer = flowData.GetWindow(functionId); * if (functionContainer != null) { * * var root = flowData.GetWindow(functionContainer.functionRootId); * if (root != null) { * * attachedWindow = root; * * } * * } * * }*/ result += UnityEditor.UI.Windows.Plugins.Flow.Flow.OnCompilerTransitionAttachedGeneration(window, attachedWindow, everyPlatformHasUniqueName); FlowEditorUtilities.CollectCallVariations(attachedWindow.GetScreen().Load <WindowBase>(), (listTypes, listNames) => { result += UnityEditor.UI.Windows.Plugins.Flow.Flow.OnCompilerTransitionTypedAttachedGeneration(window, attachedWindow, everyPlatformHasUniqueName, listTypes, listNames); }); } // Run addons transition logic result += UnityEditor.UI.Windows.Plugins.Flow.Flow.OnCompilerTransitionGeneration(window); return(result); }
private static void GenerateWindow(string newPath, FD.FlowWindow window, bool recompile, bool minimalScriptsSize) { if (window.compiled == true && recompile == false) { return; } var oldPath = window.compiledDirectory; var newInfo = new Tpl.Info(Tpl.GetNamespace(window), Tpl.GetDerivedClassName(window), Tpl.GetBaseClassName(window), Tpl.GetContainerClassName(window), window.directory); var oldInfo = new Tpl.Info(window); if (string.IsNullOrEmpty(oldPath) == true) { oldPath = newPath; } var path = oldPath; if (window.compiled == true && (oldPath != newPath)) { // If window is moving and compiled - just rename // Replace in files IO.ReplaceInFiles(CompilerSystem.currentProjectDirectory, (file) => { var text = file.text; return(text.Contains(oldInfo.baseNamespace)); }, (text) => { return(Tpl.ReplaceText(text, oldInfo, newInfo)); }); // Rename base class name IO.RenameFile(oldPath + oldInfo.baseClassnameFile, oldPath + newInfo.baseClassnameFile); // Rename derived class name IO.RenameFile(oldPath + oldInfo.classnameFile, oldPath + newInfo.classnameFile); // Rename main folder IO.RenameDirectory(oldPath, newPath); path = newPath; } // Rebuild without rename //if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log(window.title + " :: REBUILD BASE :: " + path); string baseClassTemplate = null; if (window.IsContainer() == true) { baseClassTemplate = TemplateGenerator.GenerateWindowLayoutContainerBaseClass(newInfo.baseClassname, newInfo.baseNamespace, newInfo.containerClassName); } else { baseClassTemplate = TemplateGenerator.GenerateWindowLayoutBaseClass(newInfo.baseClassname, newInfo.baseNamespace, newInfo.containerClassName, Tpl.GenerateTransitionMethods(window)); } var derivedClassTemplate = TemplateGenerator.GenerateWindowLayoutDerivedClass(newInfo.classname, newInfo.baseClassname, newInfo.baseNamespace); //if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log(newPath + " :: " + newInfo.containerClassName + " :: " + baseClassTemplate); //return; if (minimalScriptsSize == true) { baseClassTemplate = CompilerSystem.Compress(baseClassTemplate); } if (window.IsContainer() == false) { IO.CreateFile(path, ".uiwspackage", string.Empty, import: false); IO.CreateDirectory(path, string.Empty); IO.CreateDirectory(path, FlowDatabase.COMPONENTS_FOLDER); IO.CreateDirectory(path, FlowDatabase.LAYOUT_FOLDER); IO.CreateDirectory(path, FlowDatabase.SCREENS_FOLDER); } else { IO.CreateFile(path, ".uiwscontainer", string.Empty, import: false); } if (baseClassTemplate != null && derivedClassTemplate != null) { IO.CreateFile(path, newInfo.baseClassnameFile, baseClassTemplate, rewrite: true); IO.CreateFile(path, newInfo.classnameFile, derivedClassTemplate, rewrite: false); } window.compiledNamespace = newInfo.baseNamespace; window.compiledScreenName = newInfo.screenName; window.compiledBaseClassName = newInfo.baseClassname; window.compiledDerivedClassName = newInfo.classname; window.compiledDirectory = path; window.compiled = true; }