Beispiel #1
0
    private void CreateEventSystem()
    {
        // Create event system, input module, and event camera
        U.Object.AddComponent <EventSystem>(gameObject);
        m_InputModule = U.Object.AddComponent <MultipleRayInputModule>(gameObject);
        m_InputModule.getPointerLength = GetPointerLength;
        m_EventCamera             = U.Object.Instantiate(m_EventCameraPrefab.gameObject, transform).GetComponent <Camera>();
        m_EventCamera.enabled     = false;
        m_InputModule.eventCamera = m_EventCamera;
        foreach (var proxy in m_AllProxies)
        {
            foreach (var rayOriginBase in proxy.rayOrigins)
            {
                foreach (var device in InputSystem.devices)                 // Find device tagged with the node that matches this RayOrigin node
                {
                    var node = GetDeviceNode(device);
                    if (node.HasValue && node.Value == rayOriginBase.Key)
                    {
                        DeviceData deviceData;
                        if (m_DeviceData.TryGetValue(device, out deviceData))
                        {
                            // Create ui action map input for device.
                            if (deviceData.uiInput == null)
                            {
                                deviceData.uiInput = CreateActionMapInput(m_InputModule.actionMap, device);
                            }

                            // Add RayOrigin transform, proxy and ActionMapInput references to input module list of sources
                            m_InputModule.AddRaycastSource(proxy, rayOriginBase.Key, deviceData.uiInput);
                        }
                        break;
                    }
                }
            }
        }
        UpdatePlayerHandleMaps();
    }
Beispiel #2
0
    private void CreateWorkspace(Type t)
    {
        var defaultOffset = Workspace.kDefaultOffset;
        var defaultTilt   = Workspace.kDefaultTilt;

        var     viewerPivot = U.Camera.GetViewerPivot();
        Vector3 position    = viewerPivot.position + defaultOffset;

        Quaternion rotation  = defaultTilt;
        float      arcLength = Mathf.Atan(Workspace.kDefaultBounds.x /
                                          (defaultOffset.z - Workspace.kDefaultBounds.z * 0.5f)) * Mathf.Rad2Deg //Calculate arc length at front of workspace
                               + kWorkspaceAnglePadding;                                                         //Need some extra padding because workspaces are tilted
        float heightOffset = Workspace.kDefaultBounds.y + kWorkspaceYPadding;                                    //Need padding in Y as well

        float currentRotation = arcLength;
        float currentHeight   = 0;

        int     count      = 0;
        int     direction  = 1;
        Vector3 halfBounds = Workspace.kDefaultBounds * 0.5f;

        //While the current position is occupied, try a new one
        while (Physics.CheckBox(position, halfBounds, rotation) && count++ < kMaxWorkspacePlacementAttempts)
        {
            //The next position will be rotated by currentRotation, as if the hands of a clock
            Quaternion rotateAroundY = Quaternion.AngleAxis(currentRotation * direction, Vector3.up);
            position = viewerPivot.position + rotateAroundY * defaultOffset + Vector3.up * currentHeight;
            rotation = rotateAroundY * defaultTilt;

            //Every other iteration, rotate a little further
            if (direction < 0)
            {
                currentRotation += arcLength;
            }

            //Switch directions every iteration (left, right, left, right)
            direction *= -1;

            //If we've one more than half way around, we have tried the whole circle, bump up one level and keep trying
            if (currentRotation > 180)
            {
                direction       = -1;
                currentRotation = 0;
                currentHeight  += heightOffset;
            }
        }

        Workspace workspace = (Workspace)U.Object.CreateGameObjectWithComponent(t, U.Camera.GetViewerPivot());

        m_AllWorkspaces.Add(workspace);
        workspace.destroyed += OnWorkspaceDestroyed;
        ConnectInterfaces(workspace);
        workspace.transform.position = position;
        workspace.transform.rotation = rotation;

        //Explicit setup call (instead of setting up in Awake) because we need interfaces to be hooked up first
        workspace.Setup();

        var miniWorld = workspace as IMiniWorld;

        if (miniWorld == null)
        {
            return;
        }

        m_MiniWorlds.Add(miniWorld);

        foreach (var proxy in m_AllProxies)
        {
            foreach (var rayOriginBase in proxy.rayOrigins)
            {
                foreach (var device in InputSystem.devices)                 // Find device tagged with the node that matches this RayOrigin node
                {
                    var node = GetDeviceNode(device);
                    if (node.HasValue && node.Value == rayOriginBase.Key)
                    {
                        DeviceData deviceData;
                        if (m_DeviceData.TryGetValue(device, out deviceData))
                        {
                            // Create MiniWorld rayOrigin
                            var miniWorldRayOrigin = new GameObject("MiniWorldRayOrigin").transform;
                            miniWorldRayOrigin.parent = workspace.transform;

                            var uiInput = CreateActionMapInput(m_InputModule.actionMap, device);
                            m_PlayerHandle.maps.Insert(m_PlayerHandle.maps.IndexOf(deviceData.uiInput), uiInput);
                            // Add RayOrigin transform, proxy and ActionMapInput references to input module list of sources
                            m_InputModule.AddRaycastSource(proxy, rayOriginBase.Key, uiInput, miniWorldRayOrigin);
                            m_MiniWorldRays[miniWorldRayOrigin] = new MiniWorldRay()
                            {
                                originalRayOrigin = rayOriginBase.Value,
                                miniWorld         = miniWorld,
                                proxy             = proxy,
                                uiInput           = uiInput
                            };
                        }
                        break;
                    }
                }
            }
        }
    }