private bool Import(bool clear, string path)
    {
        if (string.IsNullOrEmpty(path))
        {
            return(false);
        }
        if (clear)
        {
            _keyMapManager.Clear();
            _analogMapManager.Clear();
        }
        if (!FileManagerSecure.FileExists(path))
        {
            return(false);
        }
        var jc = (JSONClass)SuperController.singleton.LoadJSON(path);

        if (jc == null)
        {
            return(false);
        }
        var version = jc["version"].AsInt;

        _settings.RestoreFromJSON(jc["settings"].AsObject);
        _keyMapManager.RestoreFromJSON(jc["keybindings"]);
        _analogMapManager.RestoreFromJSON(jc["analogMaps"]);
        if (version < 2)
        {
            if (_analogMapManager.maps.Any(m => m.commandName == "Camera.Pan_X" && m.slot == 0 && m.leftChord.Equals(new KeyChord(KeyCode.A, false, false, false))))
            {
                _analogMapManager.maps.Add(
                    new AnalogMap(new KeyChord(KeyCode.A, false, false, true), new KeyChord(KeyCode.D, false, false, true),
                                  "Camera.Pan_X.Fast", 0));
            }
            if (_analogMapManager.maps.Any(m => m.commandName == "Camera.Pan_Y" && m.slot == 0 && m.leftChord.Equals(new KeyChord(KeyCode.Z, false, false, false))))
            {
                _analogMapManager.maps.Add(
                    new AnalogMap(new KeyChord(KeyCode.Z, false, false, true), new KeyChord(KeyCode.X, false, false, true),
                                  "Camera.Pan_Y.Fast", 0));
            }
            if (_analogMapManager.maps.Any(m => m.commandName == "Camera.Pan_Z" && m.slot == 0 && m.leftChord.Equals(new KeyChord(KeyCode.W, false, false, false))))
            {
                _analogMapManager.maps.Add(
                    new AnalogMap(new KeyChord(KeyCode.W, false, false, true), new KeyChord(KeyCode.S, false, false, true),
                                  "Camera.Pan_Z.Fast", 0));
            }
        }
        return(true);
    }
예제 #2
0
    private IEnumerator DeferredInit()
    {
        yield return(new WaitForEndOfFrame());

        if (!_restored)
        {
            containingAtom.RestoreFromLast(this);
        }
        if (!_restored)
        {
            if (FileManagerSecure.FileExists(SaveFormat.DefaultsPath))
            {
                var profile = LoadJSON(SaveFormat.DefaultsPath);
                RestoreFromJSON(profile.AsObject, false, false, null, false);
            }
        }

        SuperController.singleton.BroadcastMessage("OnActionsProviderAvailable", this, SendMessageOptions.DontRequireReceiver);
    }
예제 #3
0
파일: Embody.cs 프로젝트: via5/vam-embody
 public void LoadFromDefaults()
 {
     try
     {
         if (!FileManagerSecure.FileExists(SaveFormat.DefaultsPath))
         {
             return;
         }
         var profile = LoadJSON(SaveFormat.DefaultsPath)?.AsObject;
         if (profile == null)
         {
             return;
         }
         RestoreFromJSONInternal(profile, true, false, false);
     }
     catch (Exception exc)
     {
         SuperController.LogError($"Embody: Error loading defaults file: {exc}");
     }
 }
예제 #4
0
    public override void Init()
    {
        if (containingAtom.type != "SessionPluginManager")
        {
            SuperController.LogError($"{nameof(KeybindingsExtensions_AddPlugin)} plugin can only be installed as a session plugin.");
            CreateTextField(new JSONStorableString("Error", $"{nameof(KeybindingsExtensions_AddPlugin)} plugin can only be installed as a session plugin."));
            enabledJSON.val = false;
            return;
        }

        var addButton = CreateButton("+ Add Plugin");

        addButton.buttonColor = Color.green;
        addButton.button.onClick.AddListener(() => AddPlugin());
        var clearButton = CreateButton("Clear", true);

        clearButton.textColor   = Color.white;
        clearButton.buttonColor = Color.red;
        clearButton.button.onClick.AddListener(() =>
        {
            try
            {
                _pauseListChangedEvent = true;
                foreach (var plugin in _plugins)
                {
                    plugin.onRemove.Invoke();
                }
            }
            finally
            {
                _plugins.Clear();
                _pauseListChangedEvent = false;
                OnPluginsListChanged();
            }
        });

        if (FileManagerSecure.FileExists(_configPath))
        {
            RestoreFromJSON(LoadJSON(_configPath).AsObject);
        }
    }