/// <summary> /// This is called if the button is not interacting, thus we call the normal method defined by a feature. /// </summary> /// <param name="buttonPressed">The button pressed.</param> /// <param name="action">The button action related to the method.</param> /// <param name="fixedMethod">The fixed method.</param> private void CallAction(Button.ButtonName buttonPressed, Button.ButtonActions action, bool isRight) { ControlSet platformControls = ((GenericControllerPlatform)coreSettings.CurrentPlatform).GetPlatformControls(); if (platformControls == null) { Debug.LogError("No controller scheme found."); } // This list are the methods that override the controller interaction. List <Action> methods; if (isRight) { methods = platformControls.GetButtonMethods(buttonPressed, action, ControlSet.Options.isRight); } else { methods = platformControls.GetButtonMethods(buttonPressed, action, ControlSet.Options.isLeft); } if (methods.Count == 0) { Debug.Log("Pressing the button: " + buttonPressed + ". Action type: " + action + ". Is on right hand? " + isRight + ". But no method found.."); } // Run the methods.. foreach (Action act in methods) { act.Invoke(); } }
/// <summary> /// Check the Features game object for new features. /// </summary> public void UpdateFeaturesList() { // Finds the feature's root object. if (featuresGameObject == null) { featuresGameObject = GameObject.Find(Constants.API.RootObjectName + "/" + Constants.API.RootFeatureObjectName); } if (featuresGameObject == null) { return; } // Checking if list need initialization if (FeaturesSelected == null) { Debug.Log("Initializing it.."); FeaturesSelected = new List <GenericFeatureManager>(); } // Clear the internal list. FeaturesSelected.Clear(); // Clear all the internal buttons references. Will be added back later. if (CurrentPlatform.GetType().IsSubclassOf(typeof(GenericControllerPlatform))) { ((GenericControllerPlatform)CurrentPlatform).GetPlatformControls().ClearAllButtons(); } // For every object child of Features Root object. for (int i = 0; i < featuresGameObject.transform.childCount; i++) { GameObject featureObject = featuresGameObject.transform.GetChild(i).gameObject; // Add feature to the list of features.. GenericFeatureManager feature = featureObject.GetComponent <GenericFeatureManager>(); FeaturesSelected.Add(feature); // If feature implements IControllerFeature and our platform support controllers. if (feature is IControllerFeature && CurrentPlatform.GetType().IsSubclassOf(typeof(GenericControllerPlatform))) { // Get all buttons registry from the feature. IControllerFeature controllerFeature = feature as IControllerFeature; List <Controller.ButtonRegistry> registries = controllerFeature.GetAllButtonRegistries(); // Send all buttons registry to the current platform. Controller.ControlSet controls = ((GenericControllerPlatform)CurrentPlatform).GetPlatformControls(); controls.RemoveAllButtons(feature.GetFeatureType()); foreach (Controller.ButtonRegistry reg in registries) { Action method = controllerFeature.GetButtonMethod(reg); // Register the method on the platform. (Added back the references..) if (method != null) { controls.AddButton(reg.Name, reg.Action, reg.IsRightControllerButton, method, reg.OverrideInteraction, feature.GetFeatureType()); } } } } }
/// <summary> /// Figures out if should call the interaction method or the feature method for control. /// </summary> /// <param name="buttonPressed">The button pressed.</param> /// <param name="action">The button action related to the method.</param> /// <param name="interactionMethods">An interaction method.</param> /// <param name="isRight">True if right hand.</param> private void CallAction(Button.ButtonName buttonPressed, Button.ButtonActions action, List <Action> interactionMethods, bool isRight) { ControlSet platformControls = ((GenericControllerPlatform)coreSettings.CurrentPlatform).GetPlatformControls(); if (platformControls == null) { Debug.LogError("No controller scheme found."); } // This list are the methods that override the controller interaction. List <Action> methodsThatOverride; if (isRight) { methodsThatOverride = platformControls.GetButtonMethods(buttonPressed, action, ControlSet.Options.isRight, ControlSet.Options.OverrideInteraction); } else { methodsThatOverride = platformControls.GetButtonMethods(buttonPressed, action, ControlSet.Options.isLeft, ControlSet.Options.OverrideInteraction); } // If there is something the list above meant that we will not call the interaction,istead we will call the method. if (methodsThatOverride.Count > 0) { foreach (Action act in methodsThatOverride) { act.Invoke(); } // Don't call interaction method. Debug.Log("Interaction was overriden by a button."); return; } else { // On this case there is no method that overrides an interaction, we call the interaction normally. foreach (Action act in interactionMethods) { act.Invoke(); } } }