Ejemplo n.º 1
0
        public static KBMInputMap CreateOrGetFromConfig()
        {
            //try to get it first
            if (ConfigState.Instance.CustomConfigVars.ContainsKey("ExplicitKBMInputMap") && ConfigState.Instance.CustomConfigVars["ExplicitKBMInputMap"] is KBMInputMap savedInputMap)
            {
                Debug.Log("[ExplicitKBMInput] Loaded saved input map!");
                return(savedInputMap);
            }

            //create new KBMInputMap, loading default if available and skipping if not
            KBMInputMap inputMap;



            TextAsset res;

            if (CoreUtils.CheckResource <TextAsset>("Data/ExplicitKBMInput/DefaultControls"))
            {
                res = CoreUtils.LoadResource <TextAsset>("Data/ExplicitKBMInput/DefaultControls");
            }
            else
            {
                res = CoreUtils.LoadResource <TextAsset>("Modules/ExplicitKBMInput/DefaultControls");
            }
            if (res != null)
            {
                try
                {
                    inputMap = CoreUtils.LoadJson <KBMInputMap>(res.text);
                    Debug.Log("[ExplicitKBMInput] Loaded default input map!");
                }
                catch (Exception e)
                {
                    Debug.LogError("[ExplicitKBMInput] Failed to load default input map, inputs will start unmapped!");
                    Debug.LogException(e);
                    inputMap = new KBMInputMap();
                }
            }
            else
            {
                Debug.LogWarning("[ExplicitKBMInput] Couldn't find default input map, inputs will start unmapped!");
                inputMap = new KBMInputMap();
            }

            //save to config
            inputMap.SaveToConfig();

            return(inputMap);
        }