コード例 #1
0
        public override void _Update()
        {
            // Select whichever input is present first
            if (!gamepadSource.IsPresent())
            {
                InputSources inputSources = InputSources.Instance;
                if (inputSources.netGamepad.IsPresent())
                {
                    SelectGamepadSource(inputSources.netGamepad);
                }
                else if (inputSources.hidGamepad.IsPresent())
                {
                    SelectGamepadSource(inputSources.hidGamepad);
                }
                else if (inputSources.unityGamepad.IsPresent())
                {
                    SelectGamepadSource(inputSources.unityGamepad);
                }
            }
            else
            {
                if (useJoyAdjustedDir)
                {
                    Vector2 joy = gamepadSource.leftJoyVector;
                    if (AbsoluteJoystickDrag)
                    {
                        adjustedTargetRot = buildWorldTargetRot(joy);
                    }
                    else
                    {
                        adjustedTargetRot *= buildLocalTargetVector(joy, dragSpeed * Time.deltaTime);
                    }
                }

                /*aButtonState.ApplyState(gamepadSource.aButtonState.pressed);
                 * bButtonState.ApplyState(gamepadSource.bButtonState.pressed);
                 * xButtonState.ApplyState(gamepadSource.xButtonState.pressed);
                 * yButtonState.ApplyState(gamepadSource.yButtonState.pressed);
                 * startButtonState.ApplyState(gamepadSource.startButtonState.pressed);*/
            }

            bool prev = m_Select;

            m_Select = (this as ITargetingInputSource).IsSelectPressed();
            if (prev != m_Select)
            {
                OnSelectChanged(this, m_Select);
            }

            prev   = m_Menu;
            m_Menu = (this as ITargetingInputSource).IsMenuPressed();
            if (prev != m_Menu)
            {
                OnMenuChanged(this, m_Menu);
            }

            base._Update();
        }
コード例 #2
0
        /// <summary>
        /// Manual update function, invoked by InputShellMap, after all input controls have been updated
        /// </summary>
        public void _Update()
        {
            // Fire all queued actions now that state is fully updated
            ControlStateBase.FireActions();

            // Beam activation logic
            InputSources inputSources = InputSources.Instance;
            bool         beamActive   = inputSources.touch6D.IsActiveTargetingSource();

            beamActive |= inputSources.hands.IsActiveTargetingSource() && ((ITargetingInputSource)inputSources.hands).IsSelectPressed();

#if UNITY_EDITOR
            beamActive = true;
#endif

            // beamController.SetBeamActive(beamActive);
        }
コード例 #3
0
        /// <summary>
        /// Initialization.  Stores all input sources from InputSources which implement ITargetingInputSource
        /// </summary>
        /// <param name="_inputSources"></param>
        public void Init(InputSources _inputSources)
        {
            inputSources = _inputSources;

            foreach (InputSourceBase source in inputSources.sources)
            {
                //if( source.GetType().IsAssignableFrom(typeof(ITargetingInputSource)))
                if (source is ITargetingInputSource)
                {
                    TargetingSources.Add(source as ITargetingInputSource);
                    TargetingSourceBases.Add(source);
                }
            }

            if (debugPrint)
            {
                UnityEngine.Debug.Log("TargetingSources: " + TargetingSources.Count);
            }

            CurrentTargetingSource = inputSources.hands;
        }
コード例 #4
0
        /// <summary>
        /// Initialization.  Gets all input sources that exist in the scene, then sorts virtual sources
        /// to the end.  Finally, the input source fields in InputSources are automatically assigned using reflection.
        /// </summary>
        public void Init(GameObject owner)
        {
            Instance = this;

            // Currently looks for all input sources in scene
            sources = GameObject.FindObjectsOfType <InputSourceBase>();

            // Sort so that virtual sources are after physical
            for (int i = 0; i < sources.Length; ++i)
            {
                // If we find a virtual source, look for non-virtual sources
                if (sources[i].IsVirtual)
                {
                    int h = sources.Length - 1;
                    for (; h > i; --h)
                    {
                        // Found a non-virtual source, swap them
                        if (!sources[h].IsVirtual)
                        {
                            InputSourceBase temp = sources[i];
                            sources[i] = sources[h];
                            sources[h] = temp;
                            break;
                        }
                    }

                    // There were no non-virtual sources after this one!
                    if (h <= i)
                    {
                        break;
                    }
                }
            }

            List <InputSourceBase> addedSources = new List <InputSourceBase>();

            // Auto-assign all InputSourceBase fields to the corresponding instance
#if USE_WINRT
            foreach (FieldInfo field in GetType().GetTypeInfo().DeclaredFields)
#else
            FieldInfo[] myFields = GetType().GetFields();
            foreach (FieldInfo field in myFields)
#endif
            {
                // Found an InputSourceBase field
#if USE_WINRT
                if (field.FieldType.GetTypeInfo().IsSubclassOf(typeof(InputSourceBase)))
#else
                if (field.FieldType.IsSubclassOf(typeof(InputSourceBase)))
#endif
                {
                    // Con: Must create in editor, Pro: can configure properties
                    // Find the matching component
                    bool didSet = false;
                    foreach (InputSourceBase isb in sources)
                    {
                        if (isb.GetType() == field.FieldType)
                        {
                            field.SetValue(this, isb);
                            didSet = true;
                            break;
                        }
                    }

                    if (!didSet)
                    {
                        //Debug.LogError("Didn't find InputSourceBase for field " + field.Name);
                        // Pro: Don't need to create in editor, Con: can't configure

                        // Create the component if not found.  It will just have default values.
                        Component c = owner.AddComponent(field.FieldType);
                        field.SetValue(this, c);
                        addedSources.Add(c as InputSourceBase);
                    }
                }
                else if (field.FieldType.IsArray

#if USE_WINRT
                         && field.FieldType.GetElementType().GetTypeInfo().IsSubclassOf(typeof(InputSourceBase))
#else
                         && field.FieldType.GetElementType().IsSubclassOf(typeof(InputSourceBase))
#endif
                         )
                {
                    Type elementType = field.FieldType.GetElementType();
                    List <InputSourceBase> typeSources = new List <InputSourceBase>();
                    foreach (InputSourceBase isb in sources)
                    {
                        if (isb.GetType() == elementType)
                        {
                            typeSources.Add(isb);
                        }
                    }

                    object[] arr = (object[])Array.CreateInstance(elementType, typeSources.Count);

                    for (int index = 0; index < arr.Length; index++)
                    {
                        arr[index] = typeSources[index];
                    }

                    field.SetValue(this, arr);
                }
            }

            // Add the added soruces back into the source array
            InputSourceBase[] newSourceArray = new InputSourceBase[addedSources.Count + sources.Length];
            sources.CopyTo(newSourceArray, 0);
            addedSources.CopyTo(newSourceArray, sources.Length);
            sources = newSourceArray;

            ConfigureActiveSources();
        }