//----- property -----

        //----- method -----

        public void Initialize()
        {
            if (initialized)
            {
                return;
            }

            rawImage = UnityUtility.GetComponent <RawImage>(gameObject);

            rectTransform = rawImage.rectTransform;

            // レンダーテクスチャ描画用カメラ以外のカメラから検索.
            currenCamera = UnityUtility.FindCameraForLayer(1 << gameObject.layer)
                           .FirstOrDefault(x => UnityUtility.GetComponent <RenderTarget>(x.gameObject) == null);

            // RawImageのワールド座標サイズ.
            var corners = new Vector3[4];

            rectTransform.GetWorldCorners(corners);

            // レンダーテクスチャのサイズを計算.
            var bl = currenCamera.WorldToScreenPoint(corners[0]);
            var tr = currenCamera.WorldToScreenPoint(corners[2]);

            var width  = tr.x - bl.x;
            var height = tr.y - bl.y;

            // レンダーテクスチャ生成.
            rawImage.texture = renderTarget.CreateRenderTexture((int)width, (int)height);

            initialized = true;
        }
示例#2
0
        // Canvasにカメラを適用.
        protected virtual void ModifyCanvasCamera()
        {
            var canvas = Canvas;

            if (!modifyCanvasCamera)
            {
                return;
            }

            var layerMask = 1 << canvas.gameObject.layer;

            // 最初に一致したカメラを適用.
            canvasCamera = UnityUtility.FindCameraForLayer(layerMask).FirstOrDefault();

            if (canvasCamera != null)
            {
                canvas.worldCamera = canvasCamera;
                canvas.renderMode  = RenderMode.ScreenSpaceCamera;
            }

            // この関数でカメラを設定した際にNearClipとFarClipの範囲外の場合は警告を出す.
            if (canvas.worldCamera != null)
            {
                var planeDistance = canvas.planeDistance;

                if (planeDistance < canvas.worldCamera.nearClipPlane || canvas.worldCamera.farClipPlane < planeDistance)
                {
                    Debug.LogWarning("Out of Range Canvas PanelDistance.");
                }
            }
        }
示例#3
0
        private PopupParent CreatePopupParent(string instanceName, GameObject parent, int layer, int canvasOrder)
        {
            var popupParent = UnityUtility.Instantiate <PopupParent>(parent, parentPrefab);

            popupParent.transform.name      = instanceName;
            popupParent.Canvas.sortingOrder = canvasOrder;

            UnityUtility.SetLayer(layer, popupParent.gameObject, true);

            popupParent.Canvas.worldCamera = UnityUtility.FindCameraForLayer(1 << layer).FirstOrDefault();

            return(popupParent);
        }
示例#4
0
        /// <summary>
        /// WebViewの表示範囲設定.
        /// </summary>
        private UniWebViewEdgeInsets GetDrawArea(Vector2 buffer)
        {
            var rectTransform = UnityUtility.GetComponent <RectTransform>(gameObject);

            // 描画カメラ検索.
            var camera = UnityUtility.FindCameraForLayer(gameObject.layer).FirstOrDefault();

            if (camera != null)
            {
                // webView表示する四隅のワールド座標を取得.
                var rectCorner = new Vector3[4];
                rectTransform.GetWorldCorners(rectCorner);

                // 四隅のワールド座標をスクリーン座標に変換.
                var screenToCorner = rectCorner.Select(vec => camera.WorldToScreenPoint(vec)).ToList();

                var top    = (Screen.height - screenToCorner.Max(vec => vec.y) + buffer.y + rectTransform.position.y);
                var bottom = (screenToCorner.Min(vec => vec.y) + buffer.y + rectTransform.position.y);
                var left   = (screenToCorner.Min(vec => vec.x) + buffer.x + rectTransform.position.x);
                var right  = (Screen.width - screenToCorner.Max(vec => vec.x) + buffer.x + rectTransform.position.x);


                #if UNITY_IOS && !UNITY_EDITOR
                // 単位ポイントあたりのスクリーンサイズを取得.
                var hightPerPoint = (float)Screen.height / (float)UniWebViewHelper.screenHeight;
                var widthPerPoint = (float)Screen.width / (float)UniWebViewHelper.screenWidth;

                // ポイントに変換.
                top    = top / hightPerPoint;
                bottom = bottom / hightPerPoint;
                left   = left / widthPerPoint;
                right  = right / widthPerPoint;
                #endif

                return(new UniWebViewEdgeInsets((int)top, (int)left, (int)bottom, (int)right));
            }

            Debug.LogError("WebView camera not found.");

            return(null);
        }
示例#5
0
        //----- method -----

        public virtual void Initialize()
        {
            if (isInitialized)
            {
                return;
            }

            renderCamera = UnityUtility.FindCameraForLayer(TargetLayerMask).FirstOrDefault();

            if (touchEffectPrefab != null)
            {
                cachedTouchEffects = new Queue <ParticlePlayer>();
                touchEffectRoot    = UnityUtility.CreateEmptyGameObject(rootObject, "Cache (Touch)", true);
            }

            if (dragEffectPrefab != null)
            {
                cachedDragEffects = new Queue <ParticlePlayer>();
                dragEffectRoot    = UnityUtility.CreateEmptyGameObject(rootObject, "Cache (Drag)", true);
            }

            isInitialized = true;
        }