コード例 #1
0
        /// <summary>
        /// fix the bar labels after the source has changed
        /// </summary>
        /// <param name="bar"></param>
        private void FixBarLabels(BarObject bar)
        {
            if (bar.ItemLabel && mItemLabels != null)
            {
                string text = mItemLabels.TextFormat.Format(ChartAdancedSettings.Instance.FormatFractionDigits(mItemLabels.FractionDigits, bar.Value), bar.Category, bar.Group);
                ChartCommon.UpdateTextParams(bar.ItemLabel.UIText, text);

                Vector3 newPos = AlignLabel(mItemLabels, bar.InnerPosition, bar.Size);
                bar.ItemLabel.transform.localPosition = newPos;
            }
            if (bar.GroupLabel && mGroupLabels != null)
            {
                if (mGroupLabels.Alignment == GroupLabelAlignment.BarTop || mGroupLabels.Alignment == GroupLabelAlignment.BarBottom || mGroupLabels.Alignment == GroupLabelAlignment.FirstBar)
                {
                    Vector3 newPos = AlignLabel(mGroupLabels, bar.InnerPosition, bar.Size);
                    bar.GroupLabel.transform.localPosition = newPos;
                }
                else
                {
                    bar.GroupLabel.gameObject.SetActive(false);
                }
            }
            if (bar.CategoryLabel && mCategoryLabels != null)
            {
                Vector3 newPos = AlignLabel(mCategoryLabels, bar.InnerPosition, bar.Size);
                bar.CategoryLabel.transform.localPosition = newPos;
            }
        }
コード例 #2
0
        private Vector3 GetTopPosition(BarObject barObj)
        {
            Vector3 local = new Vector3(
                0f,
                barObj.Size,
                0f);

            return(barObj.TopObject.transform.TransformPoint(local));
        }
コード例 #3
0
        private BarEventArgs UserDataToEventArgs(object userData)
        {
            BarObject barObj = userData as BarObject;

            if (barObj == null)
            {
                return(null);
            }
            return(BarObjToEventArgs(barObj));
        }
コード例 #4
0
 private BarEventArgs BarObjToEventArgs(BarObject barObj)
 {
     return(new BarEventArgs(GetTopPosition(barObj), barObj.Value, barObj.Category, barObj.Group));
 }
