public InputPlayer Clone() { InputPlayer newInputPlayer = new InputPlayer(); Dictionary <int, InputState> stateInputs; foreach (var DeviceHashStateInputPair in this.DeviceProfileStateInputs) { stateInputs = newInputPlayer.DeviceProfileStateInputs[DeviceHashStateInputPair.Key] = new Dictionary <int, InputState>(); foreach (var HashStateInputPair in DeviceHashStateInputPair.Value) { stateInputs[HashStateInputPair.Key] = HashStateInputPair.Value.Clone(); } } return(newInputPlayer); }
public InputPlayer Clone(){ InputPlayer newInputPlayer = new InputPlayer (); Dictionary<int,InputState> stateInputs; foreach (var DeviceHashStateInputPair in this.DeviceProfileStateInputs) { stateInputs=newInputPlayer.DeviceProfileStateInputs[DeviceHashStateInputPair.Key]=new Dictionary<int,InputState>(); foreach(var HashStateInputPair in DeviceHashStateInputPair.Value){ stateInputs[HashStateInputPair.Key]=HashStateInputPair.Value.Clone(); } } return newInputPlayer; }
/////////////////////////// OnGUI //////////////////////// /// <summary> /// Raises the GU event. /// </summary> void OnGUI () { int numLayers; int numStates; int i = 0; int j = 0; UnityEditor.Animations.AnimatorStateMachine stateMachine; UnityEditor.Animations.AnimatorState state; UnityEditor.Animations.AnimatorControllerLayer layer; UnityEditor.Animations.AnimatorController ac; if (_deleteStateWithHash != 0) { _stateInputCombinations.Remove (_deleteStateWithHash); _deleteStateWithHash = 0; } if (_spaceDesignator != null) { EditorGUILayout.LabelField ("Settings"); EditorGUILayout.Separator (); ////// MAX NUM COMBOS ///// maxCombosNum = EditorGUILayout.IntField ("Combos per input:", maxCombosNum, _settingsStyle); EditorGUILayout.Separator (); ////// DESIGNATORS ///// EditorGUILayout.LabelField ("Click Designators"); ///////// DOUBLE //////////// _doubleClickDesignator = EditorGUILayout.TextField ("Double click designator", _doubleClickDesignator, _settingsStyle); InputManager.Settings.doubleDesignator = _doubleClickDesignator.Length > 0 ? _doubleClickDesignator : _prevlongClickDesignator; if (_prevdoubleClickDesignator != null && _doubleClickDesignator.Length > 0 && _prevdoubleClickDesignator != _doubleClickDesignator) { replaceDesignator (_prevdoubleClickDesignator, _doubleClickDesignator); } _prevdoubleClickDesignator = _doubleClickDesignator; ////////////// LONG ////////// _longClickDesignator = EditorGUILayout.TextField ("Long click designator", _longClickDesignator, _settingsStyle); InputManager.Settings.longDesignator = _longClickDesignator.Length > 0 ? _longClickDesignator : _prevlongClickDesignator; if (_prevlongClickDesignator != null && _longClickDesignator.Length > 0 && _prevlongClickDesignator != _longClickDesignator) { replaceDesignator (_prevlongClickDesignator, _longClickDesignator); } _prevlongClickDesignator = _longClickDesignator; ///////////// SPACE ///////////// _spaceDesignator = EditorGUILayout.TextField ("Combination separator", _spaceDesignator, _settingsStyle); if (_spaceDesignator.Length > 1) _spaceDesignator = _spaceDesignator [0].ToString ();//restrict to 1 char InputManager.Settings.spaceDesignator = _spaceDesignator.Length > 0 ? _spaceDesignator : _prevSpaceDesinator.ToString (); if (_spaceDesignator.Length > 0 && _prevSpaceDesinator != _spaceDesignator [0]) { replaceDesignator (_prevSpaceDesinator.ToString (), _spaceDesignator [0].ToString ()); } _prevSpaceDesinator = _spaceDesignator [0]; EditorGUILayout.Separator (); ///// SENSITIVITY //// EditorGUILayout.LabelField ("Sensitivity"); InputManager.Settings.singleClickSensitivity = _singleClickSensitivity = EditorGUILayout.FloatField ("Single click sensitivity", _singleClickSensitivity, _settingsStyle); InputManager.Settings.doubleClickSensitivity = _doubleClickSensitivity = EditorGUILayout.FloatField ("Double click sensitivity", _doubleClickSensitivity, _settingsStyle); InputManager.Settings.longClickSensitivity = _longClickSensitivity = EditorGUILayout.FloatField ("Long click sensitivity", _longClickSensitivity, _settingsStyle); InputManager.Settings.combinationsClickSensitivity = _combosClickSensitivity = EditorGUILayout.FloatField ("Combos click sensitivity", _combosClickSensitivity, _settingsStyle); EditorGUILayout.Separator (); //////////// PLAYERS ////////////// EditorGUILayout.BeginHorizontal (); InputPlayer player = null; _playerNumber = EditorGUILayout.IntField ("Number of Players", _playerNumber); if (_playerNumber < 1) _playerNumber = 1; //create Players if (settings.Players == null || _playerNumber != settings.Players.Length) { InputPlayer[] players = new InputPlayer[_playerNumber]; for (i=0; i<_playerNumber; i++) { //don't delete previous players just add new if (settings.Players != null && settings.Players.Length > i) players [i] = settings.Players [i]; else players [i] = new InputPlayer (); } settings.Players = players; //set last player as current _playerIndexSelected = _playerNumber - 1; //reset profile to default _profileSelectedIndex = 0; } //create player display options if (_playerDisplayOptions == null || _playerNumber != _playerDisplayOptions.Length) { _playerDisplayOptions = new string [_playerNumber]; for (i=0; i<_playerNumber; i++) { _playerDisplayOptions [i] = "Player" + i; } } _playerIndexSelected = EditorGUILayout.Popup (_playerIndexSelected, _playerDisplayOptions); if (_playerNumber > 1 && GUILayout.Button ("Clone To All")) { if (EditorUtility.DisplayDialog ("Clone to All!", "Are you sure to clone selected player overwriting other player's settings?", "Yes", "Cancel")) { InputPlayer sample = settings.Players [_playerIndexSelected]; for (i = 0; i < _playerNumber; i++) { if (i != _playerIndexSelected) settings.Players [i] = sample.Clone (); } } } EditorGUILayout.EndHorizontal (); //////////// Profiles ///////////// EditorGUILayout.BeginHorizontal (); EditorGUILayout.LabelField ("Profiles"); List<IDevice> devices = InputManager.GetDevices<IDevice> (); if (devices.Count > 0) { List<string> pList = devices.Where (item => item.profile != null).Select (item => item.profile.Name).Distinct ().ToList (); pList.Insert (0, "default"); _profilesDevicesDisplayOptions = pList.ToArray (); } else { _profileSelectedIndex = 0; _profilesDevicesDisplayOptions = new string[] { "default" }; } _profileSelectedIndex = EditorGUILayout.Popup (_profileSelectedIndex, _profilesDevicesDisplayOptions); //by selecting profile we are setting Device type expectation _deviceByProfile = devices.Where (item => item.profile != null).FirstOrDefault (item => item.profile.Name == _profilesDevicesDisplayOptions [_profileSelectedIndex]); player = settings.Players [_playerIndexSelected]; Dictionary<int,InputState> stateInputsCurrent = null; //init stateInput Dictionary if player numbers is increased if (_profilesDevicesDisplayOptions.Length > _profileSelectedIndex) { if (!player.DeviceProfileStateInputs.ContainsKey (_profilesDevicesDisplayOptions [_profileSelectedIndex])) { player.DeviceProfileStateInputs [_profilesDevicesDisplayOptions [_profileSelectedIndex]] = new Dictionary<int, InputState> (); } stateInputsCurrent = player.DeviceProfileStateInputs [_profilesDevicesDisplayOptions [_profileSelectedIndex]]; } else { _profileSelectedIndex = 0; stateInputsCurrent = player.DeviceProfileStateInputs ["default"]; } if (_profileSelectedIndex > 0) { if (GUILayout.Button ("Clone default") && EditorUtility.DisplayDialog ("Clone Default!", "Are you sure to clone Default input settings to " + _profilesDevicesDisplayOptions [_profileSelectedIndex] + " device specific settings?", "Yes", "Cancel") ) { Dictionary<int,InputState> stateInputsDefault = player.DeviceProfileStateInputs ["default"]; foreach (var HashInputStatePair in stateInputsDefault) { if (!stateInputsCurrent.ContainsKey (HashInputStatePair.Key)) stateInputsCurrent.Add (HashInputStatePair.Key, HashInputStatePair.Value.Clone ()); } } } _stateInputCombinations = stateInputsCurrent; EditorGUILayout.EndHorizontal (); EditorGUILayout.Separator (); ////////// ANY/Complex Action Types(doubles,long...) /FULL AXIS Checkers /////// EditorGUILayout.BeginHorizontal (); // _isDeviceAny = GUILayout.Toggle (_isDeviceAny, "Any(Uncheck 4Testing Only"); _isComplexActionTypesAllowed = GUILayout.Toggle (_isComplexActionTypesAllowed, "Allow DOUBLE/LONG(HOLD)"); _isDeviceAxisPositionFull = GUILayout.Toggle (_isDeviceAxisPositionFull, "Full Axis"); EditorGUILayout.EndHorizontal (); EditorGUILayout.Separator (); } /////////////// GENERATING ENUM SETTINGS /////////// _enumSettingsFoldout = EditorGUILayout.Foldout (_enumSettingsFoldout, "States Enum Properties"); if (_enumSettingsFoldout) { EditorGUILayout.BeginVertical (); //settingsXML = EditorGUILayout.ObjectField (settingsXML, typeof(TextAsset), true) as TextAsset; _namespace = EditorGUILayout.TextField ("Namespace:", _namespace); _enumName = EditorGUILayout.TextField ("Enum:", _enumName); _enumFileName = EditorGUILayout.TextField ("File name:", _enumFileName); EditorGUILayout.EndVertical (); } EditorGUILayout.Separator (); ///////////////// XML //////////////////// EditorGUILayout.LabelField ("Input XML/BIN"); EditorGUILayout.BeginHorizontal (); settingsFile = EditorGUILayout.ObjectField (settingsFile, typeof(UnityEngine.Object), true); //reload if xml changed if (_lastSettingsFile != settingsFile) { _settingsLoaded = false; } _lastSettingsFile = settingsFile; if (_selectedStateHash == 0 && GUILayout.Button ("Open")) { string path; if (_isBinary) path = EditorUtility.OpenFilePanel ("Open XML Input Settings file", "", "bin"); else path = EditorUtility.OpenFilePanel ("Open XML Input Settings file", "", "xml"); if (path.Length > 0) { loadAsset (path); } return; } /////////////// SAVE //////////////////// if (_selectedStateHash == 0 && GUILayout.Button ("Save")) { EditorGUIUtility.keyboardControl = 0; _selectedStateHash = 0; if (!Directory.Exists (Application.streamingAssetsPath)) { Directory.CreateDirectory (Application.streamingAssetsPath); } if (settingsFile != null) { string path = AssetDatabase.GetAssetPath (settingsFile); if (Path.GetExtension (path) == ".xml") { saveInputSettings (Path.Combine (Application.streamingAssetsPath, settingsFile.name + ".xml")); } else { saveInputSettings (Path.Combine (Application.streamingAssetsPath, settingsFile.name + ".bin")); } } else { if (_isBinary) saveInputSettings (EditorUtility.SaveFilePanel ("Save Input Settings", Application.streamingAssetsPath, "InputSettings", "bin")); else saveInputSettings (EditorUtility.SaveFilePanel ("Save Input Settings", Application.streamingAssetsPath, "InputSettings", "xml")); return; } } if (settingsFile == null) _isBinary = GUILayout.Toggle (_isBinary, "Binary"); /////////// RELOAD //////////////// if (GUILayout.Button ("Reload")) { _settingsLoaded = false; } EditorGUILayout.EndHorizontal (); EditorGUILayout.Separator (); //loadingSettings selected thru ObjectField browser or drag and drop if ((!_settingsLoaded && settingsFile != null)) { _settingsLoaded=loadInputSettings (settingsFile); } ///////// ANIMATOR CONTROLER ////////// _lastController = controller; EditorGUILayout.LabelField ("Animator Controller States"); EditorGUILayout.BeginHorizontal (); controller = EditorGUILayout.ObjectField (controller, typeof(UnityEditor.Animations.AnimatorController), true) as UnityEditor.Animations.AnimatorController; EditorGUILayout.EndHorizontal (); EditorGUILayout.Separator (); ///////// Create AnimaitonController states GUI ////////// if (controller != null) { ac = controller as UnityEditor.Animations.AnimatorController; numLayers = ac.layers.Length; if (_showLayer == null || _showLayer.Length != numLayers) _showLayer = new bool[controller.layers.Length]; for (i=0; i<numLayers; i++) { layer = ac.layers [i]; _showLayer [i] = EditorGUILayout.Foldout (_showLayer [i], layer.name); if (_showLayer [i]) { stateMachine = layer.stateMachine; numStates = stateMachine.states.Length; scrollPosition = GUILayout.BeginScrollView (scrollPosition, false, false); for (j=0; j<numStates; j++) { state = stateMachine.states [j].state; createInputStateGUI (state.name, Animator.StringToHash (state.name)); //createInputStateGUI (state.name, state.uniqueNameHash); } GUILayout.EndScrollView (); } } EditorGUILayout.Separator (); } ///////////////////// NEW CUSTOM STATE STATE ////////////////////// EditorGUILayout.LabelField ("Custom States"); EditorGUILayout.BeginHorizontal (); EditorGUILayout.LabelField ("New state name:", _stateNameLabelStyle); _newCustomStateName = EditorGUILayout.TextField (_newCustomStateName, _stateNameLabelStyle); if (_newCustomStateName != _prevNewCustomStateName) _warrningAddStateLabel = ""; _prevNewCustomStateName = _newCustomStateName; if (GUILayout.Button ("+", _addRemoveButtonStyle)) { EditorGUIUtility.keyboardControl = 0; _selectedStateHash = 0; if (_newCustomStateName != null && _newCustomStateName.Length > 0) { int hash = Animator.StringToHash (_newCustomStateName); if (!_stateInputCombinations.ContainsKey (hash)) {//not already there _stateInputCombinations [hash] = new InputState (_newCustomStateName, hash);// string[]{"None","None"}; _stateInputCombinations [hash].Add (new InputCombination ("None")); _stateInputCombinations [hash].Add (new InputCombination ("None")); _newCustomStateName = "";//reset } else _warrningAddStateLabel = "Already exist!"; } else { _warrningAddStateLabel = "Empty state name!"; } } GUI.color = Color.red; EditorGUILayout.LabelField (_warrningAddStateLabel); EditorGUILayout.EndHorizontal (); GUI.color = Color.white; EditorGUILayout.BeginHorizontal (); scrollPosition2 = EditorGUILayout.BeginScrollView (scrollPosition2, false, false); //Debug.Log ("Loop..." + _stateInputCombinations.Count+" inputmngr "+InputManager.Settings.stateInputs.Count); if (_stateInputCombinations != null) foreach (var KeyValuePair in _stateInputCombinations) { if (!existInController (KeyValuePair.Key)) { createInputStateGUI (KeyValuePair.Value.name, KeyValuePair.Key); } } GUILayout.EndScrollView (); EditorGUILayout.EndHorizontal (); //} //if event is of key or mouse if (Event.current.isKey) { if (Event.current.keyCode == KeyCode.Return) { _selectedStateHash = 0; _previousStateInput = null; this.Repaint (); } else if (Event.current.keyCode == KeyCode.Escape) { if (_selectedStateHash != 0) { _stateInputCombinations [_selectedStateHash].combinations [_isPrimary] = _previousStateInput; _previousStateInput = null; _selectedStateHash = 0; } } } if (_selectedStateHash != 0) InputManager.processGUIEvent (Event.current);//process input from keyboard & mouses }