Exemple #1
0
        /// <summary>
        /// Sets this input to reflect the provided data object.
        /// </summary>
        /// <param name="data">Data.</param>
        virtual protected void SetInputData(StandardInputData data)
        {
            enableController           = data.enableController;
            enableKeyboard             = data.enableKeyboard;
            horizontalAxisName         = data.horizontalAxisName;
            reverseHorizontalAxis      = data.reverseHorizontalAxis;
            digitalHorizontalThreshold = data.digitalHorizontalThreshold;
            verticalAxisName           = data.verticalAxisName;
            reverseVerticalAxis        = data.reverseVerticalAxis;
            digitalVerticalThreshold   = data.digitalVerticalThreshold;

            altHorizontalAxisName         = data.altHorizontalAxisName;
            reverseAltHorizontalAxis      = data.reverseAltHorizontalAxis;
            digitalAltHorizontalThreshold = data.digitalAltHorizontalThreshold;
            altVerticalAxisName           = data.altVerticalAxisName;
            reverseAltVerticalAxis        = data.reverseAltVerticalAxis;
            digitalAltVerticalThreshold   = data.digitalAltVerticalThreshold;

            right         = data.right;
            left          = data.left;
            up            = data.up;
            down          = data.down;
            jump          = data.jump;
            run           = data.run;
            pause         = data.pause;
            actionButtons = new KeyCode[data.actionButtons.Length];
            for (int i = 0; i < data.actionButtons.Length; i++)
            {
                actionButtons[i] = data.actionButtons[i];
            }
        }
Exemple #2
0
 public static void SaveToFile(string fullPath, StandardInputData data)
 {
     if (fullPath.Length != 0)
     {
         using (StreamWriter writer = new StreamWriter(fullPath))
         {
             XmlSerializer serializer = new XmlSerializer(typeof(StandardInputData));
             serializer.Serialize(writer, data);
         }
     }
     else
     {
         Debug.LogError("Tried to save an input file but no input path was specified.");
     }
 }
Exemple #3
0
 /// <summary>
 /// Loads input data from file.
 /// </summary>
 /// <returns>The loaded data or null if data not loaded.</returns>
 /// <param name="fullPath">Full path.</param>
 public static StandardInputData LoadFromFile(string fullPath)
 {
     if (fullPath.Length != 0)
     {
         using (StreamReader reader = new StreamReader(fullPath))
         {
             XmlSerializer     serializer = new XmlSerializer(typeof(StandardInputData));
             StandardInputData inputData  = (StandardInputData)serializer.Deserialize(reader);
             return(inputData);
         }
     }
     else
     {
         Debug.LogError("Tried to load an input file but the file path was empty");
     }
     return(null);
 }
Exemple #4
0
        /// <summary>
        /// Loads input data from Unity resource folder
        /// </summary>
        /// <returns>The loaded data or null if data not loaded.</returns>
        /// <param name="resourceName">Resource name.</param>
        public static StandardInputData LoadFromResource(string resourceName)
        {
            TextAsset asset = Resources.Load(resourceName) as TextAsset;

            if (asset != null)
            {
                using (Stream stream = new MemoryStream(asset.bytes)){
                    XmlSerializer     serializer = new XmlSerializer(typeof(StandardInputData));
                    StandardInputData inputData  = (StandardInputData)serializer.Deserialize(stream);
                    return(inputData);
                }
            }
            else
            {
                Debug.LogError("Tried to load an input file but the resource named " + resourceName + " was not found:");
            }
            return(null);
        }
Exemple #5
0
        /// <summary>
        /// Sets this input to reflect the provided data object.
        /// </summary>
        /// <param name="data">Data.</param>
        virtual public StandardInputData GetInputData()
        {
            StandardInputData data = new StandardInputData();

            data.enableController           = enableController;
            data.enableKeyboard             = enableKeyboard;
            data.horizontalAxisName         = horizontalAxisName;
            data.reverseHorizontalAxis      = reverseHorizontalAxis;
            data.digitalHorizontalThreshold = digitalHorizontalThreshold;
            data.verticalAxisName           = verticalAxisName;
            data.reverseVerticalAxis        = reverseVerticalAxis;
            data.digitalVerticalThreshold   = digitalVerticalThreshold;

            data.altHorizontalAxisName         = altHorizontalAxisName;
            data.reverseAltHorizontalAxis      = reverseAltHorizontalAxis;
            data.digitalAltHorizontalThreshold = digitalAltHorizontalThreshold;
            data.altVerticalAxisName           = altVerticalAxisName;
            data.reverseAltVerticalAxis        = reverseAltVerticalAxis;
            data.digitalAltVerticalThreshold   = digitalAltVerticalThreshold;

            data.right = right;
            data.left  = left;
            data.up    = up;
            data.down  = down;
            data.jump  = jump;
            data.run   = run;
            data.pause = pause;
            // Assume there are always 8 action buttons (no harm if they aren't used). If we don't do this
            // saving data with less buttons can cause issues which aren't immediately obvious.
            data.actionButtons = new KeyCode[8];
            for (int i = 0; i < data.actionButtons.Length; i++)
            {
                if (i < actionButtons.Length)
                {
                    data.actionButtons[i] = actionButtons[i];
                }
                else
                {
                    data.actionButtons[i] = KeyCode.None;
                }
            }
            return(data);
        }