コード例 #5
0
        /// <summary>
        /// Creates a single bar game object using the chart parameters and the bar prefab
        /// </summary>
        /// <param name="innerPosition">the local position of the bar in the chart</param>
        /// <returns>the new bar game object</returns>
        private GameObject CreateBar(Vector3 innerPosition, double value, float size, float elevation, float normalizedSize, string category, string group, int index, int categoryIndex)
        {
            if (BarPrefabLink == null)
            {
                GameObject dummy = new GameObject();
                dummy.AddComponent <ChartItem>();
                dummy.transform.parent = transform;
                return(dummy);
            }

            GameObject topLevel = new GameObject();

            topLevel.AddComponent <ChartItem>();
            topLevel.layer = gameObject.layer;
            topLevel.transform.SetParent(transform, false);
            topLevel.transform.localScale    = new Vector3(1f, 1f, 1f);
            topLevel.transform.localPosition = innerPosition;
            GameObject obj = (GameObject)GameObject.Instantiate(BarPrefabLink);

            Vector3 initialScale = obj.transform.localScale;

            obj.transform.SetParent(topLevel.transform, false);
            obj.transform.localScale = new Vector3(1f, 1f, 1f);

            CharItemEffectController effect = obj.GetComponent <CharItemEffectController>();

            if (effect == null)
            {
                effect = obj.AddComponent <CharItemEffectController>();
            }
            effect.WorkOnParent = true;
            effect.InitialScale = false;
            BarInfo inf = obj.AddComponent <BarInfo>();

            obj.AddComponent <ChartItem>();
            topLevel.transform.localRotation = Quaternion.identity;
            obj.transform.localRotation      = Quaternion.identity;
            obj.transform.localPosition      = Vector3.zero;
            ChartCommon.HideObject(obj, hideHierarchy);
            IBarGenerator generator = obj.GetComponent <IBarGenerator>();

            obj.layer = gameObject.layer;   // put the bar on the same layer as this object
            BarObject barObj = new BarObject();

            ChartCommon.HideObject(topLevel, hideHierarchy);
            barObj.Bar           = generator;
            barObj.BarGameObject = obj;
            barObj.InitialScale  = initialScale;
            barObj.TopObject     = topLevel;
            barObj.InnerPosition = innerPosition;
            barObj.Size          = size;
            barObj.Category      = category;
            barObj.Group         = group;
            barObj.Value         = value;
            barObj.Elevation     = elevation;
            inf.BarObject        = barObj;
            mBars.Add(new ChartItemIndex(index, categoryIndex), barObj);
            ChartItemEvents[] events = obj.GetComponentsInChildren <ChartItemEvents>();
            for (int i = 0; i < events.Length; ++i)
            {
                if (events[i] == null)
                {
                    continue;
                }
                InternalItemEvents comp = (InternalItemEvents)events[i];
                comp.Parent   = this;
                comp.UserData = barObj;
            }

            ChartMaterialController[] materialController = obj.GetComponentsInChildren <ChartMaterialController>();

            for (int i = 0; i < materialController.Length; i++)
            {
                ChartMaterialController m   = materialController[i];
                ChartDynamicMaterial    mat = Data.GetMaterial(category);
                if (mat != null)
                {
                    m.Materials = mat;
                    m.Refresh();
                }
            }

            float ySize = 1f * size * initialScale.y;

            if (generator != null)
            {
                generator.Generate(normalizedSize, ySize);
            }

            SetBarSize(obj, new Vector3(BarSizeLink.Breadth * initialScale.x, ySize, BarSizeLink.Depth * initialScale.z), elevation);

            if (mItemLabels != null && mItemLabels.isActiveAndEnabled)
            {
                string toSet = mItemLabels.TextFormat.Format(ChartAdancedSettings.Instance.FormatFractionDigits(mItemLabels.FractionDigits, value),
                                                             category, group);
                Vector3 labelPos = AlignLabel(mItemLabels, innerPosition, size + elevation);
                float   angle    = 45f;
                if (mItemLabels.Alignment == ChartLabelAlignment.Base)
                {
                    angle = -45f;
                }
                BillboardText billboard = ChartCommon.CreateBillboardText(null, mItemLabels.TextPrefab, topLevel.transform, toSet, labelPos.x, labelPos.y, labelPos.z, angle, obj.transform, hideHierarchy, mItemLabels.FontSize, mItemLabels.FontSharpness);
                //                billboard.UserData =
                //                billboard.UIText.fontSize = ItemLabels.FontSize;
                // billboard.transform.parent =;
                barObj.ItemLabel = billboard;
                TextController.AddText(billboard);
            }

            if (mGroupLabels != null && mGroupLabels.isActiveAndEnabled)
            {
                if (mGroupLabels.Alignment == GroupLabelAlignment.BarBottom || mGroupLabels.Alignment == GroupLabelAlignment.BarTop || (mGroupLabels.Alignment == GroupLabelAlignment.FirstBar && index == 0))
                {
                    Vector3 labelPos = AlignLabel(mGroupLabels, innerPosition, size + elevation);
                    string  toSet    = mGroupLabels.TextFormat.Format(group, category, group);
                    // float angle = 45f;
                    BillboardText billboard = ChartCommon.CreateBillboardText(null, mGroupLabels.TextPrefab, topLevel.transform, toSet, labelPos.x, labelPos.y, labelPos.z, 0f, obj.transform, hideHierarchy, mGroupLabels.FontSize, mGroupLabels.FontSharpness);
                    barObj.GroupLabel = billboard;
                    TextController.AddText(billboard);
                }
            }
            if (mCategoryLabels != null && mCategoryLabels.isActiveAndEnabled)
            {
                if (mCategoryLabels.VisibleLabels != CategoryLabels.ChartCategoryLabelOptions.FirstOnly ||
                    index == 0)
                {
                    Vector3 labelPos = AlignLabel(mCategoryLabels, innerPosition, size + elevation);
                    string  toSet    = mCategoryLabels.TextFormat.Format(category, category, group);
                    float   angle    = 45f;
                    if (mCategoryLabels.Alignment == ChartLabelAlignment.Base)
                    {
                        angle = -45f;
                    }
                    BillboardText billboard = ChartCommon.CreateBillboardText(null, mCategoryLabels.TextPrefab, topLevel.transform, toSet, labelPos.x, labelPos.y, labelPos.z, angle, obj.transform, hideHierarchy, mCategoryLabels.FontSize, mCategoryLabels.FontSharpness);
                    barObj.CategoryLabel = billboard;
                    TextController.AddText(billboard);
                }
            }

            if (Orientation == ChartOrientation.Horizontal)
            {
                obj.transform.localRotation = Quaternion.Euler(0f, 0, -90f);
            }
            return(obj);
        }
コード例 #6
0
 public LabelPositionInfo(ItemLabelsBase options, BarObject bar)
 {
     Options = options;
     Bar     = bar;
 }