Пример #1
0
        private RepairModePositionIndicator()
        {
            Texture2D hammerTex = loadHammerTexture();

            if (hammerTex == null)
            {
                return;
            }
            if (!ensureHammerCam())
            {
                return;
            }
            _hammerCanvasRoot = new GameObject("RepairModeHammerIndicatorRoot");
            GameObject.DontDestroyOnLoad(_hammerCanvasRoot);
            _hammerCanvasRoot.layer  = LayerUtils.getWorldspaceUiLayer();
            _hammerCanvas            = _hammerCanvasRoot.AddComponent <Canvas>();
            _hammerCanvas.renderMode = RenderMode.WorldSpace;
            _hammerImageParent       = new GameObject("RepairModeHammerIndicatorParent");
            _hammerImageParent.transform.SetParent(_hammerCanvas.GetComponent <RectTransform>(), false);
            _hammerImageParent.transform.localPosition = _hammerCanvas.GetComponent <RectTransform>().rect.center;
            _hammerImage        = _hammerImageParent.AddComponent <Image>();
            _hammerImage.sprite =
                Sprite.Create(hammerTex,
                              new Rect(0.0f, 0.0f, hammerTex.width, hammerTex.height),
                              new Vector2(0.5f, 0.5f));
            _hammerCanvasRoot.SetActive(false);
        }
Пример #2
0
        /**
         * create:
         * - standart layer (gray)
         * - disabled equipped layers (blue)
         * - items, without sprite yet
         */
        private void initialize()
        {
            var tex_standard = new Texture2D(1, 1);

            tex_standard.SetPixel(0, 0, standard);
            tex_standard.Apply();

            var tex_hovered = new Texture2D(1, 1);

            tex_hovered.SetPixel(0, 0, hovered);
            tex_hovered.Apply();

            var tex_selected = new Texture2D(1, 1);

            tex_selected.SetPixel(0, 0, selected);
            tex_selected.Apply();

            for (int i = 0; i < MAX_ELEMENTS; i++)
            {
                elements[i] = new GameObject();
                elements[i].transform.SetParent(transform, false);

                GameObject standardLayer = new GameObject();
                standardLayer.layer = LayerUtils.getWorldspaceUiLayer();
                standardLayer.transform.SetParent(elements[i].transform, false);
                standardLayer.transform.localScale *= 4;
                var standardRenderer = standardLayer.AddComponent <SpriteRenderer>();
                standardRenderer.sprite       = Sprite.Create(tex_standard, new Rect(0.0f, 0.0f, tex_standard.width, tex_standard.height), new Vector2(0.5f, 0.5f));
                standardRenderer.sortingOrder = 0;

                GameObject equipedLayer = new GameObject();
                equipedLayer.layer = LayerUtils.getWorldspaceUiLayer();
                equipedLayer.transform.SetParent(elements[i].transform, false);
                equipedLayer.transform.localScale *= 4;
                var equipedRenderer = equipedLayer.AddComponent <SpriteRenderer>();
                equipedRenderer.sprite       = Sprite.Create(tex_selected, new Rect(0.0f, 0.0f, tex_selected.width, tex_selected.height), new Vector2(0.5f, 0.5f));
                equipedRenderer.sortingOrder = 2;
                equipedLayer.SetActive(false);

                GameObject item = new GameObject();
                item.layer = LayerUtils.getWorldspaceUiLayer();
                item.transform.SetParent(elements[i].transform, false);
                item.transform.localScale /= 15;
                var renderer = item.AddComponent <SpriteRenderer>();
                renderer.sortingOrder = 3;
            }

            hoveredItem       = new GameObject();
            hoveredItem.layer = LayerUtils.getWorldspaceUiLayer();
            hoveredItem.transform.SetParent(transform, false);
            hoveredItem.transform.localScale *= 4;
            var hoveredItemRenderer = hoveredItem.AddComponent <SpriteRenderer>();

            hoveredItemRenderer.sprite       = Sprite.Create(tex_hovered, new Rect(0.0f, 0.0f, tex_hovered.width, tex_hovered.height), new Vector2(0.5f, 0.5f));
            hoveredItemRenderer.sortingOrder = 1;
            hoveredItem.SetActive(false);
        }