Exemple #6
0
        /// <summary>
        /// Saves the input data.
        /// </summary>
        /// <returns><c>true</c>, if input data was saved, <c>false</c> otherwise.</returns>
        /// <param name="dataName">Data name.</param>
        virtual public bool SaveInputData(string dataName)
        {
            string prefsName = SavedPreferencePrefix + dataName;

            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(StandardInputData));
            StandardInputData dataToSave = GetInputData();

            try
            {
                using (var stream = new StringWriter()) {
                    serializer.Serialize(stream, dataToSave);
                    PlayerPrefs.SetString(prefsName, stream.ToString());
                }
            }
            catch (System.IO.IOException e)
            {
                Debug.LogError("Error saving input data:" + e.Message);
                return(false);
            }
            return(true);
        }
Exemple #7
0
 /// <summary>
 /// Loads the provided input data.
 /// </summary>
 /// <param name="data">Data to load.</param>
 override public void LoadInputData(StandardInputData data)
 {
     SetInputData(data);
 }
Exemple #8
0
 /// <summary>
 /// Loads the provided input data.
 /// </summary>
 /// <param name="data">Data to load.</param>
 override public void LoadInputData(StandardInputData data)
 {
     Debug.LogError("UnityInput does not allow for in game control configuration.");
 }
 public override void LoadInputData(StandardInputData data)
 {
     Debug.LogWarning("You can't configure a disabled input");
 }
 /// <summary>
 /// Loads the input data for the given data name.
 /// </summary>
 /// <param name="dataName">Data to load.</param>
 /// <param name="data">Data.</param>
 override public void LoadInputData(StandardInputData data)
 {
     Debug.LogWarning("BufferedInput should not be updated directly, update the underlying input implementation.");
 }
 public static void SaveToFile(string fullPath, StandardInputData data)
 {
     if (fullPath.Length != 0) {
         using (StreamWriter writer = new StreamWriter(fullPath))
         {
             XmlSerializer serializer = new XmlSerializer(typeof(StandardInputData));
             serializer.Serialize(writer, data);
         }
     }
     else
     {
         Debug.LogError ("Tried to save an input file but no input path was specified.");
     }
 }
        /// <summary>
        /// Sets this input to reflect the provided data object.
        /// </summary>
        /// <param name="data">Data.</param>
        public virtual StandardInputData GetInputData()
        {
            StandardInputData data = new StandardInputData ();
            data.enableController = enableController;
            data.enableKeyboard = enableKeyboard;
            data.horizontalAxisName = horizontalAxisName;
            data.reverseHorizontalAxis = reverseHorizontalAxis;
            data.digitalHorizontalThreshold = digitalHorizontalThreshold;
            data.verticalAxisName = verticalAxisName;
            data.reverseVerticalAxis = reverseVerticalAxis;
            data.digitalVerticalThreshold = digitalVerticalThreshold;

            data.altHorizontalAxisName = altHorizontalAxisName;
            data.reverseAltHorizontalAxis = reverseAltHorizontalAxis;
            data.digitalAltHorizontalThreshold = digitalAltHorizontalThreshold;
            data.altVerticalAxisName = altVerticalAxisName;
            data.reverseAltVerticalAxis = reverseAltVerticalAxis;
            data.digitalAltVerticalThreshold = digitalAltVerticalThreshold;

            data.right = right;
            data.left = left;
            data.up = up;
            data.down = down;
            data.jump = jump;
            data.run = run;
            data.pause = pause;
            // Assume there are always 8 action buttons (no harm if they aren't used). If we don't do this
            // saving data with less buttons can cause issues which aren't immediately obvious.
            data.actionButtons = new KeyCode[8];
            for (int i = 0; i < data.actionButtons.Length; i++)
            {
                if (i < actionButtons.Length) data.actionButtons[i] = actionButtons[i];
                else data.actionButtons[i] = KeyCode.None;
            }
            return data;
        }
 /// <summary>
 /// Loads the input data for the given data name. NOT AVAILABLE in MultiInput.
 /// </summary>
 /// <returns>true</returns>
 /// <c>false</c>
 /// <param name="dataName">Data to load.</param>
 /// <param name="data">Data.</param>
 public override void LoadInputData(StandardInputData data)
 {
     Debug.LogWarning("You cannot configure a MultiInput directly. Call this method on the wrapped inputs.");
 }
 /// <summary>
 /// Loads the provided input data.
 /// </summary>
 /// <param name="data">Data to load.</param>
 abstract public void LoadInputData(StandardInputData data);
