/* internal static BillboardText CreateBillboardText(Text prefab, Transform parentTransform, string text, float x, float y, float z, float angle, bool hideHirarechy, int fontSize, float sharpness)
         * {
         *   return CreateBillboardText(prefab, parentTransform, text, x, y, z, angle, null, hideHirarechy, fontSize, sharpness);
         * }*/

        internal static BillboardText UpdateBillboardText(BillboardText billboardText, Transform parentTransform, string text, float x, float y, float z, float angle, Transform relativeFrom, bool hideHirarechy, bool yMirror)
        {
            GameObject UIText    = billboardText.UIText.gameObject;
            GameObject billboard = billboardText.gameObject;

            ChartCommon.HideObject(billboard, hideHirarechy);
            TextDirection direction = UIText.GetComponent <TextDirection>();
            GameObject    TextObj   = billboardText.UIText;

            billboardText.YMirror = yMirror;
            if (direction != null)
            {
                TextObj = direction.Text.gameObject;
                if (relativeFrom != null)
                {
                    direction.SetRelativeTo(relativeFrom, billboard.transform);
                }
                //  else
                direction.SetDirection(angle);
            }
            // if (parentTransform != null && billboard.transform.parent != parentTransform)
            // {
            //    billboard.transform.SetParent(parentTransform, false);
            // }
            UpdateTextParams(TextObj, text);
            billboard.transform.localPosition = new Vector3(x, y, z);
            return(billboardText);
        }
        internal static BillboardText CreateBillboardText(BillboardText item, MonoBehaviour prefab, Transform parentTransform, string text, float x, float y, float z, float angle, Transform relativeFrom, bool hideHirarechy, int fontSize, float sharpness)
        {
            if (item != null)
            {
                return(UpdateBillboardText(item, parentTransform, text, x, y, z, angle, relativeFrom, hideHirarechy, prefab != null && prefab.transform.localScale.y < 0));
            }
            if (prefab == null || prefab.gameObject == null)
            {
                GameObject g = Resources.Load("Chart And Graph/DefaultText") as GameObject;
                prefab = g.GetComponent <Text>();
            }

            GameObject UIText    = (GameObject)GameObject.Instantiate(prefab.gameObject);
            GameObject billboard = new GameObject();

            ChartCommon.HideObject(billboard, hideHirarechy);
            if (parentTransform.GetComponent <RectTransform>())
            {
                billboard.AddComponent <RectTransform>();
            }

            if (parentTransform != null)
            {
                billboard.transform.SetParent(parentTransform, false);
                UIText.transform.SetParent(parentTransform, false);
            }

            BillboardText billboardText = billboard.AddComponent <BillboardText>();

            billboard.AddComponent <ChartItem>();
            TextDirection direction = UIText.GetComponent <TextDirection>();

            GameObject obj = null;

            if (direction != null)
            {
                obj = direction.Text.gameObject;
                if (relativeFrom != null)
                {
                    direction.SetRelativeTo(relativeFrom, billboard.transform);
                }
                //  else
                direction.SetDirection(angle);
            }

            if (obj == null)
            {
                obj = UIText;
            }
            sharpness = Mathf.Clamp(sharpness, 1f, 3f);
            bool setParams = SetTextParams(obj, text, fontSize, sharpness);

            if (billboardText == null || setParams == false)
            {
                SafeDestroy(UIText);
                SafeDestroy(billboard);
                return(null);
            }


            if (prefab != null && prefab.transform.localScale.y < 0)
            {
                billboardText.YMirror = true;
            }
            billboardText.Scale     = (1f / sharpness);
            billboardText.UIText    = obj;
            billboardText.Direction = direction;
            if (direction != null)
            {
                billboardText.RectTransformOverride = direction.GetComponent <RectTransform>();
            }
            else
            {
                billboardText.RectTransformOverride = null;
            }
            billboard.transform.localPosition = new Vector3(x, y, z);
            return(billboardText);
        }
        internal static BillboardText CreateBillboardText(BillboardText item, Text prefab, Transform parentTransform, string text, float x, float y, float z, float angle, Transform relativeFrom, bool hideHirarechy, int fontSize, float sharpness)
        {
            if (item != null)
            {
                return(UpdateBillboardText(item, parentTransform, text, x, y, z, angle, relativeFrom, hideHirarechy));
            }
            if (prefab == null || prefab.gameObject == null)
            {
                GameObject g = Resources.Load("Chart And Graph/DefaultText") as GameObject;
                prefab = g.GetComponent <Text>();
            }

            GameObject UIText    = (GameObject)GameObject.Instantiate(prefab.gameObject);
            GameObject billboard = new GameObject();

            ChartCommon.HideObject(billboard, hideHirarechy);

            if (parentTransform != null)
            {
                billboard.transform.SetParent(parentTransform, false);
                UIText.transform.SetParent(parentTransform, false);
            }

            BillboardText billboardText = billboard.AddComponent <BillboardText>();

            billboard.AddComponent <ChartItem>();
            TextDirection direction = UIText.GetComponent <TextDirection>();
            Text          TextObj   = UIText.GetComponent <Text>();

            if (direction != null)
            {
                TextObj = direction.Text;
                if (relativeFrom != null)
                {
                    direction.SetRelativeTo(relativeFrom, billboard.transform);
                }
                else
                {
                    direction.SetDirection(angle);
                }
            }

            if (billboardText == null || TextObj == null)
            {
                SafeDestroy(UIText);
                SafeDestroy(billboard);
                return(null);
            }

            sharpness                    = Mathf.Clamp(sharpness, 1f, 3f);
            TextObj.fontSize             = (int)(fontSize * sharpness);
            TextObj.horizontalOverflow   = HorizontalWrapMode.Overflow;
            TextObj.verticalOverflow     = VerticalWrapMode.Overflow;
            TextObj.resizeTextForBestFit = false;
            billboardText.Scale          = 1f / sharpness;

            TextObj.text            = text;
            billboardText.UIText    = TextObj;
            billboardText.Direction = direction;
            if (direction != null)
            {
                billboardText.RectTransformOverride = direction.GetComponent <RectTransform>();
            }
            else
            {
                billboardText.RectTransformOverride = null;
            }
            billboard.transform.localPosition = new Vector3(x, y, z);
            return(billboardText);
        }