コード例 #1
0
        /// <summary>
        /// sets the prefabs for a 3d graph category,
        /// </summary>
        /// <param name="category"></param>
        /// <param name="linePrefab"></param>
        /// <param name="fillPrefab"></param>
        /// <param name="dotPrefab"></param>
        public void Set3DCategoryPrefabs(string category, PathGenerator linePrefab, FillPathGenerator fillPrefab, GameObject dotPrefab)
        {
            if (mData.ContainsKey(category) == false)
            {
                Debug.LogWarning("Invalid category name. Make sure the category is present in the graph");
                return;
            }
            CategoryData data = (CategoryData)mData[category];

            data.LinePrefab = linePrefab;
            data.DotPrefab  = dotPrefab;
            data.FillPrefab = fillPrefab;
            RaiseDataChanged();
        }
コード例 #2
0
        private PathGenerator CreateLineObject(GraphData.CategoryData data)
        {
            GameObject obj = GameObject.Instantiate(data.LinePrefab.gameObject);

            ChartCommon.HideObject(obj, hideHierarchy);
            PathGenerator lines = obj.GetComponent <PathGenerator>();

            if (obj.GetComponent <ChartItem>() == null)
            {
                obj.AddComponent <ChartItem>();
            }
            obj.transform.SetParent(transform);
            obj.transform.localScale    = new Vector3(1f, 1f, 1f);
            obj.transform.localPosition = Vector3.zero;
            obj.transform.localRotation = Quaternion.identity;
            return(lines);
        }
コード例 #3
0
 protected void SetInnerCategoryLine(string category, PathGenerator linePrefab, Material lineMaterial, float lineThickness)
 {
     try
     {
         CategoryData data = mDataSource.Columns[category].UserData as CategoryData;
         if (data == null)
         {
             throw new Exception("category not set"); // should never happen
         }
         data.LineMaterial  = lineMaterial;
         data.LinePrefab    = linePrefab;
         data.LineThickness = lineThickness;
         RaiseDataChanged();
     }
     catch
     {
         Debug.LogWarning("Invalid category name. Make sure the category is present in the graph");
     }
 }
コード例 #4
0
            public void Restore(object store)
            {
                var cat = (CategoryData)store;

                LineHoverPrefab  = cat.LineHoverPrefab;
                PointHoverPrefab = cat.PointHoverPrefab;
                LineMaterial     = cat.LineMaterial;
                LineTiling       = cat.LineTiling;
                LineThickness    = cat.LineThickness;
                FillMaterial     = cat.FillMaterial;
                StetchFill       = cat.StetchFill;
                PointMaterial    = cat.PointMaterial;
                PointSize        = cat.PointSize;
                LinePrefab       = cat.LinePrefab;
                FillPrefab       = cat.FillPrefab;
                DotPrefab        = cat.DotPrefab;
                Depth            = cat.Depth;
                IsBezierCurve    = cat.IsBezierCurve;
                SegmentsPerCurve = cat.SegmentsPerCurve;
            }
コード例 #5
0
        protected override GameObject CreateAxisObject(float thickness, Vector3[] path)
        {
            GameObject obj = ChartCommon.CreateChartItem();

            ChartCommon.HideObject(obj, true);
            if (AxisPrefab != null && AxisThickness > 0.0001f)
            {
                GameObject axis = GameObject.Instantiate(AxisPrefab.gameObject);
                axis.AddComponent <ChartItem>();
                ChartCommon.HideObject(axis, hideHierarchy);
                axis.transform.SetParent(obj.transform, true);
                axis.transform.localScale    = new Vector3(1f, 1f, 1f);
                axis.transform.localPosition = Vector3.zero;
                axis.transform.rotation      = Quaternion.identity;
                Renderer rend = axis.GetComponent <Renderer>();
                if (rend != null && AxisLineMaterial != null)
                {
                    rend.material = AxisLineMaterial;
                }
                PathGenerator gen = axis.GetComponent <PathGenerator>();
                gen.Generator(path, thickness, true);
            }

            if (AxisPointPrefab != null && AxisPointSize > 0.0001f)
            {
                for (int i = 0; i < path.Length; i++)
                {
                    GameObject point = GameObject.Instantiate(AxisPointPrefab.gameObject);
                    point.transform.SetParent(obj.transform, true);
                    point.transform.localScale    = new Vector3(AxisPointSize, AxisPointSize, AxisPointSize);
                    point.transform.localPosition = path[i];
                    point.transform.rotation      = Quaternion.identity;
                    Renderer rend = point.GetComponent <Renderer>();
                    if (rend != null && AxisPointMaterial != null)
                    {
                        rend.material = AxisPointMaterial;
                    }
                }
            }
            return(obj);
        }
