// ------------------- static public TouchSteeringWheelSpriteAnimator CreateWheelAnimator( TouchSteeringWheel target, string nameSuffix, Sprite sprite, float scale, string undoLabel = null) { RectTransform subObj = CreateSubRectTr(target.transform, target.name + nameSuffix, scale); // Create Sprite animator... TouchSteeringWheelSpriteAnimator sprAnimator = subObj.gameObject.AddComponent <TouchSteeringWheelSpriteAnimator>(); sprAnimator.autoConnectToSource = true; sprAnimator.SetSourceControl(target); sprAnimator.SetStateSprite(TouchSteeringWheelSpriteAnimator.ControlState.Neutral, sprite); SetImagePreserveAspectRatio(subObj.gameObject, true); if (undoLabel != null) { Undo.RegisterCreatedObjectUndo(subObj.gameObject, undoLabel); } return(sprAnimator); }
// --------------- public override void OnInspectorGUI() { TouchSteeringWheelSpriteAnimator target = this.target as TouchSteeringWheelSpriteAnimator; if ((target == null)) { return; } if (!TouchControlSpriteAnimatorInspector.DrawSourceGUI(target)) { return; } TouchSteeringWheel wheel = target.sourceControl as TouchSteeringWheel; InspectorUtils.BeginIndentedSection(new GUIContent("Sprite Settings")); this.spriteNeutral.Draw(target.spriteNeutral, target, true, false); EditorGUILayout.Space(); this.spritePressed.Draw(target.spritePressed, target, target.IsIllegallyAttachedToSource()); InspectorUtils.EndIndentedSection(); // Scaling GUI... float rotationRange = target.rotationRange, rotationSmoothingTime = target.rotationSmoothingTime; InspectorUtils.BeginIndentedSection(new GUIContent("Transform Animation Settings")); if ((wheel != null) && (wheel.wheelMode == TouchSteeringWheel.WheelMode.Turn)) { GUI.enabled = false; CFGUI.FloatField(new GUIContent("Rot. range", "Wheel's Rotation Range - in TURN wheel mode it's taken from Wheel."), wheel.maxTurnAngle, 0, 100000, 65); GUI.enabled = true; } else { rotationRange = CFGUI.Slider(new GUIContent("Rot. range", "Wheel's Rotation Range"), rotationRange, 0, 180, 65); } rotationSmoothingTime = CFGUI.FloatFieldEx(new GUIContent("Smooting Time (ms)", "Wheel Rotation Smooting Time in milliseconds"), rotationSmoothingTime, 0, 10, 1000, true, 120); EditorGUILayout.Space(); // TouchControlSpriteAnimatorInspector.DrawScaleGUI(target); InspectorUtils.EndIndentedSection(); if ((rotationRange != target.rotationRange) || (rotationSmoothingTime != target.rotationSmoothingTime)) { CFGUI.CreateUndo("Sprite Animator Trsnaform modification", target); target.rotationRange = rotationRange; target.rotationSmoothingTime = rotationSmoothingTime; CFGUI.EndUndo(target); } }
// --------------- public override void OnInspectorGUI() { TouchSteeringWheel c = (TouchSteeringWheel)this.target; GUILayout.Box(GUIContent.none, CFEditorStyles.Inst.headerWheel, GUILayout.ExpandWidth(true)); this.DrawWarnings(c); // Steerign wheel GUI... TouchSteeringWheel.WheelMode wheelMode = c.wheelMode; bool limitTurnSpeed = c.limitTurnSpeed; float minTurnTime = c.minTurnTime, maxReturnTime = c.maxReturnTime, maxTurnAngle = c.maxTurnAngle, turnModeDeadZone = c.turnModeDeadZone; // digitalThresh = c.digitalThresh; bool physicalMode = c.physicalMode, sendInputWhileReturning = c.sendInputWhileReturning; float physicalMoveRangeCm = c.physicalMoveRangeCm; this.emulateTouchPressure = c.emulateTouchPressure; const float LABEL_WIDTH = 120; // Steering Wheel specific inspector.... InspectorUtils.BeginIndentedSection(new GUIContent("Steering Wheel Settings")); wheelMode = (TouchSteeringWheel.WheelMode)CFGUI.EnumPopup(new GUIContent("Wheel Mode"), wheelMode, LABEL_WIDTH); if (c.wheelMode == TouchSteeringWheel.WheelMode.Turn) { maxTurnAngle = CFGUI.FloatField(new GUIContent("Max. Turn Angle", "Maximal Turn angle in degrees (TURN Wheel Mode)."), maxTurnAngle, 1, 3600, LABEL_WIDTH); turnModeDeadZone = CFGUI.Slider(new GUIContent("Dead-zone", "Dead-zone - how far from wheel's center a finger must be to interact with it."), turnModeDeadZone, 0.01f, 0.9f, LABEL_WIDTH); } else { physicalMode = EditorGUILayout.ToggleLeft(new GUIContent("Physical Swipe Mode", "Define wheel's range in centimeters."), physicalMode); if (physicalMode) { InspectorUtils.BeginIndentedSection(); physicalMoveRangeCm = CFGUI.FloatFieldEx(new GUIContent("Range (cm)", "Physical Mode's range in centimeters."), physicalMoveRangeCm, 0.1f, 10, 1, false, LABEL_WIDTH); InspectorUtils.EndIndentedSection(); } } limitTurnSpeed = EditorGUILayout.ToggleLeft(new GUIContent("Limit turn speed", "Limit how fast the wheel can turn and how fast it can return to neutral position."), limitTurnSpeed); if (limitTurnSpeed) { InspectorUtils.BeginIndentedSection(); minTurnTime = CFGUI.FloatFieldEx(new GUIContent("Turn Time", "Turn Time in milliseconds - how quick can this wheel move from neutral position to maximal turn angle.\nSet to zero to remove speed limit."), minTurnTime, 0, 5, 1000, true, LABEL_WIDTH); maxReturnTime = CFGUI.FloatFieldEx(new GUIContent("Return Time", "Time in milliseconds needed to return from maximal turn angle to neutral position."), maxReturnTime, 0, 5, 1000, true, LABEL_WIDTH); InspectorUtils.EndIndentedSection(); } EditorGUILayout.Space(); this.analogConfigInsp.DrawGUI(c.analogConfig); InspectorUtils.EndIndentedSection(); InspectorUtils.BeginIndentedSection(new GUIContent("Steering Wheel Bindings")); sendInputWhileReturning = EditorGUILayout.ToggleLeft(new GUIContent("Send input while returning", "If enabled, wheel's analog state will be sent to the rig while the wheel is returning to the neutral position."), sendInputWhileReturning, GUILayout.MinWidth(30)); EditorGUILayout.Space(); this.pressBindingInsp.Draw(c.pressBinding, c.rig); this.touchPressureBindingInsp.Draw(c.touchPressureBinding, c.rig); this.analogTurnBindingInsp.Draw(c.analogTurnBinding, c.rig); this.turnLeftBindingInsp.Draw(c.turnLeftBinding, c.rig); this.turnRightBindingInsp.Draw(c.turnRightBinding, c.rig); InspectorUtils.EndIndentedSection(); // Register undo... if ((limitTurnSpeed != c.limitTurnSpeed) || (minTurnTime != c.minTurnTime) || (maxReturnTime != c.maxReturnTime) || (wheelMode != c.wheelMode) || (maxTurnAngle != c.maxTurnAngle) || (turnModeDeadZone != c.turnModeDeadZone) || (sendInputWhileReturning != c.sendInputWhileReturning) || (this.emulateTouchPressure != c.emulateTouchPressure) || (physicalMode != c.physicalMode) || (physicalMoveRangeCm != c.physicalMoveRangeCm)) { if ((wheelMode == TouchSteeringWheel.WheelMode.Turn) && (wheelMode != c.wheelMode) && (c.analogConfig.analogDeadZone != 0)) { c.analogConfig.analogDeadZone = 0; } CFGUI.CreateUndo("CF2 Steering Wheel modification", c); c.limitTurnSpeed = limitTurnSpeed; c.minTurnTime = minTurnTime; c.maxReturnTime = maxReturnTime; c.emulateTouchPressure = this.emulateTouchPressure; c.physicalMode = physicalMode; c.physicalMoveRangeCm = physicalMoveRangeCm; c.wheelMode = wheelMode; c.maxTurnAngle = maxTurnAngle; c.turnModeDeadZone = turnModeDeadZone; c.sendInputWhileReturning = sendInputWhileReturning; CFGUI.EndUndo(c); } // Draw Shared Dynamic Control Params... this.DrawDynamicTouchControlGUI(c); }
// --------------- public override void OnInspectorGUI() { TouchSteeringWheel c = (TouchSteeringWheel)this.target; GUILayout.Box(GUIContent.none, CFEditorStyles.Inst.headerWheel, GUILayout.ExpandWidth(true)); this.DrawWarnings(c); // Steerign wheel GUI... bool limitTurnSpeed = c.limitTurnSpeed; float minTurnTime = c.minTurnTime, maxReturnTime = c.maxReturnTime; // digitalThresh = c.digitalThresh; bool physicalMode = c.physicalMode; float physicalMoveRangeCm = c.physicalMoveRangeCm; // const float LABEL_WIDTH = 120; // Steering Wheel specific inspector.... InspectorUtils.BeginIndentedSection(new GUIContent("Steering Wheel Settings")); limitTurnSpeed = EditorGUILayout.ToggleLeft(new GUIContent("Limit turn speed", "Limit how fast the wheel can turn and how fast it can return to neutral position."), limitTurnSpeed); if (limitTurnSpeed) { InspectorUtils.BeginIndentedSection(); minTurnTime = CFGUI.FloatFieldEx(new GUIContent("Min. Turn Time", "Minimal Turn Time in milliseconds - how quick can this wheel move from neutral position to maximal turn angle."), minTurnTime, 0, 5, 1000, true, LABEL_WIDTH); maxReturnTime = CFGUI.FloatFieldEx(new GUIContent("Max. Return Time", "Time in milliseconds needed to return from maximal turn angle to neutral position."), maxReturnTime, 0, 5, 1000, true, LABEL_WIDTH); InspectorUtils.EndIndentedSection(); } physicalMode = EditorGUILayout.ToggleLeft(new GUIContent("Physical Mode", "Define wheel's range in centimeters."), physicalMode); if (physicalMode) { InspectorUtils.BeginIndentedSection(); physicalMoveRangeCm = CFGUI.FloatFieldEx(new GUIContent("Range (cm)", "Physical Mode's range in centimeters."), physicalMoveRangeCm, 0.1f, 10, 1, false, LABEL_WIDTH); InspectorUtils.EndIndentedSection(); } EditorGUILayout.Space(); this.analogConfigInsp.DrawGUI(c.analogConfig); InspectorUtils.EndIndentedSection(); InspectorUtils.BeginIndentedSection(new GUIContent("Steering Wheel Bindings")); this.pressBindingInsp.Draw(c.pressBinding, c.rig); this.analogTurnBindingInsp.Draw(c.analogTurnBinding, c.rig); this.turnLeftBindingInsp.Draw(c.turnLeftBinding, c.rig); this.turnRightBindingInsp.Draw(c.turnRightBinding, c.rig); InspectorUtils.EndIndentedSection(); // Register undo... if ((limitTurnSpeed != c.limitTurnSpeed) || (minTurnTime != c.minTurnTime) || (maxReturnTime != c.maxReturnTime) || //(digitalThresh != c.digitalThresh) || (physicalMode != c.physicalMode) || (physicalMoveRangeCm != c.physicalMoveRangeCm)) { CFGUI.CreateUndo("CF2 Steering Wheel modification", c); c.limitTurnSpeed = limitTurnSpeed; c.minTurnTime = minTurnTime; c.maxReturnTime = maxReturnTime; //c.digitalThresh = digitalThresh; c.physicalMode = physicalMode; c.physicalMoveRangeCm = physicalMoveRangeCm; CFGUI.EndUndo(c); } // Draw Shared Dynamic Control Params... this.DrawDynamicTouchControlGUI(c); }