Exemple #15
0
 /// <summary>
 /// Loads the provided input data.
 /// </summary>
 /// <param name="data">Data to load.</param>
 public override void LoadInputData(StandardInputData data)
 {
     Debug.LogError ("UnityInput does not allow for in game control configuration.");
 }
 /// <summary>
 /// Loads the input data for the given data name.
 /// </summary>
 /// <param name="dataName">Data to load.</param>
 /// <param name="data">Data.</param>
 public override void LoadInputData(StandardInputData data)
 {
     Debug.LogWarning ("BufferedInput should not be updated directly, update the underlying input implementation.");
 }
 /// <summary>
 /// Loads the provided input data.
 /// </summary>
 /// <param name="data">Data to load.</param>
 public override void LoadInputData(StandardInputData data)
 {
     SetInputData (data);
 }
        /// <summary>
        /// Sets this input to reflect the provided data object.
        /// </summary>
        /// <param name="data">Data.</param>
        protected virtual void SetInputData(StandardInputData data)
        {
            enableController = data.enableController;
            enableKeyboard = data.enableKeyboard;
            horizontalAxisName = data.horizontalAxisName;
            reverseHorizontalAxis = data.reverseHorizontalAxis;
            digitalHorizontalThreshold = data.digitalHorizontalThreshold;
            verticalAxisName = data.verticalAxisName;
            reverseVerticalAxis = data.reverseVerticalAxis;
            digitalVerticalThreshold = data.digitalVerticalThreshold;

            altHorizontalAxisName = data.altHorizontalAxisName;
            reverseAltHorizontalAxis = data.reverseAltHorizontalAxis;
            digitalAltHorizontalThreshold = data.digitalAltHorizontalThreshold;
            altVerticalAxisName = data.altVerticalAxisName;
            reverseAltVerticalAxis = data.reverseAltVerticalAxis;
            digitalAltVerticalThreshold = data.digitalAltVerticalThreshold;

            right = data.right;
            left = data.left;
            up = data.up;
            down = data.down;
            jump = data.jump;
            run = data.run;
            pause = data.pause;
            actionButtons = new KeyCode[data.actionButtons.Length];
            for (int i = 0; i < data.actionButtons.Length; i++) actionButtons[i] = data.actionButtons[i];
        }
        /// <summary>
        /// Draw the inspector GUI.
        /// </summary>
        public override void OnInspectorGUI()
        {
            myTarget = (StandardInput)target;

            // Arguments to load
            string newDataToLoad = EditorGUILayout.TextField(new GUIContent("Data To Load", "Data identifier for the inputs, should match the identifier in the configurable controls UI."), myTarget.dataToLoad);

            if (myTarget.dataToLoad != newDataToLoad)
            {
                myTarget.dataToLoad = newDataToLoad;
                EditorUtility.SetDirty(target);
            }
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Load from File"))
            {
                string path = EditorUtility.OpenFilePanel("Load Input Settings", "", "xml");
                if (path.Length > 0)
                {
                    StandardInputData data = StandardInputData.LoadFromFile(path);
                    if (data != null)
                    {
                        myTarget.LoadInputData(data);
                        EditorUtility.SetDirty(target);
                    }
                }
            }
            if (GUILayout.Button("Save to File"))
            {
                string path = EditorUtility.SaveFilePanel("Save Input Settings", "", "CustomInput", "xml");
                if (path.Length > 0)
                {
                    StandardInputData data = myTarget.GetInputData();
                    StandardInputData.SaveToFile(path, data);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Load from Preferencess"))
            {
                UIInputOverlay overlay = (UIInputOverlay)FindObjectOfType(typeof(UIInputOverlay));
                if (overlay != null)
                {
                    overlay.Show((Input)target);
                }
                myTarget.LoadInputData(myTarget.dataToLoad);
            }
            if (GUILayout.Button("Clear Preferencess"))
            {
                string prefsName = StandardInput.SavedPreferencePrefix + myTarget.dataToLoad;
                PlayerPrefs.DeleteKey(prefsName);
            }

            GUILayout.EndHorizontal();


            EditorGUILayout.HelpBox("Note that the defaults below are only applied if no PlayerPreference data has been set.", MessageType.Info);

            // Defaults
            showDefaults = EditorGUILayout.Foldout(showDefaults, "Default Controls");
            if (showDefaults)
            {
                // GUILayout.Label("Controls", EditorStyles.boldLabel);
                DrawDefaultInspector();
            }
        }
Exemple #20
0
 /// <summary>
 /// Loads the provided input data.
 /// </summary>
 /// <param name="data">Data to load.</param>
 public abstract void LoadInputData(StandardInputData data);