Begin a vertical group and get its rect back.
private void OnGUI() { UG.BeginVertical(); UG.BeginHorizontal(); UG.LabelField("当前数据源:" + (_dataPath.IsNullPath() ? "未在本地保存,已编辑内容随时可能丢失!" : _dataPath)); if (GUILayout.Button("选择")) { string path = EditorUtility.OpenFilePanelWithFilters("选择数据源文件", Application.dataPath + "/Hotassets/Data", new [] { "text", "txt" }); if (!string.IsNullOrEmpty(path)) { Dictionary <string, List <InterlocutionData> > temperData = null; try { temperData = JsonConvert.DeserializeObject <Dictionary <string, List <InterlocutionData> > >(File.ReadAllText(path)); } catch (JsonException) { temperData = _data; path = _dataPath; EditorApplication.Beep(); EditorUtility.DisplayDialog("异常捕获!", "数据源文件不能被正确加载,请确定.json文件的有效性", "知道了"); } finally { _data = temperData; _dataPath = path; } } } UG.EndHorizontal(); UG.BeginHorizontal(); int subject = UG.Popup("所属学科", _editingSubject, InterlocutionData.Keys); if (subject != _editingSubject) { _editingInterlocution = -1; } _editingSubject = subject; string key = InterlocutionData.Keys[_editingSubject]; UG.LabelField("分组", _editingSubject != InterlocutionData.Keys.Length - 1 ? Subject.ToSubject(InterlocutionData.Keys[_editingSubject]).group.ToString() : "无"); UG.EndHorizontal(); _scrollPostion = UG.BeginScrollView(_scrollPostion); if (!_data.ContainsKey(key)) { _data[key] = new List <InterlocutionData>(); } List <InterlocutionData> interlocutions = _data[key]; int _deletedInterlocution = -1; UG.LabelField("[已有 " + interlocutions.Count + " 道问答]"); for (int i = 0, l = interlocutions.Count; i < l; i++) { UG.BeginHorizontal(); UG.LabelField("[Q " + i + "] " + interlocutions[i].question); if (GUILayout.Button("编辑")) { _editingInterlocution = i; } if (GUILayout.Button("删除")) { EditorApplication.Beep(); if (EditorUtility.DisplayDialog("危险操作警告⚠️", "即将删除问答 [Q" + i + "] (该操作不可逆)", "确认", "取消")) { _deletedInterlocution = i; if (_editingInterlocution == _deletedInterlocution) { _editingInterlocution = -1; } } } UG.EndHorizontal(); } if (_deletedInterlocution != -1) { interlocutions.RemoveAt(_deletedInterlocution); } UG.EndScrollView(); if (GUILayout.Button("添加问答")) { _editingInterlocution = interlocutions.Count; interlocutions.Add(new InterlocutionData()); } UG.LabelField("问答编辑区"); if (_editingInterlocution != -1) { UG.LabelField("Q " + _editingInterlocution); InterlocutionData interlocution = interlocutions[_editingInterlocution]; interlocution.question = UG.TextArea(interlocution.question); interlocution.answer = (Option)UG.EnumPopup("正确选项", interlocution.answer); UG.LabelField("选项A"); interlocution.optionA = UG.TextArea(interlocution.optionA); UG.LabelField("选项B"); interlocution.optionB = UG.TextArea(interlocution.optionB); UG.LabelField("选项C"); interlocution.optionC = UG.TextArea(interlocution.optionC); UG.LabelField("选项D"); interlocution.optionD = UG.TextArea(interlocution.optionD); } else { UG.HelpBox("需要选择一个问答进行编辑!", MessageType.Warning); } if (GUILayout.Button("保存")) { bool toSave = true; bool toImport = false; if (_dataPath.IsNullPath()) { string path = EditorUtility.SaveFilePanel("保存问答数据", Application.dataPath + "/Hotassets/Data", "InterlocutionData", "txt"); if (string.IsNullOrEmpty(path)) { toSave = false; } else { _dataPath = path; toImport = true; } } if (toSave) { File.WriteAllText(_dataPath, JsonConvert.SerializeObject(_data)); EditorPrefs.SetString(DATA_SAVE_PATH, _dataPath); } if (toImport) { AssetDatabase.ImportAsset(_dataPath.Substring(_dataPath.IndexOf("Assets"))); } } UG.EndVertical(); }
private void OnGUI() { if (settings == null) { settings = ConstantGenerator.GetSettingsFile(); } if (logo == null) { logo = ConstantGenerator.GetLogo(); } if (border == null) { border = ConstantGenerator.GetBorder(); } EditorGUI.BeginChangeCheck(); StartGUI("Layers"); if (DrawGenButton()) { LayersGen.Generate(); window.Close(); } if (DrawForceGenButton()) { LayersGen.ForceGenerate(); window.Close(); } EndGUI(); // ------------------------------------------------------------------------------------- StartGUI("Tags"); if (DrawGenButton()) { TagsGen.Generate(); window.Close(); } if (DrawForceGenButton()) { TagsGen.ForceGenerate(); window.Close(); } EndGUI(); // ------------------------------------------------------------------------------------- StartGUI("Sort Layers"); if (DrawGenButton()) { SortingLayersGen.Generate(); window.Close(); } if (DrawForceGenButton()) { SortingLayersGen.ForceGenerate(); window.Close(); } EndGUI(); // ------------------------------------------------------------------------------------- StartGUI("Scenes"); if (DrawGenButton()) { ScenesGen.Generate(); window.Close(); } if (DrawForceGenButton()) { ScenesGen.ForceGenerate(); window.Close(); } EndGUI(); // ------------------------------------------------------------------------------------- StartGUI("Shader Props"); if (DrawGenButton()) { ShaderPropsGen.Generate(false); window.Close(); } if (DrawForceGenButton()) { ShaderPropsGen.ForceGenerate(); window.Close(); } EndGUI(); // ------------------------------------------------------------------------------------- StartGUI("Anim Params"); if (DrawGenButton()) { AnimParamsGen.Generate(); window.Close(); } if (DrawForceGenButton()) { AnimParamsGen.ForceGenerate(); window.Close(); } EndGUI(); // ------------------------------------------------------------------------------------- StartGUI("Anim Layers"); if (DrawGenButton()) { AnimLayersGen.Generate(); window.Close(); } if (DrawForceGenButton()) { AnimLayersGen.ForceGenerate(); window.Close(); } EndGUI(); // ------------------------------------------------------------------------------------- StartGUI("Anim States"); if (DrawGenButton()) { AnimStatesGen.Generate(); window.Close(); } if (DrawForceGenButton()) { AnimStatesGen.ForceGenerate(); window.Close(); } EndGUI(); // ------------------------------------------------------------------------------------- StartGUI("Nav Areas"); if (DrawGenButton()) { NavAreasGen.Generate(); window.Close(); } if (DrawForceGenButton()) { NavAreasGen.ForceGenerate(); window.Close(); } EndGUI(); // ========================================================================================= DrawLine(Color.white, 2, 5); GUIStyle style = new GUIStyle(GUI.skin.button); style.alignment = TextAnchor.MiddleCenter; style.fontStyle = FontStyle.Bold; EGL.BeginHorizontal(); EGL.BeginVertical(); EGL.BeginHorizontal(); if (GL.Button("GENERATE ALL", style)) { LayersGen.Generate(); TagsGen.Generate(); SortingLayersGen.Generate(); ScenesGen.Generate(); ShaderPropsGen.Generate(false); AnimParamsGen.Generate(); AnimLayersGen.Generate(); AnimStatesGen.Generate(); window.Close(); } GL.FlexibleSpace(); EGL.EndHorizontal(); EGL.BeginHorizontal(); if (GL.Button("FORCE GENERATE ALL", style)) { LayersGen.ForceGenerate(); TagsGen.ForceGenerate(); SortingLayersGen.ForceGenerate(); ScenesGen.ForceGenerate(); ShaderPropsGen.ForceGenerate(); AnimParamsGen.ForceGenerate(); AnimLayersGen.ForceGenerate(); AnimStatesGen.ForceGenerate(); window.Close(); } GL.FlexibleSpace(); EGL.EndHorizontal(); EGL.EndVertical(); EGL.BeginVertical(); // --------------------------------------------------------------------------------------- Color genOnReloadColor; Color updateOnReloadColor; if (settings.regenerateOnMissing) { genOnReloadColor = Color.green * 2; } else { genOnReloadColor = Color.white * 1.5f; } if (settings.updateOnReload) { updateOnReloadColor = Color.green * 2; } else { updateOnReloadColor = Color.white * 1.5f; } EGL.BeginHorizontal(); GUI.backgroundColor = genOnReloadColor; if (GL.Button(new GUIContent("ReGen On Missing", "Automatically re-generates the constants file is none is present."), style)) { settings.regenerateOnMissing = !settings.regenerateOnMissing; EditorUtility.SetDirty(settings); } EGL.EndHorizontal(); EGL.BeginHorizontal(); GUI.backgroundColor = updateOnReloadColor; if (GL.Button(new GUIContent("Update On Reload", "Automatically re-generates the constants on editor recompile if any changes are detected."), style)) { settings.updateOnReload = !settings.updateOnReload; EditorUtility.SetDirty(settings); } EGL.EndHorizontal(); EGL.EndVertical(); EGL.EndHorizontal(); // ========================================================================================= DrawLine(Color.white, 2, 5); GUI.backgroundColor = Color.gray; GUI.contentColor = Color.white * 10; // check for unity versions using conditional directives // NOTE: there is no "BeginFoldoutHeaderGroup" in below 2019.1 #if UNITY_2019_OR_NEWER showFoldOut = EGL.BeginFoldoutHeaderGroup(showFoldOut, "Create Generator Script"); #else showFoldOut = EGL.Foldout(showFoldOut, "Create Generator Script"); #endif if (showFoldOut) { GL.Space(5); GUI.contentColor = Color.white * 10; generatorName = EGL.TextField("Generator Name", generatorName); outputFileName = EGL.TextField("Output File Name", outputFileName); GL.Space(5); EGL.BeginHorizontal(); if (!settings.regenerateOnMissing) { EGL.BeginVertical(); GL.FlexibleSpace(); EGL.HelpBox("NOTE: Force Generate will only delete the file but will NOT generate a new one if the [ReGen On Missing] is turned off", MessageType.Warning); EGL.EndVertical(); } else { // ============================================================================ // Draw Ma Awesome Logo EGL.BeginVertical(); GL.FlexibleSpace(); Rect horiRect = EGL.BeginHorizontal(); Rect boxRect = new Rect(horiRect.x + 3, horiRect.y - 54, 125, 52); Rect backgroundRect = boxRect; backgroundRect.width = border.width; backgroundRect.height = border.height; GUI.DrawTexture(backgroundRect, border); // GUI.Box( boxRect, iconBackground, ); GUI.Label(new Rect(boxRect.x + 3, boxRect.y + 16, 100, 20), "Created BY: "); Rect logoRect = new Rect(boxRect.x + 76, boxRect.y + 2, logo.width, logo.height); GUI.DrawTexture(logoRect, logo); EGL.EndHorizontal(); EGL.EndVertical(); // ============================================================================ } GL.FlexibleSpace(); GUI.contentColor = Color.white * 5; EGL.BeginVertical(); GL.FlexibleSpace(); GUI.backgroundColor = Color.white * 2.5f; GUI.contentColor = Color.black * 5; if (GL.Button("Create", new GUIStyle(GUI.skin.button) { fontStyle = FontStyle.Bold, fontSize = 12 }, GL.Width(75), GL.Height(30))) { if (generatorName == string.Empty || outputFileName == string.Empty || generatorName == null || outputFileName == null) { Debug.LogWarning("Fill out all the fields"); } else { TemplateGen.GenerateTemplate(generatorName, outputFileName); window.Close(); } } EGL.EndVertical(); GL.Space(1); EGL.EndHorizontal(); } #if UNITY_2019_OR_NEWER EGL.EndFoldoutHeaderGroup(); #endif if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(settings); } }
public override void OnInspectorGUI() { if (initializeException != null) { ShowLoadErrorExceptionGUI(initializeException); ApplyRevertGUI(); return; } extraDataSerializedObject.Update(); var platforms = Compilation.CompilationPipeline.GetAssemblyDefinitionPlatforms(); using (new EditorGUI.DisabledScope(false)) { if (targets.Length > 1) { using (new EditorGUI.DisabledScope(true)) { var value = string.Join(", ", extraDataTargets.Select(t => t.name).ToArray()); EditorGUILayout.TextField(Styles.name, value, EditorStyles.textField); } } else { EditorGUILayout.PropertyField(m_AssemblyName, Styles.name); } GUILayout.Label(Styles.generalOptions, EditorStyles.boldLabel); EditorGUILayout.BeginVertical(GUI.skin.box); EditorGUILayout.PropertyField(m_AllowUnsafeCode, Styles.allowUnsafeCode); EditorGUILayout.PropertyField(m_AutoReferenced, Styles.autoReferenced); EditorGUILayout.PropertyField(m_OverrideReferences, Styles.overrideReferences); EditorGUILayout.PropertyField(m_NoEngineReferences, Styles.noEngineReferences); EditorGUILayout.EndVertical(); GUILayout.Space(10f); GUILayout.Label(Styles.defineConstraints, EditorStyles.boldLabel); m_DefineConstraints.DoLayoutList(); GUILayout.Label(Styles.references, EditorStyles.boldLabel); EditorGUILayout.BeginVertical(GUI.skin.box); EditorGUILayout.PropertyField(m_UseGUIDs, Styles.useGUIDs); EditorGUILayout.EndVertical(); m_ReferencesList.DoLayoutList(); if (extraDataTargets.Any(data => ((AssemblyDefinitionState)data).references != null && ((AssemblyDefinitionState)data).references.Any(x => x.asset == null))) { EditorGUILayout.HelpBox("The grayed out assembly references are missing and will not be referenced during compilation.", MessageType.Info); } if (m_OverrideReferences.boolValue && !m_OverrideReferences.hasMultipleDifferentValues) { GUILayout.Label(Styles.precompiledReferences, EditorStyles.boldLabel); UpdatePrecompiledReferenceListEntry(); m_PrecompiledReferencesList.DoLayoutList(); if (extraDataTargets.Any(data => ((AssemblyDefinitionState)data).precompiledReferences.Any(x => string.IsNullOrEmpty(x.path) && !string.IsNullOrEmpty(x.name)))) { EditorGUILayout.HelpBox("The grayed out assembly references are missing and will not be referenced during compilation.", MessageType.Info); } } GUILayout.Label(Styles.platforms, EditorStyles.boldLabel); EditorGUILayout.BeginVertical(GUI.skin.box); using (var change = new EditorGUI.ChangeCheckScope()) { EditorGUILayout.PropertyField(m_CompatibleWithAnyPlatform, Styles.anyPlatform); if (change.changed) { // Invert state include/exclude compatibility of states that have the opposite compatibility, // so all states are either include or exclude. var compatibleWithAny = m_CompatibleWithAnyPlatform.boolValue; var needToSwap = extraDataTargets.Cast <AssemblyDefinitionState>().Where(p => p.compatibleWithAnyPlatform != compatibleWithAny).ToList(); extraDataSerializedObject.ApplyModifiedProperties(); foreach (var state in needToSwap) { InversePlatformCompatibility(state); } extraDataSerializedObject.Update(); } } if (!m_CompatibleWithAnyPlatform.hasMultipleDifferentValues) { GUILayout.Label(m_CompatibleWithAnyPlatform.boolValue ? Styles.excludePlatforms : Styles.includePlatforms, EditorStyles.boldLabel); for (int i = 0; i < platforms.Length; ++i) { SerializedProperty property; if (i >= m_PlatformCompatibility.arraySize) { m_PlatformCompatibility.arraySize++; property = m_PlatformCompatibility.GetArrayElementAtIndex(i); property.boolValue = false; } else { property = m_PlatformCompatibility.GetArrayElementAtIndex(i); } EditorGUILayout.PropertyField(property, new GUIContent(platforms[i].DisplayName)); } EditorGUILayout.Space(); GUILayout.BeginHorizontal(); if (GUILayout.Button(Styles.selectAll)) { var prop = m_PlatformCompatibility.GetArrayElementAtIndex(0); var end = m_PlatformCompatibility.GetEndProperty(); do { prop.boolValue = true; }while (prop.Next(false) && !SerializedProperty.EqualContents(prop, end)); } if (GUILayout.Button(Styles.deselectAll)) { var prop = m_PlatformCompatibility.GetArrayElementAtIndex(0); var end = m_PlatformCompatibility.GetEndProperty(); do { prop.boolValue = false; }while (prop.Next(false) && !SerializedProperty.EqualContents(prop, end)); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); GUILayout.Space(10f); EditorGUILayout.BeginVertical(GUI.skin.box); GUILayout.Label(Styles.versionDefines, EditorStyles.boldLabel); m_VersionDefineList.DoLayoutList(); EditorGUILayout.EndVertical(); } extraDataSerializedObject.ApplyModifiedProperties(); ApplyRevertGUI(); }
public VerticalGroup(GUILayoutOption[] options = null) { EGL.BeginVertical(options); }
private void OnGUI() { bool recording = NetworkProfiler.IsRunning; float deltaTime = (float)(EditorApplication.timeSinceStartup - lastSetup); lastSetup = EditorApplication.timeSinceStartup; //Draw top bar EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(recording ? "Stop" : "Capture")) { ChangeRecordState(); } if (GUILayout.Button("Clear")) { ClearDrawing(); } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); if (GUILayout.Button("Import datafile")) { string path = EditorUtility.OpenFilePanel("Choose a NetworkProfiler file", "", ""); if (!string.IsNullOrEmpty(path)) { ProfilerTick[] ticks = BinarySerializer.Deserialize <ProfilerContainer>(File.ReadAllBytes(path)).ticks; if (ticks.Length >= 2) { curve = AnimationCurve.Constant(ticks[0].EventId, ticks[(ticks.Length - 1)].EventId, 0); showMax = ticks.Length; showMin = ticks.Length - Mathf.Clamp(100, 0, ticks.Length); } else { curve = AnimationCurve.Constant(0, 1, 0); } currentTicks.Clear(); for (int i = 0; i < ticks.Length; i++) { currentTicks.Add(ticks[i]); uint bytes = 0; if (ticks[i].Events.Count > 0) { for (int j = 0; j < ticks[i].Events.Count; j++) { TickEvent tickEvent = ticks[i].Events[j]; bytes += tickEvent.Bytes; } } curve.AddKey(ticks[i].EventId, bytes); } } } if (GUILayout.Button("Export datafile")) { int max = (int)showMax; int min = (int)showMin; int ticksInRange = max - min; ProfilerTick[] ticks = new ProfilerTick[ticksInRange]; for (int i = min; i < max; i++) { ticks[i - min] = currentTicks[i]; } string path = EditorUtility.SaveFilePanel("Save NetworkProfiler data", "", "networkProfilerData", ""); if (!string.IsNullOrEmpty(path)) { File.WriteAllBytes(path, BinarySerializer.Serialize(new ProfilerContainer() { ticks = ticks })); } } EditorGUILayout.EndHorizontal(); float prevHis = captureCount; captureCount = EditorGUILayout.DelayedIntField("History count", captureCount); if (captureCount <= 0) { captureCount = 1; } updateDelay = EditorGUILayout.Slider("Refresh delay", updateDelay, 0.1f, 10f); EditorGUILayout.EndVertical(); if (prevHis != captureCount) { StartRecording(); } //Cache if (NetworkProfiler.IsRunning) { if (Time.unscaledTime - lastDrawn > updateDelay) { lastDrawn = Time.unscaledTime; currentTicks.Clear(); if (NetworkProfiler.Ticks.Count >= 2) { curve = AnimationCurve.Constant(NetworkProfiler.Ticks.ElementAt(0).EventId, NetworkProfiler.Ticks.ElementAt(NetworkProfiler.Ticks.Count - 1).EventId, 0); } for (int i = 0; i < NetworkProfiler.Ticks.Count; i++) { ProfilerTick tick = NetworkProfiler.Ticks.ElementAt(i); currentTicks.Add(tick); uint bytes = 0; if (tick.Events.Count > 0) { for (int j = 0; j < tick.Events.Count; j++) { TickEvent tickEvent = tick.Events[j]; bytes += tickEvent.Bytes; } } curve.AddKey(tick.EventId, bytes); } } } //Draw Animation curve and slider curve = EditorGUILayout.CurveField(curve); EditorGUILayout.MinMaxSlider(ref showMin, ref showMax, 0, currentTicks.Count); //Verify slider values if (showMin < 0) { showMin = 0; } if (showMax > currentTicks.Count) { showMax = currentTicks.Count; } if (showMin <= 0 && showMax <= 0) { showMin = 0; showMax = currentTicks.Count; } //Draw main board bool hover = false; int nonEmptyTicks = 0; int largestTickCount = 0; int totalTicks = ((int)showMax - (int)showMin); for (int i = (int)showMin; i < (int)showMax; i++) { if (currentTicks[i].Events.Count > 0) { nonEmptyTicks++; //Count non empty ticks } if (currentTicks[i].Events.Count > largestTickCount) { largestTickCount = currentTicks[i].Events.Count; //Get how many events the tick with most events has } } int emptyTicks = totalTicks - nonEmptyTicks; float equalWidth = position.width / totalTicks; float propWidth = equalWidth * 0.3f; float widthPerTick = ((position.width - emptyTicks * propWidth) / nonEmptyTicks); float currentX = 0; int emptyStreak = 0; for (int i = (int)showMin; i < (int)showMax; i++) { ProfilerTick tick = currentTicks[i]; if (tick.Events.Count == 0 && i != totalTicks - 1) { emptyStreak++; continue; } else if (emptyStreak > 0 || i == totalTicks - 1) { Rect dataRect = new Rect(currentX, 140f, propWidth * emptyStreak, position.height - 140f); currentX += propWidth * emptyStreak; if (emptyStreak >= 2) { EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y, dataRect.width, dataRect.height), emptyStreak.ToString(), wrapStyle); } emptyStreak = 0; } if (tick.Events.Count > 0) { float heightPerEvent = ((position.height - 140f) - (5f * largestTickCount)) / largestTickCount; float currentY = 140f; for (int j = 0; j < tick.Events.Count; j++) { TickEvent tickEvent = tick.Events[j]; Rect dataRect = new Rect(currentX, currentY, widthPerTick, heightPerEvent); if (dataRect.Contains(Event.current.mousePosition)) { hover = true; eventHover = tickEvent; } EditorGUI.DrawRect(dataRect, TickTypeToColor(tickEvent.EventType, true)); EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y, dataRect.width, dataRect.height / 2), tickEvent.EventType.ToString(), wrapStyle); EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y + dataRect.height / 2, dataRect.width, dataRect.height / 2), tickEvent.Bytes + "B", wrapStyle); currentY += heightPerEvent + 5f; } } EditorGUI.DrawRect(new Rect(currentX, 100, widthPerTick, 40), TickTypeToColor(tick.Type, false)); EditorGUI.LabelField(new Rect(currentX, 100, widthPerTick, 20), tick.Type.ToString(), wrapStyle); EditorGUI.LabelField(new Rect(currentX, 120, widthPerTick, 20), tick.Frame.ToString(), wrapStyle); currentX += widthPerTick; } //Calculate alpha if (hover) { hoverAlpha += deltaTime * 10f; if (hoverAlpha > 1f) { hoverAlpha = 1f; } else if (hoverAlpha < 0f) { hoverAlpha = 0f; } } else { hoverAlpha -= deltaTime * 10f; if (hoverAlpha > 1f) { hoverAlpha = 1f; } else if (hoverAlpha < 0f) { hoverAlpha = 0f; } } //Draw hover thingy if (eventHover != null) { Rect rect = new Rect(Event.current.mousePosition, new Vector2(500, 100)); EditorGUI.DrawRect(rect, GetEditorColorWithAlpha(hoverAlpha)); float heightPerField = (rect.height - 5) / 4; EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + 5, rect.width, rect.height), "EventType: " + eventHover.EventType.ToString(), GetStyleWithTextAlpha(EditorStyles.label, hoverAlpha)); EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + heightPerField * 1 + 5, rect.width, rect.height), "Size: " + eventHover.Bytes + "B", GetStyleWithTextAlpha(EditorStyles.label, hoverAlpha)); EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + heightPerField * 2 + 5, rect.width, rect.height), "Channel: " + eventHover.ChannelName, GetStyleWithTextAlpha(EditorStyles.label, hoverAlpha)); EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + heightPerField * 3 + 5, rect.width, rect.height), "MessageType: " + eventHover.MessageType, GetStyleWithTextAlpha(EditorStyles.label, hoverAlpha)); } Repaint(); }
private void OnGUI() { HandleContextMenu(); EditorGUILayout.BeginVertical(); GUILayout.Space(10f); EditorGUILayout.BeginHorizontal(); float leftMargin = (Screen.width / EditorGUIUtility.pixelsPerPoint - Styles.toolbarWidth) * 0.5f; GUILayout.Space(leftMargin); EditMode.DoInspectorToolbar(k_SceneViewEditModes, Styles.toolContents, GridPaintingState.instance); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(leftMargin); DoActiveTargetsGUI(); EditorGUILayout.EndHorizontal(); GUILayout.Space(6f); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); Rect clipboardToolbarRect = EditorGUILayout.BeginHorizontal(GUIContent.none, "Toolbar"); DoClipboardHeader(); EditorGUILayout.EndHorizontal(); Rect dragRect = new Rect(k_DropdownWidth + k_ResizerDragRectPadding, 0, position.width - k_DropdownWidth - k_ResizerDragRectPadding, k_ToolbarHeight); float brushInspectorSize = m_PreviewResizer.ResizeHandle(position, k_MinBrushInspectorHeight, k_MinClipboardHeight, k_ToolbarHeight, dragRect); float clipboardHeight = position.height - brushInspectorSize - k_TopAreaHeight; Rect clipboardRect = new Rect(0f, clipboardToolbarRect.yMax, position.width, clipboardHeight); OnClipboardGUI(clipboardRect); EditorGUILayout.EndVertical(); GUILayout.Space(clipboardRect.height); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(GUIContent.none, "Toolbar"); DoBrushesDropdown(); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); m_BrushScroll = GUILayout.BeginScrollView(m_BrushScroll, false, false); GUILayout.Space(5f); OnBrushInspectorGUI(); GUILayout.EndScrollView(); EditorGUILayout.EndVertical(); Color oldColor = Handles.color; Handles.color = Color.black; Handles.DrawLine(new Vector3(0, clipboardRect.yMax + 0.5f, 0), new Vector3(Screen.width, clipboardRect.yMax + 0.5f, 0)); Handles.color = Color.black.AlphaMultiplied(0.33f); Handles.DrawLine(new Vector3(0, GUILayoutUtility.GetLastRect().yMax + 0.5f, 0), new Vector3(Screen.width, GUILayoutUtility.GetLastRect().yMax + 0.5f, 0)); Handles.color = oldColor; EditorGUILayout.BeginVertical(); GUILayout.Space(2f); EditorGUILayout.EndVertical(); // Keep repainting until all previews are loaded if (AssetPreview.IsLoadingAssetPreviews(GetInstanceID())) { Repaint(); } // Release keyboard focus on click to empty space if (Event.current.type == EventType.MouseDown) { GUIUtility.keyboardControl = 0; } }
public override void OnInspectorGUI() { bool GUIEnabledValue = GUI.enabled; if (Provider.enabled && !Provider.isActive && !EditorUserSettings.WorkOffline) { GUI.enabled = false; } if (m_Edited) { UpdateOrder(m_Edited); m_Edited = null; } EditorGUILayout.BeginVertical(EditorStyles.inspectorFullWidthMargins); { GUILayout.Label(Content.helpText, EditorStyles.helpBox); EditorGUILayout.Space(); // Vertical that contains box and the toolbar below it Rect listRect = EditorGUILayout.BeginVertical(); { int dropFieldId = EditorGUIUtility.GetControlID(s_DropFieldHash, FocusType.Passive, listRect); MonoScript dropped = EditorGUI.DoDropField(listRect, dropFieldId, typeof(MonoScript), MonoScriptValidatorCallback, false, Styles.dropField) as MonoScript; if (dropped) { AddScriptToCustomOrder(dropped); } // Vertical that is used as a border around the scrollview EditorGUILayout.BeginVertical(Styles.boxBackground); { // The scrollview itself m_Scroll = EditorGUILayout.BeginVerticalScrollView(m_Scroll); { // List Rect r = GUILayoutUtility.GetRect(10, kListElementHeight * m_CustomTimeScripts.Count, GUILayout.ExpandWidth(true)); int changed = DragReorderGUI.DragReorder(r, kListElementHeight, m_CustomTimeScripts, DrawElement); if (changed >= 0) { // Give dragged item value in between neighbors SetExecutionOrderAtIndexAccordingToNeighbors(changed, 0); // Update neighbors if needed UpdateOrder(m_CustomTimeScripts[changed]); // Neighbors may have been moved so there's more space around dragged item, // so set order again to get possible rounding benefits SetExecutionOrderAtIndexAccordingToNeighbors(changed, 0); } } EditorGUILayout.EndScrollView(); } EditorGUILayout.EndVertical(); // The toolbar below the box GUILayout.BeginHorizontal(Styles.toolbar); { GUILayout.FlexibleSpace(); Rect r2; GUIContent content = Content.iconToolbarPlus; r2 = GUILayoutUtility.GetRect(content, Styles.toolbarDropDown); if (EditorGUI.DropdownButton(r2, content, FocusType.Passive, Styles.toolbarDropDown)) { ShowScriptPopup(r2); } } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); ApplyRevertGUI(); } GUILayout.EndVertical(); GUI.enabled = GUIEnabledValue; if (Provider.enabled && !Provider.isActive && !EditorUserSettings.WorkOffline) { EditorGUILayout.HelpBox("Version control is disconnected", MessageType.Warning); } GUILayout.FlexibleSpace(); }
private void MultiParticleSystemGUI(bool verticalLayout) { // Background GUILayout.BeginVertical(ParticleSystemStyles.Get().effectBgStyle); m_EmitterAreaScrollPos = EditorGUILayout.BeginScrollView(m_EmitterAreaScrollPos); { Rect emitterAreaRect = EditorGUILayout.BeginVertical(); { // Click-Drag with Alt pressed in entire area m_EmitterAreaScrollPos -= EditorGUI.MouseDeltaReader(emitterAreaRect, Event.current.alt); // Top padding GUILayout.Space(3); GUILayout.BeginHorizontal(); // Left padding GUILayout.Space(3); // added because cannot use padding due to clippling // Draw Emitters Color orgColor = GUI.color; bool isRepaintEvent = Event.current.type == EventType.Repaint; bool isShowOnlySelected = IsShowOnlySelectedMode(); List <ParticleSystemUI> selectedSystems = GetSelectedParticleSystemUIs(); for (int i = 0; i < m_Emitters.Length; ++i) { if (i != 0) { GUILayout.Space(ModuleUI.k_SpaceBetweenModules); } bool isSelected = selectedSystems.Contains(m_Emitters[i]); ModuleUI rendererModuleUI = m_Emitters[i].GetParticleSystemRendererModuleUI(); if (isRepaintEvent && rendererModuleUI != null && !rendererModuleUI.enabled) { GUI.color = GetDisabledColor(); } if (isRepaintEvent && isShowOnlySelected && !isSelected) { GUI.color = GetDisabledColor(); } Rect psRect = EditorGUILayout.BeginVertical(); { if (isRepaintEvent && isSelected && m_Emitters.Length > 1) { DrawSelectionMarker(psRect); } m_Emitters[i].OnGUI(ModuleUI.k_CompactFixedModuleWidth, true); } EditorGUILayout.EndVertical(); GUI.color = orgColor; } GUILayout.Space(5); if (GUILayout.Button(s_Texts.addParticleSystem, "OL Plus", GUILayout.Width(20))) { // Store state of inspector before creating new particle system that will reload the inspector (new selected object) //SessionState.SetFloat("CurrentEmitterAreaScroll", m_EmitterAreaScrollPos.x); CreateParticleSystem(ParticleSystemEditorUtils.GetRoot(m_SelectedParticleSystems[0]), SubModuleUI.SubEmitterType.None); } GUILayout.FlexibleSpace(); // prevent centering GUILayout.EndHorizontal(); GUILayout.Space(4); // Click-Drag in background (does not require Alt pressed) m_EmitterAreaScrollPos -= EditorGUI.MouseDeltaReader(emitterAreaRect, true); GUILayout.FlexibleSpace(); // Makes the emitter area background extend to bottom } EditorGUILayout.EndVertical(); // EmitterAreaRect } EditorGUILayout.EndScrollView(); GUILayout.EndVertical(); // Background //GUILayout.FlexibleSpace(); // Makes the emitter area background align to bottom of highest emitter // Handle shortcut keys last so we do not activate them if inputfield has used the event HandleKeyboardShortcuts(); }
public override void OnInspectorGUI() { //RG_NetworkLobbyManager rg_NetworkLobbyManager = (RG_NetworkLobbyManager)target; EditorGUILayout.BeginVertical("Box"); if (m_DontDestroyOnLoadProperty == null || m_DontDestroyOnLoadLabel == null) { m_Initialized = false; } InitLobby(); if (!m_Initialized) { m_LobbySceneLabel = new GUIContent("Lobby Scene", "The scene loaded for the lobby"); //m_PlaySceneLabel = new GUIContent("Play Scene", "The scene loaded to play the game"); m_MaxPlayersLabel = new GUIContent("Max Players", "The maximum number of players allowed in the lobby."); m_MaxPlayersPerConnectionLabel = new GUIContent("Max Players Per Connection", "The maximum number of players that each connection/client can have in the lobby. Defaults to 1."); m_MinPlayersLabel = new GUIContent("Minimum Players", "The minimum number of players required to be ready for the game to start. If this is zero then the game can start with any number of players."); //m_ShowLobbyGUIProperty = serializedObject.FindProperty("m_ShowLobbyGUI"); m_MaxPlayersProperty = serializedObject.FindProperty("m_MaxPlayers"); m_MaxPlayersPerConnectionProperty = serializedObject.FindProperty("m_MaxPlayersPerConnection"); m_MinPlayersProperty = serializedObject.FindProperty("m_MinPlayers"); m_LobbyPlayerPrefabProperty = serializedObject.FindProperty("m_LobbyPlayerPrefab"); //m_GamePlayerPrefabProperty = serializedObject.FindProperty("m_GamePlayerPrefab"); m_GamePlayerPrefabProperty = serializedObject.FindProperty("m_GamePlayerPrefab"); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_GamePlayerPrefabProperty, true); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } } Init(); var lobby = target as NetworkLobbyManager; if (lobby == null) { return; } serializedObject.Update(); ShowLobbyScenes(); EditorGUILayout.PropertyField(m_LobbyPlayerPrefabProperty); EditorGUI.BeginChangeCheck(); var newGamPlayer = EditorGUILayout.ObjectField("Game Player Prefab", lobby.gamePlayerPrefab, typeof(NetworkIdentity), false); if (EditorGUI.EndChangeCheck()) { if (newGamPlayer == null) { m_GamePlayerPrefabProperty.objectReferenceValue = null; } else { var newGamePlayerIdentity = newGamPlayer as NetworkIdentity; if (newGamePlayerIdentity != null) { if (newGamePlayerIdentity.gameObject != lobby.gamePlayerPrefab) { m_GamePlayerPrefabProperty.objectReferenceValue = newGamePlayerIdentity.gameObject; } } } } EditorGUILayout.PropertyField(m_DontDestroyOnLoadProperty, m_DontDestroyOnLoadLabel); EditorGUILayout.PropertyField(m_RunInBackgroundProperty, m_RunInBackgroundLabel); EditorGUILayout.PropertyField(m_MaxPlayersProperty, m_MaxPlayersLabel); EditorGUILayout.PropertyField(m_MaxPlayersPerConnectionProperty, m_MaxPlayersPerConnectionLabel); EditorGUILayout.PropertyField(m_MinPlayersProperty, m_MinPlayersLabel); if (EditorGUILayout.PropertyField(m_LogLevelProperty)) { LogFilter.currentLogLevel = (int)m_NetworkManager.logLevel; } ShowConfigInfo(); ShowSimulatorInfo(); ShowNetworkInfo(); ShowSpawnInfo(); serializedObject.ApplyModifiedProperties(); EditorGUILayout.EndVertical(); EditorGUILayout.Separator(); //EditorGUILayout.PropertyField(m_ShowLobbyGUIProperty); if (!Application.isPlaying) { return; } ShowLobbySlots(); //ShowDerivedProperties(typeof(NetworkLobbyManager), typeof(NetworkManager)); }
private static void DisplayAgentControls(UnityEngine.Object target, SceneView sceneView) { EditorGUIUtility.labelWidth = 150f; bool flag = false; if (Event.current.type == EventType.Layout) { s_NavMeshEditorWindow.m_HasPendingAgentDebugInfo = NavMeshVisualizationSettings.hasPendingAgentDebugInfo; } bool showAgentPath = NavMeshVisualizationSettings.showAgentPath; if (showAgentPath != EditorGUILayout.Toggle(EditorGUIUtility.TextContent("Show Path Polygons|Shows the polygons leading to goal."), showAgentPath, new GUILayoutOption[0])) { NavMeshVisualizationSettings.showAgentPath = !showAgentPath; flag = true; } bool showAgentPathInfo = NavMeshVisualizationSettings.showAgentPathInfo; if (showAgentPathInfo != EditorGUILayout.Toggle(EditorGUIUtility.TextContent("Show Path Query Nodes|Shows the nodes expanded during last path query."), showAgentPathInfo, new GUILayoutOption[0])) { NavMeshVisualizationSettings.showAgentPathInfo = !showAgentPathInfo; flag = true; } bool showAgentNeighbours = NavMeshVisualizationSettings.showAgentNeighbours; if (showAgentNeighbours != EditorGUILayout.Toggle(EditorGUIUtility.TextContent("Show Neighbours|Show the agent neighbours cosidered during simulation."), showAgentNeighbours, new GUILayoutOption[0])) { NavMeshVisualizationSettings.showAgentNeighbours = !showAgentNeighbours; flag = true; } bool showAgentWalls = NavMeshVisualizationSettings.showAgentWalls; if (showAgentWalls != EditorGUILayout.Toggle(EditorGUIUtility.TextContent("Show Walls|Shows the wall segments handled during simulation."), showAgentWalls, new GUILayoutOption[0])) { NavMeshVisualizationSettings.showAgentWalls = !showAgentWalls; flag = true; } bool showAgentAvoidance = NavMeshVisualizationSettings.showAgentAvoidance; if (showAgentAvoidance != EditorGUILayout.Toggle(EditorGUIUtility.TextContent("Show Avoidance|Shows the processed avoidance geometry from simulation."), showAgentAvoidance, new GUILayoutOption[0])) { NavMeshVisualizationSettings.showAgentAvoidance = !showAgentAvoidance; flag = true; } if (showAgentAvoidance) { if (s_NavMeshEditorWindow.m_HasPendingAgentDebugInfo) { GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.MaxWidth(165f) }; EditorGUILayout.BeginVertical(options); EditorGUILayout.HelpBox("Avoidance display is not valid until after next game update.", MessageType.Warning); EditorGUILayout.EndVertical(); } if (s_NavMeshEditorWindow.m_SelectedNavMeshAgentCount > 10) { GUILayoutOption[] optionArray2 = new GUILayoutOption[] { GUILayout.MaxWidth(165f) }; EditorGUILayout.BeginVertical(optionArray2); EditorGUILayout.HelpBox(string.Concat(new object[] { "Avoidance visualization can be drawn for ", 10, " agents (", s_NavMeshEditorWindow.m_SelectedNavMeshAgentCount, " selected)." }), MessageType.Warning); EditorGUILayout.EndVertical(); } } if (flag) { RepaintSceneAndGameViews(); } }
internal bool DrawInspector() { serializedObject.Update(); GameObject go = target as GameObject; // Don't let icon be null as it will create null reference exceptions. Texture2D icon = (Texture2D)(Styles.typelessIcon.image); // Leave iconContent to be default if multiple objects not the same type. if (m_AllOfSamePrefabType) { icon = PrefabUtility.GetIconForGameObject(go); } // Can't do this in OnEnable since it will cause Styles static initializer to be called and // access properties on EditorStyles static class before that one has been initialized. if (m_OpenPrefabContent == null) { if (targets.Length == 1) { GameObject originalSourceOrVariant = PrefabUtility.GetOriginalSourceOrVariantRoot((GameObject)target); if (originalSourceOrVariant != null) { m_OpenPrefabContent = new GUIContent( Styles.openPrefab.text, string.Format(Styles.openPrefab.tooltip, originalSourceOrVariant.name)); } } if (m_OpenPrefabContent == null) { m_OpenPrefabContent = new GUIContent(Styles.openPrefab.text); } } EditorGUILayout.BeginHorizontal(); Vector2 dropDownSize = EditorGUI.GetObjectIconDropDownSize(kIconSize, kIconSize); EditorGUI.ObjectIconDropDown(GUILayoutUtility.GetRect(dropDownSize.x, dropDownSize.y, GUILayout.ExpandWidth(false)), targets, true, icon, m_Icon); DrawPostIconContent(); using (new EditorGUI.DisabledScope(m_ImmutableSelf)) { EditorGUILayout.BeginVertical(); { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.BeginHorizontal(GUILayout.Width(Styles.tagFieldWidth)); { GUILayout.FlexibleSpace(); // IsActive EditorGUI.PropertyField( GUILayoutUtility.GetRect(EditorStyles.toggle.padding.left, EditorGUIUtility.singleLineHeight, EditorStyles.toggle, GUILayout.ExpandWidth(false)), m_IsActive, GUIContent.none); } EditorGUILayout.EndHorizontal(); // Disable the name field of root GO in prefab asset using (new EditorGUI.DisabledScope(m_IsAsset && m_IsAssetRoot)) { // Name EditorGUILayout.DelayedTextField(m_Name, GUIContent.none, EditorStyles.boldTextField); } // Static flags toggle DoStaticToggleField(go); // Static flags dropdown DoStaticFlagsDropDown(go); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(EditorGUI.kControlVerticalSpacing); EditorGUILayout.BeginHorizontal(); { // Tag DoTagsField(go); EditorGUILayout.Space(EditorGUI.kDefaultSpacing, false); // Layer DoLayerField(go); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); // Prefab Toolbar if (EditorGUIUtility.comparisonViewMode == EditorGUIUtility.ComparisonViewMode.None) { EditorGUILayout.Space(EditorGUI.kControlVerticalSpacing); DoPrefabButtons(); } serializedObject.ApplyModifiedProperties(); return(true); }
public override void OnInspectorGUI() { // Tabs. { // Select tabs. EditorGUI.BeginChangeCheck(); var rect = EditorGUILayout.BeginVertical(Styles.kSettingsFramebox); // Draw General Settings Tab. GUIStyle buttonStyle = null; var buttonRect = GetTabSelection(rect, 0, out buttonStyle); if (GUI.Toggle(buttonRect, generalSettingsSelected, Content.kGeneralLabel, buttonStyle)) { generalSettingsSelected = true; } // Draw Collision Settings Tab. buttonRect = GetTabSelection(rect, 1, out buttonStyle); if (GUI.Toggle(buttonRect, !generalSettingsSelected, Content.kCollisionLabel, buttonStyle)) { generalSettingsSelected = false; } GUILayoutUtility.GetRect(10, EditorGUI.kTabButtonHeight); EditorGUI.EndChangeCheck(); } // Draw tab selection. if (generalSettingsSelected) { // Update object. serializedObject.Update(); // Draw standard property settings. EditorGUILayout.Space(); EditorGUILayout.Space(); DrawPropertiesExcluding(serializedObject, "m_JobOptions", "m_ReuseCollisionCallbacks", "m_AutoSyncTransforms", "m_GizmoOptions"); // Reuse Collision Callbacks. EditorGUILayout.PropertyField(m_ReuseCollisionCallbacks); if (!m_ReuseCollisionCallbacks.boolValue) { EditorGUILayout.HelpBox(Content.kReuseCollisionCallbacksLabel.ToString(), MessageType.Warning, false); EditorGUILayout.Space(); } // Auto Sync Transforms. EditorGUILayout.PropertyField(m_AutoSyncTransforms); if (m_AutoSyncTransforms.boolValue) { EditorGUILayout.HelpBox(Content.kAutoSyncTransformsLabel.ToString(), MessageType.Warning, false); EditorGUILayout.Space(); } // Draw the Gizmo options. Physics2D.GizmoOptions gizmoOptions = (Physics2D.GizmoOptions)m_GizmoOptions.intValue; gizmoOptions = (Physics2D.GizmoOptions)EditorGUILayout.EnumFlagsField(Content.kGizmosLabel, gizmoOptions); m_GizmoOptions.intValue = (int)gizmoOptions; // Multithreading. GUILayout.BeginHorizontal(); GUILayout.Space(0); EditorGUILayout.PropertyField(m_Multithreading, Content.kMultithreadingLabel, true); GUILayout.EndHorizontal(); // Padding. EditorGUILayout.Space(); // Apply changes. serializedObject.ApplyModifiedProperties(); } else { // Layer Collision Matrix. LayerCollisionMatrixGUI2D.Draw( Content.kLayerCollisionMatrixLabel, (int layerA, int layerB) => { return(!Physics2D.GetIgnoreLayerCollision(layerA, layerB)); }, (int layerA, int layerB, bool val) => { Physics2D.IgnoreLayerCollision(layerA, layerB, !val); } ); } EditorGUILayout.EndVertical(); }
private void DrawToolbar() { if (!canEditInScene) { EditorGUILayout.HelpBox(Styles.disabledEditMessage, MessageType.Info); } EditorGUILayout.BeginVertical("GroupBox"); GUILayout.Label(Styles.sceneTools); EditorGUI.BeginDisabled(!canEditInScene); EditorGUILayout.Space(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); EditMode.DoInspectorToolbar(Styles.sceneViewEditModes, Styles.toolContents, GetBounds, this); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); // Tools box GUILayout.BeginVertical(EditorStyles.helpBox); string helpText = Styles.baseSceneEditingToolText; if (sceneViewEditing) { int index = ArrayUtility.IndexOf(Styles.sceneViewEditModes, EditMode.editMode); if (index >= 0) { helpText = Styles.ToolNames[index].text; } } GUILayout.Label(helpText, Styles.richTextMiniLabel); GUILayout.EndVertical(); // Editing mode toolbar if (sceneViewEditing) { switch (EditMode.editMode) { case EditMode.SceneViewEditMode.LineRendererEdit: DrawEditPointTools(); break; case EditMode.SceneViewEditMode.LineRendererCreate: CreatePointTools(); break; } } if (!sceneViewEditing) { EditorGUI.BeginChangeCheck(); showSimplifyPreview = EditorGUILayout.Toggle(Styles.simplifyPreview, showSimplifyPreview); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(Styles.tolerance); simplifyTolerance = Mathf.Max(0, EditorGUILayout.FloatField(simplifyTolerance, GUILayout.MaxWidth(35.0f))); if (GUILayout.Button(Styles.simplify, EditorStyles.miniButton)) { SimplifyPoints(); } if (EditorGUI.EndChangeCheck()) { ResetSimplifyPreview(); SceneView.RepaintAll(); } EditorGUILayout.EndHorizontal(); } EditorGUI.EndDisabled(); EditorGUILayout.EndVertical(); }