protected override GameObject CreateAxisObject(float thickness, Vector3[] path) { Vector3[] newPath = new Vector3[path.Length + 1]; path.CopyTo(newPath, 0); newPath[path.Length] = path[0]; path = newPath; List <CanvasLines.LineSegement> seg = new List <CanvasLines.LineSegement>(); seg.Add(new CanvasLines.LineSegement(path)); GameObject conatiner = ChartCommon.CreateChartItem(); ChartCommon.HideObject(conatiner, hideHierarchy); conatiner.transform.SetParent(transform, false); conatiner.transform.localScale = new Vector3(1f, 1f, 1f); conatiner.transform.localPosition = Vector3.zero; conatiner.transform.localRotation = Quaternion.identity; if (AxisLineMaterial != null && AxisThickness > 0f) { CanvasLines lines = CreateLinesObject(conatiner); lines.material = AxisLineMaterial; lines.Thickness = thickness; lines.SetLines(seg); } if (AxisPointMaterial != null && AxisPointSize > 0f) { CanvasLines points = CreateLinesObject(conatiner); points.material = AxisPointMaterial; points.MakePointRender(AxisPointSize); points.SetLines(seg); } return(conatiner); }
internal protected virtual IAxisGenerator InternalUpdateAxis(ref GameObject axisObject, AxisBase axisBase, ChartOrientation axisOrientation, bool isSubDiv, bool forceRecreate, double scrollOffset) { IAxisGenerator res = null; if (axisObject == null || forceRecreate || CanvasChanged) { ChartCommon.SafeDestroy(axisObject); GameObject axis = null; if (IsUnderCanvas) { axis = ChartCommon.CreateCanvasChartItem(); axis.transform.SetParent(transform, false); var rect = axis.GetComponent <RectTransform>(); rect.anchorMin = new Vector2(0f, 0f); rect.anchorMax = new Vector2(0f, 0f); rect.localScale = new Vector3(1f, 1f, 1f); rect.localRotation = Quaternion.identity; rect.anchoredPosition = new Vector3(); } else { axis = ChartCommon.CreateChartItem(); axis.transform.SetParent(transform, false); axis.transform.localScale = new Vector3(1f, 1f, 1f); axis.transform.localRotation = Quaternion.identity; axis.transform.localPosition = new Vector3(); } axisBase.ClearFormats(); axis.layer = gameObject.layer; // put the axis on the same layer as the chart ChartCommon.HideObject(axis, hideHierarchy); axisObject = axis; if (IsUnderCanvas) { res = axis.AddComponent <CanvasAxisGenerator>(); } else { res = axis.AddComponent <AxisGenerator>(); } } else { if (IsUnderCanvas) { res = axisObject.GetComponent <CanvasAxisGenerator>(); } else { res = axisObject.GetComponent <AxisGenerator>(); } } res.SetAxis(scrollOffset, this, axisBase, axisOrientation, isSubDiv); // axisObject.transform.localScale = new Vector3(1f, 1f, 1f); // axisObject.transform.localRotation = Quaternion.identity; // axisObject.transform.localPosition = new Vector3(); return(res); }
protected RadarFillGenerator CreateFillObject(GameObject conatiner) { GameObject obj = ChartCommon.CreateChartItem(); ChartCommon.HideObject(obj, hideHierarchy); obj.AddComponent <ChartItem>(); RadarFillGenerator fill = obj.AddComponent <RadarFillGenerator>(); obj.transform.SetParent(conatiner.transform, false); obj.transform.localScale = new Vector3(1f, 1f, 1f); obj.transform.localPosition = Vector3.zero; obj.transform.localRotation = Quaternion.identity; return(fill); }
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); }
protected override GameObject CreateCategoryObject(Vector3[] path, int category) { Vector3[] newPath = new Vector3[path.Length + 1]; path.CopyTo(newPath, 0); newPath[path.Length] = path[0]; path = newPath; List <CanvasLines.LineSegement> seg = new List <CanvasLines.LineSegement>(); seg.Add(new CanvasLines.LineSegement(path)); 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 = Vector3.zero; container.transform.localRotation = Quaternion.identity; if (cat.FillMaterial != null) { RadarFill fill = CreateFillObject(container); fill.material = cat.FillMaterial; fill.SetPath(path, Radius); } if (cat.LineMaterial != null && cat.LineThickness > 0) { CanvasLines lines = CreateLinesObject(container); lines.material = cat.LineMaterial; lines.Thickness = cat.LineThickness; lines.SetHoverPrefab(cat.LineHover); lines.SetLines(seg); } if (cat.PointMaterial != null && cat.PointSize > 0f) { CanvasLines points = CreateLinesObject(container); points.material = cat.PointMaterial; points.MakePointRender(cat.PointSize); points.SetHoverPrefab(cat.PointHover); points.SetLines(seg); string name = cat.Name; points.Hover += (int arg1, int t, object d, Vector2 arg2) => Points_Hover(name, arg1, arg2); points.Leave += () => Points_Leave(name); points.Click += (int arg1, int t, object d, Vector2 arg2) => Points_Click(name, arg1, arg2); } if (mCategoryLabels != null && mCategoryLabels.isActiveAndEnabled) { for (int i = 0; i < path.Length - 1; 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, CustomNumberFormat), 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); }
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); }