public virtual UnitOptionRow Serialize() { var row = new UnitOptionRow(); if (sourceScriptGuids.Count == 0) { // Important to set to null here, because the code relies on // null checks, not empty string checks. row.sourceScriptGuids = null; } else { row.sourceScriptGuids = string.Join(",", sourceScriptGuids.ToArray()); } row.optionType = Codebase.SerializeType(GetType()); row.unitType = Codebase.SerializeType(unitType); row.unit = unit.Serialize().json; row.category = category?.fullName; row.labelHuman = labelHuman; row.labelProgrammer = labelProgrammer; row.order = order; row.haystackHuman = haystackHuman; row.haystackProgrammer = haystackProgrammer; row.favoriteKey = favoriteKey; row.controlInputCount = controlInputCount; row.controlOutputCount = controlOutputCount; row.valueInputTypes = valueInputTypes.Select(Codebase.SerializeType).ToSeparatedString("|").NullIfEmpty(); row.valueOutputTypes = valueOutputTypes.Select(Codebase.SerializeType).ToSeparatedString("|").NullIfEmpty(); return(row); }
public override UnitOptionRow Serialize() { var row = base.Serialize(); row.tag1 = Codebase.SerializeType(structType); return(row); }
public TabTool(Type windowType) { Ensure.That(nameof(windowType)).IsNotNull(windowType); this.windowType = windowType; tabKey = Codebase.SerializeType(windowType); try { FromTitleContent((GUIContent)UnityEditorDynamic.EditorWindow.GetLocalizedTitleContentFromType(windowType)); } catch { label = windowType.DisplayName(); icon = windowType.Icon()?[IconSize.Small]; tooltip = windowType.DisplayName(); } }
private static void AnalyzeWindowLayout() { var tabs = ListPool <EditorWindow> .New(); try { foreach (var window in Resources.FindObjectsOfTypeAll <EditorWindow>()) { // Skip invalid windows if (window == null) { continue; } // Abort the operation if any window is maximized, we don't want to save that layout if (window.maximized) { return; } // Skip windows that are invalid or not part of the layout dynamic dWindow = window.AsDynamic(); if (dWindow.m_Parent == null || dWindow.m_Parent.window == null || dWindow.m_Parent.window.m_DontSaveToLayout) { continue; } var parentWindowShowMode = (int)dWindow.m_Parent.window.showMode; // Skip windows not in the main window (4 in the ShowMode enum) if (parentWindowShowMode != 4) { continue; } tabs.Add(window); } // Sort tabs by screen position tabs.Sort(compareLayoutTab); // Store the tabs in the configuration // To minimize serialization operations, first check if changed from last time var config = PeekPlugin.Configuration; var tabsChanged = tabs.Count != config.tabsInLayout.Count; var positionsChanged = false; var dataChanged = false; // Store the fact that this tab is in the layout, which we'll need as fallback // in case the assembly reloads while the scene view is already maximized if (!tabsChanged) { for (int i = 0; i < tabs.Count; i++) { var tabKey = Codebase.SerializeType(tabs[i].GetType()); var configTabKey = config.tabsInLayout[i]; if (tabKey != configTabKey) { tabsChanged = true; break; } } } if (tabsChanged) { config.tabsInLayout.Clear(); foreach (var tab in tabs) { var tabKey = Codebase.SerializeType(tab.GetType()); config.tabsInLayout.Add(tabKey); } config.Save(nameof(PeekConfiguration.tabsInLayout)); } foreach (var tab in tabs) { var tabKey = Codebase.SerializeType(tab.GetType()); // Store the position if the user hasn't configured it already if (!config.tabsPositions.ContainsKey(tabKey)) { config.tabsPositions[tabKey] = tab.position; positionsChanged = true; } // Store the data if the user hasn't configured it already if (!config.tabsData.ContainsKey(tabKey)) { config.tabsData[tabKey] = EditorJsonUtility.ToJson(tab); dataChanged = true; } } if (positionsChanged) { config.Save(nameof(PeekConfiguration.tabsPositions)); } if (dataChanged) { config.Save(nameof(PeekConfiguration.tabsData)); } } catch (Exception ex) { Debug.LogWarning($"Failed to analyze window layout:\n{ex}"); } finally { tabs.Free(); } }