Ejemplo n.º 1
0
        /// <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());
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Removes a feature from the feature list.
        /// </summary>
        private static void RemoveFeature(GenericFeatureManager genericFeature)
        {
            GameObject FeaturesGameObject = GameObject.Find(Constants.API.RootObjectName + "/" + Constants.API.RootFeatureObjectName);

            Type typeToRemove = genericFeature.GetType();

            // Add features
            for (int i = 0; i < FeaturesGameObject.transform.childCount; i++)
            {
                // If not add the feature..
                if (FeaturesGameObject.transform.GetChild(i).GetComponent <Features.GenericFeatureManager>().GetType() == typeToRemove)
                {
                    GameObject.DestroyImmediate(FeaturesGameObject.transform.GetChild(i).gameObject);
                }
            }
        }