Ejemplo n.º 1
0
    private void triggerJoystickEvent(int index, float axisValue)
    {
        if (joystickListeners == null)
        {
            List <GameObject> allObject = GetAllObjectsInScene();
            joystickListeners = new List <INibiruJoystickListener>();
            foreach (GameObject obj in allObject)
            {
                Component[] joystickcomps = obj.GetComponents(typeof(INibiruJoystickListener));

                if (joystickcomps != null)
                {
                    INibiruJoystickListener[] listeners = new INibiruJoystickListener[joystickcomps.Length];

                    for (int p = 0; p < joystickcomps.Length; p++)
                    {
                        listeners[p] = (INibiruJoystickListener)joystickcomps[p];
                    }
                    // INibiruJoystickListener
                    notifyJoystickPressed(listeners, index, axisValue);
                    foreach (Component cp in joystickcomps)
                    {
                        joystickListeners.Add((INibiruJoystickListener)cp);
                    }
                }
            }
        }
        else
        {
            notifyJoystickPressed(joystickListeners.ToArray(), index, axisValue);
        }
    }
Ejemplo n.º 2
0
    private void notifyJoystickPressed(INibiruJoystickListener[] comps, int index, float axisValue)
    {
        if (comps == null)
        {
            return;
        }
        for (int i = 0; i < comps.Length; i++)
        {
            INibiruJoystickListener joystickListener = (INibiruJoystickListener)comps[i];
            if (joystickListener == null)
            {
                continue;
            }
            switch (index)
            {
            case 0:
                // l1
                joystickListener.OnPressL1();
                break;

            case 1:
                // l2
                joystickListener.OnPressL2();
                break;

            case 2:
                // r1
                joystickListener.OnPressR1();
                break;

            case 3:
                // r2
                joystickListener.OnPressR2();
                break;

            case 4:
                // select
                joystickListener.OnPressSelect();
                break;

            case 5:
                // start
                joystickListener.OnPressStart();
                break;

            case 6:
                // x
                joystickListener.OnPressX();
                break;

            case 7:
                // y
                joystickListener.OnPressY();
                break;

            case 8:
                // a
                joystickListener.OnPressA();
                break;

            case 9:
                // b
                joystickListener.OnPressB();
                break;

            case 10:
                // leftstickx
                joystickListener.OnLeftStickX(axisValue);
                break;

            case 11:
                // leftsticky
                joystickListener.OnLeftStickY(axisValue);
                break;

            case 12:
                // rightstickx
                joystickListener.OnRightStickX(axisValue);
                break;

            case 13:
                // rightsticky
                joystickListener.OnRightStickY(axisValue);
                break;

            case 14:
                // dpad-up
                joystickListener.OnPressDpadUp();
                break;

            case 15:
                // dpad-down
                joystickListener.OnPressDpadDown();
                break;

            case 16:
                // dpad-left
                joystickListener.OnPressDpadLeft();
                break;

            case 17:
                // dpad-right
                joystickListener.OnPressDpadRight();
                break;
            }
        }
    }