protected override void Init() { var flow = this.flow; #if UNITY_MOBILE if (this.flowMobileOnly != null) { flow = this.flowMobileOnly; } #endif #if UNITY_STANDALONE if (this.flowStandaloneOnly != null) { flow = this.flowStandaloneOnly; } #endif FlowSystem.SetData(flow); this.defaults.AddRange(flow.GetDefaultScreens()); this.windows.AddRange(flow.GetAllScreens()); base.Init(); this.OnStart(); }
public static void Run(FlowData data) { UnityEditor.EditorUtility.DisplayProgressBar("Upgrading", string.Format("Migrating from {0} to {1}", data.version, VersionInfo.BUNDLE_VERSION), 0f); var type = data.GetType(); while (data.version < VersionInfo.BUNDLE_VERSION) { var nextVersion = data.version + 1; try { // Try to find upgrade method var methodName = "UpgradeTo" + nextVersion.ToSmallWithoutTypeString(); var methodInfo = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public); if (methodInfo != null) { var result = (bool)methodInfo.Invoke(data, null); if (result == true) { // Need to recompile var prevData = FlowSystem.GetData(); FlowSystem.SetData(data); UnityEngine.UI.Windows.Plugins.FlowCompiler.CompilerSystem.currentNamespace = data.namespaceName; var path = UnityEditor.AssetDatabase.GetAssetPath(data); UnityEngine.UI.Windows.Plugins.FlowCompiler.CompilerSystem.Generate(path, recompile: true); FlowSystem.SetData(prevData); } if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) { UnityEngine.Debug.Log("[UPGRADE] Invoked: `" + methodName + "`, version " + nextVersion); } } else { if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) { UnityEngine.Debug.Log("[UPGRADE] Method `" + methodName + "` was not found: version " + nextVersion + " skipped"); } } UnityEditor.EditorUtility.DisplayProgressBar("Upgrading", string.Format("Migrating from {0} to {1}", data.version, nextVersion), 0.5f); } catch (UnityException) { } finally { UnityEditor.EditorUtility.ClearProgressBar(); } data.version = nextVersion; UnityEditor.EditorUtility.SetDirty(data); } UnityEditor.EditorUtility.DisplayProgressBar("Upgrading", string.Format("Migrating from {0} to {1}", data.version, VersionInfo.BUNDLE_VERSION), 1f); UnityEditor.EditorUtility.ClearProgressBar(); }
protected override void Init() { #region FLOW DEFAULT { var flow = this.flow; if (flow == null) { Debug.LogError("Flow data was not set to WindowSystemFlow."); return; } #if UNITY_MOBILE if (this.flowMobileOnly != null) { flow = this.flowMobileOnly; } #endif #if UNITY_STANDALONE if (this.flowStandaloneOnly != null) { flow = this.flowStandaloneOnly; } #endif #if UNITY_CONSOLE if (this.flowConsoleOnly != null) { flow = this.flowConsoleOnly; } #endif FlowSystem.SetData(flow); Audio.Manager.InitAndAdd(flow.audio); this.defaults.AddRange(flow.GetDefaultScreens()); this.windows.AddRange(flow.GetAllScreens()); this.rootScreen = this.flow.GetRootScreen(); } #endregion #region FLOW ADDITIONAL { var additionalFlow = this.additionalFlow; #if UNITY_MOBILE if (this.additionalFlowMobileOnly != null) { flow = this.additionalFlowMobileOnly; } #endif #if UNITY_STANDALONE if (this.additionalFlowStandaloneOnly != null) { flow = this.additionalFlowStandaloneOnly; } #endif #if UNITY_CONSOLE if (this.additionalFlowConsoleOnly != null) { flow = this.additionalFlowConsoleOnly; } #endif if (additionalFlow != null) { var screens = additionalFlow.GetAllScreens((w) => ((this.additionalLoadType & LoadType.Function) != 0 && (w.IsFunction() == true || w.GetFunctionContainer() != null)) || ((this.additionalLoadType & LoadType.Window) != 0 && w.IsFunction() == false)); this.windows.AddRange(screens); if ((this.additionalLoadType & LoadType.Audio) != 0) { Audio.Manager.InitAndAdd(flow.audio); } } } #endregion base.Init(); }
public void DrawProjectSelector() { var darkLabel = ME.Utilities.CacheStyle("FlowEditor.DataSelection.Styles", "DarkLabel", (name) => { var style = new GUIStyle(FlowSystemEditorWindow.defaultSkin.FindStyle(name)); style.alignment = TextAnchor.MiddleLeft; return(style); }); var headerStyle = new GUIStyle("LODLevelNotifyText"); headerStyle.normal.textColor = EditorGUIUtility.isProSkin == true ? Color.white : Color.black; headerStyle.fontSize = 18; headerStyle.alignment = TextAnchor.MiddleCenter; GUILayoutExt.LabelWithShadow(string.Format("UI.Windows Flow Extension v{0}", VersionInfo.BUNDLE_VERSION), headerStyle); GUILayout.Space(10f); GUILayout.Label("Open one of your projects:", darkLabel); var backStyle = new GUIStyle("sv_iconselector_labelselection"); var skin = GUI.skin; GUI.skin = FlowSystemEditorWindow.defaultSkin; this.dataSelectionScroll = GUILayout.BeginScrollView(this.dataSelectionScroll, false, true, GUI.skin.horizontalScrollbar, GUI.skin.verticalScrollbar, backStyle); { GUI.skin = skin; this.scannedData = EditorUtilities.GetAssetsOfType <FlowData>(useCache: false); if (this.scannedData.Length == 0) { var center = new GUIStyle(darkLabel); center.fixedWidth = 0f; center.fixedHeight = 0f; center.stretchWidth = true; center.stretchHeight = true; center.alignment = TextAnchor.MiddleCenter; center.wordWrap = true; GUILayout.Label("No projects were found. Create a new one by Right-Click on any folder in Project View and choose `Create->UI.Windows->Flow->Graph` option.", center); } else { var buttonStyle = new GUIStyle("flow node 1 on"); buttonStyle.alignment = TextAnchor.MiddleLeft; buttonStyle.padding = new RectOffset(15, 15, 15, 15); buttonStyle.margin = new RectOffset(2, 2, 2, 2); buttonStyle.overflow = new RectOffset(); buttonStyle.contentOffset = Vector2.zero; buttonStyle.fixedWidth = 0f; buttonStyle.fixedHeight = 0f; buttonStyle.stretchWidth = true; buttonStyle.stretchHeight = false; buttonStyle.normal.textColor = Color.white; buttonStyle.fontSize = 12; buttonStyle.richText = true; var buttonStyleSelected = new GUIStyle(buttonStyle); buttonStyle.normal.background = null; buttonStyle.normal.textColor = Color.black; this.scannedData = this.scannedData.OrderByDescending((data) => (data != null ? data.lastModifiedUnix : 0)).ToArray(); foreach (var data in this.scannedData) { if (data == null) { continue; } var isSelected = (this.cachedData == data); var title = data.name + "\n"; title += string.Format("<color={1}><size=10>Modified: {0}</size></color>\n", data.lastModified, isSelected == true ? "#ccc" : "#999"); title += string.Format("<color={1}><size=10>Version: {0}</size></color>", data.version, isSelected == true ? "#ccc" : "#999"); if (GUILayout.Button(title, isSelected ? buttonStyleSelected : buttonStyle) == true) { this.cachedData = data; } } } GUILayout.FlexibleSpace(); } GUILayout.EndScrollView(); GUILayout.Space(10f); GUILayout.Label("Or select the project file:", darkLabel); this.cachedData = GUILayoutExt.ObjectField <FlowData>(this.cachedData, false, FlowSystemEditorWindow.defaultSkin.FindStyle("ObjectField")); CustomGUI.Splitter(); GUILayout.BeginHorizontal(); { if (GUILayout.Button("Create Project...", FlowSystemEditorWindow.defaultSkin.button, GUILayout.Width(150f), GUILayout.Height(40f)) == true) { this.state = State.NewProject; } GUILayout.FlexibleSpace(); var oldState = GUI.enabled; GUI.enabled = oldState && this.cachedData != null; if (this.cachedData != null && this.cachedData.version < VersionInfo.BUNDLE_VERSION) { // Need to upgrade if (GUILayout.Button("Upgrade to " + VersionInfo.BUNDLE_VERSION, FlowSystemEditorWindow.defaultSkin.button, GUILayout.Width(150f), GUILayout.Height(40f)) == true) { FlowUpdater.Run(this.cachedData); } } else if (this.cachedData != null && this.cachedData.version > VersionInfo.BUNDLE_VERSION) { var info = string.Format( "Selected Project has `{0}` version while UI.Windows System has `{1}` version number. Click here to download a new version.", this.cachedData.version, VersionInfo.BUNDLE_VERSION ); if (GUILayout.Button(new GUIContent(info, new GUIStyle("CN EntryWarn").normal.background), EditorStyles.helpBox, GUILayout.Height(40f)) == true) { Application.OpenURL(VersionInfo.DOWNLOAD_LINK); } } else { if (GUILayout.Button("Open", FlowSystemEditorWindow.defaultSkin.button, GUILayout.Width(100f), GUILayout.Height(40f)) == true) { FlowSystem.SetData(this.cachedData); } } GUI.enabled = oldState; } GUILayout.EndHorizontal(); }
protected override void Init() { #region FLOW DEFAULT { var customDefaults = false; List <WindowItem> defaults = new List <WindowItem>(); FlowData flow = null; for (int i = 0; i < this.flow.Length; ++i) { var item = this.flow[i]; if (item.IsValid() == false) { continue; } flow = item.flow; if (item.HasCustomDefaults() == true) { if (item.IsDefaultsOverride() == true) { defaults.Clear(); defaults.AddRange(item.customDefaults); } else { defaults.AddRange(item.customDefaults); } customDefaults = true; } } if (flow == null) { Debug.LogErrorFormat("Flow data was not found for current platform: {0}.", Application.platform); return; } this.currentFlow = flow; #if UNITY_EDITOR flow.RefreshAllScreens(); #endif FlowSystem.SetData(flow); Audio.Manager.InitAndAdd(flow.audio); if (customDefaults == false) { this.defaults.AddRange(flow.GetDefaultScreens(runtime: true)); } else { this.defaults.AddRange(defaults); } this.windows.AddRange(flow.GetAllScreens(runtime: true)); this.rootScreen = flow.GetRootScreen(runtime: true); } #endregion #region FLOW ADDITIONAL { for (int i = 0; i < this.flowAdditive.Length; ++i) { var item = this.flowAdditive[i]; if (item.IsValid() == false) { continue; } var additionalFlow = item.flow; var loadType = item.loadType; #if UNITY_EDITOR additionalFlow.RefreshAllScreens(); #endif var screens = additionalFlow.GetAllScreens((w) => ((loadType & LoadType.Function) != 0 && (w.IsFunction() == true || w.GetFunctionContainer() != null)) || ((loadType & LoadType.Window) != 0 && w.IsFunction() == false), runtime: true); this.windows.RemoveAll(x => screens.Select(w => w.windowId).Contains(x.windowId)); this.windows.AddRange(screens); if ((loadType & LoadType.Audio) != 0) { Audio.Manager.InitAndAdd(additionalFlow.audio); } } } #endregion base.Init(); }
public void DrawProjectSelector() { var darkLabel = ME.Utilities.CacheStyle("FlowEditor.DataSelection.Styles", "DarkLabel", (name) => { var style = new GUIStyle(FlowSystemEditorWindow.defaultSkin.FindStyle(name)); style.alignment = TextAnchor.MiddleLeft; return(style); }); var headerStyle = new GUIStyle("LODLevelNotifyText"); headerStyle.normal.textColor = EditorGUIUtility.isProSkin == true ? Color.white : Color.black; headerStyle.fontSize = 18; headerStyle.alignment = TextAnchor.MiddleCenter; GUILayoutExt.LabelWithShadow("UI.Windows Flow Extension v" + VersionInfo.BUNDLE_VERSION, headerStyle); GUILayout.Space(10f); GUILayout.Label("Open one of your projects:", darkLabel); var backStyle = new GUIStyle("sv_iconselector_labelselection"); var skin = GUI.skin; GUI.skin = FlowSystemEditorWindow.defaultSkin; this.dataSelectionScroll = GUILayout.BeginScrollView(this.dataSelectionScroll, false, true, GUI.skin.horizontalScrollbar, GUI.skin.verticalScrollbar, backStyle); { GUI.skin = skin; this.scannedData = EditorUtilities.GetAssetsOfType <FlowData>(); if (this.scannedData.Length == 0) { var center = new GUIStyle(darkLabel); center.fixedWidth = 0f; center.fixedHeight = 0f; center.stretchWidth = true; center.stretchHeight = true; center.alignment = TextAnchor.MiddleCenter; center.wordWrap = true; GUILayout.Label("No projects was found. Create a new one by Right-Click on any folder in Project View and choosing Create->UI.Windows->Flow->Graph option.", center); } else { var buttonStyle = new GUIStyle("U2D.createRect"); buttonStyle.padding = new RectOffset(15, 15, 15, 15); buttonStyle.margin = new RectOffset(2, 2, 2, 2); buttonStyle.fixedWidth = 0f; buttonStyle.fixedHeight = 0f; buttonStyle.stretchWidth = true; buttonStyle.stretchHeight = false; buttonStyle.normal.textColor = Color.black; buttonStyle.fontSize = 12; buttonStyle.richText = true; var buttonStyleSelected = new GUIStyle(buttonStyle); buttonStyle.normal.background = null; this.scannedData = this.scannedData.OrderByDescending((data) => (data != null ? data.lastModified : string.Empty)).ToArray(); foreach (var data in this.scannedData) { if (data == null) { continue; } var title = data.name + "\n"; title += "<color=#777><size=10>Modified: " + data.lastModified + "</size></color>\n"; title += "<color=#888><size=10>Version: " + data.version + "</size></color>"; if (GUILayout.Button(title, this.cachedData == data ? buttonStyleSelected : buttonStyle) == true) { this.cachedData = data; } } } GUILayout.FlexibleSpace(); } GUILayout.EndScrollView(); GUILayout.Space(10f); GUILayout.Label("Or select the project file:", darkLabel); this.cachedData = GUILayoutExt.ObjectField <FlowData>(this.cachedData, false, FlowSystemEditorWindow.defaultSkin.FindStyle("ObjectField")); CustomGUI.Splitter(); GUILayout.BeginHorizontal(); { if (GUILayout.Button("Create Project...", FlowSystemEditorWindow.defaultSkin.button, GUILayout.Width(150f), GUILayout.Height(40f)) == true) { this.state = State.NewProject; } GUILayout.FlexibleSpace(); var oldState = GUI.enabled; GUI.enabled = oldState && this.cachedData != null; if (this.cachedData != null && this.cachedData.version < VersionInfo.BUNDLE_VERSION) { // Need to upgrade if (GUILayout.Button("Upgrade to " + VersionInfo.BUNDLE_VERSION, FlowSystemEditorWindow.defaultSkin.button, GUILayout.Width(150f), GUILayout.Height(40f)) == true) { UnityEditor.EditorUtility.DisplayProgressBar("Upgrading", string.Format("Migrating from {0} to {1}", this.cachedData.version, VersionInfo.BUNDLE_VERSION), 0f); var type = this.cachedData.GetType(); while (this.cachedData.version < VersionInfo.BUNDLE_VERSION) { var nextVersion = this.cachedData.version + 1; // Try to find upgrade method var methodName = "UpgradeTo" + nextVersion.ToSmallWithoutTypeString(); var methodInfo = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public); if (methodInfo != null) { methodInfo.Invoke(this.cachedData, null); Debug.Log("[UPGRADE] Invoked: `" + methodName + "`, version " + nextVersion); } else { Debug.Log("[UPGRADE] Method `" + methodName + "` was not found: version " + nextVersion + " skipped"); } UnityEditor.EditorUtility.DisplayProgressBar("Upgrading", string.Format("Migrating from {0} to {1}", this.cachedData.version, nextVersion), 0.5f); this.cachedData.version = nextVersion; UnityEditor.EditorUtility.SetDirty(this.cachedData); } UnityEditor.EditorUtility.DisplayProgressBar("Upgrading", string.Format("Migrating from {0} to {1}", this.cachedData.version, VersionInfo.BUNDLE_VERSION), 1f); UnityEditor.EditorUtility.ClearProgressBar(); } } else if (this.cachedData != null && this.cachedData.version > VersionInfo.BUNDLE_VERSION) { EditorGUILayout.HelpBox(string.Format("Selected Project has {0} version while UI.Windows System has {1} version number. Please, download a new version.", this.cachedData.version, VersionInfo.BUNDLE_VERSION), MessageType.Warning); if (GUILayout.Button("Download", FlowSystemEditorWindow.defaultSkin.button, GUILayout.Width(100f), GUILayout.Height(40f)) == true) { Application.OpenURL(VersionInfo.DOWNLOAD_LINK); } } else { if (GUILayout.Button("Open", FlowSystemEditorWindow.defaultSkin.button, GUILayout.Width(100f), GUILayout.Height(40f)) == true) { FlowSystem.SetData(this.cachedData); } } GUI.enabled = oldState; } GUILayout.EndHorizontal(); }