コード例 #6
0
        /// <summary>
        /// Adds a new category to the radar chart. Each category has it's own materials and name.
        /// Note: you must also add groups to the radar data.
        /// Example: you can set the chart categories to be "Player 1","Player 2","Player 3" in order to compare player achivments
        /// </summary>
        protected void AddInnerCategory(string name, PathGenerator linePrefab, Material lineMaterial, float lineThickness, GameObject pointPrefab, Material pointMaterial, float pointSize, Material fillMaterial, int fillSmoothing, float curve, float seperation)
        {
            ChartDataColumn column = new ChartDataColumn(name);
            CategoryData    data   = new CategoryData();

            data.LinePrefab    = linePrefab;
            data.LineMaterial  = lineMaterial;
            data.LineThickness = lineThickness;
            data.PointMaterial = pointMaterial;
            data.PointSize     = pointSize;
            data.PointPrefab   = pointPrefab;
            data.FillMaterial  = fillMaterial;
            if (fillSmoothing < 1)
            {
                fillSmoothing = 1;
            }
            data.FillSmoothing = fillSmoothing;
            data.Curve         = curve;
            data.Seperation    = seperation;
            data.Name          = name;
            column.UserData    = data;
            mDataSource.mColumns.Add(column);
        }
コード例 #7
0
 /// <summary>
 /// Adds a new category to the radar chart. Each category has it's own materials and name.
 /// Note: you must also add groups to the radar data.
 /// Example: you can set the chart categories to be "Player 1","Player 2","Player 3" in order to compare player achivments
 public void AddCategory(string name, PathGenerator linePrefab, Material lineMaterial, float lineThickness, GameObject pointPrefab, Material pointMaterial, float pointSize, Material fillMaterial)
 {
     AddInnerCategory(name, null, lineMaterial, lineThickness, null, pointMaterial, pointSize, fillMaterial, 5, 0f, 0f);
 }
