public int registerControllerInstance(WVR_DeviceType type, GameObject controller)
    {
        PrintDebugLog("registerControllerInstance() " + type + ", controller: " + (controller != null ? controller.name : "null"));
        if (type != WVR_DeviceType.WVR_DeviceType_Controller_Left && type != WVR_DeviceType.WVR_DeviceType_Controller_Right)
        {
            PrintDebugLog("registerControllerInstance, type is not allowed");
            return(0);
        }

        if (controller == null)
        {
            PrintDebugLog("registerControllerInstance, controller is null");
            return(0);
        }

        ControllerIdx++;

        ControllerInstance t = new ControllerInstance();

        t.type     = type;
        t.instance = controller;
        t.index    = ControllerIdx;

        t.eventEnabled = getEventSystemParameter(type);
        t.showBeam     = getComponentParameter(controller, CComponent.Beam);
        t.showPointer  = getComponentParameter(controller, CComponent.ControllerPointer);

        ctrInstanceList.Add(t);
        PrintDebugLog("registerControllerInstance, add controller index: " + t.index + ", type: " + t.type + ", name: " + t.instance.name
                      + ", event able: " + t.eventEnabled + ", ShowBeam: " + t.showBeam + ", showPointer: " + t.showPointer);

        return(ControllerIdx);
    }
Exemple #2
0
 /// <summary>
 /// IOレジスタ書き込み
 /// </summary>
 /// <param name="address">Address.</param>
 /// <param name="value">Value.</param>
 public void WriteIoRegister(ushort address, byte value)
 {
     if ((address >= 0x2000 && address <= 0x2007) || address == 0x4014)
     {
         ppu.WritePpuRegister(address, value);
     }
     if (address == 0x4016 || address == 0x4017)
     {
         ControllerInstance.WriteIoRegister(address, value);
     }
 }
Exemple #3
0
        /// <summary>
        /// IOレジスタ読み込み
        /// </summary>
        /// <returns>The io register.</returns>
        /// <param name="address">Address.</param>
        public byte ReadIoRegister(ushort address)
        {
            switch (address)
            {
            case 0x2002:
            case 0x2007:
                return(ppu.ReadPpuRegister(address));

            case 0x4016:
            case 0x4017:
                return((byte)(ControllerInstance.ReadIoRegister(address) ? 1 : 0));
            }
            return(0x00);
        }
Exemple #4
0
        public static void StopByThread(string name)
        {
            ControllerInstance instance = instances[name];

            instance.StopWatch.Stop();
            long wait = instance.StopWatch.ElapsedMilliseconds - instance.ClockTime;

            if (wait <= 0)
            {
                Thread.Sleep(1);
            }
            else
            {
                Thread.Sleep((int)wait);
            }
        }