Пример #3
0
 private void createSphere()
 {
     sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
     sphere.transform.SetParent(transform);
     sphere.transform.localScale *= 0.02f;
     sphere.layer = LayerUtils.getWorldspaceUiLayer();
     sphere.GetComponent <MeshRenderer>().material.color = Color.red;
     Destroy(sphere.GetComponent <Collider>());
 }
Пример #4
0
 private static void updateGuiLayers(Transform gui)
 {
     if (gui == null)
     {
         return;
     }
     gui.gameObject.layer = LayerUtils.getWorldspaceUiLayer();
     foreach (Transform child in gui)
     {
         updateGuiLayers(child);
     }
 }
Пример #5
0
 private void configureCrosshairElements(GameObject clone)
 {
     if (clone == null)
     {
         LogError("Null Crosshair Clone while configuring clones.");
         return;
     }
     clone.layer = LayerUtils.getWorldspaceUiLayer();
     foreach (Transform t in clone.transform)
     {
         configureCrosshairElements(t.gameObject);
     }
 }
Пример #6
0
 private void maybeCreatePieceHealthObjects()
 {
     if (_pieceHealthCanvasParent != null && _pieceHealthCanvas != null || !ensureCrosshairCamera())
     {
         return;
     }
     _pieceHealthCanvasParent = new GameObject("WorldSpacePieceHealthCanvasParent");
     GameObject.DontDestroyOnLoad(_pieceHealthCanvasParent);
     _pieceHealthCanvasParent.layer = LayerUtils.getWorldspaceUiLayer();
     _pieceHealthCanvas             = _pieceHealthCanvasParent.AddComponent <Canvas>();
     _pieceHealthCanvas.renderMode  = RenderMode.WorldSpace;
     _pieceHealthCanvas.worldCamera = _crosshairCamera;
 }
Пример #7
0
        private GameObject createEnemyHudCanvas()
        {
            GameObject hudCanvasRoot = new GameObject(System.Guid.NewGuid().ToString());

            GameObject.DontDestroyOnLoad(hudCanvasRoot);
            hudCanvasRoot.layer = LayerUtils.getWorldspaceUiLayer();
            Canvas hudCanvas = hudCanvasRoot.AddComponent <Canvas>();

            hudCanvas.renderMode = RenderMode.WorldSpace;
            ensureHudCamera();
            hudCanvas.worldCamera = _hudCamera;
            hudCanvas.GetComponent <RectTransform>().SetParent(hudCanvasRoot.transform, false);
            return(hudCanvasRoot);
        }
Пример #8
0
        private void enableVrCamera()
        {
            if (_instance == null)
            {
                LogError("Cannot enable VR Camera with null SteamVR Player instance.");
                return;
            }
            Camera mainCamera = CameraUtils.getCamera(CameraUtils.MAIN_CAMERA);

            if (mainCamera == null)
            {
                LogError("Main Camera is null.");
                return;
            }
            Camera vrCam = CameraUtils.getCamera(CameraUtils.VR_CAMERA);

            CameraUtils.copyCamera(mainCamera, vrCam);
            maybeCopyPostProcessingEffects(vrCam, mainCamera);
            maybeAddAmplifyOcclusion(vrCam);
            // Prevent visibility of the head
            vrCam.nearClipPlane = VHVRConfig.GetNearClipPlane();
            // Turn off rendering the UI panel layer. We need to capture
            // it in a camera of higher depth so that it
            // is rendered on top of everything else. (except hands)
            vrCam.cullingMask &= ~(1 << LayerUtils.getUiPanelLayer());
            vrCam.cullingMask &= ~(1 << LayerMask.NameToLayer("UI"));
            vrCam.cullingMask &= ~(1 << LayerUtils.getHandsLayer());
            vrCam.cullingMask &= ~(1 << LayerUtils.getWorldspaceUiLayer());
            mainCamera.enabled = false;
            AudioListener mainCamListener = mainCamera.GetComponent <AudioListener>();

            if (mainCamListener != null)
            {
                LogDebug("Destroying MainCamera AudioListener");
                DestroyImmediate(mainCamListener);
            }
            //Add fade component to camera for transition handling
            _fadeManager = vrCam.gameObject.AddComponent <FadeToBlackManager>();
            _instance.SetActive(true);
            vrCam.enabled = true;
            _vrCam        = vrCam;
            _vrCameraRig  = vrCam.transform.parent;

            _fadeManager.OnFadeToWorld += () => {
                //Recenter
                VRPlayer.headPositionInitialized = false;
                VRPlayer.vrPlayerInstance?.ResetRoomscaleCamera();
            };
        }
