Beispiel #1
0
        /// <summary>
        /// Removes a registry from the list to be serialized.
        /// </summary>
        /// <param name="name">The ButtonName of the button.</param>
        /// <param name="action">The ButtonActions of the button.</param>
        /// <param name="overridesInteraction">True if this button overrides interaction.</param>
        /// <param name="isRightController">True if this button stays on the right controller.</param>
        private void RemoveButtonChoice(Button.ButtonName name, Button.ButtonActions action, bool overridesInteraction, bool isRightController)
        {
            ButtonRegistry registry = ScriptableObject.CreateInstance <ButtonRegistry>();

            registry.Name   = name;
            registry.Action = action;
            registry.OverrideInteraction     = overridesInteraction;
            registry.IsRightControllerButton = isRightController;


            if (action == Button.ButtonActions.PressUp)
            {
                registry.methodName = nameof(Teleport);
            }
            else if (action == Button.ButtonActions.HoldDown)
            {
                registry.methodName = nameof(WhileHoldingButtonDown);
            }
            else
            {
                Debug.LogError("Could not find a method to register for this action, is there something off?");
            }

            if (TeleportSettings.ButtonsSelected.Contains(registry))
            {
                TeleportSettings.ButtonsSelected.Remove(registry);
            }
        }
Beispiel #2
0
        /// <summary>
        /// <para>Returns true if the ButtonAction on the specified controller GameObject and ButtonName button is happening.</para>
        /// <para>Else returns null.</para>
        /// </summary>
        /// <param name="button">The ControllerButtons for this button.</param>
        /// <param name="action">A button action.</param>
        /// <param name="controller">The Controller game object.</param>
        /// <returns>True if the ButtonAction on the specified controller GameObject and ButtonName button is happening.</returns>
        public override bool GetActionStatus(Button.ButtonName button, Button.ButtonActions action, GameObject controller)
        {
            Hand controllerHand = controller.GetComponent <Hand>();

            if (controllerHand == null)
            {
                Debug.LogError("Could't find the 'Hand' component on the supplied controller gameobject.");
                return(false);
            }
            else if (controllerHand.controller != null)
            {
                if (action == Button.ButtonActions.PressUp)
                {
                    return(controllerHand.controller.GetPressUp(TranslateControllerButton(button)));
                }
                else if (action == Button.ButtonActions.HoldDown)
                {
                    return(controllerHand.controller.GetPressDown(TranslateControllerButton(button)));
                }
                else
                {
                    Debug.Log("Could not find desired action maybe it's not implemented by the platform.");
                }
            }
            else
            {
                // Control might be still initializing.. return false.
                Debug.Log("Controller could be still initializing.. no interaction identified.");
                return(false);
            }
            return(false);
        }
