using UnityEngine; namespace CarbonInput { /// /// Base class for all touch controls. /// public class BaseTouchInput : MonoBehaviour { /// /// The index of the player this control belongs to. If set to Any, it will use the first free player. /// [Tooltip("The index of the player this control belongs to. If set to Any, it will use the first free player.")] public PlayerIndex Index; /// /// Mapping of this control. /// protected TouchMapping Mapping; /// /// Initialize this input by injecting a into . /// protected void InitMapping() { if(Index == PlayerIndex.Any) { ControllerInstance[] mappings = GamePad.GetPlayerMappings(); for(int i = 1; i < CarbonController.PlayerIndices; i++) { if(mappings[i].Controller.Replacable || mappings[i].Controller is TouchMapping) { UseMapping(i); return; } } // all mappings already in use } else { UseMapping((int)Index); } } /// /// Changes index of the to a . /// /// private void UseMapping(int idx) { ControllerInstance[] mappings = GamePad.GetPlayerMappings(); // if there is already a TouchMapping, use it. if(mappings[idx] != null && mappings[idx].Controller is TouchMapping) Mapping = (TouchMapping)mappings[idx].Controller; else {//otherwise overwrite the old value Mapping = ScriptableObject.CreateInstance(); mappings[idx] = new ControllerInstance(Mapping, 0); } // if we set PlayerIndex.One, we must also set PlayerIndex.Any, because AnyBehaviour.UseMappingOne needs this if(idx == 1) mappings[0] = mappings[1]; } } }