Ejemplo n.º 1
0
 public Info(FD.FlowWindow window)
 {
     this.baseNamespace = window.compiledNamespace;
     this.classname     = window.compiledDerivedClassName;
     this.baseClassname = window.compiledBaseClassName;
     this.screenName    = window.directory;
     this.containerName = Tpl.GetContainerClassName(window);
 }
Ejemplo n.º 2
0
        public static string GetContainerClassName(FD.FlowWindow flowWindow)
        {
            var container = flowWindow.GetParentContainer();

            if (container == null)
            {
                return("Container");
            }

            return(Tpl.GetDerivedClassName(container));
        }
Ejemplo n.º 3
0
        public static string GenerateTransitionMethods(FlowWindow window)
        {
            var flowData = FlowSystem.GetData();

            var transitions = flowData.windows.Where(w => window.attachItems.Any((item) => item.targetId == w.id) && w.CanCompiled() && !w.IsContainer());

            var result = string.Empty;

            foreach (var each in transitions)
            {
                var className = each.directory;
                var classNameWithNamespace = Tpl.GetNamespace(each) + "." + Tpl.GetDerivedClassName(each);

                result += FlowTemplateGenerator.GenerateWindowLayoutTransitionMethod(window, each, className, classNameWithNamespace);
            }

            // Make FlowDefault() method if exists
            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)
                {
                    result += FlowTemplateGenerator.GenerateWindowLayoutTransitionMethodDefault();
                }

                result += UnityEditor.UI.Windows.Plugins.Flow.Flow.OnCompilerTransitionAttachedGeneration(window, attachedWindow, everyPlatformHasUniqueName);
            }

            // Run addons transition logic
            result += UnityEditor.UI.Windows.Plugins.Flow.Flow.OnCompilerTransitionGeneration(window);

            return(result);
        }
Ejemplo n.º 4
0
        public static string GenerateTransitionMethods(FlowWindow window)
        {
            var flowData = FlowSystem.GetData();

            var transitions = flowData.windows.Where(w => window.attaches.Contains(w.id) && !w.isDefaultLink && !w.isContainer);

            var result = string.Empty;

            foreach (var each in transitions)
            {
                var className = each.directory;
                var classNameWithNamespace = Tpl.GetNamespace(each) + "." + Tpl.GetDerivedClassName(each);                //GetBaseClassName( each );

                result = result + FlowTemplateGenerator.GenerateWindowLayoutTransitionMethod(className, classNameWithNamespace);
            }

            return(result);
        }
		/*
		 * Template can contains:
		 * 
		 * {NAMESPACE_NAME}
		 * {CLASS_NAME}
		 * {BASE_CLASS_NAME}
		 * {CLASS_NAME_WITH_NAMESPACE}
		 */

		public static string ReplaceText(string text, Tpl.Info oldInfo, Tpl.Info newInfo) {

			var file = Resources.Load("UI.Windows/Templates/TemplateReplaceRules") as TextAsset;
			if (file == null) {
				
				Debug.LogError("Template Loading Error: Could not load template 'TemplateReplaceRules'");
				
				return text;

			}

			var path = AssetDatabase.GetAssetPath(file);
			var replaceRules = System.IO.File.ReadAllLines(path);

			//text = text.Replace(oldInfo.baseNamespace, newInfo.baseNamespace);
			
			for (int i = 0; i < replaceRules.Length; ++i) {
				
				// Prepare rule
				var replace = replaceRules[i];
				replace = replace.Replace(" ", @"\s?");
				replace = replace.Replace("(", @"\(").Replace(")", @"\)");
				replace = oldInfo.Replace(replace, (r) => r.Replace("{VARIABLE}", "([a-zA-Z]+[a-zA-Z0-9]*)"));
				
				var replacement = replaceRules[i];
				replacement = newInfo.Replace(replacement, (r) => r.Replace("{VARIABLE}", "$1"));
				
				var pattern = @"" + replace + "";

				var rgx = new Regex(pattern, RegexOptions.Singleline);
				text = rgx.Replace(text, replacement);
				
			}
			
			return text;
			
		}
Ejemplo n.º 6
0
 public static string GetNamespace(FlowWindow window)
 {
     return(Tpl.GetNamespace() + IO.GetRelativePath(window, "."));
 }