コード例 #8
0
        public override void InternalGenerateChart()
        {
            if (gameObject.activeInHierarchy == false)
            {
                return;
            }
            base.InternalGenerateChart();
            ClearChart();

            if (Data == null)
            {
                return;
            }

            double        minX = (float)((IInternalGraphData)Data).GetMinValue(0, false);
            double        minY = (float)((IInternalGraphData)Data).GetMinValue(1, false);
            double        maxX = (float)((IInternalGraphData)Data).GetMaxValue(0, false);
            double        maxY = (float)((IInternalGraphData)Data).GetMaxValue(1, false);
            DoubleVector3 min  = new DoubleVector3(minX, minY);
            DoubleVector3 max  = new DoubleVector3(maxX, maxY);

            Rect viewRect = new Rect(0f, 0f, widthRatio, heightRatio);

            int    index         = 0;
            int    total         = ((IInternalGraphData)Data).TotalCategories + 1;
            double positiveDepth = 0f;
            double maxThickness  = 0f;
            bool   edit          = false;

            m3DTexts.Clear();
            mActiveTexts.Clear();
            foreach (GraphData.CategoryData data in ((IInternalGraphData)Data).Categories)
            {
                maxThickness = Math.Max(data.LineThickness, maxThickness);
                DoubleVector3[] points = data.getPoints().ToArray();
                TransformPoints(points, viewRect, min, max);
                if (points.Length == 0 && ChartCommon.IsInEditMode)
                {
                    edit = true;
                    int           tmpIndex = total - 1 - index;
                    float         y1       = (((float)tmpIndex) / (float)total);
                    float         y2       = (((float)tmpIndex + 1) / (float)total);
                    DoubleVector3 pos1     = ChartCommon.interpolateInRect(viewRect, new DoubleVector3(0f, y1, -1f)).ToDoubleVector3();
                    DoubleVector3 pos2     = ChartCommon.interpolateInRect(viewRect, new DoubleVector3(0.5f, y2, -1f)).ToDoubleVector3();
                    DoubleVector3 pos3     = ChartCommon.interpolateInRect(viewRect, new DoubleVector3(1f, y1, -1f)).ToDoubleVector3();
                    points = new DoubleVector3[] { pos1, pos2, pos3 };
                    index++;
                }

                /*if (data.FillMaterial != null)
                 * {
                 *  CanvasLines fill = CreateDataObject(data);
                 *  fill.material = data.FillMaterial;
                 *  fill.SetLines(list);
                 *  fill.MakeFillRender(viewRect, data.StetchFill);
                 * }*/

                if (data.Depth > 0)
                {
                    positiveDepth = Math.Max(positiveDepth, data.Depth);
                }
                // if (data.DotPrefab != null)
                //{
                for (int i = 0; i < points.Length; i++)
                {
                    DoubleVector3 pointValue = points[i];
                    if (edit == false)
                    {
                        pointValue = Data.GetPoint(data.Name, i);
                    }

                    string xFormat = StringFromAxisFormat(pointValue.x, mHorizontalAxis);
                    string yFormat = StringFromAxisFormat(pointValue.y, mVerticalAxis);

                    GraphEventArgs    args   = new GraphEventArgs(i, (points[i] + new DoubleVector3(0.0, 0.0, data.Depth)).ToVector3(), pointValue.ToDoubleVector2(), (float)pointValue.z, data.Name, xFormat, yFormat);
                    GameObject        point  = CreatePointObject(data);
                    ChartItemEvents[] events = point.GetComponentsInChildren <ChartItemEvents>();

                    for (int j = 0; j < events.Length; ++j)
                    {
                        if (events[j] == null)
                        {
                            continue;
                        }
                        InternalItemEvents comp = (InternalItemEvents)events[j];
                        comp.Parent   = this;
                        comp.UserData = args;
                    }

                    double pointSize = points[i].z * data.PointSize;
                    if (pointSize < 0f)
                    {
                        pointSize = data.PointSize;
                    }



                    point.transform.localScale = new DoubleVector3(pointSize, pointSize, pointSize).ToVector3();

                    if (data.PointMaterial != null)
                    {
                        Renderer rend = point.GetComponent <Renderer>();
                        if (rend != null)
                        {
                            rend.material = data.PointMaterial;
                        }
                        ChartMaterialController controller = point.GetComponent <ChartMaterialController>();
                        if (controller != null && controller.Materials != null)
                        {
                            Color hover    = controller.Materials.Hover;
                            Color selected = controller.Materials.Selected;
                            controller.Materials = new ChartDynamicMaterial(data.PointMaterial, hover, selected);
                        }
                    }
                    DoubleVector3 position = points[i];
                    position.z = data.Depth;
                    point.transform.localPosition = position.ToVector3();
                    if (mItemLabels != null && mItemLabels.isActiveAndEnabled)
                    {
                        Vector3 labelPos = (points[i] + new DoubleVector3(mItemLabels.Location.Breadth, mItemLabels.Seperation, mItemLabels.Location.Depth + data.Depth)).ToVector3();
                        if (mItemLabels.Alignment == ChartLabelAlignment.Base)
                        {
                            labelPos.y -= (float)points[i].y;
                        }
                        FormatItem(mRealtimeStringBuilder, xFormat, yFormat);
                        string        formatted = mRealtimeStringBuilder.ToString();
                        string        toSet     = mItemLabels.TextFormat.Format(formatted, data.Name, "");
                        BillboardText billboard = ChartCommon.CreateBillboardText(null, mItemLabels.TextPrefab, transform, toSet, labelPos.x, labelPos.y, labelPos.z, 0f, null, hideHierarchy, mItemLabels.FontSize, mItemLabels.FontSharpness);
                        TextController.AddText(billboard);
                        AddBillboardText(data.Name, billboard);
                    }
                }
                //}
                for (int i = 0; i < points.Length; i++)
                {
                    points[i].z = 0f;
                }
                Vector3[] floatPoints = points.Select(x => x.ToVector3()).ToArray();
                if (data.LinePrefab != null)
                {
                    PathGenerator lines = CreateLineObject(data);
                    //    float tiling = 1f;

                    if (data.LineTiling.EnableTiling == true && data.LineTiling.TileFactor > 0f)
                    {
                        float length = 0f;
                        for (int i = 1; i < points.Length; i++)
                        {
                            length += (float)(points[i - 1] - points[i]).magnitude;
                        }
                        //  tiling = length / data.LineTiling.TileFactor;
                    }

                    lines.Generator(floatPoints, (float)data.LineThickness, false);
                    Vector3 tmp = lines.transform.localPosition;
                    tmp.z = (float)data.Depth;
                    lines.transform.localPosition = tmp;
                    if (data.LineMaterial != null)
                    {
                        Renderer rend = lines.GetComponent <Renderer>();
                        if (rend != null)
                        {
                            rend.material = data.LineMaterial;
                        }
                        ChartMaterialController controller = lines.GetComponent <ChartMaterialController>();
                        if (controller != null && controller.Materials != null)
                        {
                            Color hover    = controller.Materials.Hover;
                            Color selected = controller.Materials.Selected;
                            controller.Materials = new ChartDynamicMaterial(data.LineMaterial, hover, selected);
                        }
                    }
                }
                totalDepth = (float)(positiveDepth + maxThickness * 2f);


                if (data.FillPrefab != null)
                {
                    FillPathGenerator fill = CreateFillObject(data);
                    Vector3           tmp  = fill.transform.localPosition;
                    tmp.z = (float)data.Depth;
                    fill.transform.localPosition = tmp;

                    if (data.LinePrefab == null || !(data.LinePrefab is SmoothPathGenerator))
                    {
                        fill.SetLineSmoothing(false, 0, 0f);
                    }
                    else
                    {
                        SmoothPathGenerator smooth = ((SmoothPathGenerator)data.LinePrefab);
                        fill.SetLineSmoothing(true, smooth.JointSmoothing, smooth.JointSize);
                    }

                    fill.SetGraphBounds(viewRect.yMin, viewRect.yMax);
                    fill.SetStrechFill(data.StetchFill);
                    fill.Generator(floatPoints, (float)data.LineThickness * 1.01f, false);

                    if (data.FillMaterial != null)
                    {
                        Renderer rend = fill.GetComponent <Renderer>();
                        if (rend != null)
                        {
                            rend.material = data.FillMaterial;
                        }
                        ChartMaterialController controller = fill.GetComponent <ChartMaterialController>();

                        if (controller != null && controller.Materials != null)
                        {
                            Color hover    = controller.Materials.Hover;
                            Color selected = controller.Materials.Selected;
                            controller.Materials = new ChartDynamicMaterial(data.FillMaterial, hover, selected);
                        }
                    }
                }
            }
            GenerateAxis(true);
        }
