{"TotalCount":4,"Files":[{"Ident":"null.fuib","Path":"Code/FixedUpdateInputSystem.cs","FileName":"FixedUpdateInputSystem.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":62303,"IsPrivate":false,"Code":"using System.Collections.Generic;\r\n\r\nnamespace Sandbox;\r\n\r\n/// \u003Csummary\u003E\r\n/// How to use the system: \r\n/// \u003Ccode\u003E\r\n/// public sealed class ExampleComponent : Component\r\n/// {\r\n///\t\t// Reference to the system.\r\n///\t\tprivate FixedUpdateInputSystem _fixedInput;\r\n///\t\t\r\n///\t\tprotected override void Start()\r\n///\t\t{\r\n///\t\t\t// Get the reference like this:\r\n///\t\t\t_fixedInput = Scene.GetSystem\u0026lt;FixedUpdateInputSystem\u0026gt;();\r\n///\t\t\t\r\n///\t\t\tbase.OnStart();\r\n///\t\t}\r\n///\t\t\r\n///\t\tprotected override void OnFixedUpdate()\r\n///\t\t{\r\n///\t\t\t// Query for input like usual.\r\n///\t\t\tif( _fixedInput.Pressed(\u0022jump\u0022) )\r\n///\t\t\t{\r\n///\t\t\t\tLog.Info(\u0022Jumped\u0022);\r\n///\t\t\t}\r\n///\t\t\t\r\n///\t\t\tbase.OnFixedUpdate();\r\n///\t\t}\r\n/// }\r\n/// \u003C/code\u003E\r\n/// \u003C/summary\u003E\r\npublic sealed class FixedUpdateInputSystem : GameObjectSystem\r\n{\r\n\tprivate struct FixedUpdateInputBuffer\r\n\t{\r\n\t\tprivate class State\r\n\t\t{\r\n\t\t\tpublic bool Held;\r\n\t\t\tpublic bool Pressed;\r\n\t\t\tpublic bool Released;\r\n\t\t}\r\n\r\n\t\tprivate Dictionary\u003Cstring, State\u003E _actionStates;\r\n\r\n\t\tpublic FixedUpdateInputBuffer()\r\n\t\t{\r\n\t\t\t_actionStates = new Dictionary\u003Cstring, State\u003E();\r\n\r\n\t\t\tforeach ( var b in Input.GetActions() )\r\n\t\t\t{\r\n\t\t\t\t_actionStates[b.Name.ToLowerInvariant()] = new State();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t/// \u003Csummary\u003E\r\n\t\t/// Call from a \u003Csee cref=\u0022Component.OnUpdate\u0022/\u003E method\r\n\t\t/// to update the states of the actions.\r\n\t\t/// \u003C/summary\u003E\r\n\t\tpublic void OnUpdate()\r\n\t\t{\r\n\t\t\tforeach ( var (name, state) in _actionStates )\r\n\t\t\t{\r\n\t\t\t\tif ( Input.Down( name ) )\r\n\t\t\t\t\t_actionStates[name].Held = true;\r\n\r\n\t\t\t\tif ( Input.Pressed( name ) )\r\n\t\t\t\t\t_actionStates[name].Pressed = true;\r\n\r\n\t\t\t\tif ( Input.Released( name ) )\r\n\t\t\t\t\t_actionStates[name].Released = true;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t/// \u003Csummary\u003E\r\n\t\t/// Call from a \u003Csee cref=\u0022Component.OnFixedUpdate\u0022/\u003E\r\n\t\t/// method to get the \u003Csee cref=\u0022State.Held\u0022/\u003E state of this action.\r\n\t\t/// \u003C/summary\u003E\r\n\t\t/// \u003Cparam name=\u0022action\u0022\u003EThe action name (case insensitive).\u003C/param\u003E\r\n\t\t/// \u003Creturns\u003E\u003C/returns\u003E\r\n\t\t/// \r\n\t\tpublic bool Held( string action )\r\n\t\t{\r\n\t\t\treturn _actionStates[action.ToLowerInvariant()].Held;\r\n\t\t}\r\n\r\n\t\t/// \u003Csummary\u003E\r\n\t\t/// Call from a \u003Csee cref=\u0022Component.OnFixedUpdate\u0022/\u003E\r\n\t\t/// method to get the \u003Csee cref=\u0022State.Pressed\u0022/\u003E state of this action.\r\n\t\t/// \u003C/summary\u003E\r\n\t\t/// \u003Cparam name=\u0022action\u0022\u003EThe action name (case insensitive).\u003C/param\u003E\r\n\t\t/// \u003Creturns\u003E\u003C/returns\u003E\r\n\t\tpublic bool Pressed( string action )\r\n\t\t{\r\n\t\t\treturn _actionStates[action.ToLowerInvariant()].Pressed;\r\n\t\t}\r\n\r\n\t\t/// \u003Csummary\u003E\r\n\t\t/// Call from a \u003Csee cref=\u0022Component.OnFixedUpdate\u0022/\u003E\r\n\t\t/// method to get the \u003Csee cref=\u0022State.Pressed\u0022/\u003E state of this action.\r\n\t\t/// \u003C/summary\u003E\r\n\t\t/// \u003Cparam name=\u0022action\u0022\u003EThe action name (case insensitive).\u003C/param\u003E\r\n\t\t/// \u003Creturns\u003E\u003C/returns\u003E\r\n\t\tpublic bool Released( string action )\r\n\t\t{\r\n\t\t\treturn _actionStates[action.ToLowerInvariant()].Released;\r\n\t\t}\r\n\r\n\t\t/// \u003Csummary\u003E\r\n\t\t/// Call at the end of your \u003Csee cref=\u0022Component.OnFixedUpdate\u0022/\u003E method\r\n\t\t/// to clear the state of the struct and reset.\r\n\t\t/// \u003C/summary\u003E\r\n\t\tpublic void Clear()\r\n\t\t{\r\n\t\t\tforeach ( var actionName in _actionStates.Keys )\r\n\t\t\t{\r\n\t\t\t\t_actionStates[actionName].Held = false;\r\n\t\t\t\t_actionStates[actionName].Pressed = false;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tprivate FixedUpdateInputBuffer _buffer;\r\n\r\n\tpublic FixedUpdateInputSystem( Scene scene ) : base( scene )\r\n\t{\r\n\t\t_buffer = new();\r\n\t\tListen( Stage.StartUpdate, int.MinValue, OnStartUpdate, \u0022FUIB.OnStartUpdate\u0022 );\r\n\t\tListen( Stage.FinishFixedUpdate, int.MaxValue, OnFinishFixedUpdate, \u0022FUIB.OnFinishFixedUpdate\u0022 );\r\n\t}\r\n\r\n\tprivate void OnStartUpdate()\r\n\t{\r\n\t\t_buffer.OnUpdate();\r\n\t}\r\n\r\n\tprivate void OnFinishFixedUpdate()\r\n\t{\r\n\t\t_buffer.Clear();\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Is the action currently held down?\r\n\t/// \u003C/summary\u003E\r\n\t/// \u003Cparam name=\u0022action\u0022\u003EThe action name (case insensitive).\u003C/param\u003E\r\n\t/// \u003Creturns\u003E\u003C/returns\u003E\r\n\t/// \r\n\tpublic bool Held( string action ) =\u003E _buffer.Held( action );\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Was the action pressed?\r\n\t/// \u003C/summary\u003E\r\n\t/// \u003Cparam name=\u0022action\u0022\u003EThe action name (case insensitive).\u003C/param\u003E\r\n\t/// \u003Creturns\u003E\u003C/returns\u003E\r\n\tpublic bool Pressed( string action ) =\u003E _buffer.Pressed( action );\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Was the action released?\r\n\t/// \u003C/summary\u003E\r\n\t/// \u003Cparam name=\u0022action\u0022\u003EThe action name (case insensitive).\u003C/param\u003E\r\n\t/// \u003Creturns\u003E\u003C/returns\u003E\r\n\tpublic bool Released( string action ) =\u003E _buffer.Released( action );\r\n}\r\n"},{"Ident":"null.fuib","Path":"UnitTests/UnitTest.cs","FileName":"UnitTest.cs","PackageType":"library","CodeKind":"UnitTest","AssetVersionId":62303,"IsPrivate":false,"Code":"global using Microsoft.VisualStudio.TestTools.UnitTesting;\r\n\r\n[TestClass]\r\npublic class TestInit\r\n{\r\n\t[AssemblyInitialize]\r\n\tpublic static void ClassInitialize( TestContext context )\r\n\t{\r\n\t\tSandbox.Application.InitUnitTest();\r\n\t}\r\n}\r\n"},{"Ident":"null.fuib","Path":"Editor/MyEditorMenu.cs","FileName":"MyEditorMenu.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":62303,"IsPrivate":false,"Code":"using Editor;\r\n\r\npublic static class MyEditorMenu\r\n{\r\n\t[Menu( \u0022Editor\u0022, \u0022fuib/My Menu Option\u0022 )]\r\n\tpublic static void OpenMyMenu()\r\n\t{\r\n\t\tEditorUtility.DisplayDialog( \u0022It worked!\u0022, \u0022This is being called from your library\u0027s editor code!\u0022 );\r\n\t}\r\n}\r\n"},{"Ident":"null.fuib","Path":"UnitTests/LibraryTest.cs","FileName":"LibraryTest.cs","PackageType":"library","CodeKind":"UnitTest","AssetVersionId":62303,"IsPrivate":false,"Code":"using Sandbox;\r\n\r\n[TestClass]\r\npublic partial class LibraryTests\r\n{\r\n\t[TestMethod]\r\n\tpublic void SceneTest()\r\n\t{\r\n\t\tvar scene = new Scene();\r\n\t\tusing ( scene.Push() )\r\n\t\t{\r\n\t\t\tvar go = new GameObject();\r\n\r\n\t\t\tAssert.AreEqual( 1, scene.Directory.GameObjectCount );\r\n\t\t}\r\n\t}\r\n\r\n}\r\n"}]}