Esempio n. 1
0
        private static void CreateTouchManager()
        {
            TCKInput.CheckUIEventSystem();

            if (tckUIobj == null)
            {
                TCKInput tckInputObj = Object.FindObjectOfType <TCKInput>();
                tckUIobj = (tckInputObj != null) ? tckInputObj.gameObject : null;
            }

            if (tckUIobj != null)
            {
                UpdateSpritesPath <TCKInput>(tckUIobj);
                return;
            }

            tckUIobj       = new GameObject(k_MainGOName, typeof(Canvas), typeof(GraphicRaycaster), typeof(CanvasScaler), typeof(TCKInput));
            tckUIobj.layer = LayerMask.NameToLayer("UI");

            Transform camTransform = new GameObject("tckUICamera", typeof(GuiCamera)).transform;

            camTransform.parent        = tckUIobj.transform;
            camTransform.localPosition = Vector3.zero;

            UpdateSpritesPath <GuiCamera>(camTransform.gameObject);

            float maxCameraDepth = -1f;

            Array.ForEach(Object.FindObjectsOfType <Camera>(), cam => maxCameraDepth = Mathf.Max(cam.depth, maxCameraDepth));

            Camera camera = camTransform.GetComponent <Camera>();

            camera.useOcclusionCulling = false;
            camera.orthographic        = true;
            camera.allowMSAA           = false;
            camera.allowHDR            = false;
            camera.cullingMask         = 32;
            camera.depth            = ++maxCameraDepth;
            camera.orthographicSize = 100f;
            camera.nearClipPlane    = -.25f;
            camera.farClipPlane     = .25f;
            camera.renderingPath    = RenderingPath.Forward;
            camera.clearFlags       = CameraClearFlags.Depth;

            Canvas canvas = tckUIobj.GetComponent <Canvas>();

            canvas.renderMode   = RenderMode.ScreenSpaceCamera;
            canvas.worldCamera  = camera;
            canvas.pixelPerfect = true;

            CanvasScaler canvasScaler = tckUIobj.GetComponent <CanvasScaler>();

            canvasScaler.uiScaleMode         = CanvasScaler.ScaleMode.ScaleWithScreenSize;
            canvasScaler.screenMatchMode     = CanvasScaler.ScreenMatchMode.Expand;
            canvasScaler.referenceResolution = new Vector2(1920, 1080);

            MarkActiveSceneDirty();
        }