public static BBInputProfile FromTydTable(TydTable table) { var profile = new BBInputProfile(); profile.Axes = new List <BBInputAxis>(); profile.Name = table.Name; profile.Enabled = false; InGameDebug.Log("Loading new BBInputProfile..."); foreach (var node in table.Nodes) { if (node.Name.ToLowerInvariant() == "enabled") { profile.Enabled = bool.Parse((node as TydString).Value); } else if (node.Name.ToLowerInvariant() == "alwaysenabled") { profile.AlwaysEnabled = bool.Parse((node as TydString).Value); } else if (node.Name.ToLowerInvariant() == "name") { profile.Name = (node as TydString).Value; } else if (node.Name.ToLowerInvariant() == "axes") { foreach (var axisNodes in (node as TydCollection).Nodes) { profile.Axes.Add(BBInputAxis.FromTydTable(axisNodes as TydTable)); } } } profile.Axes.Sort((x, y) => y.Priority - x.Priority); InGameDebug.Log("Loaded BBInputProfile: " + profile.Name); return(profile); }
/// <summary> /// Initialises the input system. Call after LoadProfiles. /// </summary> public static void Initialize() { InGameDebug.Log("BBInput initialized."); var go = GameObject.Instantiate(new GameObject()); go.AddComponent <BBInputUpdater>(); go.name = "BBInputUpdater"; GameObject.DontDestroyOnLoad(go); }
/// <summary> /// Loads all input profiles from the defs. /// </summary> public static void LoadProfiles() { InGameDebug.Log("-----BBInput: Loading input profiles..."); var profilesNode = StreamingAssetsDatabase.GetDef("Input.Profiles") as TydTable; foreach (var profileNode in profilesNode.Nodes) { Profiles.Add(BBInputProfile.FromTydTable(profileNode as TydTable)); } InGameDebug.Log("-----Input profiles loaded."); }
// Start is called before the first frame update void Start() { if (Profile == null) { InGameDebug.Log(GetType().Name + ": Profile was not set."); } _profileNameText.text = Profile.Name; foreach (var axis in Profile.Axes) { Instantiate(_inputAxisDisplay, transform).GetComponent <BBInputAxisDisplay>().Axis = axis; } Canvas.ForceUpdateCanvases(); }
public static void AddOnAxisPressed(string axisName, Action action, int priority = 0) { foreach (var profile in Profiles) { foreach (var axis in profile.Axes) { if (axis.Name == axisName) { axis.AddOnPressed(action, priority); return; } } } InGameDebug.Log("No axis with name '" + axisName + "'."); }
/// <summary> /// Adds an action to be called when an axis is released. /// </summary> /// <param name="axisName">Te name of the axis.</param> /// <param name="action">The action to perform.</param> /// <param name="priority">The priority of the action.</param> public static void AddOnAxisReleased(string axisName, DynValue action, int priority = 0) { foreach (var profile in Profiles) { foreach (var axis in profile.Axes) { if (axis.Name == axisName) { axis.AddOnReleased(() => LuaManager.Call(action), priority); return; } } } InGameDebug.Log("No axis with name '" + axisName + "'."); }
// Start is called before the first frame update void Start() { if (Axis == null) { InGameDebug.Log(GetType().Name + ": Axis was not set."); } _axisNameText.text = Axis.Name; foreach (var binding in Axis.PositiveKeyCodes) { var bindingDisplay = Instantiate(_bindingsDisplayPrefab, transform).GetComponent <BBInputBindingDisplay>(); bindingDisplay.Binding = binding; bindingDisplay.Axis = Axis; } Canvas.ForceUpdateCanvases(); }
private void LogTick(int tick) { InGameDebug.Log("Tick test: Tick = " + tick); }