Esempio n. 1
0
        public static Vector3 Raycast(Vector3 oragin, Vector3 dir, string layerName, out bool isHit)
        {
            Ray        ray = new Ray(dir, oragin);
            RaycastHit hit;

            isHit = Physics.Raycast(ray, out hit, 10000, 1 << LayerName.GetIndexOfLayerName(layerName));
            if (isHit)
            {
                return(hit.point);
            }
            return(oragin);
        }
Esempio n. 2
0
        public static Vector3 Raycast(Transform trans, Vector3 dir, string layerName, out bool isHit)
        {
            Ray        ray = new Ray(dir, trans.position);
            RaycastHit hit;

            isHit = Physics.Raycast(ray, out hit, 10000, 1 << LayerName.GetIndexOfLayerName(layerName));
            if (isHit)
            {
                return(hit.point);
            }
            return(trans.position);
        }
Esempio n. 3
0
        public static Camera CreateCamera(string name, int depth, Transform parent)
        {
            GameObject go  = new GameObject(name);
            Camera     cam = go.AddComponent <Camera>();

            cam.name             = name;
            cam.clearFlags       = CameraClearFlags.Depth;
            cam.cullingMask      = 1 << LayerName.GetIndexOfLayerName(LayerName.UI);
            cam.orthographic     = true;
            cam.orthographicSize = 3.75f;
            cam.nearClipPlane    = -1;
            cam.farClipPlane     = 1;
            cam.depth            = depth;
            cam.transform.parent = parent;
            return(cam);
        }
Esempio n. 4
0
        /// <summary>
        /// 初始化
        /// </summary>
        public static void Init()
        {
            GameObject   go     = GameObject.FindWithTag(TagName.UICamera);
            Canvas       canvas = null;
            CanvasScaler scaler = null;

            if (go == null)
            {
                go                    = UITool.CreateCanvas("UIRoot");
                go.tag                = TagName.UICamera;
                canvas                = go.GetComponent <Canvas>();
                scaler                = go.GetComponent <CanvasScaler>();
                canvas.renderMode     = RenderMode.ScreenSpaceCamera;
                canvas.pixelPerfect   = false;
                canvas.planeDistance  = 0;
                canvas.sortingLayerID = 1 << LayerName.GetIndexOfLayerName(LayerName.Default);
                UICamera              = CreateCamera("UICamera", 1, go.transform);
                UIFXCamera            = CreateCamera("UIFXCamera", 2, go.transform);
                GameObject ui = new GameObject();
                ui.name             = "UI";
                ui.transform.parent = go.transform;
                UITrans             = ui.transform;
                GameObject fx = new GameObject();
                fx.name             = "FX";
                fx.transform.parent = go.transform;
                FXTrans             = fx.transform;
            }
            else
            {
                UICamera   = ComTool.Find <Camera>(go, "UICamera");
                UIFXCamera = ComTool.Find <Camera>(go, "UIFXCamera");
                UITrans    = TransTool.Find(go.transform, "UI");
                FXTrans    = TransTool.Find(go.transform, "FX");
            }
            if (go != null)
            {
                GameObject.DontDestroyOnLoad(go.transform);
                UIRoot = go;
            }

            /**
             * if (go == null)
             * {
             *  go = UITool.CreateCanvas("UIRoot");
             *  go.tag = TagName.UICamera;
             *  canvas = go.GetComponent<Canvas>();
             *  scaler = go.GetComponent<CanvasScaler>();
             *  canvas.renderMode = RenderMode.ScreenSpaceOverlay;
             *  canvas.pixelPerfect = false;
             *  canvas.sortingOrder = 0;
             *  scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
             *  scaler.referenceResolution = new Vector2(GameSetting.ScreenW, GameSetting.ScreenH);
             *  scaler.screenMatchMode = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight;
             *  scaler.matchWidthOrHeight = 1;
             * }
             *
             * Transform UILayerTrans = TransTool.Find(go.transform, "UILayer");
             * if (UILayerTrans == null) UILayer = UITool.CreateCanvas("UILayer", UIRoot.transform);
             * else UILayer = UILayerTrans.gameObject;
             * Transform TipLayerTrans = TransTool.Find(go.transform, "TipLayer");
             * if (TipLayerTrans == null) TipLayer = UITool.CreateCanvas("TipLayer", UIRoot.transform);
             * else TipLayer = UILayerTrans.gameObject;
             */
        }