Exemple #5
0
        public static Task Stop(string name)
        {
            ControllerInstance instance = instances[name];

            instance.StopWatch.Stop();
            long wait = instance.StopWatch.ElapsedMilliseconds - instance.ClockTime;

            if (wait <= 0)
            {
                return(Task.Delay(1));
            }
            else
            {
                return(Task.Delay((int)wait));
            }
        }
        /// <summary>
        /// 初始化环境
        /// </summary>
        /// <param name="receiveBufferSize"></param>
        internal static void InitContext(IApplicationBuilder app)
        {
            WebSocketControllerManager.ServiceProvider = app.ApplicationServices;
            Controllers = new List <ControllerInstance>();
            var  assemblys              = AppDomain.CurrentDomain.GetAssemblies();
            Type sessiontype            = typeof(WebSocketController);
            Type websocketAttributetype = typeof(WebSocketsAttribute);

            foreach (var assembly in assemblys)
            {
                Type[] types = assembly.GetTypes();

                foreach (var classly in types)
                {
                    if (classly.IsClass && !classly.IsAbstract && classly.IsPublic && classly.IsSubclassOf(sessiontype))
                    {
                        var attribure = classly.GetCustomAttribute(websocketAttributetype) as WebSocketsAttribute;
                        if (attribure != null)
                        {
                            WebSocketController controller = null;
                            List <Object>       paramer    = new List <Object>();
                            var constructors = classly.GetConstructors();
                            foreach (var constructor in constructors)
                            {
                                foreach (var item in constructor.GetParameters())
                                {
                                    paramer.Add(WebSocketControllerManager.ServiceProvider.GetService(item.ParameterType));
                                }
                                if (constructor.GetParameters().Length == paramer.Count)
                                {
                                    controller = Activator.CreateInstance(classly, paramer.ToArray()) as WebSocketController;
                                    break;
                                }
                            }
                            if (controller == null)
                            {
                                controller = Activator.CreateInstance(classly) as WebSocketController;
                            }
                            Autowired(controller);
                            var instance = new ControllerInstance(attribure.Path, controller);
                            Controllers.Add(instance);
                        }
                    }
                }
            }
        }
    public void removeControllerInstance(int index)
    {
        ControllerInstance waitforRemove = null;

        foreach (ControllerInstance t in ctrInstanceList)
        {
            if (t.index == index)
            {
                PrintDebugLog("removeControllerInstance, remove controller index: " + t.index + ", type: " + t.type);
                waitforRemove = t;
            }
        }

        if (waitforRemove != null)
        {
            ctrInstanceList.Remove(waitforRemove);
        }
    }
    private void ForceSetActiveOfEmitter(ControllerInstance ci, bool enabled)
    {
        GameObject _controller = ci.instance;

        if (_controller != null)
        {
            if (ci.showBeam != enabled)
            {
                WaveVR_Beam _beam = _controller.GetComponentInChildren <WaveVR_Beam> ();
                if (_beam != null)
                {
                    ci.showBeam    = enabled;
                    _beam.ShowBeam = enabled;
                    PrintDebugLog("ForceSetActiveOfEmitter() Set " + ci.type + " controller " + _controller.name
                                  + ", index: " + ci.index
                                  + ", beam: " + _beam.ShowBeam);
                }
            }

            if (ci.showPointer != enabled)
            {
                WaveVR_ControllerPointer _pointer = _controller.GetComponentInChildren <WaveVR_ControllerPointer> ();
                if (_pointer != null)
                {
                    ci.showPointer       = enabled;
                    _pointer.ShowPointer = enabled;
                    PrintDebugLog("ForceSetActiveOfEmitter() Set " + ci.type + " controller " + _controller.name
                                  + ", index: " + ci.index
                                  + ", pointer: " + _pointer.ShowPointer);
                }
            }
        }
        else
        {
            if (Log.gpl.Print)
            {
                PrintDebugLog("ForceSetActiveOfEmitter() controller " + ci.type + " , index: " + ci.index + " controller is null, remove it from list.");
            }
            removeControllerInstance(ci.index);
        }
    }
    private bool ForceSetActiveOfEmitter(ControllerInstance ci, bool enabled)
    {
        bool _ret = false;

        GameObject _controller = ci.instance;

        if (_controller != null)
        {
            WaveVR_Beam _beam = _controller.GetComponentInChildren <WaveVR_Beam> ();
            WaveVR_ControllerPointer _pointer = _controller.GetComponentInChildren <WaveVR_ControllerPointer> ();

            if (_beam != null && _pointer != null)
            {
                _beam.ShowBeam       = enabled & ci.ShowBeam;
                _pointer.ShowPointer = enabled & ci.showPointer;

                PrintDebugLog("ForceSetActiveOfEmitter() Set " + ci.type + " controller " + _controller.name
                              + ", index: " + ci.index
                              + ", beam: " + _beam.ShowBeam
                              + ", pointer: " + _pointer.ShowPointer);

                _ret = true;
            }
            else
            {
                PrintIntervalLog(() => "ForceSetActiveOfEmitter() " + ci.type + " controller " + _controller.name
                                 + ", beam is " + (_beam == null ? "disabled" : "enabled")
                                 + ", pointer is " + (_pointer == null ? "disabled" : "enabled"));
            }
        }
        else
        {
            PrintDebugLog("ForceSetActiveOfEmitter() controller " + ci.type + " , index: " + ci.index + " controller is null, remove it from list.");
            removeControllerInstance(ci.index);
        }

        return(_ret);
    }
 protected virtual void OnControllerInstance(EventControllerInstanceArgs e)
 {
     ControllerInstance?.Invoke(this, e);
 }
Exemple #11
0
        public static void Start(string name)
        {
            ControllerInstance instance = instances[name];

            instance.StopWatch.Restart();
        }
Exemple #12
0
 public void InputKey(int player, int key)
 {
     ControllerInstance.InputKey(player, key);
 }