コード例 #9
0
 public void AddCategory3DGraph(string category, PathGenerator linePrefab, Material lineMaterial, double lineThickness, MaterialTiling lineTiling, FillPathGenerator fillPrefab, Material innerFill, bool strechFill, GameObject pointPrefab, Material pointMaterial, double pointSize, double depth, bool isCurve, int segmentsPerCurve)
 {
     AddInnerCategoryGraph(category, linePrefab, lineMaterial, lineThickness, lineTiling, fillPrefab, innerFill, strechFill, pointPrefab, pointMaterial, pointSize, depth, isCurve, segmentsPerCurve);
 }
コード例 #10
0
        protected override GameObject CreateCategoryObject(Vector3[] path, int category)
        {
            RadarChartData.CategoryData cat = ((IInternalRadarData)DataSource).getCategoryData(category);
            GameObject container            = ChartCommon.CreateChartItem();

            ChartCommon.HideObject(container, hideHierarchy);
            container.transform.SetParent(transform, false);
            container.transform.localScale    = new Vector3(1f, 1f, 1f);
            container.transform.localPosition = new Vector3(0f, 0f, cat.Seperation);
            container.transform.localRotation = Quaternion.identity;

            if (cat.FillMaterial != null)
            {
                RadarFillGenerator fill = CreateFillObject(container);
                fill.Smoothing = cat.FillSmoothing;
                Renderer rend = fill.GetComponent <Renderer>();
                if (rend != null)
                {
                    rend.material = cat.FillMaterial;
                }
                fill.Generate(path, Radius, cat.Curve);
            }

            if (cat.LinePrefab != null && cat.LineMaterial != null && cat.LineThickness > 0)
            {
                GameObject    line    = CreatePrefab(container, cat.LinePrefab.gameObject);
                PathGenerator pathGen = line.GetComponent <PathGenerator>();
                Renderer      rend    = line.GetComponent <Renderer>();
                if (rend != null)
                {
                    rend.material = cat.LineMaterial;
                }

                pathGen.Generator(path, cat.LineThickness, true);
            }
            GameObject prefab = cat.PointPrefab;

            if (prefab == null)
            {
                if (mEmptyPointPrefab == null)
                {
                    mEmptyPointPrefab = (GameObject)Resources.Load("Chart And Graph/SelectHandle");
                }
                prefab = mEmptyPointPrefab;
            }
            if (prefab != null)
            {
                for (int i = 0; i < path.Length; i++)
                {
                    GameObject     point = CreatePrefab(container, prefab);
                    string         group = DataSource.GetGroupName(i);
                    double         value = DataSource.GetValue(cat.Name, group);
                    RadarEventArgs args  = new RadarEventArgs(cat.Name, group, value, path[i], i);
                    point.transform.localPosition = path[i];
                    point.transform.localScale    = new Vector3(cat.PointSize, cat.PointSize, cat.PointSize);

                    Renderer rend = point.GetComponent <Renderer>();
                    if (rend != null)
                    {
                        rend.material = cat.PointMaterial;
                    }
                    ChartMaterialController controller = point.GetComponent <ChartMaterialController>();
                    if (controller != null && controller.Materials != null)
                    {
                        Color hover    = controller.Materials.Hover;
                        Color selected = controller.Materials.Selected;
                        controller.Materials = new ChartDynamicMaterial(cat.PointMaterial, hover, selected);
                    }
                    ChartItemEvents[] events = point.GetComponentsInChildren <ChartItemEvents>();
                    for (int j = 0; j < events.Length; ++j)
                    {
                        if (events[j] == null)
                        {
                            continue;
                        }
                        InternalItemEvents comp = (InternalItemEvents)events[j];
                        comp.Parent   = this;
                        comp.UserData = args;
                    }
                }
            }

            if (mCategoryLabels != null && mCategoryLabels.isActiveAndEnabled)
            {
                for (int i = 0; i < path.Length; i++)
                {
                    string  group    = DataSource.GetGroupName(i);
                    double  val      = DataSource.GetValue(cat.Name, group);
                    Vector3 labelPos = path[i];
                    Vector3 dir      = labelPos.normalized;
                    labelPos += dir * mCategoryLabels.Seperation;
                    labelPos += new Vector3(mCategoryLabels.Location.Breadth, 0f, mCategoryLabels.Location.Depth);
                    int fractionDigits = 2;
                    if (mItemLabels != null)
                    {
                        fractionDigits = mItemLabels.FractionDigits;
                    }
                    string        toSet     = mCategoryLabels.TextFormat.Format(ChartAdancedSettings.Instance.FormatFractionDigits(fractionDigits, val), cat.Name, group);
                    BillboardText billboard = ChartCommon.CreateBillboardText(null, mCategoryLabels.TextPrefab, transform, toSet, labelPos.x, labelPos.y, labelPos.z, 0f, null, hideHierarchy, mCategoryLabels.FontSize, mCategoryLabels.FontSharpness);
                    TextController.AddText(billboard);
                    AddBillboardText(cat.Name, billboard);
                }
            }
            return(container);
        }
