void Awake() { // Default control slots layout slots[0] = new ControlSlot() { controlType = ControlType.Player }; slots[1] = new ControlSlot() { controlType = ControlType.AI }; slots[2] = new ControlSlot() { controlType = ControlType.Closed }; slots[3] = new ControlSlot() { controlType = ControlType.Closed }; DontDestroyOnLoad(gameObject); // Solution to the madness of duplicate objects somehow being retained (WTF?) // See: http://answers.unity3d.com/answers/485933/view.html if (FindObjectsOfType(GetType()).Length > 1) { Destroy(gameObject); } }
void SnapToSlot() { ControlSlot closestSlot = manager.slotPositions[0]; float minDistance = (manager.slotPositions[0].position - transform.position).sqrMagnitude; foreach (ControlSlot t in manager.slotPositions) { float dist = (t.position - transform.position).sqrMagnitude; if (dist < minDistance) { minDistance = dist; closestSlot = t; } } if (closestSlot.actionName.Equals(currentSlot.actionName)) { isConfiguring = true; GameInputManager.isConfiguringControls = true; GetComponent <Image>().color = editingColor; } else { Keybind otherKey = closestSlot.button; closestSlot.button = this; currentSlot.button = otherKey; if (otherKey != null) { otherKey.SetSlot(currentSlot); } else { GameInputManager.SetKeyMap(currentSlot.actionName, KeyCode.None); } SetSlot(closestSlot); GameInputManager.isConfiguringControls = false; } }
public void SetSlot(ControlSlot slot) { currentSlot = slot; GameInputManager.SetKeyMap(slot.actionName, key); }