Exemple #13
0
    /// <summary>
    /// Initializes this library by loading all mappings from file and matching the given gamepads.
    /// </summary>
    private static void Initialize()
    {
        if (!IsInitialized)          // first init
        {
            new GameObject("GamePad ReInit").AddComponent <ReInit>();
        }
        List <CarbonController> mappings = new List <CarbonController>(Resources.LoadAll <CarbonController>("Mappings")); // load all mappings

        mappings.RemoveAll(mapping => !mapping.SupportedOnThisPlatform());                                                // keep only mappings for this platform
        mappings.Sort((a, b) => a.Priority - b.Priority);                                                                 // sort by priority, lower is better
        AllMappings = mappings.ToArray();
        // now try to match with the names of the connected joysticks
        int nameIndex = 0;

        gamepadCount = 0;
        List <ControllerInstance> matches = new List <ControllerInstance>();

        foreach (string name in Input.GetJoystickNames())
        {
            CarbonController toRemove = null;
            foreach (CarbonController cc in mappings)
            {
                if (!string.IsNullOrEmpty(cc.RegEx) && Regex.IsMatch(name, cc.RegEx, RegexOptions.IgnoreCase))
                {
                    matches.Add(new ControllerInstance(cc, nameIndex));
                    gamepadCount++;
                    if (cc.UseOnce)
                    {
                        toRemove = cc;
                    }
                    break;
                }
            }
            if (toRemove != null)
            {
                mappings.Remove(toRemove);
            }
            nameIndex++;
        }
        // add fallbacks (keyboard)
        var fallbacks = AllMappings.Where(x => x.IsFallback()).ToList();

        fallbacks.Add(disabledInput);

        PlayerMappings = new ControllerInstance[CarbonController.PlayerIndices];
        for (int i = 1; i < CarbonController.PlayerIndices; i++)
        {
            int idx = i - 1;
            if (idx < matches.Count)
            {
                PlayerMappings[i] = matches[idx]; // real GamePad
            }
            else                                  // Keyboard Fallback
            {
                var fallback = fallbacks.First();
                PlayerMappings[i] = new ControllerInstance(fallback, idx);
                if (fallback.UseOnce)
                {
                    fallbacks.RemoveAt(0);
                }
            }
        }
        PlayerMappings[0] = PlayerMappings[1];         // always use first found mapping as the "global" mapping for Anyone
        for (int i = 0; i < CarbonController.PlayerIndices; i++)
        {
            States[i] = new GamePadState((PlayerIndex)i);
        }

        settings      = CarbonSettings.Default();
        IsInitialized = true;
    }
    // Update is called once per frame
    void Update()
    {
#if UNITY_EDITOR
        if (Application.isPlaying)
        {
            return;
        }
#endif
        if (Interop.WVR_IsInputFocusCapturedBySystem())
        {
            if (!isFocusCapturedBySystemLastFrame)
            {
                foreach (ControllerInstance t in ctrInstanceList)
                {
                    bool ret = ForceSetActiveOfEmitter(t, false);
                }
            }
            isFocusCapturedBySystemLastFrame = true;

            return;
        }

        if (isFocusCapturedBySystemLastFrame)
        {
            systemEventType = WaveVR_Utils.WVR_GetFocusedController();
            PrintDebugLog("back from overlay() Focus controller: " + systemEventType);
            isFocusCapturedBySystemLastFrame = false;
            this.toSetActiveOfEmitter        = true;
        }

        if (this.ctrInstanceList.Count < 1)
        {
            this.lastEventType = WVR_DeviceType.WVR_DeviceType_Invalid;
            return;
        }

        PrintIntervalLog(() => "Controller instance: " + ctrInstanceList.Count + ", Focus controller: " + systemEventType);

        if (this.ctrInstanceList.Count == 1)
        {
            ControllerInstance t = ctrInstanceList [0];
            this.systemEventType = t.type;
            if (this.isCtrInstanceUpdated)
            {
                this.isCtrInstanceUpdated = !this.isCtrInstanceUpdated;
                PrintDebugLog("Update() Controller focus changes to " + this.systemEventType);
            }
        }
        else   // count > 1
        {
            if (this.systemEventType == WVR_DeviceType.WVR_DeviceType_Controller_Right)
            {
                if (WaveVR_Controller.Input(WVR_DeviceType.WVR_DeviceType_Controller_Left).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Digital_Trigger) ||
                    WaveVR_Controller.Input(WVR_DeviceType.WVR_DeviceType_Controller_Left).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Trigger))
                {
                    this.systemEventType = WVR_DeviceType.WVR_DeviceType_Controller_Left;
                    PrintDebugLog("Update() Controller focus changes from Right to Left, set to runtime.");
                }
            }
            if (this.systemEventType == WVR_DeviceType.WVR_DeviceType_Controller_Left)
            {
                // Listen to right
                if (WaveVR_Controller.Input(WVR_DeviceType.WVR_DeviceType_Controller_Right).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Digital_Trigger) ||
                    WaveVR_Controller.Input(WVR_DeviceType.WVR_DeviceType_Controller_Right).GetPressUp(WVR_InputId.WVR_InputId_Alias1_Trigger))
                {
                    this.systemEventType = WVR_DeviceType.WVR_DeviceType_Controller_Right;
                    PrintDebugLog("Update() Controller focus changes from Left to Right, set to runtime.");
                }
            }
        }

        if (this.lastEventType != this.systemEventType || this.connectionUpdated)
        {
            this.lastEventType = this.systemEventType;
            PrintDebugLog("Update() current focus: " + this.systemEventType);
            this.connectionUpdated = false;

            if (this.systemEventType == WVR_DeviceType.WVR_DeviceType_Controller_Right)
            {
                activateEventSystem(WVR_DeviceType.WVR_DeviceType_Controller_Right, true);
                activateEventSystem(WVR_DeviceType.WVR_DeviceType_Controller_Left, false);
            }

            if (this.systemEventType == WVR_DeviceType.WVR_DeviceType_Controller_Left)
            {
                activateEventSystem(WVR_DeviceType.WVR_DeviceType_Controller_Right, false);
                activateEventSystem(WVR_DeviceType.WVR_DeviceType_Controller_Left, true);
            }

            WaveVR_Utils.WVR_SetFocusedController(this.systemEventType);
            this.toSetActiveOfEmitter = true;
        }

        setActiveOfEmitter();
    }