Пример #9
0
        private static int getCrosshairRaycastLayerMask()
        {
            int mask = Physics.DefaultRaycastLayers;

            // Ignore these layers
            mask &= ~(1 << 14); // character_trigger
            mask &= ~(1 << 21); // WaterVolume
            mask &= ~(1 << 4);  // Water
            mask &= ~(1 << 25); // viewblock
            mask &= ~(1 << 31); // smoke
            mask &= ~(1 << 5);  // UI
            mask &= ~(1 << 24); // pathblocker
            mask &= ~(1 << LayerUtils.getUiPanelLayer());
            mask &= ~(1 << LayerUtils.getHandsLayer());
            mask &= ~(1 << LayerUtils.getWorldspaceUiLayer());
            return(mask);
        }
Пример #10
0
 private bool ensureCrosshairCanvas()
 {
     if (_crosshairCanvas != null)
     {
         return(true);
     }
     ensureCrosshairCamera();
     _crosshairCanvasParent       = new GameObject("CrosshairCanvasGameObject");
     _crosshairCanvasParent.layer = LayerUtils.getWorldspaceUiLayer();
     GameObject.DontDestroyOnLoad(_crosshairCanvasParent);
     _crosshairCanvas             = _crosshairCanvasParent.AddComponent <Canvas>();
     _crosshairCanvas.renderMode  = RenderMode.WorldSpace;
     _crosshairCanvas.worldCamera = _crosshairCamera;
     _crosshairCanvas.GetComponent <RectTransform>().SetParent(_crosshairCanvasParent.transform, false);
     _crosshairCamera.orthographicSize = _crosshairCanvas.GetComponent <RectTransform>().rect.height * 0.5f;
     LogDebug("Created Crosshair Canvas");
     return(true);
 }
Пример #11
0
        private void maybeCreateHoverNameObjects()
        {
            if ((_hoverNameCanvasParent != null && _hoverNameCanvas != null && _hoverNameCanvasParentLeft != null && _hoverNameCanvasLeft != null) || !ensureCrosshairCamera())
            {
                return;
            }
            _hoverNameCanvasParent = new GameObject("HoverNameCanvasParent");
            GameObject.DontDestroyOnLoad(_hoverNameCanvasParent);
            _hoverNameCanvasParent.layer = LayerUtils.getWorldspaceUiLayer();
            _hoverNameCanvas             = _hoverNameCanvasParent.AddComponent <Canvas>();
            _hoverNameCanvas.renderMode  = RenderMode.WorldSpace;
            _hoverNameCanvas.worldCamera = _crosshairCamera;

            // Left hand
            _hoverNameCanvasParentLeft = new GameObject("HoverNameCanvasParentLeft");
            GameObject.DontDestroyOnLoad(_hoverNameCanvasParentLeft);
            _hoverNameCanvasParentLeft.layer = LayerUtils.getWorldspaceUiLayer();
            _hoverNameCanvasLeft             = _hoverNameCanvasParentLeft.AddComponent <Canvas>();
            _hoverNameCanvasLeft.renderMode  = RenderMode.WorldSpace;
            _hoverNameCanvasLeft.worldCamera = _crosshairCamera;
            hoverNameCloneLeftHand           = GameObject.Instantiate(_hoverNameClone);
            crosshairCloneLeftHand           = GameObject.Instantiate(_crosshairClone);
        }