Beispiel #3
0
        /// <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();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Remove the button method from this control set.
        /// </summary>
        /// <param name="button">Which button we are setting.</param>
        /// <param name="action">The button action related to the method.</param>
        /// <param name="isRight">True if this button is on the right controller.</param>
        /// <param name="method">The method that it will execute when run.</param>
        /// <param name="featureOwner">The type of the feature that instatiated this button.</param>
        protected override void RemoveButton(Button.ButtonName name, Button.ButtonActions action, bool isRight, Action method, Type featureOwner)
        {
            Button button;

            if (isRight)
            {
                button = rightButtons.Find(b => b.Name == name && b.Action == action && b.GetMethod() == method && b.FeatureOwner == featureOwner);
                if (button == null)
                {
                    Debug.LogError("Could not find the button you are trying to delete.");
                    return;
                }
                rightButtons.Remove(button);
            }
            else
            {
                button = leftButtons.Find(b => b.Name == name && b.Action == action && b.GetMethod() == method && b.FeatureOwner == featureOwner);
                if (button == null)
                {
                    Debug.LogError("Could not find the button you are trying to delete.");
                    return;
                }
                leftButtons.Remove(button);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Creates the registry of a button (ButtonRegistry) on the serializable data class.
        /// </summary>
        /// <param name="name">The ButtonName of the button.</param>
        /// <param name="action">The ButtonActions of the button.</param>
        /// <param name="overridesInteraction">True if this button overrides interaction.</param>
        /// <param name="isRightController">True if this button stays on the right controller.</param>
        private void SaveButtonChoice(Button.ButtonName name, Button.ButtonActions action, bool overridesInteraction, bool isRightController)
        {
            ButtonRegistry registry = ScriptableObject.CreateInstance <ButtonRegistry>();

            registry.Name   = name;
            registry.Action = action;
            registry.OverrideInteraction     = overridesInteraction;
            registry.IsRightControllerButton = isRightController;

            if (action == Button.ButtonActions.PressUp)
            {
                registry.methodName = nameof(Teleport);
            }
            else if (action == Button.ButtonActions.HoldDown)
            {
                registry.methodName = nameof(WhileHoldingButtonDown);
            }
            else
            {
                Debug.LogError("Could not find a method to register for this action, is there something off?");
                return;
            }

            // Append it to the teleport Settings object.
            registry.AddToAsset(TeleportSettings.GetPathToData()); // This is a costy operation..

            if (!TeleportSettings.ButtonsSelected.Contains(registry))
            {
                TeleportSettings.ButtonsSelected.Add(registry);
            }

            TeleportSettings.Save();// This is a costy operation..
        }
Beispiel #6
0
        /// <summary>
        /// Check if a given button and action is interacting. Has interacted in the last frame.
        /// </summary>
        /// <param name="button">A button.</param>
        /// <param name="actions">An action.</param>
        /// <returns></returns>
        public bool CheckButtonInteracting(Button.ButtonName name, Button.ButtonActions actions, bool isRight)
        {
            PressControl ctrl = controllerPressControl.Find(btn => btn.Name == name && btn.Action == actions && btn.isRightController == isRight);

            if (ctrl != null)
            {
                return(ctrl.isActionActive);
            }
            else
            {
                return(false);

                Debug.LogError("This button don't seem to be registered.. Something could be off");
            }
        }
Beispiel #7
0
        /// <summary>
        /// Sets the button method on this control set.
        /// </summary>
        /// <param name="button">Which button we are setting.</param>
        /// <param name="action">The button action related to the method.</param>
        /// <param name="isRight">True if this button is on the right controller.</param>
        /// <param name="method">The method that it will execute when run.</param>
        /// <param name="shouldOverrideInteraction">True if it should override ongoing interactions.</param>
        /// <param name="featureOwner">The type of the feature that instatiated this button. Null if not a feature button.</param>
        public override void AddButton(Button.ButtonName name, Button.ButtonActions action, bool isRight,
                                       Action method, bool shouldOverrideInteraction, Type featureOwner)
        {
            Button button = new Button(name, action, isRight, shouldOverrideInteraction, method, featureOwner);

            if (isRight)
            {
                rightButtons.Add(button);
                // You can add a verification if you are worried about several methods using the same button.
            }
            else
            {
                leftButtons.Add(button);
                // You can add a verification if you are worried about several methods using the same button.
            }
        }
Beispiel #8
0
        /// <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();
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// Converts a ButtonName to a String
        /// </summary>
        /// <param name="name"></param>
        /// <param name="isRight"></param>
        /// <returns></returns>
        public static string ConvertNames(Button.ButtonName name, bool isRight)
        {
            if (isRight)
            {
                if (name == Button.ButtonName.ApplicationMenu)
                {
                    return("RightOptions");
                }
                if (name == Button.ButtonName.Grip)
                {
                    return("RightGrip");
                }
                if (name == Button.ButtonName.Touchpad)
                {
                    return("RightTouchpad");
                }
                if (name == Button.ButtonName.Trigger)
                {
                    return("RightTrigger");
                }
            }
            else
            {
                if (name == Button.ButtonName.ApplicationMenu)
                {
                    return("LeftOptions");
                }
                if (name == Button.ButtonName.Grip)
                {
                    return("LeftGrip");
                }
                if (name == Button.ButtonName.Touchpad)
                {
                    return("LeftTouchpad");
                }
                if (name == Button.ButtonName.Trigger)
                {
                    return("LeftTrigger");
                }
            }

            return("");
        }
Beispiel #10
0
        /// <summary>
        /// Converts a ButtonName to a ButtonID
        /// </summary>
        /// <param name="name">A ButtonName</param>
        /// <param name="isRight"></param>
        /// <returns>A ButtonID, undefined if can't find it.</returns>
        public static HintManager.ButtonID ConverNames(Button.ButtonName name, bool isRight)
        {
            if (isRight)
            {
                if (name == Button.ButtonName.ApplicationMenu)
                {
                    return(HintManager.ButtonID.RightOptions);
                }
                if (name == Button.ButtonName.Grip)
                {
                    return(HintManager.ButtonID.RightGrip);
                }
                if (name == Button.ButtonName.Touchpad)
                {
                    return(HintManager.ButtonID.RightTouchpad);
                }
                if (name == Button.ButtonName.Trigger)
                {
                    return(HintManager.ButtonID.RightTrigger);
                }
            }
            else
            {
                if (name == Button.ButtonName.ApplicationMenu)
                {
                    return(HintManager.ButtonID.LeftOptions);
                }
                if (name == Button.ButtonName.Grip)
                {
                    return(HintManager.ButtonID.LeftGrip);
                }
                if (name == Button.ButtonName.Touchpad)
                {
                    return(HintManager.ButtonID.LeftTouchpad);
                }
                if (name == Button.ButtonName.Trigger)
                {
                    return(HintManager.ButtonID.LeftTrigger);
                }
            }

            return(HintManager.ButtonID.Undefined);
        }
Beispiel #11
0
        /// <summary>
        /// Given a ButtonName and a ButtonAction return the list of actions to perform.
        /// </summary>
        /// <param name="name">The ButtonName for to return the selected actions.</param>
        /// <param name="action">The ButtonAction for to return the selected actions.</param>
        /// <returns>A list of actions.</returns>
        public List <Action> GetButtonMethods(Button.ButtonName name, Button.ButtonActions action)
        {
            List <Action> returnActions = new List <Action>();

            if (ButtonsSelected == null)
            {
                Debug.LogError("No button selected.");
                return(null);
            }
            if (ButtonsSelected.Contains(null))
            {
                Debug.LogError("This object interaction: " + this.gameObject.name + " is not properly initialized! Maybe you copied its values." +
                               "Please go to it's game object inspector to update it automatically.");
            }

            // If this button is registered return the action.
            if (ButtonsSelected.Find(reg => reg.Name == name && reg.Action == action))
            {
                returnActions.Add(LoadAScene);
            }

            return(returnActions);
        }
Beispiel #12
0
 /// <summary>
 /// Return the method defined for the specific button.
 /// </summary>
 /// <param name="button">The button enum, listed under Controller. ButtonName</param>
 /// <param name="action">The button action related to the method.</param>
 /// <param name="isRight">True if this button is on the right hand.</param>
 /// <param name="overridesInteraction">True if this button method overrides interaction.</param>
 /// <returns>A method to be invoked.</returns>
 public abstract List <Action> GetButtonMethods(Button.ButtonName button, Button.ButtonActions action, params Options[] options);
Beispiel #13
0
        /// <summary>
        /// Return the method defined for the specific button.
        /// </summary>
        /// <param name="button">The button enum, listed under Controller. </param>
        /// <param name="action">The button action related to the method.</param>
        /// <param name="isRight">True if this button is on the right hand.</param>
        /// <param name="overridesInteraction">True if this button method overrides interaction.</param>
        /// <returns>A method to be invoked.</returns>
        public override List <Action> GetButtonMethods(Button.ButtonName button, Button.ButtonActions action, params Options[] options)
        {
            bool isRight                 = false;
            bool isLeft                  = false;
            bool overrideInteraction     = false;
            bool dontOverrideInteraction = false;

            for (int i = 0; i < options.Length; i++)
            {
                isRight                 = (options[i] == Options.isRight) ? true : isRight;
                isLeft                  = (options[i] == Options.isLeft) ? true : isLeft;
                overrideInteraction     = (options[i] == Options.OverrideInteraction) ? true : overrideInteraction;
                dontOverrideInteraction = (options[i] == Options.DontOverrideInteraction) ? true : dontOverrideInteraction;
            }

            List <Action> actions = new List <Action>();
            List <Button> buttons = null;

            // Return all the buttons.
            if (isRight && overrideInteraction && isLeft && dontOverrideInteraction || !isRight && !overrideInteraction && !isLeft && !dontOverrideInteraction)
            {
                buttons = rightButtons.FindAll(b => b.Name == button && b.Action == action);
                buttons.AddRange(leftButtons.FindAll(b => b.Name == button && b.Action == action));
            }
            // Return all right buttons
            else if (isRight && !(overrideInteraction ^ dontOverrideInteraction))
            {
                buttons = rightButtons.FindAll(b => b.Name == button && b.Action == action);
            }
            // Return all left buttons
            else if (isLeft && !(overrideInteraction ^ dontOverrideInteraction))
            {
                buttons = leftButtons.FindAll(b => b.Name == button && b.Action == action);
            }
            // Return all right buttons with override.
            else if (isRight && overrideInteraction)
            {
                buttons = rightButtons.FindAll(b => b.Name == button && b.Action == action && b.OverridesInteraction == true);
            }
            // Return all left buttons with override.
            else if (isLeft && overrideInteraction)
            {
                buttons = leftButtons.FindAll(b => b.Name == button && b.Action == action && b.OverridesInteraction == true);
            }
            // Return all right buttons without override.
            else if (isRight && overrideInteraction)
            {
                buttons = rightButtons.FindAll(b => b.Name == button && b.Action == action && b.OverridesInteraction == false);
            }
            // Return all left buttons without override.
            else if (isLeft && overrideInteraction)
            {
                buttons = leftButtons.FindAll(b => b.Name == button && b.Action == action && b.OverridesInteraction == false);
            }
            // Return all buttons with override.
            else if (overrideInteraction && !(isRight ^ isLeft))
            {
                buttons = rightButtons.FindAll(b => b.Name == button && b.Action == action && b.OverridesInteraction == true);
                buttons.AddRange(leftButtons.FindAll(b => b.Name == button && b.Action == action && b.OverridesInteraction == true));
            }
            // Return all buttons without override
            else if (dontOverrideInteraction && !(isRight ^ isLeft))
            {
                buttons = rightButtons.FindAll(b => b.Name == button && b.Action == action && b.OverridesInteraction == false);
                buttons.AddRange(leftButtons.FindAll(b => b.Name == button && b.Action == action && b.OverridesInteraction == false));
            }
            else
            {
                Debug.LogError("Something is off could not identify which buttons return.");
            }

            if (buttons != null)
            {
                foreach (Button b in buttons)
                {
                    actions.Add(b.GetMethod());
                }
                return(actions);
            }
            else
            {
                Debug.LogError("Could not find button.");
                return(null);
            }
        }
Beispiel #14
0
        /// <summary>
        /// Register the selected buttons on the interaction.
        /// </summary>
        private void RegisterSelectedButtons()
        {
            InteractableObject interactableObject = (InteractableObject)this.target;

            // We must add for all known positions! The ControllerManager always calls the correct position Method.
            Button.ButtonName[]    finalButtonNames   = new Button.ButtonName[interactableObject.AmountOfButtons * 2];
            Button.ButtonActions[] finalButtonActions = new Button.ButtonActions[interactableObject.AmountOfButtons * 2];
            bool[] finalPositions = new bool[interactableObject.AmountOfButtons * 2];

            // Creating positions and setting final buttons to be passed.
            for (int i = 0; i < interactableObject.AmountOfButtons; i++)
            {
                // Copy buttons
                finalButtonNames[i]     = userSelectedButtons[i];
                finalButtonNames[i + 1] = userSelectedButtons[i];

                // Copy Actions
                finalButtonActions[i]     = finalButtonActions[i];
                finalButtonActions[i + 1] = finalButtonActions[i];

                // Create Positions
                finalPositions[i]     = true;
                finalPositions[i + 1] = false;
            }

            // Calling unregister and register methods.
            IActiveInteraction interaction = interactableObject as IActiveInteraction;

            // Unregister all buttons..
            interactableObject.ButtonsSelected.Clear();

            // Register all buttons..
            Debug.Log("Registering...");

            if (interactableObject.ButtonsSelected == null)
            {
                interactableObject.ButtonsSelected = new List <ButtonRegistry>();
            }

            // Foreach userSelectedButton we add the button.
            for (int i = 0; i < finalButtonNames.Length; i++)
            {
                ButtonRegistry reg = ScriptableObject.CreateInstance <ButtonRegistry>();
                reg.Name   = finalButtonNames[i];
                reg.Action = finalButtonActions[i];
                reg.IsRightControllerButton = finalPositions[i];
                reg.OverrideInteraction     = true;
                interactableObject.ButtonsSelected.Add(reg);
            }


            // This saves the button selection.
            SerializedProperty buttons = serializedObject.FindProperty("ButtonsSelected");

            buttons.arraySize = interactableObject.ButtonsSelected.Count;
            //int j = 0;
            buttons.Next(true); // Go further on this property (Ends up on Array)
            buttons.Next(true); // Go further on again.. (Ends up probaly on the array size.
            buttons.Next(true); // Go further on more time.. (Ends up on first element)
            foreach (ButtonRegistry b in interactableObject.ButtonsSelected)
            {
                buttons.objectReferenceValue = b;
                buttons.Next(false); // move to the next element. (The argument here is false because the next element is adjacent to this
                // if it was true we would go to a property inside the current element).
            }

            serializedObject.ApplyModifiedProperties();
        }
Beispiel #15
0
        //private void CreateBehaviourDropdown(int amountOfItems, List<Type> behaviourNames)
        //{
        //    for (int k = 0; k < amountOfItems; k++)
        //    {
        //        // Create the labels that will be shown on the screen.
        //        GUIContent[] items = new GUIContent[amountOfItems];

        //        // Write all the infor on the label we just created.
        //        for (int i = 0; i < amountOfItems; i++)
        //        {
        //            items[i] = new GUIContent();
        //            items[i].text = behaviourNames[i].Name;
        //        }

        //        bool changesWereMade = false;

        //        Type[] newUserSelection = new Type[amountOfItems];

        //        // Start writing on the screen.
        //        EditorGUILayout.BeginHorizontal();
        //        // Write on the window

        //        // This is the index on the controllerLabels array of the previously selected button.
        //        int selectedIndex = Array.FindIndex(items, element => element.text.Equals(userSelectedBehaviours[k].Name));

        //        // This is newly selected index by the user. We must transform it int a Type to save it.
        //        int newlySelectedIndex = EditorGUILayout.Popup(selectedIndex, items);
        //        newUserSelection[k] = behaviourNames[newlySelectedIndex];

        //        if (!(newUserSelection[k] == userSelectedBehaviours[k]))
        //            changesWereMade = true;

        //        EditorGUILayout.EndHorizontal();
        //        EditorGUILayout.Space();

        //        // If there were changes do something..
        //        if (changesWereMade)
        //        {
        //            // Loop through the list of components to add missing ones.
        //            for (int i = 0; i < newUserSelection.Length; i++)
        //            {
        //                Type foundType = null;
        //                foundType = Array.Find(userSelectedBehaviours, b => b == newUserSelection[i]);
        //                // Add the missing component to this game object.
        //                if (foundType == null)
        //                {
        //                    Component p = null;
        //                    // Case we didn't find this type among the behaviours types already added.
        //                    if (interactableObject != null)
        //                        p = interactableObject.gameObject.AddComponent(newUserSelection[i]);
        //                    if (p == null || interactableObject == null)
        //                        Debug.LogError("Problem adding game object. Check here.");
        //                }
        //            }

        //            // Loop through the list of components to remove unused ones.

        //            // Update the list of added components.
        //            userSelectedBehaviours = newUserSelection;
        //        }
        //    }
        //}

        /// <summary>
        /// Creates a pickable dropdown of buttons, so player selects which button will activate the feature.
        /// </summary>
        /// <param name="fixedButtonNames">An array of buttons to be displayed. If null will display all the available buttons for the selected platform.</param>
        /// <param name="fixedButtonActions">An array of actions that can be used with this feature. If null will use all available for the selected platform.</param>
        protected virtual void CreateSelectionButton(Button.ButtonName[] fixedButtonNames,
                                                     params Button.ButtonActions[] fixedButtonActions)
        {
            InteractableObject interactableObject = (InteractableObject)this.target;

            if (!(interactableObject is IActiveInteraction))
            {
                // If the interactable object in question don't implement IActiveInteraction there is nothing we can do..
                Debug.LogError("OOps! Seems like you are trying to implement an active interaction but you are not implementing IActiveInteraction");
                return;
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(new GUIContent("Activation Button"));
            interactableObject.AmountOfButtons = EditorGUILayout.IntField(interactableObject.AmountOfButtons);
            EditorGUILayout.EndHorizontal();

            bool changesWereMade = false;

            Button.ButtonName[]    newUserSelection        = new Button.ButtonName[interactableObject.AmountOfButtons];
            Button.ButtonActions[] newUserSelectionActions = new Button.ButtonActions[interactableObject.AmountOfButtons];

            // Load any previous choices.
            LoadSelectedButtons();

            for (int k = 0; k < interactableObject.AmountOfButtons; k++)
            {
                // Get the available buttons and positions for this platform.
                Button.ButtonName[] controllerButtons;
                if (fixedButtonNames != null)
                {
                    controllerButtons = fixedButtonNames;
                }
                else
                {
                    controllerButtons = SupportedPlatforms.GetButtons(Core.CoreSettings.EditorSelectedPlatform);
                }

                Button.ButtonActions[] buttonActions;
                if (fixedButtonActions.Length > 0)
                {
                    buttonActions = fixedButtonActions;
                }
                else
                {
                    buttonActions = SupportedPlatforms.GetButtonActions(Core.CoreSettings.EditorSelectedPlatform);
                }

                string[] positions = SupportedPlatforms.GetPositions(Core.CoreSettings.EditorSelectedPlatform);

                // Create the labels that will be shown on the screen.
                GUIContent[] controllerLabels   = new GUIContent[controllerButtons.Length];
                GUIContent[] buttonActionLabels = new GUIContent[buttonActions.Length];
                GUIContent[] positionLabels     = new GUIContent[positions.Length];

                // Write all the infor on the labels we just created.
                for (int i = 0; i < controllerButtons.Length; i++)
                {
                    controllerLabels[i]      = new GUIContent();
                    controllerLabels[i].text = controllerButtons[i].ToString();
                }
                for (int i = 0; i < buttonActions.Length; i++)
                {
                    buttonActionLabels[i]      = new GUIContent();
                    buttonActionLabels[i].text = buttonActions[i].ToString();
                }

                // Start writing on the screen.
                EditorGUILayout.BeginHorizontal();
                // Write on the window

                // This is the index on the controllerLabels array of the previously selected button.
                int selectedIndex = Array.FindIndex(controllerLabels, element => element.text.Equals(userSelectedButtons[k].ToString()));
                // This is the index on the buttonActionLabels array of the previously selected button.
                int selectedIndexActionButton = Array.FindIndex(buttonActionLabels, element => element.text.Equals(userSelectedActions[k].ToString()));

                // This is newly selected index by the user. We must transform it int a ControllerButtons to save it.
                int newlySelectedIndex = EditorGUILayout.Popup(selectedIndex, controllerLabels);
                newUserSelection[k] = (Button.ButtonName)Enum.Parse(typeof(Button.ButtonName), controllerLabels[newlySelectedIndex].text, true);

                int newlySelectedIndexActionButton = EditorGUILayout.Popup(selectedIndexActionButton, buttonActionLabels);
                newUserSelectionActions[k] = (Button.ButtonActions)Enum.Parse(typeof(Button.ButtonActions), buttonActionLabels[newlySelectedIndexActionButton].text, true);

                if (!(newUserSelection[k] == userSelectedButtons[k]))
                {
                    changesWereMade = true;
                }
                if (!(newUserSelectionActions[k] == userSelectedActions[k]))
                {
                    changesWereMade = true;
                }
                if (!hasInitialized)
                {
                    changesWereMade = true;
                }

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();
            }

            // Check if there was changes to the selected buttons or position (right or left) || !newUserSelectionIsRight.Equals(userSelectionIsRight) || !newUserSelectionActions.Equals(userSelectedActions)
            if (changesWereMade)
            {
                // If so update the inspector.
                userSelectedButtons = newUserSelection;
                userSelectedActions = newUserSelectionActions;

                // Register everythingy
                RegisterSelectedButtons();

                hasInitialized = true;
            }
        }
        ///// <summary>
        ///// Returns true if the button has just been released on the controller.
        ///// </summary>
        ///// <param name="button">The ControllerButtons for this button.</param>
        ///// <param name="controller">The Controller game object.</param>
        ///// <returns>True if the button has just been released in the controller.</returns>
        //public abstract bool GetPressUp(ButtonName button, GameObject controller);

        ///// <summary>
        ///// Returns true if the button is being hold down.
        ///// </summary>
        ///// <param name="button">The ControllerButtons for this button.</param>
        ///// <param name="controller">The Controller game object.</param>
        ///// <returns>True if the button is being hold down.</returns>
        //public abstract bool GetHoldDown(ButtonName button, GameObject controller);

        /// <summary>
        /// <para>Returns true if the ButtonAction on the specified controller GameObject and ButtonName button is happening.</para>
        /// <para>Else returns null.</para>
        /// </summary>
        /// <param name="button">The ControllerButtons for this button.</param>
        /// <param name="action">A button action.</param>
        /// <param name="controller">The Controller game object.</param>
        /// <returns>True if the button is being hold down.</returns>
        public abstract bool GetActionStatus(Button.ButtonName button, Button.ButtonActions action, GameObject controller);
Beispiel #17
0
        /// <summary>
        /// Creates a pickable dropdown of buttons, so player selects which button will activate the feature.
        /// </summary>
        /// <param name="registerActions">A method to register the buttons on the platform.</param>
        /// <param name="unregisterActions"> A method to unregister the buttons on the platform.</param>
        /// <param name="featureType">The type of the feature for instance(ArcTeleport).</param>
        /// <param name="fixedButtonNames">An array of buttons to be displayed. If null will display all the available buttons for the selected platform.</param>
        /// <param name="fixedButtonActions">An array of actions that can be used with this feature. If null will use all available for the selected platform.</param>
        /// <param name="initialValues">An array of initial values that were serialized.</param>
        protected virtual void CreateSelectionButton(Action <GameObject> registerActions, Action <GameObject> unregisterActions,
                                                     Type featureType, Button.ButtonName[] fixedButtonNames, Button.ButtonActions[] fixedButtonActions, params ButtonRegistry[] initialValues)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(new GUIContent("Activation Button"));
            amountOfButtons = EditorGUILayout.IntField(amountOfButtons);
            EditorGUILayout.EndHorizontal();

            bool changesWereMade = false;

            // No previous serialized settings setting or this was already serialized.
            // We only load from the serialized settings when the window is open.
            if (initialValues.Length != 0 && !hasInitialized)
            {
                amountOfButtons = initialValues.Length;
            }

            // Initialize vectors that will hold the new selection by the user..
            Button.ButtonName[]    newUserSelection        = new Button.ButtonName[amountOfButtons];
            Button.ButtonActions[] newUserSelectionActions = new Button.ButtonActions[amountOfButtons];
            bool[] newUserSelectionIsRight = new bool[amountOfButtons];

            // Expand or retract the vectors of selected options.
            if (amountOfButtons < userSelectedButtons.Length)
            {
                // Retract..
                userSelectedButtons  = userSelectedButtons.DescreaseArray(userSelectedButtons, userSelectedButtons.Length - amountOfButtons);
                userSelectedActions  = userSelectedActions.DescreaseArray(userSelectedActions, userSelectedActions.Length - amountOfButtons);
                userSelectionIsRight = newUserSelectionIsRight.DescreaseArray(userSelectionIsRight, userSelectionIsRight.Length - amountOfButtons);
            }
            else if (amountOfButtons > userSelectedButtons.Length)
            {
                // Expand..
                userSelectedButtons  = userSelectedButtons.ExpandArray(userSelectedButtons, amountOfButtons - userSelectedButtons.Length);
                userSelectedActions  = userSelectedActions.ExpandArray(userSelectedActions, amountOfButtons - userSelectedActions.Length);
                userSelectionIsRight = newUserSelectionIsRight.ExpandArray(userSelectionIsRight, amountOfButtons - userSelectionIsRight.Length);
            }

            // If it haven't been initialized yet and we have values to initialize do it.
            if (!hasInitialized && initialValues.Length != 0)
            {
                // Copy initial values to the user selected buttons.
                if (amountOfButtons >= initialValues.Length)
                {
                    for (int i = 0; i < initialValues.Length; i++)
                    {
                        userSelectedButtons[i]  = initialValues[i].Name;
                        userSelectedActions[i]  = initialValues[i].Action;
                        userSelectionIsRight[i] = initialValues[i].IsRightControllerButton;
                    }
                }
            }

            // Now we set each dropdown..
            for (int k = 0; k < amountOfButtons; k++)
            {
                // Get the available buttons for this platform..
                Button.ButtonName[] controllerButtons;
                if (fixedButtonNames != null)
                {
                    controllerButtons = fixedButtonNames;
                }
                else
                {
                    controllerButtons = SupportedPlatforms.GetButtons(Core.CoreSettings.EditorSelectedPlatform);
                }

                // Get the available actions for this platform..
                Button.ButtonActions[] buttonActions;
                if (fixedButtonActions.Length > 0)
                {
                    buttonActions = fixedButtonActions;
                }
                else
                {
                    buttonActions = SupportedPlatforms.GetButtonActions(Core.CoreSettings.EditorSelectedPlatform);
                }

                // Get the availble positions for this platform..
                string[] positions = SupportedPlatforms.GetPositions(Core.CoreSettings.EditorSelectedPlatform);

                // Create the labels that will be shown on the screen.
                GUIContent[] controllerLabels   = new GUIContent[controllerButtons.Length];
                GUIContent[] buttonActionLabels = new GUIContent[buttonActions.Length];
                GUIContent[] positionLabels     = new GUIContent[positions.Length];

                // Write all the info on the labels we just created.
                for (int i = 0; i < controllerButtons.Length; i++)
                {
                    controllerLabels[i]      = new GUIContent();
                    controllerLabels[i].text = controllerButtons[i].ToString();
                }
                for (int i = 0; i < buttonActions.Length; i++)
                {
                    buttonActionLabels[i]      = new GUIContent();
                    buttonActionLabels[i].text = buttonActions[i].ToString();
                }
                for (int i = 0; i < positions.Length; i++)
                {
                    positionLabels[i]      = new GUIContent();
                    positionLabels[i].text = positions[i];
                }

                // Start writing on the screen.
                EditorGUILayout.BeginHorizontal();
                // Write on the window
                int selectedPosition = 0;
                if (userSelectionIsRight[k])
                {
                    selectedPosition = EditorGUILayout.Popup(1, positionLabels);
                }
                else
                {
                    selectedPosition = EditorGUILayout.Popup(0, positionLabels);
                }

                // This is the index on the controllerLabels array of the previously selected button.
                int selectedIndex = Array.FindIndex(controllerLabels, element => element.text.Equals(userSelectedButtons[k].ToString()));
                // This is the index on the buttonActionLabels array of the previously selected button.
                int selectedIndexActionButton = Array.FindIndex(buttonActionLabels, element => element.text.Equals(userSelectedActions[k].ToString()));

                // This is newly selected index by the user. We must transform it int a ControllerButtons to save it.
                int newlySelectedIndex = EditorGUILayout.Popup(selectedIndex, controllerLabels);
                newUserSelection[k] = (Button.ButtonName)Enum.Parse(typeof(Button.ButtonName), controllerLabels[newlySelectedIndex].text, true);

                int newlySelectedIndexActionButton = EditorGUILayout.Popup(selectedIndexActionButton, buttonActionLabels);
                newUserSelectionActions[k] = (Button.ButtonActions)Enum.Parse(typeof(Button.ButtonActions), buttonActionLabels[newlySelectedIndexActionButton].text, true);

                if (positions[selectedPosition].Equals("Right"))
                {
                    newUserSelectionIsRight[k] = true;
                }
                else
                {
                    newUserSelectionIsRight[k] = false;
                }

                if (!(newUserSelection[k] == userSelectedButtons[k]))
                {
                    changesWereMade = true;
                }
                if (!(newUserSelectionIsRight[k] == userSelectionIsRight[k]))
                {
                    changesWereMade = true;
                }
                if (!(newUserSelectionActions[k] == userSelectedActions[k]))
                {
                    changesWereMade = true;
                }
                if (!hasInitialized)
                {
                    hasInitialized  = true;
                    changesWereMade = true;
                }


                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();
            }

            // Check if there was changes to the selected buttons or position (right or left) || !newUserSelectionIsRight.Equals(userSelectionIsRight) || !newUserSelectionActions.Equals(userSelectedActions)
            if (changesWereMade)
            {
                // If so update the inspector.
                userSelectedButtons  = newUserSelection;
                userSelectedActions  = newUserSelectionActions;
                userSelectionIsRight = newUserSelectionIsRight;

                // Update on the main script (send info to the core too).
                GameObject feature = FindFeatureOfType(featureType);

                // if (hasInitialized)
                unregisterActions(feature);

                Debug.Log("Registering...");
                registerActions(feature);
            }
        }
Beispiel #18
0
 /// <summary>
 /// Sets the button method on this control set.
 /// </summary>
 /// <param name="button">Which button we are setting.</param>
 /// <param name="action">The button action related to the method.</param>
 /// <param name="isRight">True if this button is on the right controller.</param>
 /// <param name="method">The method that it will execute when run.</param>
 /// <param name="shouldOverrideInteraction">True if it should override ongoing interactions.</param>
 /// <param name="featureOwner">The type of the feature that instatiated this button.</param>
 public abstract void AddButton(Button.ButtonName button, Button.ButtonActions action, bool isRight,
                                Action method, bool shouldOverrideInteraction, Type featureOwner);
Beispiel #19
0
 /// <summary>
 /// Remove the button method from this control set.
 /// </summary>
 /// <param name="button">Which button we are setting.</param>
 /// <param name="action">The button action related to the method.</param>
 /// <param name="isRight">True if this button is on the right controller.</param>
 /// <param name="method">The method that it will execute when run.</param>
 /// <param name="owner">The type of the object that instatiated this button. This should be unique.</param>
 protected abstract void RemoveButton(Button.ButtonName button, Button.ButtonActions action, bool isRight, Action method, Type owner);
Beispiel #20
0
            public bool isRightController = true;  // True if the button press was on the right controller.

            public PressControl(Button.ButtonName name, Button.ButtonActions action, bool active, bool isRight)
            {
                Name = name; Action = action; isActionActive = active; isRightController = isRight;
            }
Beispiel #21
0
        private static void CreateHintSelectionDropdown(CoreSettings coreSettings)
        {
            int oldAmountOfButtons = 1;
            int amountOfButtons    = oldAmountOfButtons;

            // No previous serialized settings setting or this was already serialized.
            // We only load from the serialized settings when the window is open.
            if (coreSettings.DefaultHintButtons.Count != 0 /*&& !hasInitialized*/)
            {
                oldAmountOfButtons = coreSettings.DefaultHintButtons.Count;
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(new GUIContent("Amount of Hints"));
            amountOfButtons = EditorGUILayout.IntField(oldAmountOfButtons);
            EditorGUILayout.EndHorizontal();

            bool changesWereMade = false;

            Button.ButtonName[] userSelectedButtons  = new Button.ButtonName[coreSettings.DefaultHintButtons.Count];
            string[]            userSelectedContents = coreSettings.DefaultHintsContent.ToArray();
            bool[] userSelectionIsRight = coreSettings.DefaultHintPositions.ToArray();

            for (int i = 0; i < coreSettings.DefaultHintButtons.Count; i++)
            {
                userSelectedButtons[i] = HintConvert.ConvertToButtonName(coreSettings.DefaultHintButtons[i]);
            }

            // Initialize vectors that will hold the new selection by the user..
            Button.ButtonName[] newUserSelection      = new Button.ButtonName[amountOfButtons];
            string[]            newUserInputedContent = new string[amountOfButtons];
            bool[] newUserSelectionIsRight            = new bool[amountOfButtons];

            // Expand or retract the vectors of selected options.
            if (amountOfButtons < userSelectedButtons.Length)
            {
                // Retract..
                userSelectedButtons  = userSelectedButtons.DescreaseArray(userSelectedButtons, userSelectedButtons.Length - amountOfButtons);
                userSelectedContents = userSelectedContents.DescreaseArray(userSelectedContents, userSelectedContents.Length - amountOfButtons);
                userSelectionIsRight = newUserSelectionIsRight.DescreaseArray(userSelectionIsRight, userSelectionIsRight.Length - amountOfButtons);
            }
            else if (amountOfButtons > userSelectedButtons.Length)
            {
                // Expand..
                userSelectedButtons  = userSelectedButtons.ExpandArray(userSelectedButtons, amountOfButtons - userSelectedButtons.Length);
                userSelectedContents = userSelectedContents.ExpandArray(userSelectedContents, amountOfButtons - userSelectedContents.Length);
                userSelectionIsRight = newUserSelectionIsRight.ExpandArray(userSelectionIsRight, amountOfButtons - userSelectionIsRight.Length);
            }

            // Now we set each dropdown..
            for (int k = 0; k < amountOfButtons; k++)
            {
                // Get the available buttons for this platform..
                Button.ButtonName[] controllerButtons;
                controllerButtons = SupportedPlatforms.GetButtons(CoreSettings.EditorSelectedPlatform);

                // Get the availble positions for this platform..
                string[] positions = SupportedPlatforms.GetPositions(CoreSettings.EditorSelectedPlatform);

                // Create the labels that will be shown on the screen.
                GUIContent[] controllerLabels = new GUIContent[controllerButtons.Length];
                GUIContent[] positionLabels   = new GUIContent[positions.Length];

                // Write all the info on the labels we just created.
                for (int i = 0; i < controllerButtons.Length; i++)
                {
                    controllerLabels[i]      = new GUIContent();
                    controllerLabels[i].text = controllerButtons[i].ToString();
                }
                for (int i = 0; i < positions.Length; i++)
                {
                    positionLabels[i]      = new GUIContent();
                    positionLabels[i].text = positions[i];
                }

                // Start writing on the screen.
                EditorGUILayout.BeginHorizontal();
                // Write on the window
                int selectedPosition = 0;
                if (userSelectionIsRight[k])
                {
                    selectedPosition = EditorGUILayout.Popup(1, positionLabels);
                }
                else
                {
                    selectedPosition = EditorGUILayout.Popup(0, positionLabels);
                }

                // This is the index on the controllerLabels array of the previously selected button.
                int selectedIndex = Array.FindIndex(controllerLabels, element => element.text.Equals(userSelectedButtons[k].ToString()));

                string inputedContent = "";
                if (k < coreSettings.DefaultHintsContent.Count)
                {
                    inputedContent = EditorGUILayout.TextField(coreSettings.DefaultHintsContent[k]);
                }

                // This is the newly inputed content.
                newUserInputedContent[k] = inputedContent;
                if (inputedContent == null)
                {
                    continue; // We dont register inputs..
                }
                // This is newly selected index by the user. We must transform it int a ControllerButtons to save it.
                int newlySelectedIndex = EditorGUILayout.Popup(selectedIndex, controllerLabels);
                newUserSelection[k] = (Button.ButtonName)Enum.Parse(typeof(Button.ButtonName), controllerLabels[newlySelectedIndex].text, true);


                if (positions[selectedPosition].Equals("Right"))
                {
                    newUserSelectionIsRight[k] = true;
                }
                else
                {
                    newUserSelectionIsRight[k] = false;
                }

                if (!(newUserSelection[k] == userSelectedButtons[k]))
                {
                    changesWereMade = true;
                }
                if (!(newUserSelectionIsRight[k] == userSelectionIsRight[k]))
                {
                    changesWereMade = true;
                }
                if (!(newUserInputedContent[k].Equals(userSelectedContents[k])))
                {
                    changesWereMade = true;
                }
                if (amountOfButtons != oldAmountOfButtons)
                {
                    changesWereMade = true;
                }

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();
            }

            // Check if there was changes
            if (changesWereMade)
            {
                coreSettings.DefaultHintButtons.Clear();
                coreSettings.DefaultHintPositions.Clear();
                coreSettings.DefaultHintsContent.Clear();

                // If so update the inspector.
                for (int i = 0; i < newUserSelection.Length; i++)
                {
                    coreSettings.DefaultHintButtons.Add(HintConvert.ConvertNames(newUserSelection[i], newUserSelectionIsRight[i]));
                    coreSettings.DefaultHintPositions.Add(newUserSelectionIsRight[i]);
                    coreSettings.DefaultHintsContent.Add(newUserInputedContent[i]);
                }

                // Serialize Changes!
                coreSettings.Save(coreSettings);
            }
            return;
        }
Beispiel #22
0
        /// <summary>
        ///  Register the buttons on the platform and on this feature serializeble registries.
        /// </summary>
        /// <param name="userSelectedButtons">The name of the selected buttons.</param>
        /// <param name="userSelectedActions">The actions of each button.</param>
        /// <param name="userSelectionIsRight">If each button is on the right hand side.</param>
        /// <param name="overrideInteraction">If each button should override interaction.</param>
        public void RegisterActionButtons(Button.ButtonName[] userSelectedButtons, Button.ButtonActions[] userSelectedActions,
                                          bool[] userSelectionIsRight, bool[]  overrideInteraction)
        {
            // For the case of the Arc teleport we must, add a fixed HoldDown for the same button.

            // Adding an extra button to be used as a HoldDown
            Button.ButtonName[] buttonName = new Button.ButtonName[userSelectedButtons.Length * 2];
            int j = 0;

            for (int i = 0; i < userSelectedButtons.Length; i++)
            {
                buttonName[j]     = userSelectedButtons[i];
                buttonName[j + 1] = userSelectedButtons[i];
                j += 2;
            }

            // Making the extra button have the holddown action.
            Button.ButtonActions[] buttonActions = new Button.ButtonActions[userSelectedActions.Length * 2];
            j = 0;
            for (int i = 0; i < userSelectedActions.Length; i++)
            {
                buttonActions[j]     = userSelectedActions[i];
                buttonActions[j + 1] = Button.ButtonActions.HoldDown;
                j += 2;
            }

            bool[] position = new bool[userSelectionIsRight.Length * 2];
            j = 0;
            for (int i = 0; i < userSelectionIsRight.Length; i++)
            {
                position[j]     = userSelectionIsRight[i];
                position[j + 1] = userSelectionIsRight[i];
                j += 2;
            }

            // Retrieve the Actions(methods) from the ArcTeleportManager.
            Action teleportMethod = GetTeleportMethod();
            Action holdingMethod  = GetHoldingButtonAction();

            // Attempt to register them on the current selected platform.

            // Retrieve the platform.
            GenericControllerPlatform platform;

            if (coreSettings.CurrentPlatform.GetType().IsSubclassOf(typeof(GenericControllerPlatform)))
            {
                platform = (GenericControllerPlatform)coreSettings.CurrentPlatform;
            }
            else
            {
                Debug.LogError("Platform doesn't support controllers. ArcTeleport require controls to work.");
                return;
            }

            //  Foreach button register it on the platform.
            for (int i = 0; i < buttonName.Length; i++)
            {
                // Register feature method. Register the teleport method to PushUp events and the selection method to HoldDown events.
                if (buttonActions[i] == Button.ButtonActions.HoldDown)
                {
                    /* Registering the method (On the Platform Controller). */
                    platform.GetPlatformControls().AddButton(buttonName[i], buttonActions[i], position[i], holdingMethod, false, GetFeatureType());

                    // Saving a reference to the button on the settings to be serialized.
                    SaveButtonChoice(buttonName[i], buttonActions[i], false, position[i]);
                }
                else if (buttonActions[i] == Button.ButtonActions.PressUp)
                {
                    /* Registering the method (On the Platform Controller). */
                    platform.GetPlatformControls().AddButton(buttonName[i], buttonActions[i], position[i], teleportMethod, false, GetFeatureType());

                    // Saving a reference to the button on the settings to be serialized.
                    SaveButtonChoice(buttonName[i], buttonActions[i], false, position[i]);
                }
                else
                {
                    Debug.LogError("Something is of Arc Teleport is not set to either HoldDown or PressUp");
                }
            }
        }