예제 #1
0
        /// <summary>
        /// 分别返回Unity屏幕概念下UGUI的4个点,左下角,左上角,右上角,右下角
        /// </summary>
        /// <param name="gameObject"></param>
        /// <returns></returns>
        public static Vector2[] GetWorldCorner(GameObject gameObject)
        {
            //Logger.d("GetWorldCorner");
            if (!isUGUIElement(gameObject))
            {
                return(null);
            }

            Canvas canvas = gameObject.GetComponentInParent <Canvas>();

            if (canvas == null || canvas.renderMode == null)
            {
                return(null);
            }

            GameObject o = canvas.gameObject;

            Logger.d("Canvas name " + o.name);
            RenderMode mode = canvas.renderMode;

            Camera c = null;

            //Screen Space Overlay模式非常特别,没有对应的摄像机
            if (mode.Equals(RenderMode.ScreenSpaceOverlay))
            {
                Logger.d("ScreenSpaceOverlay");
                c = null;
            }
            else if (mode.Equals(RenderMode.ScreenSpaceCamera))
            {
                Logger.d("ScreenSpaceCamera");
                c = canvas.worldCamera;
            }
            else if (mode.Equals(RenderMode.WorldSpace))
            {
                Logger.d("WorldSpace");
                c = UIBase.FindBestCamera(gameObject);
            }
            else
            {
                return(null);
            }

            RectTransform rectTran = gameObject.GetComponent <RectTransform>();

            Vector3[] core = new Vector3[4];
            rectTran.GetWorldCorners(core);
            Vector2[] vectors = new Vector2[4];
            vectors[0] = RectTransformUtility.WorldToScreenPoint(c, core[0]);
            vectors[1] = RectTransformUtility.WorldToScreenPoint(c, core[1]);
            vectors[2] = RectTransformUtility.WorldToScreenPoint(c, core[2]);
            vectors[3] = RectTransformUtility.WorldToScreenPoint(c, core[3]);

            return(vectors);
        }
예제 #2
0
 protected override void RenderEndTag(HtmlTextWriter writer)
 {
     base.RenderEndTag(writer);
     if (RenderMode.Equals(Mode.SWFObject))
     {
         writer.Write(BuildSwfObjectScript());
     }
 }
 public override void Draw(Graphics g, RenderMode rm)
 {
     g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
     Rectangle rect = GuiRectangle.GetGuiRectangle(this.Left, this.Top, this.Width, this.Height);
     if (Selected && rm.Equals(RenderMode.EDIT)) DrawSelectionBorder(g, rect);
     Brush fontBrush = new SolidBrush(foreColor);
     g.DrawString(childLabel.Text, childLabel.Font, fontBrush, rect);
 }
        public override void Draw(Graphics g, RenderMode rm)
        {
            Rectangle rect = GuiRectangle.GetGuiRectangle(this.Left, this.Top, this.Width, this.Height);

            if (Selected && rm.Equals(RenderMode.EDIT))
            {
                DrawSelectionBorder(g, rect);
            }
            Brush fontBrush = new SolidBrush(foreColor);

            g.DrawString(childLabel.Text, childLabel.Font, fontBrush, rect);
        }
예제 #5
0
 protected override void RenderChildren(HtmlTextWriter writer)
 {
     if (RenderMode.Equals(Mode.SWFObject2))
     {
         writer.Write(BuildSWFFixBeginTag());
         base.RenderChildren(writer);
         writer.Write(SwffixEndTag);
     }
     else if (RenderMode.Equals(Mode.SWFObject2Embedded))
     {
         writer.Write("<div id=\"" + ClientID + "_inner\">");
         base.RenderChildren(writer);
         writer.Write("</div>");
     }
     else
     {
         base.RenderChildren(writer);
     }
 }
예제 #6
0
        static GameObject CreateUICanvas(RectTransform parentTransform,
                                         string name, int order, RenderMode renderMode, Camera uiCamera)
        {
            var canvas = new GameObject(name);

            // 设置组件
            canvas.AddComponent <Canvas>().renderMode = renderMode;
            canvas.AddComponent <CanvasScaler>();
            canvas.AddComponent <GraphicRaycaster>();

            // 渲染相机
            if (renderMode.Equals(RenderMode.ScreenSpaceCamera))
            {
                canvas.GetComponent <Canvas>().worldCamera = uiCamera;
            }

            // 设置渲染顺序
            canvas.GetComponent <Canvas>().sortingOrder = order;

            // 设置父子关系
            canvas.GetComponent <RectTransform>().SetParent(parentTransform);

            return(canvas);
        }