Exemplo n.º 1
0
        //初期化
        public void Init(AdvGraphicManager manager, AdvLayerSettingData settingData)
        {
            this.Manager     = manager;
            this.SettingData = settingData;

            //UI用のコード
            this.Canvas = this.GetComponent <Canvas>();
#if UNITY_5_6_OR_NEWER
            this.Canvas.additionalShaderChannels = AdditionalCanvasShaderChannels.TexCoord1 | AdditionalCanvasShaderChannels.Normal | AdditionalCanvasShaderChannels.Tangent;
#endif

            if (!string.IsNullOrEmpty(SettingData.LayerMask))
            {
#if UNITY_EDITOR
                if (!LayerMaskEditor.ContainsInLayerNames(SettingData.LayerMask))
                {
                    Debug.LogWarning("Please add Layer name [ " + SettingData.LayerMask + " ]");
                    this.Canvas.gameObject.layer = 8;
                }
                else
                {
                    this.Canvas.gameObject.layer = LayerMask.NameToLayer(SettingData.LayerMask);
                }
#else
                this.Canvas.gameObject.layer = LayerMask.NameToLayer(SettingData.LayerMask);
#endif
            }
            this.Canvas.sortingOrder = SettingData.Order;

            //入力受け付ける可能性があるので、イベントカメラとRaycasterを設定
            this.Camera = Engine.CameraManager.FindCameraByLayer(this.Canvas.gameObject.layer);
            if (Camera == null)
            {
                Debug.LogError("Cant find camera");
                this.Camera = Engine.CameraManager.FindCameraByLayer(0);
            }
            this.LetterBoxCamera    = Camera.gameObject.GetComponent <LetterBoxCamera> ();
            this.Canvas.worldCamera = Camera;
            GraphicRaycaster raycaster = this.Canvas.gameObject.AddComponent <GraphicRaycaster>();
            raycaster.enabled = false;

            this.rootObjects = this.Canvas.transform;
            ResetCanvasRectTransform();
            //ToDo
            //キャンバスのアニメーションの最中でリセットされると破綻するが・・・
            if (Manager.DebugAutoResetCanvasPosition)
            {
                this.LetterBoxCamera.OnGameScreenSizeChange.AddListener(x => ResetCanvasRectTransform());
            }
        }
        void ChangeCameraMaskInScene()
        {
            //すでにカメラがある場合は、宴関係のレイヤー設定を無効化する
            Camera[] cameras = UtageEditorToolKit.FindComponentsAllInTheScene <Camera>();

            List <string> changeLayers = new List <string>();

            if (OldLayerName != layerName)
            {
                changeLayers.Add(layerName);
                LayerMaskEditor.TryAddLayerName(layerName);
            }
            if (OldLayerNameUI != layerNameUI)
            {
                changeLayers.Add(layerNameUI);
                LayerMaskEditor.TryAddLayerName(layerNameUI);
            }
            int mask = LayerMask.GetMask(changeLayers.ToArray());

            foreach (Camera camera in cameras)
            {
                camera.cullingMask = camera.cullingMask & ~mask;
            }
        }