public void AddText(BillboardText billboard)
    {
        if (billboard.UIText == null)
        {
            return;
        }

        mInvalidated = false;
        mText.Add(billboard);

        TextDirection dir = billboard.Rect.GetComponent <TextDirection>();

        if (dir != null)
        {
            dir.SetTextController(this);
        }

        GameObject    obj = ChartCommon.CreateCanvasChartItem();
        RectTransform t   = obj.GetComponent <RectTransform>();

        obj.AddComponent <Canvas>();
        obj.transform.SetParent(transform, false);

        billboard.parent = t;
        billboard.Rect.SetParent(t, false);
        if (mParent != null)
        {
            obj.layer = mParent.gameObject.layer;
            billboard.Rect.gameObject.layer = mParent.gameObject.layer;
        }

        billboard.Rect.localRotation = Quaternion.identity;
        billboard.Rect.localPosition = Vector3.zero;
        billboard.Rect.localScale    = new Vector3(1f, 1f, 1f);

        //Vector3 scale = new Vector3(1f/transform.lossyScale.x, 1f/transform.lossyScale.y, 1f/transform.lossyScale.z);//SafeCanvas.transform.localScale;
        //Vector3 scale = SafeCanvas.transform.localScale;

        //if (mUnderCanvas)
        //  billboard.UIText.transform.localScale = scale;
        //else

        billboard.UIText.transform.localScale = new Vector3(billboard.Scale, billboard.Scale, 1f);

        //        ContentSizeFitter fitter = billboard.UIText.gameObject.GetComponent<ContentSizeFitter>();
        //        if(fitter == null)
        //            fitter = billboard.UIText.gameObject.AddComponent<ContentSizeFitter>();
        //        fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
        //        fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;

        RectTransform rect = billboard.Rect;

        //    rect.anchoredPosition3D = new Vector3();
        if (dir == null)
        {
            rect.anchorMin = Vector2.zero;
            rect.anchorMax = Vector2.zero;
        }
        billboard.parent.position = billboard.transform.position;
    }
예제 #2
0
    public void AddText(BillboardText billboard)
    {
        if (billboard == null)
        {
            return;
        }
        if (billboard.UIText == null)
        {
            return;
        }

        mInvalidated = false;
        mText.Add(billboard);
        var rect = billboard.Rect;

        EnsureCanvas();
        float yScale = (billboard.YMirror == true) ? -1f : 1f;

        if (rect == null)
        {
            var           meshObj = billboard.UIText;
            TextDirection dir     = meshObj.GetComponent <TextDirection>();
            if (dir != null)
            {
                dir.SetTextController(this);
            }

            billboard.parent = null;
            meshObj.transform.SetParent(transform, false);
            if (mParent != null)
            {
                meshObj.layer = mParent.gameObject.layer;
            }

            //  meshObj.transform.localRotation = Quaternion.identity;
            meshObj.transform.position = billboard.transform.position;
            //  meshObj.transform.localScale = new Vector3(1f, 1f, 1f);

            meshObj.transform.localScale = new Vector3(billboard.Scale * mInnerScale, yScale * billboard.Scale * mInnerScale, 1f);
        }
        else
        {
            TextDirection dir = rect.GetComponent <TextDirection>();
            if (dir != null)
            {
                dir.SetTextController(this);
            }

            GameObject    obj = ChartCommon.CreateCanvasChartItem();
            RectTransform t   = obj.GetComponent <RectTransform>();
            obj.AddComponent <Canvas>();
            var addUnder = mAddCanvasUnder;
            if (addUnder == null)
            {
                addUnder = gameObject;
            }

            obj.transform.SetParent(addUnder.transform, false);
            obj.transform.localPosition = Vector3.zero;
            //  obj.transform.localRotation = Quaternion.identity;
            obj.transform.localScale = new Vector3(1f, 1f, 1f);

            billboard.parent = t;
            billboard.Rect.SetParent(t, false);
            if (mParent != null)
            {
                obj.layer = mParent.gameObject.layer;
                billboard.Rect.gameObject.layer = mParent.gameObject.layer;
            }
            //  billboard.Rect.localRotation = Quaternion.identity;
            billboard.Rect.localPosition = Vector3.zero;
            billboard.Rect.localScale    = new Vector3(1f, 1f, 1f);

            //    rect.anchoredPosition3D = new Vector3();
            if (dir == null)
            {
                rect.anchorMin = Vector2.zero;
                rect.anchorMax = Vector2.zero;
            }

            billboard.parent.position = billboard.transform.position;

            billboard.UIText.transform.localScale = new Vector3(billboard.Scale * mInnerScale, yScale * billboard.Scale * mInnerScale, 1f);
        }



        //Vector3 scale = new Vector3(1f/transform.lossyScale.x, 1f/transform.lossyScale.y, 1f/transform.lossyScale.z);//SafeCanvas.transform.localScale;
        //Vector3 scale = SafeCanvas.transform.localScale;

        //if (mUnderCanvas)
        //  billboard.UIText.transform.localScale = scale;
        //else



        //        ContentSizeFitter fitter = billboard.UIText.gameObject.GetComponent<ContentSizeFitter>();
        //        if(fitter == null)
        //            fitter = billboard.UIText.gameObject.AddComponent<ContentSizeFitter>();
        //        fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
        //        fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
    }