public override void Update(double deltaTime) { base.Update(deltaTime); sliderDrawable.Update(deltaTime); if (this.HasFocus) { if (Add()) { if (ShouldHandle(SliderAction.Add, deltaTime)) { //sliderInfo.Move(sliderInfo.Step); sliderDrawable.MoveByPercentageSmoothly(sliderInfo.PercentageStep); } scriptHasEvaluated = true; } if (Subtract()) { if (ShouldHandle(SliderAction.Subtract, deltaTime)) { //sliderInfo.Move(-sliderInfo.Step); sliderDrawable.MoveByPercentageSmoothly(-sliderInfo.PercentageStep); } scriptHasEvaluated = true; } } CheckMouseIntegration(); sliderAction = scriptHasEvaluated ? sliderAction : SliderAction.None; scriptHasEvaluated = false; }
public IEnumerator ApplySettings() { yield return(null); //Wait for the actions to complete during this frame, then apply during the next. foreach (SettingInfo sInfo in settingsList) { string val = ""; if (sInfo.settingType == GameType.SettingType.Slider) { SliderAction sAction = sInfo.settingObjInstance.GetComponentInChildren <SliderAction>(); val = sAction.currentValue.ToString(); NetworkingGeneral.currentGameType.customSettings[sInfo.settingName].currentValue = val; PlayerPrefs.SetFloat(sInfo.settingName, sAction.currentValue); } else if (sInfo.settingType == GameType.SettingType.Checkbox) { UIToggle toggle = sInfo.settingObjInstance.GetComponentInChildren <UIToggle>(); val = toggle.value.ToString(); NetworkingGeneral.currentGameType.customSettings[sInfo.settingName].currentValue = val; PlayerPrefs.SetInt(sInfo.settingName, (toggle.value) ? 1 : 0); } if (Topan.Network.isConnected && Topan.Network.isServer) { Topan.Network.SetServerInfo(sInfo.settingName, val); } } }
public PlotControl() { // InitializeComponent(); DoubleBuffered = true; Model = new PlotModel(); panAction = new PanAction(this); zoomAction = new ZoomAction(this); sliderAction = new SliderAction(this); MouseActions = new List <MouseAction>(); MouseActions.Add(panAction); MouseActions.Add(zoomAction); MouseActions.Add(sliderAction); }
private bool ShouldHandle(SliderAction action, double deltaTime) { if (this.sliderAction != action) { sliderRepeatTimer = keyRepetition.KeyRepeatStartDuration; this.sliderAction = action; return(true); } if (this.sliderAction == action) { sliderRepeatTimer -= deltaTime; if (sliderRepeatTimer <= 0.0f) { sliderRepeatTimer += keyRepetition.KeyRepeatDuration; return(true); } } return(false); }
public void SliderAction_OnNearestControl_InvokesBeginChangedEnd_WantsRepaint() { var begin = false; var changed = false; var end = false; var control = AddControl("TestControl", 0f); var action = new SliderAction(control); action.onSliderBegin = (s, c, p) => { begin = true; }; action.onSliderChanged = (s, c, p) => { changed = true; }; action.onSliderEnd = (s, c, p) => { end = true; }; m_GUISystem.AddAction(action); SendDrag(); Assert.IsTrue(begin, "OnSliderBegin was not invoked"); Assert.IsTrue(changed, "OnSliderChanged was not invoked"); Assert.IsTrue(end, "OnSliderEnd was not invoked"); Assert.IsTrue(m_GUIState.repaintFlag, "OnRepaint was not invoked"); }
public void ChangedGameType() { settingsList.Clear(); gameTypeName = gameModePopup.value; modeLabel.text = "[A0A0A0]- " + gameTypeName + "[-]"; NetworkingGeneral.currentGameType = (GameTypeInterface)System.Activator.CreateInstance(MultiplayerMenu.possibleGameTypes[gameTypeName]); NetworkingGeneral.currentGameType.InitializeSettings(); foreach (Transform trans in spawnStart) { Destroy(trans.gameObject); } int i = 0; foreach (KeyValuePair <string, GameType.GameTypeSetting> pair in NetworkingGeneral.currentGameType.customSettings) { GameObject settingInst = null; if (pair.Value.settingType == GameType.SettingType.Slider) { settingInst = (GameObject)Instantiate(sliderSettingPrefab); SettingInfo info = new SettingInfo(); info.settingObjInstance = settingInst; info.settingName = pair.Key; info.settingType = GameType.SettingType.Slider; SliderAction sAction = settingInst.GetComponentInChildren <SliderAction>(); if (pair.Key == "Kill Limit") { sAction.minValue = 25f; sAction.maxValue = 500f; sAction.defaultValue = PlayerPrefs.GetFloat("Kill Limit", float.Parse(pair.Value.currentValue)); sAction.suffix = " kills"; sAction.SetIntervalSteps((int)(sAction.maxValue - sAction.minValue)); } settingsList.Add(info); } else if (pair.Value.settingType == GameType.SettingType.Checkbox) { settingInst = (GameObject)Instantiate(checkboxSettingPrefab); SettingInfo info = new SettingInfo(); info.settingObjInstance = settingInst; info.settingName = pair.Key; info.settingType = GameType.SettingType.Checkbox; UIToggle toggle = settingInst.GetComponentInChildren <UIToggle>(); if (pair.Key == "Friendly Fire") { toggle.value = (PlayerPrefs.GetInt("Friendly Fire", (pair.Value.currentValue == "True") ? 1 : 0) == 1) ? true : false; } else if (pair.Key == "Team Auto-Balance") { toggle.value = (PlayerPrefs.GetInt("Team Auto-Balance", (pair.Value.currentValue == "True") ? 1 : 0) == 1) ? true : false; } settingsList.Add(info); } if (settingInst != null) { settingInst.transform.parent = spawnStart; settingInst.transform.localPosition = -Vector3.up * i * spacing; settingInst.transform.localScale = Vector3.one; settingInst.name = pair.Key; settingInst.GetComponentInChildren <UILabel>().text = pair.Key + ":"; } i++; } StartCoroutine(ApplySettings()); }
private GUISystem CreateSystem(UnityObject target) { var guiSystem = new GUISystem(new GUIState()); GUIAction removePointAction = null; var pointControl = new GenericControl("Point") { count = () => { return(GetPointCount(target)); }, distance = (guiState, i) => { var position = GetPointWorld(target, i); return(ShapeEditorUtility.DistanceToCircle(position, ShapeEditorUtility.GetHandleSize(position) * 10f)); }, position = (i) => { return(GetPointWorld(target, i)); }, forward = (i) => { return(GetForward(target)); }, up = (i) => { return(GetUp(target)); }, right = (i) => { return(GetRight(target)); }, onRepaint = (IGUIState guiState, Control control, int index) => { var position = GetPointWorld(target, index); if (guiState.hotControl == control.actionID && control.hotLayoutData.index == index) { m_Drawer.DrawPointSelected(position); } else if (guiState.hotControl == 0 && guiState.nearestControl == control.ID && control.layoutData.index == index) { if (removePointAction.IsEnabled(guiState)) { m_Drawer.DrawRemovePointPreview(position); } else { m_Drawer.DrawPointHovered(position); } } else { m_Drawer.DrawPoint(position); } } }; var edgeControl = new GenericControl("Edge") { count = () => { return(GetPointCount(target)); }, distance = (IGUIState guiState, int index) => { return(ShapeEditorUtility.DistanceToSegment(GetPointWorld(target, index), NextControlPoint(target, index))); }, position = (i) => { return(GetPointWorld(target, i)); }, forward = (i) => { return(GetForward(target)); }, up = (i) => { return(GetUp(target)); }, right = (i) => { return(GetRight(target)); }, onRepaint = (IGUIState guiState, Control control, int index) => { var nextIndex = NextIndex(target, index); var prevIndex = PrevIndex(target, index); var isEndpointHovered = guiState.hotControl == 0 && guiState.nearestControl == pointControl.ID && (index == pointControl.layoutData.index || nextIndex == pointControl.layoutData.index); var isPointHovered = guiState.hotControl == 0 && guiState.nearestControl == pointControl.ID && index == pointControl.layoutData.index; var color = Color.white; if (guiState.hotControl == 0 && guiState.nearestControl == control.ID && control.layoutData.index == index) { color = Color.yellow; } else if (removePointAction.IsEnabled(guiState) && isEndpointHovered) { if (isPointHovered) { m_Drawer.DrawDottedLine(GetPointWorld(target, prevIndex), GetPointWorld(target, nextIndex), 5f, color); } color = Color.red; } m_Drawer.DrawLine(GetPointWorld(target, index), GetPointWorld(target, nextIndex), 5f, color); } }; var createPointAction = new CreatePointAction(pointControl, edgeControl) { enable = (guiState, action) => { return(guiState.isShiftDown); }, enableRepaint = (IGUIState guiState, GUIAction action) => { return(guiState.nearestControl != pointControl.ID && guiState.hotControl == 0); }, repaintOnMouseMove = (guiState, action) => { return(true); }, guiToWorld = (mousePosition) => { return(GUIToWorld(target, mousePosition)); }, onCreatePoint = (int index, Vector3 position) => { InsertPointWorld(target, index + 1, position); }, onPreRepaint = (guiState, action) => { var position = ClosestPointInEdge(target, guiState.mousePosition, edgeControl.layoutData.index); m_Drawer.DrawCreatePointPreview(position); } }; removePointAction = new ClickAction(pointControl, 0) { enable = (guiState, action) => { return(guiState.isActionKeyDown); }, onClick = (GUIState, control) => { if (GetPointCount(target) > 3) { RemovePoint(target, control.layoutData.index); } } }; var movePointAction = new SliderAction(pointControl) { onSliderChanged = (guiState, control, position) => { var index = control.hotLayoutData.index; var pointPosition = GetPointWorld(target, index); pointPosition = position; SetPointWorld(target, index, pointPosition); } }; var moveEdgeAction = new SliderAction(edgeControl) { onSliderChanged = (guiState, control, position) => { var index = control.hotLayoutData.index; var pointPosition = GetPointWorld(target, index); var delta = position - pointPosition; pointPosition += delta; SetPointWorld(target, index, pointPosition); pointPosition = NextControlPoint(target, index); pointPosition += delta; SetPointWorld(target, NextIndex(target, index), pointPosition); } }; guiSystem.AddControl(edgeControl); guiSystem.AddControl(pointControl); guiSystem.AddAction(createPointAction); guiSystem.AddAction(removePointAction); guiSystem.AddAction(movePointAction); guiSystem.AddAction(moveEdgeAction); return(guiSystem); }
public PathEditor(GUISystem guiSystem) { m_GUISystem = guiSystem; var m_PointControl = new GenericControl("Point") { count = GetPointCount, distance = (guiState, i) => { var position = GetPoint(i).position; return(guiState.DistanceToCircle(position, guiState.GetHandleSize(position) * 10f)); }, position = (i) => { return(GetPoint(i).position); }, forward = (i) => { return(GetForward()); }, up = (i) => { return(GetUp()); }, right = (i) => { return(GetRight()); }, onRepaint = DrawPoint }; var m_EdgeControl = new GenericControl("Edge") { count = GetEdgeCount, distance = DistanceToEdge, position = (i) => { return(GetPoint(i).position); }, forward = (i) => { return(GetForward()); }, up = (i) => { return(GetUp()); }, right = (i) => { return(GetRight()); }, onRepaint = DrawEdge }; m_EdgeControl.onEndLayout = (guiState) => { controller.AddClosestPath(m_EdgeControl.layoutData.distance); }; var m_LeftTangentControl = new GenericControl("LeftTangent") { count = () => { if (GetShapeType() != ShapeType.Spline) { return(0); } return(GetPointCount()); }, distance = (guiState, i) => { if (linearTangentIsZero && GetPoint(i).tangentMode == TangentMode.Linear) { return(float.MaxValue); } if (!IsSelected(i) || IsOpenEnded() && i == 0) { return(float.MaxValue); } var position = GetLeftTangent(i); return(guiState.DistanceToCircle(position, guiState.GetHandleSize(position) * 10f)); }, position = (i) => { return(GetLeftTangent(i)); }, forward = (i) => { return(GetForward()); }, up = (i) => { return(GetUp()); }, right = (i) => { return(GetRight()); }, onRepaint = (guiState, control, i) => { if (!IsSelected(i) || IsOpenEnded() && i == 0) { return; } var point = GetPoint(i); if (linearTangentIsZero && point.tangentMode == TangentMode.Linear) { return; } var position = point.position; var leftTangent = GetLeftTangent(i); drawer.DrawTangent(position, leftTangent); } }; var m_RightTangentControl = new GenericControl("RightTangent") { count = () => { if (GetShapeType() != ShapeType.Spline) { return(0); } return(GetPointCount()); }, distance = (guiState, i) => { if (linearTangentIsZero && GetPoint(i).tangentMode == TangentMode.Linear) { return(float.MaxValue); } if (!IsSelected(i) || IsOpenEnded() && i == GetPointCount() - 1) { return(float.MaxValue); } var position = GetRightTangent(i); return(guiState.DistanceToCircle(position, guiState.GetHandleSize(position) * 10f)); }, position = (i) => { return(GetRightTangent(i)); }, forward = (i) => { return(GetForward()); }, up = (i) => { return(GetUp()); }, right = (i) => { return(GetRight()); }, onRepaint = (guiState, control, i) => { if (!IsSelected(i) || IsOpenEnded() && i == GetPointCount() - 1) { return; } var point = GetPoint(i); if (linearTangentIsZero && point.tangentMode == TangentMode.Linear) { return; } var position = point.position; var rightTangent = GetRightTangent(i); drawer.DrawTangent(position, rightTangent); } }; var m_CreatePointAction = new CreatePointAction(m_PointControl, m_EdgeControl) { enable = (guiState, action) => !IsAltDown(guiState) && !guiState.isActionKeyDown && controller.closestEditablePath == controller.editablePath, enableRepaint = (guiState, action) => EnableCreatePointRepaint(guiState, m_PointControl, m_LeftTangentControl, m_RightTangentControl), repaintOnMouseMove = (guiState, action) => true, guiToWorld = GUIToWorld, onCreatePoint = (index, position) => { controller.RegisterUndo("Create Point"); controller.CreatePoint(index, position); }, onPreRepaint = (guiState, action) => { if (GetPointCount() > 0) { var position = ClosestPointInEdge(guiState, guiState.mousePosition, m_EdgeControl.layoutData.index); drawer.DrawCreatePointPreview(position); } } }; Action <IGUIState> removePoints = (guiState) => { controller.RegisterUndo("Remove Point"); controller.RemoveSelectedPoints(); guiState.changed = true; }; var m_RemovePointAction1 = new CommandAction(kDeleteCommandName) { enable = (guiState, action) => { return(GetSelectedPointCount() > 0); }, onCommand = removePoints }; var m_RemovePointAction2 = new CommandAction(kSoftDeleteCommandName) { enable = (guiState, action) => { return(GetSelectedPointCount() > 0); }, onCommand = removePoints }; var dragged = false; var m_MovePointAction = new SliderAction(m_PointControl) { enable = (guiState, action) => !IsAltDown(guiState), onClick = (guiState, control) => { dragged = false; var index = control.layoutData.index; if (!IsSelected(index)) { controller.RegisterUndo("Selection"); if (!guiState.isActionKeyDown) { controller.ClearSelection(); } controller.SelectPoint(index, true); guiState.changed = true; } }, onSliderChanged = (guiState, control, position) => { var index = control.hotLayoutData.index; var delta = SnapIfNeeded(position) - GetPoint(index).position; if (!dragged) { controller.RegisterUndo("Move Point"); dragged = true; } controller.MoveSelectedPoints(delta); } }; var m_MoveEdgeAction = new SliderAction(m_EdgeControl) { enable = (guiState, action) => !IsAltDown(guiState) && guiState.isActionKeyDown, onSliderBegin = (guiState, control, position) => { dragged = false; }, onSliderChanged = (guiState, control, position) => { var index = control.hotLayoutData.index; var delta = position - GetPoint(index).position; if (!dragged) { controller.RegisterUndo("Move Edge"); dragged = true; } controller.MoveEdge(index, delta); } }; var cachedRightTangent = Vector3.zero; var cachedLeftTangent = Vector3.zero; var cachedTangentMode = TangentMode.Linear; var m_MoveLeftTangentAction = new SliderAction(m_LeftTangentControl) { enable = (guiState, action) => !IsAltDown(guiState), onSliderBegin = (guiState, control, position) => { dragged = false; var point = GetPoint(control.hotLayoutData.index); cachedRightTangent = point.rightTangent; cachedTangentMode = point.tangentMode; }, onSliderChanged = (guiState, control, position) => { var index = control.hotLayoutData.index; var setToLinear = m_PointControl.distance(guiState, index) <= DefaultControl.kPickDistance; if (!dragged) { controller.RegisterUndo("Move Tangent"); dragged = true; } position = SnapIfNeeded(position); controller.SetLeftTangent(index, position, setToLinear, guiState.isShiftDown, cachedRightTangent, cachedTangentMode); } }; var m_MoveRightTangentAction = new SliderAction(m_RightTangentControl) { enable = (guiState, action) => !IsAltDown(guiState), onSliderBegin = (guiState, control, position) => { dragged = false; var point = GetPoint(control.hotLayoutData.index); cachedLeftTangent = point.leftTangent; cachedTangentMode = point.tangentMode; }, onSliderChanged = (guiState, control, position) => { var index = control.hotLayoutData.index; var setToLinear = m_PointControl.distance(guiState, index) <= DefaultControl.kPickDistance; if (!dragged) { controller.RegisterUndo("Move Tangent"); dragged = true; } position = SnapIfNeeded(position); controller.SetRightTangent(index, position, setToLinear, guiState.isShiftDown, cachedLeftTangent, cachedTangentMode); } }; m_GUISystem.AddControl(m_EdgeControl); m_GUISystem.AddControl(m_PointControl); m_GUISystem.AddControl(m_LeftTangentControl); m_GUISystem.AddControl(m_RightTangentControl); m_GUISystem.AddAction(m_CreatePointAction); m_GUISystem.AddAction(m_RemovePointAction1); m_GUISystem.AddAction(m_RemovePointAction2); m_GUISystem.AddAction(m_MovePointAction); m_GUISystem.AddAction(m_MoveEdgeAction); m_GUISystem.AddAction(m_MoveLeftTangentAction); m_GUISystem.AddAction(m_MoveRightTangentAction); }
public override void OnInspectorGUI() { SliderAction sa = target as SliderAction; if (sa.label == null) { GUILayout.Label("Please assign all GUI Objects!", EditorStyles.boldLabel); GUILayout.Space(10); sa.label = (UILabel)EditorGUILayout.ObjectField("Label:", sa.label, typeof(UILabel), true); } sa.minValue = EditorGUILayout.FloatField("Minimum Value:", Mathf.Clamp(sa.minValue, 0, Mathf.Infinity)); sa.maxValue = EditorGUILayout.FloatField("Maximum Value:", Mathf.Clamp(sa.maxValue, sa.minValue, Mathf.Infinity)); sa.defaultValue = EditorGUILayout.Slider("Default Value:", sa.defaultValue, sa.minValue, sa.maxValue); sa.decimalPlaces = EditorGUILayout.IntField("Decimal Places:", Mathf.Clamp(sa.decimalPlaces, 0, 10)); sa.prefix = EditorGUILayout.TextField("Prefix:", sa.prefix); sa.suffix = EditorGUILayout.TextField("Suffix:", sa.suffix); GUILayout.Space(15); sa.isSensitivitySlider = EditorGUILayout.Toggle("Sensitivity:", sa.isSensitivitySlider); if (sa.isSensitivitySlider) { sa.sDir = (SliderAction.SensitivityDir)EditorGUILayout.EnumPopup("Direction", sa.sDir); } sa.isMouseSmoothingSlider = EditorGUILayout.Toggle("Mouse Smoothing:", sa.isMouseSmoothingSlider); sa.isShadowDistanceSlider = EditorGUILayout.Toggle("Shadow Distance:", sa.isShadowDistanceSlider); sa.isVegetationDistanceSlider = EditorGUILayout.Toggle("Vegetation Distance:", sa.isVegetationDistanceSlider); sa.isVegetationDensitySlider = EditorGUILayout.Toggle("Vegetation Density:", sa.isVegetationDensitySlider); sa.isTreeDrawDistanceSlider = EditorGUILayout.Toggle("Tree Draw Distance", sa.isTreeDrawDistanceSlider); sa.isMaxTreesSlider = EditorGUILayout.Toggle("Tree Mesh Limit:", sa.isMaxTreesSlider); sa.isSoundVolumeSlider = EditorGUILayout.Toggle("Sound Volume:", sa.isSoundVolumeSlider); sa.isFOVSlider = EditorGUILayout.Toggle("FOV:", sa.isFOVSlider); sa.isGammaSlider = EditorGUILayout.Toggle("Brightness:", sa.isGammaSlider); sa.isGameDurationSlider = EditorGUILayout.Toggle("Game Duration:", sa.isGameDurationSlider); if (sa.isGameDurationSlider) { EditorGUI.indentLevel += 1; isOpen = EditorGUILayout.Foldout(isOpen, "Available Durations (" + sa.availableDurations.Length + "):"); if (isOpen) { int length = sa.availableDurations.Length; int[] tempStorage = sa.availableDurations; EditorGUI.indentLevel += 1; length = EditorGUILayout.IntField("Length:", length); if (length != sa.availableDurations.Length) { sa.availableDurations = new int[length]; for (int i = 0; i < tempStorage.Length; i++) { if (i < sa.availableDurations.Length) { sa.availableDurations[i] = tempStorage[i]; } } } EditorGUI.indentLevel += 1; for (int i = 0; i < length; i++) { sa.availableDurations[i] = EditorGUILayout.IntField("Element " + i.ToString() + ":", sa.availableDurations[i]); } EditorGUI.indentLevel -= 1; EditorGUI.indentLevel -= 1; } EditorGUI.indentLevel -= 1; } sa.isRoundAmountSlider = EditorGUILayout.Toggle("Round Amount:", sa.isRoundAmountSlider); if (sa.isRoundAmountSlider) { EditorGUI.indentLevel += 1; isOpen1 = EditorGUILayout.Foldout(isOpen1, "Available Round Amounts (" + sa.availableRoundCounts.Length + "):"); if (isOpen1) { int length = sa.availableRoundCounts.Length; int[] tempStorage = sa.availableRoundCounts; EditorGUI.indentLevel += 1; length = EditorGUILayout.IntField("Length:", length); if (length != sa.availableRoundCounts.Length) { sa.availableRoundCounts = new int[length]; for (int i = 0; i < tempStorage.Length; i++) { if (i < sa.availableRoundCounts.Length) { sa.availableRoundCounts[i] = tempStorage[i]; } } } EditorGUI.indentLevel += 1; for (int i = 0; i < length; i++) { sa.availableRoundCounts[i] = EditorGUILayout.IntField("Element " + i.ToString() + ":", sa.availableRoundCounts[i]); } EditorGUI.indentLevel -= 1; EditorGUI.indentLevel -= 1; } EditorGUI.indentLevel -= 1; } sa.isIdleTimerSlider = EditorGUILayout.Toggle("Idle Timer Limit:", sa.isIdleTimerSlider); if (sa.isIdleTimerSlider) { EditorGUI.indentLevel += 1; isOpen2 = EditorGUILayout.Foldout(isOpen2, "Available Idle Times (" + sa.availableIdleLimit.Length + "):"); if (isOpen2) { int length = sa.availableIdleLimit.Length; int[] tempStorage = sa.availableIdleLimit; EditorGUI.indentLevel += 1; length = EditorGUILayout.IntField("Length:", length); if (length != sa.availableIdleLimit.Length) { sa.availableIdleLimit = new int[length]; for (int i = 0; i < tempStorage.Length; i++) { if (i < sa.availableIdleLimit.Length) { sa.availableIdleLimit[i] = tempStorage[i]; } } } EditorGUI.indentLevel += 1; for (int i = 0; i < length; i++) { sa.availableIdleLimit[i] = EditorGUILayout.IntField("Element " + i.ToString() + ":", sa.availableIdleLimit[i]); } EditorGUI.indentLevel -= 1; EditorGUI.indentLevel -= 1; } EditorGUI.indentLevel -= 1; } sa.isMaxPlayerSlider = EditorGUILayout.Toggle("Max Players:", sa.isMaxPlayerSlider); sa.isBotCountSlider = EditorGUILayout.Toggle("Bot Count:", sa.isBotCountSlider); if (GUI.changed) { EditorUtility.SetDirty(sa); } }