Beispiel #1
0
 /// <summary>
 /// Save setting to the file.
 /// </summary>
 public void SaveHandler()
 {
     InputSaver.WriteHandler(this);
 }
Beispiel #2
0
        /// <summary>
        /// Fills dictionaries with InputListeners from the saving file.
        /// If file doesn't exist - with default data filled from the Editor.
        /// <remark> Called from InputManager Awake() </remark>
        /// </summary>
        public bool Init()
        {
            if (_inited)
            {
                return(false);
            }

            List <InputListener> JustPressedSource;
            List <InputListener> PressedSource;
            List <InputListener> JustReleasedSource;

            var savedHandler = InputSaver.ReadHandler(this.Name);

            if (savedHandler != null)
            {
                JustPressedSource  = savedHandler.JustPressed;
                PressedSource      = savedHandler.Pressed;
                JustReleasedSource = savedHandler.JustReleased;
                _axes = savedHandler.Axes;
            }
            else
            {
                JustPressedSource  = JustPressedTemplate;
                PressedSource      = PressedTemplate;
                JustReleasedSource = JustReleasedTemplate;
            }

            foreach (var l in JustPressedSource)
            {
                if (l.Positive != KeyCode.None)
                {
                    JustPressed.Add(l.Positive, l);
                }
                if (l.Alternative != KeyCode.None)
                {
                    JustPressed.Add(l.Alternative, l);
                }

                if (!AllListeners.ContainsKey(l.Name))
                {
                    AllListeners.Add(l.Name, l);
                }
            }

            foreach (var l in PressedSource)
            {
                if (l.Positive != KeyCode.None)
                {
                    Pressed.Add(l.Positive, l);
                }
                if (l.Alternative != KeyCode.None)
                {
                    Pressed.Add(l.Alternative, l);
                }

                if (!AllListeners.ContainsKey(l.Name))
                {
                    AllListeners.Add(l.Name, l);
                }
            }

            foreach (var l in JustReleasedSource)
            {
                if (l.Positive != KeyCode.None)
                {
                    JustReleased.Add(l.Positive, l);
                }
                if (l.Alternative != KeyCode.None)
                {
                    JustReleased.Add(l.Alternative, l);
                }

                if (!AllListeners.ContainsKey(l.Name))
                {
                    AllListeners.Add(l.Name, l);
                }
            }

            _inited = true;

            if (savedHandler == null)
            {
                SaveHandler();
            }

            return(true);
        }