public static DelayedIntField ( |
||
label | Optional label to display in front of the int field. | |
value | int | The value to edit. |
Результат | int |
public override void OnInspectorGUI() { if (play) { EGL.LabelField("Play mode", gm.playMode.ToString()); EGL.LabelField("Gen. seed", gm.generatorSeed.ToString()); } else { gm.playMode = (PlayMode)EGL.EnumPopup("Play mode", gm.playMode); if (gm.playMode == PlayMode.RandomDungeon) { gm.generatorSeed = EGL.DelayedIntField("Gen. seed", gm.generatorSeed); if (GL.Button("Random seed")) { gm.generatorSeed = new Random().Next(); } } } }
private void OnPlaneGenerationGUI() { planeGenerationData = planeGenerationData ?? new PlaneGenerationData(); planeGenerationData.direction = (PlaneGenerationData.Direction)UG.EnumPopup("平面方向", planeGenerationData.direction); UG.BeginHorizontal(); planeGenerationData.length = UG.DelayedFloatField("长", planeGenerationData.length); planeGenerationData.width = UG.DelayedFloatField("宽", planeGenerationData.width); UG.EndHorizontal(); UG.BeginHorizontal(); planeGenerationData.verticesPerLength = UG.DelayedIntField("长顶点数", planeGenerationData.verticesPerLength); planeGenerationData.verticesPerWidth = UG.DelayedIntField("宽顶点数", planeGenerationData.verticesPerWidth); UG.EndHorizontal(); bool legal = true; string errorMessage = String.Empty; if (defaultMaterial == null) { legal = false; errorMessage += "默认材质不能为空"; } if (planeGenerationData.length <= 0) { legal = false; errorMessage += "平面长必须大于0\n"; } if (planeGenerationData.width <= 0) { legal = false; errorMessage += "平面宽必须大于0\n"; } if (planeGenerationData.verticesPerLength <= 0) { legal = false; errorMessage += "平面长顶点数必须大于0\n"; } if (planeGenerationData.verticesPerWidth <= 0) { legal = false; errorMessage += "平面宽顶点数必须大于0\n"; } if (legal) { if (GUILayout.Button("生成")) { MeshTool.InstantiatePlane(planeGenerationData, defaultMaterial); } } else { UG.HelpBox(errorMessage, MessageType.Error); } }
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 heightPerTotalBackground = ((position.height - 140f) - (5f * largestTickCount)) / tick.Events.Count; 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(); }
protected void OnRenderTextureGUI(GUIElements guiElements) { GUI.changed = false; bool isTexture3D = (m_Dimension.intValue == (int)UnityEngine.Rendering.TextureDimension.Tex3D); EditorGUILayout.IntPopup(m_Dimension, styles.dimensionStrings, styles.dimensionValues, styles.dimension); GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(styles.size, EditorStyles.popup); EditorGUILayout.DelayedIntField(m_Width, GUIContent.none, GUILayout.MinWidth(40)); GUILayout.Label(styles.cross); EditorGUILayout.DelayedIntField(m_Height, GUIContent.none, GUILayout.MinWidth(40)); if (isTexture3D) { GUILayout.Label(styles.cross); EditorGUILayout.DelayedIntField(m_Depth, GUIContent.none, GUILayout.MinWidth(40)); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if ((guiElements & GUIElements.RenderTargetAAGUI) != 0) { EditorGUILayout.IntPopup(m_AntiAliasing, styles.renderTextureAntiAliasing, styles.renderTextureAntiAliasingValues, styles.antiAliasing); } EditorGUILayout.PropertyField(m_ColorFormat, styles.colorFormat); if ((guiElements & GUIElements.RenderTargetDepthGUI) != 0) { EditorGUILayout.PropertyField(m_DepthFormat, styles.depthBuffer); } bool isHDRRenderTexture = IsHDRFormat((RenderTextureFormat)m_ColorFormat.intValue); using (new EditorGUI.DisabledScope(isHDRRenderTexture)) { EditorGUILayout.PropertyField(m_sRGB, styles.sRGBTexture); } using (new EditorGUI.DisabledScope(isTexture3D)) { EditorGUILayout.PropertyField(m_EnableMipmaps, styles.enableMipmaps); using (new EditorGUI.DisabledScope(!m_EnableMipmaps.boolValue)) EditorGUILayout.PropertyField(m_AutoGeneratesMipmaps, styles.autoGeneratesMipmaps); } if (isTexture3D) { // Mip map generation is not supported yet for 3D textures. EditorGUILayout.HelpBox("3D RenderTextures do not support Mip Maps.", MessageType.Info); } EditorGUILayout.PropertyField(m_UseDynamicScale, styles.useDynamicScale); var rt = target as RenderTexture; if (GUI.changed && rt != null) { rt.Release(); } EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); DoWrapModePopup(); DoFilterModePopup(); using (new EditorGUI.DisabledScope(RenderTextureHasDepth())) // Render Textures with depth are forced to 0 Aniso Level { DoAnisoLevelSlider(); } if (RenderTextureHasDepth()) { // RenderTextures don't enforce this nicely. RenderTexture only forces Aniso to 0 if the gfx card // supports depth, rather than forcing Aniso to zero depending on what the user asks of the RT. If the // user requests any kind of depth then we will force aniso to zero here. m_Aniso.intValue = 0; EditorGUILayout.HelpBox("RenderTextures with depth must have an Aniso Level of 0.", MessageType.Info); } if (EditorGUI.EndChangeCheck()) { ApplySettingsToTextures(); } }
protected void OnRenderTextureGUI(GUIElements guiElements) { GUI.changed = false; bool isTexture3D = (m_Dimension.intValue == (int)UnityEngine.Rendering.TextureDimension.Tex3D); EditorGUILayout.IntPopup(m_Dimension, styles.dimensionStrings, styles.dimensionValues, styles.dimension); GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(styles.size, EditorStyles.popup); EditorGUILayout.DelayedIntField(m_Width, GUIContent.none, GUILayout.MinWidth(40)); GUILayout.Label(styles.cross); EditorGUILayout.DelayedIntField(m_Height, GUIContent.none, GUILayout.MinWidth(40)); if (isTexture3D) { GUILayout.Label(styles.cross); EditorGUILayout.DelayedIntField(m_Depth, GUIContent.none, GUILayout.MinWidth(40)); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if ((guiElements & GUIElements.RenderTargetAAGUI) != 0) { EditorGUILayout.IntPopup(m_AntiAliasing, styles.renderTextureAntiAliasing, styles.renderTextureAntiAliasingValues, styles.antiAliasing); } GraphicsFormat format = (GraphicsFormat)m_ColorFormat.intValue; GraphicsFormat compatibleFormat = SystemInfo.GetCompatibleFormat(format, FormatUsage.Render); using (new EditorGUI.DisabledScope(compatibleFormat == GraphicsFormat.None)) EditorGUILayout.PropertyField(m_EnableCompatibleFormat, styles.enableCompatibleFormat); EditorGUILayout.PropertyField(m_ColorFormat, styles.colorFormat); if (compatibleFormat != format) { string text = string.Format("Format {0} is not supported on this platform. ", format.ToString()); if (compatibleFormat != GraphicsFormat.None) { if (m_EnableCompatibleFormat.boolValue) { text += string.Format("Using {0} as a compatible format.", compatibleFormat.ToString()); } else { text += string.Format("You may enable Compatible Color Format to fallback automatically to a platform specific compatible format, {0} on this device.", compatibleFormat.ToString()); } } EditorGUILayout.HelpBox(text, m_EnableCompatibleFormat.boolValue && compatibleFormat != GraphicsFormat.None ? MessageType.Warning : MessageType.Error); } if ((guiElements & GUIElements.RenderTargetDepthGUI) != 0) { EditorGUILayout.PropertyField(m_DepthFormat, styles.depthBuffer); } m_sRGB.boolValue = GraphicsFormatUtility.IsSRGBFormat(format); using (new EditorGUI.DisabledScope(isTexture3D)) { EditorGUILayout.PropertyField(m_EnableMipmaps, styles.enableMipmaps); using (new EditorGUI.DisabledScope(!m_EnableMipmaps.boolValue)) EditorGUILayout.PropertyField(m_AutoGeneratesMipmaps, styles.autoGeneratesMipmaps); } if (isTexture3D) { // Mip map generation is not supported yet for 3D textures. EditorGUILayout.HelpBox("3D RenderTextures do not support Mip Maps.", MessageType.Info); } EditorGUILayout.PropertyField(m_UseDynamicScale, styles.useDynamicScale); var rt = target as RenderTexture; if (GUI.changed && rt != null) { rt.Release(); } EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); DoWrapModePopup(); DoFilterModePopup(); using (new EditorGUI.DisabledScope(RenderTextureHasDepth())) // Render Textures with depth are forced to 0 Aniso Level { DoAnisoLevelSlider(); } if (RenderTextureHasDepth()) { // RenderTextures don't enforce this nicely. RenderTexture only forces Aniso to 0 if the gfx card // supports depth, rather than forcing Aniso to zero depending on what the user asks of the RT. If the // user requests any kind of depth then we will force aniso to zero here. m_Aniso.intValue = 0; EditorGUILayout.HelpBox("RenderTextures with depth must have an Aniso Level of 0.", MessageType.Info); } if (EditorGUI.EndChangeCheck()) { ApplySettingsToTextures(); } }
public override void OnPaintInspectorGUI() { EditorGUI.BeginChangeCheck(); randomBrush.pickRandomTiles = EditorGUILayout.Toggle("Pick Random Tiles", randomBrush.pickRandomTiles); using (new EditorGUI.DisabledScope(!randomBrush.pickRandomTiles)) { randomBrush.addToRandomTiles = EditorGUILayout.Toggle("Add To Random Tiles", randomBrush.addToRandomTiles); } EditorGUI.BeginChangeCheck(); randomBrush.randomTileSetSize = EditorGUILayout.Vector3IntField("Tile Set Size", randomBrush.randomTileSetSize); if (EditorGUI.EndChangeCheck()) { for (int i = 0; i < randomBrush.randomTileSets.Length; ++i) { int sizeCount = randomBrush.randomTileSetSize.x * randomBrush.randomTileSetSize.y * randomBrush.randomTileSetSize.z; randomBrush.randomTileSets[i].randomTiles = new TileBase[sizeCount]; } } int randomTileSetCount = EditorGUILayout.DelayedIntField("Number of Tiles", randomBrush.randomTileSets != null ? randomBrush.randomTileSets.Length : 0); if (randomTileSetCount < 0) { randomTileSetCount = 0; } if (randomBrush.randomTileSets == null || randomBrush.randomTileSets.Length != randomTileSetCount) { Array.Resize(ref randomBrush.randomTileSets, randomTileSetCount); for (int i = 0; i < randomBrush.randomTileSets.Length; ++i) { int sizeCount = randomBrush.randomTileSetSize.x * randomBrush.randomTileSetSize.y * randomBrush.randomTileSetSize.z; if (randomBrush.randomTileSets[i].randomTiles == null || randomBrush.randomTileSets[i].randomTiles.Length != sizeCount) { randomBrush.randomTileSets[i].randomTiles = new TileBase[sizeCount]; } } } if (randomTileSetCount > 0) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Place random tiles."); for (int i = 0; i < randomTileSetCount; i++) { EditorGUILayout.LabelField("Tile Set " + (i + 1)); for (int j = 0; j < randomBrush.randomTileSets[i].randomTiles.Length; ++j) { randomBrush.randomTileSets[i].randomTiles[j] = (TileBase)EditorGUILayout.ObjectField("Tile " + (j + 1), randomBrush.randomTileSets[i].randomTiles[j], typeof(TileBase), false, null); } } } if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(randomBrush); } }
protected void OnRenderTextureGUI(RenderTextureEditor.GUIElements guiElements) { GUI.changed = false; bool flag = this.m_Dimension.intValue == 3; EditorGUILayout.IntPopup(this.m_Dimension, RenderTextureEditor.styles.dimensionStrings, RenderTextureEditor.styles.dimensionValues, RenderTextureEditor.styles.dimension, new GUILayoutOption[0]); GUILayout.BeginHorizontal(new GUILayoutOption[0]); EditorGUILayout.PrefixLabel(RenderTextureEditor.styles.size, EditorStyles.popup); EditorGUILayout.DelayedIntField(this.m_Width, GUIContent.none, new GUILayoutOption[] { GUILayout.MinWidth(40f) }); GUILayout.Label(RenderTextureEditor.styles.cross, new GUILayoutOption[0]); EditorGUILayout.DelayedIntField(this.m_Height, GUIContent.none, new GUILayoutOption[] { GUILayout.MinWidth(40f) }); if (flag) { GUILayout.Label(RenderTextureEditor.styles.cross, new GUILayoutOption[0]); EditorGUILayout.DelayedIntField(this.m_Depth, GUIContent.none, new GUILayoutOption[] { GUILayout.MinWidth(40f) }); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if ((guiElements & RenderTextureEditor.GUIElements.RenderTargetAAGUI) != RenderTextureEditor.GUIElements.RenderTargetNoneGUI) { EditorGUILayout.IntPopup(this.m_AntiAliasing, RenderTextureEditor.styles.renderTextureAntiAliasing, RenderTextureEditor.styles.renderTextureAntiAliasingValues, RenderTextureEditor.styles.antiAliasing, new GUILayoutOption[0]); } EditorGUILayout.PropertyField(this.m_ColorFormat, RenderTextureEditor.styles.colorFormat, new GUILayoutOption[0]); if ((guiElements & RenderTextureEditor.GUIElements.RenderTargetDepthGUI) != RenderTextureEditor.GUIElements.RenderTargetNoneGUI) { EditorGUILayout.PropertyField(this.m_DepthFormat, RenderTextureEditor.styles.depthBuffer, new GUILayoutOption[0]); } bool disabled = RenderTextureEditor.IsHDRFormat((RenderTextureFormat)this.m_ColorFormat.intValue); using (new EditorGUI.DisabledScope(disabled)) { EditorGUILayout.PropertyField(this.m_sRGB, RenderTextureEditor.styles.sRGBTexture, new GUILayoutOption[0]); } using (new EditorGUI.DisabledScope(flag)) { EditorGUILayout.PropertyField(this.m_EnableMipmaps, RenderTextureEditor.styles.enableMipmaps, new GUILayoutOption[0]); using (new EditorGUI.DisabledScope(!this.m_EnableMipmaps.boolValue)) { EditorGUILayout.PropertyField(this.m_AutoGeneratesMipmaps, RenderTextureEditor.styles.autoGeneratesMipmaps, new GUILayoutOption[0]); } } if (flag) { EditorGUILayout.HelpBox("3D RenderTextures do not support Mip Maps.", MessageType.Info); } RenderTexture renderTexture = base.target as RenderTexture; if (GUI.changed && renderTexture != null) { renderTexture.Release(); } EditorGUILayout.Space(); base.DoWrapModePopup(); base.DoFilterModePopup(); using (new EditorGUI.DisabledScope(this.RenderTextureHasDepth())) { base.DoAnisoLevelSlider(); } if (this.RenderTextureHasDepth()) { this.m_Aniso.intValue = 0; EditorGUILayout.HelpBox("RenderTextures with depth must have an Aniso Level of 0.", MessageType.Info); } }