Ejemplo n.º 7
0
        /*
         * private static bool CompiledInfoIsInvalid( FlowWindow flowWindow ) {
         *
         *      return GetBaseClassName( flowWindow ) != flowWindow.compiledBaseClassName
         || GetNamespace( flowWindow ) != flowWindow.compiledNamespace;
         ||}
         ||
         ||private static void UpdateInheritedClasses( string oldBaseClassName, string newBaseClassName, string oldDerivedClassName, string newDerivedClassName, string oldNamespace, string newNamespace ) {
         ||
         ||     if ( string.IsNullOrEmpty( oldBaseClassName ) || string.IsNullOrEmpty( newBaseClassName ) ) {
         ||
         ||             return;
         ||     }
         ||
         ||     var oldFullClassPath = oldNamespace + oldBaseClassName;
         ||     var newFullClassPath = newNamespace + newBaseClassName;
         ||
         ||     AssetDatabase.StartAssetEditing();
         ||
         ||     try {
         ||
         ||             var scripts =
         ||                     AssetDatabase.FindAssets( "t:MonoScript" )
         ||                             .Select( _ => AssetDatabase.GUIDToAssetPath( _ ) )
         ||                             .Select( _ => AssetDatabase.LoadAssetAtPath( _, typeof( MonoScript ) ) )
         ||                             .OfType<MonoScript>()
         ||                             .Where( _ => _.text.Contains( oldBaseClassName ) || _.text.Contains( oldDerivedClassName ) || _.text.Contains( oldNamespace ) )
         ||                             .Where( _ => _.name != newBaseClassName );
         ||
         ||             foreach ( var each in scripts ) {
         ||
         ||                     var path = AssetDatabase.GetAssetPath( each );
         ||
         ||                     var lines = File.ReadAllLines( path );
         ||
         ||                     var writer = new StreamWriter( path );
         ||
         ||                     foreach ( var line in lines ) {
         ||
         ||                             writer.WriteLine( line.Replace( oldFullClassPath, newFullClassPath )
         ||                                                                       .Replace( oldNamespace, newNamespace )
         ||                                                                       .Replace( oldBaseClassName, newBaseClassName )
         ||                                                                       .Replace( oldDerivedClassName, newDerivedClassName ) );
         ||                     }
         ||
         ||                     writer.Dispose();
         ||             }
         ||     } catch ( Exception e ) { Debug.LogException( e ); }
         ||
         ||     AssetDatabase.StopAssetEditing();
         ||     AssetDatabase.Refresh( ImportAssetOptions.ForceUpdate );
         ||
         ||}
         ||
         ||private static void GenerateUIWindow( string fullpath, FlowWindow window, bool recompile = false ) {
         ||
         ||     var isCompiledInfoInvalid = window.compiled && CompiledInfoIsInvalid( window );
         ||
         ||     if ( window.compiled == false || recompile == true || isCompiledInfoInvalid ) {
         ||
         ||             var baseClassName = GetBaseClassName( window );
         ||             var derivedClassName = GetDerivedClassName( window );
         ||             var classNamespace = GetNamespace( window );
         ||
         ||             var baseClassTemplate = FlowTemplateGenerator.GenerateWindowLayoutBaseClass( baseClassName, classNamespace, GenerateTransitionMethods( window ) );
         ||             var derivedClassTemplate = FlowTemplateGenerator.GenerateWindowLayoutDerivedClass( derivedClassName, baseClassName, classNamespace );
         ||
         #if !UNITY_WEBPLAYER
         ||             var baseClassPath = ( fullpath + "/" + baseClassName + ".cs" ).Replace( "//", "/" );
         ||             var derivedClassPath = ( fullpath + "/" + derivedClassName + ".cs" ).Replace( "//", "/" );
         #endif
         ||
         ||             if ( baseClassTemplate != null && derivedClassTemplate != null ) {
         ||
         ||                     IO.CreateDirectory( fullpath, string.Empty );
         ||                     IO.CreateDirectory( fullpath, FlowDatabase.COMPONENTS_FOLDER );
         ||                     IO.CreateDirectory( fullpath, FlowDatabase.LAYOUT_FOLDER );
         ||                     IO.CreateDirectory( fullpath, FlowDatabase.SCREENS_FOLDER );
         ||
         #if !UNITY_WEBPLAYER
         ||
         ||                     Directory.CreateDirectory( fullpath );
         ||
         ||                     File.WriteAllText( baseClassPath, baseClassTemplate );
         ||
         ||                     if ( !File.Exists( derivedClassPath ) ) {
         ||
         ||                             File.WriteAllText( derivedClassPath, derivedClassTemplate );
         ||
         ||                             AssetDatabase.ImportAsset( derivedClassName );
         ||                     }
         ||
         ||                     AssetDatabase.ImportAsset( baseClassPath );
         ||
         #endif
         ||
         ||             } else {
         ||
         ||                     return;
         ||             }
         ||
         ||             var oldBaseClassName = window.compiledBaseClassName;
         ||             var newBaseClassName = baseClassName;
         ||             var oldDerivedClassName = window.compiledDerivedClassName;
         ||             var newDerivedClassName = derivedClassName;
         ||
         ||             var oldNamespace = window.compiledNamespace;
         ||
         ||             window.compiledBaseClassName = baseClassName;
         ||             window.compiledDerivedClassName = derivedClassName;
         ||             window.compiledNamespace = classNamespace;
         ||
         ||             var newNamespace = window.compiledNamespace;
         ||
         ||             window.compiledDirectory = fullpath;
         ||
         ||             window.compiled = true;
         ||
         ||             AssetDatabase.Refresh( ImportAssetOptions.ForceUpdate );
         ||
         ||             if ( isCompiledInfoInvalid ) {
         ||
         ||                     EditorApplication.delayCall += () => UpdateInheritedClasses( oldBaseClassName, newBaseClassName, oldDerivedClassName, newDerivedClassName, oldNamespace, newNamespace );
         ||             }
         ||     }
         ||
         ||}
         ||
         ||public static void GenerateUI( string pathToData, bool recompile = false, Func<FlowWindow, bool> predicate = null ) {
         ||
         ||     var filename = Path.GetFileName( pathToData );
         ||     var directory = pathToData.Replace( filename, "" );
         ||
         ||     currentProject = Path.GetFileNameWithoutExtension( pathToData );
         ||     var basePath = directory + currentProject;
         ||
         ||     CreateDirectory( basePath, string.Empty );
         ||     CreateDirectory( basePath, FlowDatabase.OTHER_NAME );
         ||
         ||     AssetDatabase.StartAssetEditing();
         ||
         ||     predicate = predicate ?? delegate { return true; };
         ||
         ||     try {
         ||
         ||             foreach ( var each in FlowSystem.GetWindows().Where( _ => !_.isDefaultLink && predicate( _ ) ) ) {
         ||
         ||                     var relativePath = GetRelativePath( each, "/" );
         ||
         ||                     if ( !string.IsNullOrEmpty( each.directory ) ) {
         ||
         ||                             CreateDirectory( basePath, relativePath );
         ||                     }
         ||
         ||                     GenerateUIWindow( basePath + relativePath + "/", each, recompile );
         ||             }
         ||     } catch ( Exception e ) {
         ||
         ||             Debug.LogException( e );
         ||     }
         ||
         ||     AssetDatabase.StopAssetEditing();
         ||     AssetDatabase.Refresh( ImportAssetOptions.ForceUpdate );
         ||
         ||}*/
        #endregion

        private static void GenerateWindow(string newPath, FlowWindow window, bool recompile)
        {
            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), 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(FlowCompilerSystem.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
            //Debug.Log(window.title + " :: REBUILD BASE :: " + path);

            IO.CreateDirectory(path, string.Empty);
            IO.CreateDirectory(path, FlowDatabase.COMPONENTS_FOLDER);
            IO.CreateDirectory(path, FlowDatabase.LAYOUT_FOLDER);
            IO.CreateDirectory(path, FlowDatabase.SCREENS_FOLDER);

            var baseClassTemplate    = FlowTemplateGenerator.GenerateWindowLayoutBaseClass(newInfo.baseClassname, newInfo.baseNamespace, Tpl.GenerateTransitionMethods(window));
            var derivedClassTemplate = FlowTemplateGenerator.GenerateWindowLayoutDerivedClass(newInfo.classname, newInfo.baseClassname, newInfo.baseNamespace);

            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;
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
 public static string GetClassNameWithNamespace(FD.FlowWindow window)
 {
     return(string.Format("{0}.{1}", Tpl.GetNamespace(window), Tpl.GetDerivedClassName(window)));
 }
Ejemplo n.º 10
0
 public static string GetNamespace(FD.FlowWindow window)
 {
     return(string.Format("{0}{1}", Tpl.GetNamespace(), IO.GetRelativePath(window, ".")));
 }
Ejemplo n.º 11
0
        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;
        }
Ejemplo n.º 12
0
 public static string GetClassNameWithNamespace(FD.FlowWindow window)
 {
     return(Tpl.GetNamespace(window) + "." + Tpl.GetDerivedClassName(window));
 }