コード例 #11
0
        public override void InternalGenerateChart()
        {
            if (gameObject.activeInHierarchy == false)
            {
                return;
            }
            base.InternalGenerateChart();
            ClearChart();

            if (Data == null)
            {
                return;
            }

            double minX = ((IInternalGraphData)Data).GetMinValue(0, false);
            double minY = ((IInternalGraphData)Data).GetMinValue(1, false);
            double maxX = ((IInternalGraphData)Data).GetMaxValue(0, false);
            double maxY = ((IInternalGraphData)Data).GetMaxValue(1, false);

            double xScroll = GetScrollOffset(0);
            double yScroll = GetScrollOffset(1);
            double xSize   = maxX - minX;
            double ySize   = maxY - minY;
            double xOut    = minX + xScroll + xSize;
            double yOut    = minY + yScroll + ySize;

            DoubleVector3 min = new DoubleVector3(xScroll + minX, yScroll + minY);
            DoubleVector3 max = new DoubleVector3(xOut, yOut);

            Rect viewRect = new Rect(0f, 0f, widthRatio, heightRatio);

            int    index         = 0;
            int    total         = ((IInternalGraphData)Data).TotalCategories + 1;
            double positiveDepth = 0f;
            double maxThickness  = 0f;
            bool   edit          = false;

            m3DTexts.Clear();
            mActiveTexts.Clear();
            foreach (GraphData.CategoryData data in ((IInternalGraphData)Data).Categories)
            {
                mClipped.Clear();
                maxThickness = Math.Max(data.LineThickness, maxThickness);
                DoubleVector3[] points = data.getPoints().ToArray();
                Rect            uv;
                int             refrenceIndex = ClipPoints(points, mClipped, out uv);
                TransformPoints(mClipped, mTransformed, viewRect, min, max);

                if (points.Length == 0 && ChartCommon.IsInEditMode)
                {
                    edit = true;
                    int           tmpIndex = total - 1 - index;
                    float         y1       = (((float)tmpIndex) / (float)total);
                    float         y2       = (((float)tmpIndex + 1) / (float)total);
                    DoubleVector3 pos1     = ChartCommon.interpolateInRect(viewRect, new DoubleVector3(0f, y1, -1f)).ToDoubleVector3();
                    DoubleVector3 pos2     = ChartCommon.interpolateInRect(viewRect, new DoubleVector3(0.5f, y2, -1f)).ToDoubleVector3();
                    DoubleVector3 pos3     = ChartCommon.interpolateInRect(viewRect, new DoubleVector3(1f, y1, -1f)).ToDoubleVector3();
                    points = new DoubleVector3[] { pos1, pos2, pos3 };
                    mTransformed.AddRange(points.Select(x => (Vector4)x.ToVector3()));
                    index++;
                }

                /*if (data.FillMaterial != null)
                 * {
                 *  CanvasLines fill = CreateDataObject(data);
                 *  fill.material = data.FillMaterial;
                 *  fill.SetLines(list);
                 *  fill.MakeFillRender(viewRect, data.StetchFill);
                 * }*/

                if (data.Depth > 0)
                {
                    positiveDepth = Math.Max(positiveDepth, data.Depth);
                }
                // if (data.DotPrefab != null)
                //{
                float minViewX = Math.Min(viewRect.xMin, viewRect.xMax);
                float maxViewX = Math.Max(viewRect.xMin, viewRect.xMax);
                float minViewY = Math.Min(viewRect.yMin, viewRect.yMax);
                float maxViewY = Math.Max(viewRect.yMin, viewRect.yMax);

                for (int i = 0; i < mTransformed.Count; i++)
                {
                    float transX = mTransformed[i].x;
                    float transY = mTransformed[i].y;
                    if (minViewX > transX || maxViewX < transX)
                    {
                        continue;
                    }
                    if (minViewX > transY || maxViewX < transY)
                    {
                        continue;
                    }
                    DoubleVector3 pointValue = points[i];
                    if (edit == false)
                    {
                        pointValue = Data.GetPoint(data.Name, i + refrenceIndex);
                    }

                    string xFormat = StringFromAxisFormat(pointValue, mHorizontalAxis, true);
                    string yFormat = StringFromAxisFormat(pointValue, mVerticalAxis, false);

                    GraphEventArgs    args   = new GraphEventArgs(i, (mTransformed[i] + new Vector4(0f, 0f, (float)data.Depth)), pointValue.ToDoubleVector2(), (float)pointValue.z, data.Name, xFormat, yFormat);
                    GameObject        point  = CreatePointObject(data);
                    ChartItemEvents[] events = point.GetComponentsInChildren <ChartItemEvents>();

                    for (int j = 0; j < events.Length; ++j)
                    {
                        if (events[j] == null)
                        {
                            continue;
                        }
                        InternalItemEvents comp = (InternalItemEvents)events[j];
                        comp.Parent   = this;
                        comp.UserData = args;
                    }

                    double pointSize = mTransformed[i].w * data.PointSize;
                    if (pointSize < 0f)
                    {
                        pointSize = data.PointSize;
                    }



                    point.transform.localScale = new DoubleVector3(pointSize, pointSize, pointSize).ToVector3();

                    if (data.PointMaterial != null)
                    {
                        Renderer rend = point.GetComponent <Renderer>();
                        if (rend != null)
                        {
                            rend.material = data.PointMaterial;
                        }
                        ChartMaterialController controller = point.GetComponent <ChartMaterialController>();
                        if (controller != null && controller.Materials != null)
                        {
                            Color hover    = controller.Materials.Hover;
                            Color selected = controller.Materials.Selected;
                            controller.Materials = new ChartDynamicMaterial(data.PointMaterial, hover, selected);
                        }
                    }

                    DoubleVector3 position = new DoubleVector3(mTransformed[i]);
                    position.z = data.Depth;
                    point.transform.localPosition = position.ToVector3();
                    if (mItemLabels != null && mItemLabels.isActiveAndEnabled)
                    {
                        Vector3 labelPos = (new DoubleVector3(mTransformed[i]) + new DoubleVector3(mItemLabels.Location.Breadth, mItemLabels.Seperation, mItemLabels.Location.Depth + data.Depth)).ToVector3();
                        if (mItemLabels.Alignment == ChartLabelAlignment.Base)
                        {
                            labelPos.y -= (float)mTransformed[i].y;
                        }
                        FormatItem(mRealtimeStringBuilder, xFormat, yFormat);
                        string        formatted = mRealtimeStringBuilder.ToString();
                        string        toSet     = mItemLabels.TextFormat.Format(formatted, data.Name, "");
                        BillboardText billboard = ChartCommon.CreateBillboardText(null, mItemLabels.TextPrefab, transform, toSet, labelPos.x, labelPos.y, labelPos.z, 0f, null, hideHierarchy, mItemLabels.FontSize, mItemLabels.FontSharpness);
                        TextController.AddText(billboard);
                        AddBillboardText(data.Name, billboard);
                    }
                }
                //}
                for (int i = 0; i < mTransformed.Count; i++)
                {
                    var t = mTransformed[i];
                    t.z             = 0f;
                    t.w             = 0f;
                    mTransformed[i] = t;
                }
                Vector3[] floatPoints = mTransformed.Select(x => (Vector3)x).ToArray();
                if (floatPoints.Length >= 2)
                {
                    Vector2 res;
                    float   maxF    = Math.Max(floatPoints[0].y, floatPoints[1].y);
                    float   minF    = Math.Min(floatPoints[0].y, floatPoints[1].y);
                    float   firstX  = viewRect.x;
                    float   secondX = viewRect.x + viewRect.width;
                    if (min.x > max.x)
                    {
                        float tmp = firstX;
                        firstX  = secondX;
                        secondX = tmp;
                    }
                    if (ChartCommon.SegmentIntersection(floatPoints[0], floatPoints[1], new Vector3(firstX, maxF, 0f), new Vector3(firstX, minF, 0f), out res))
                    {
                        floatPoints[0] = res;
                    }
                    Vector3 last       = floatPoints[floatPoints.Length - 1];
                    Vector3 secondLast = floatPoints[floatPoints.Length - 2];
                    maxF = Math.Max(last.y, secondLast.y);
                    minF = Math.Min(last.y, secondLast.y);

                    if (ChartCommon.SegmentIntersection(last, secondLast, new Vector3(secondX, maxF, 0f), new Vector3(secondX, minF, 0f), out res))
                    {
                        floatPoints[floatPoints.Length - 1] = res;
                    }
                }
                List <List <Vector3> > clippedLines     = new List <List <Vector3> >(8);
                List <List <Vector3> > fillClippedLines = new List <List <Vector3> >(8);
                List <Vector3>         current          = null;
                List <Vector3>         currentFill      = null;
                for (int i = 1; i < floatPoints.Length; i++)
                {
                    Vector3 v1   = floatPoints[i - 1];
                    Vector3 v2   = floatPoints[i];
                    bool    last = i == floatPoints.Length - 1;
                    if ((v1.y <= minViewY && v2.y <= minViewY))
                    {
                        continue;
                    }
                    if (currentFill == null)
                    {
                        currentFill = new List <Vector3>(30);
                        fillClippedLines.Add(currentFill);
                    }
                    if ((v1.y >= maxViewY && v2.y >= maxViewY))
                    {
                        currentFill.Add(new Vector3(v1.x, maxViewY, v1.z));
                        if (last)
                        {
                            currentFill.Add(new Vector3(v2.x, maxViewY, v2.z));
                        }
                        continue;
                    }
                    if (current == null)
                    {
                        current = new List <Vector3>(30);
                        clippedLines.Add(current);
                    }

                    if ((v1.y >= minViewY && v2.y >= minViewY) && (v1.y <= maxViewY && v2.y <= maxViewY))
                    {
                        current.Add(v1);
                        currentFill.Add(v1);
                        if (last)
                        {
                            current.Add(v2);
                            currentFill.Add(v2);
                        }
                        continue;
                    }
                    if (v1.y <= minViewY)
                    {
                        var v = ChartCommon.LineCrossing(v1, v2, minViewY);
                        current.Add(v);
                        currentFill.Add(v);
                    }
                    else
                    {
                        if (v1.y >= maxViewY)
                        {
                            var v = ChartCommon.LineCrossing(v1, v2, maxViewY);
                            current.Add(v);
                            currentFill.Add(new Vector3(v1.x, maxViewY, v1.z));
                            currentFill.Add(v);
                        }
                        else
                        {
                            current.Add(v1);
                            currentFill.Add(v1);
                        }
                    }
                    if (v2.y <= minViewY)
                    {
                        var v = ChartCommon.LineCrossing(v1, v2, minViewY);
                        current.Add(v);
                        currentFill.Add(v);
                        currentFill = null;
                    }
                    else
                    {
                        if (v2.y >= maxViewY)
                        {
                            var v = ChartCommon.LineCrossing(v1, v2, maxViewY);
                            current.Add(v);
                            currentFill.Add(v);
                            if (last)
                            {
                                currentFill.Add(new Vector3(v2.x, maxViewY, v2.z));
                            }
                        }
                        else
                        {
                            current.Add(v2);
                            if (last)
                            {
                                currentFill.Add(v2);
                            }
                        }
                    }
                    current = null;
                }
                if (data.LinePrefab != null)
                {
                    for (int i = 0; i < clippedLines.Count; i++)
                    {
                        if (clippedLines[i].Count == 0)
                        {
                            continue;
                        }

                        PathGenerator lines = CreateLineObject(data);
                        //    float tiling = 1f;

                        if (data.LineTiling.EnableTiling == true && data.LineTiling.TileFactor > 0f)
                        {
                            float length = 0f;
                            for (int j = 1; j < mTransformed.Count; j++)
                            {
                                length += (float)(((Vector3)mTransformed[j - 1]) - (Vector3)mTransformed[j]).magnitude;
                            }
                            //  tiling = length / data.LineTiling.TileFactor;
                        }

                        lines.Generator(clippedLines[i].ToArray(), (float)data.LineThickness, false);
                        Vector3 tmp = lines.transform.localPosition;
                        tmp.z = (float)data.Depth;
                        lines.transform.localPosition = tmp;
                        if (data.LineMaterial != null)
                        {
                            Renderer rend = lines.GetComponent <Renderer>();
                            if (rend != null)
                            {
                                rend.material = data.LineMaterial;
                            }
                            ChartMaterialController controller = lines.GetComponent <ChartMaterialController>();
                            if (controller != null && controller.Materials != null)
                            {
                                Color hover    = controller.Materials.Hover;
                                Color selected = controller.Materials.Selected;
                                controller.Materials = new ChartDynamicMaterial(data.LineMaterial, hover, selected);
                            }
                        }
                    }
                }
                totalDepth = (float)(positiveDepth + maxThickness * 2f);


                if (data.FillPrefab != null)
                {
                    for (int i = 0; i < fillClippedLines.Count; i++)
                    {
                        if (fillClippedLines[i].Count == 0)
                        {
                            continue;
                        }
                        FillPathGenerator fill = CreateFillObject(data);
                        Vector3           tmp  = fill.transform.localPosition;
                        tmp.z = (float)data.Depth;
                        fill.transform.localPosition = tmp;

                        if (data.LinePrefab == null || !(data.LinePrefab is SmoothPathGenerator))
                        {
                            fill.SetLineSmoothing(false, 0, 0f);
                        }
                        else
                        {
                            SmoothPathGenerator smooth = ((SmoothPathGenerator)data.LinePrefab);
                            fill.SetLineSmoothing(true, smooth.JointSmoothing, smooth.JointSize);
                        }

                        fill.SetGraphBounds(viewRect.yMin, viewRect.yMax);
                        fill.SetStrechFill(data.StetchFill);
                        fill.Generator(fillClippedLines[i].ToArray(), (float)data.LineThickness * 1.01f, false);

                        if (data.FillMaterial != null)
                        {
                            Renderer rend = fill.GetComponent <Renderer>();
                            if (rend != null)
                            {
                                rend.material = data.FillMaterial;
                            }
                            ChartMaterialController controller = fill.GetComponent <ChartMaterialController>();

                            if (controller != null && controller.Materials != null)
                            {
                                Color hover    = controller.Materials.Hover;
                                Color selected = controller.Materials.Selected;
                                controller.Materials = new ChartDynamicMaterial(data.FillMaterial, hover, selected);
                            }
                        }
                    }
                }
            }
            GenerateAxis(true);
        }
コード例 #12
0
 /// <summary>
 /// Adds a new category to the radar chart. Each category has it's own materials and name.
 /// Note: you must also add groups to the radar data.
 /// Example: you can set the chart categories to be "Player 1","Player 2","Player 3" in order to compare player achivments
 /// </summary>
 public void Add3DCategory(string name, PathGenerator linePrefab, Material lineMaterial, float lineThickness, GameObject pointPrefab, Material pointMaterial, float pointSize, Material fillMaterial, int fillSmoothing, float curve, float seperation)
 {
     AddInnerCategory(name, linePrefab, lineMaterial, lineThickness, pointPrefab, pointMaterial, pointSize, fillMaterial, fillSmoothing, curve, seperation);
 }