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); }
void OnDestroy() { if (mRenderer != null) { ChartCommon.SafeDestroy(mRenderer.material); } ChartCommon.SafeDestroy(mMat); }
void IMixedChartDelegate.RealaseChart(ScrollableAxisChart chart) { if (mContainedCharts.Remove(chart) == false) { Debug.LogWarning("chart is not contained within the mixedSeriesChart"); } ChartCommon.SafeDestroy(chart.gameObject); }
public static void ClearChartGarbage() { ChartItem[] children = GameObject.FindObjectsOfType <ChartItem>(); for (int i = 0; i < children.Length; ++i) { if (children[i] != null) { ChartCommon.SafeDestroy(children[i].gameObject); } } }
public void DestoryAll() { for (int i = 0; i < mPool.Count; i++) { T t = mPool[i]; if (t != null && t.gameObject != null) { ChartCommon.SafeDestroy(t.gameObject); } } mPool.Clear(); }
/// <summary> /// /// </summary> /// <param name="newMesh"></param> /// <param name="cleanMesh"></param> internal static void CleanMesh(Mesh newMesh, ref Mesh cleanMesh) { if (cleanMesh == newMesh) { return; } if (cleanMesh != null) { ChartCommon.SafeDestroy(cleanMesh); } cleanMesh = newMesh; }
/// <summary> /// override this method in a dervied class to add custom clearing for any chart type. default implementation deletes all chartItem components from this transform /// </summary> protected virtual void ClearChart() { mHovered.Clear(); if (TextController != null) // destroy all child text object { TextController.DestroyAll(); TextController.transform.SetParent(transform, false); // the text controller my not be a direct child of this gameobject , make it so that it is. } // destroy all child ChartItem objects ChartItem[] children = GetComponentsInChildren <ChartItem>(); for (int i = 0; i < children.Length; ++i) { if (children[i] != null) { RectMask2D mask = children[i].GetComponent <RectMask2D>(); if (mask != null) { Debug.Log(mask.gameObject); } if (TextController != null && children[i].gameObject == TextController.gameObject) { continue; } if (children[i].gameObject.GetComponent <ChartItemNoDelete>() != null) { continue; } if (children[i].gameObject != gameObject) { ChartCommon.SafeDestroy(children[i].gameObject); } } } // ensure the text controller has been created ( it is generated only when the graph chart is first created) EnsureTextController(); //destroy all axis components in this chart for (int i = 0; i < mAxis.Count; i++) { if (mAxis[i] != null && mAxis[i].This() != null) { ChartCommon.SafeDestroy(mAxis[i].GetGameObject()); } } mAxis.Clear(); }
void SetRendererColor(Color c) { if (mRenderer == null) { mRenderer = GetComponent <Renderer>(); } if (mRenderer != null) { if (c == GetColorCombine(materials.Normal) && mMouseOver == false && mMouseDown == false) { ChartCommon.SafeDestroy(mRenderer.material); mRenderer.material = null; mRenderer.sharedMaterial = materials.Normal; mLerping = false; } else { SetColorCombine(mRenderer.material, c); } } else { if (mCanvasRenderer == null) { mCanvasRenderer = GetComponent <Graphic>(); } if (mCanvasRenderer != null) { if (mMat == null) { mMat = new Material(materials.Normal); mMat.hideFlags = HideFlags.DontSave; mCanvasRenderer.material = mMat; } if (mCanvasRenderer.material != mMat) { mCanvasRenderer.material = mMat; } SetColorCombine(mMat, c); if (c == GetColorCombine(materials.Normal) && mMouseOver == false && mMouseDown == false) { mLerping = false; mCanvasRenderer.material = materials.Normal; } } } }
void FitCanvas() { RectTransform trans = GetComponent <RectTransform>(); mLastSetSize = trans.rect.size; if (FitAspectCanvas == false) { return; } ChartMagin margin = MarginLink; if (mFixPosition != null) { ChartCommon.SafeDestroy(mFixPosition); } GameObject fixPosition = new GameObject(); mFixPosition = fixPosition; ChartCommon.HideObject(fixPosition, hideHierarchy); // fixPosition.AddComponent<ChartItem>(); // var fixPositionRect = fixPosition.GetComponent<RectTransform>(); // fixPositionRect.anchorMin = new Vector2(1f, 1f); // fixPositionRect.anchorMax = new Vector2(1f, 1f); fixPosition.transform.position = transform.position; while (gameObject.transform.childCount > 0) { transform.GetChild(0).SetParent(fixPosition.transform, false); } fixPosition.transform.SetParent(transform, false); fixPosition.transform.localScale = new Vector3(1f, 1f, 1f); float totalWidth = TotalWidthLink; // + margin.Left + margin.Right; float totalHeight = TotalHeightLink; // + margin.Top + margin.Bottom; float widthScale = (trans.rect.size.x - margin.Left - margin.Right) / totalWidth; float heightScale = (trans.rect.size.y - margin.Top - margin.Bottom) / totalHeight; float uniformScale = Math.Min(widthScale, heightScale); fixPosition.transform.localScale = new Vector3(uniformScale, uniformScale, uniformScale); if (MaintainLabelSize) { TextController.SetInnerScale(1f / uniformScale); } else { TextController.SetInnerScale(1f); } Vector3 offs = CanvasFitOffset; fixPosition.transform.localPosition = new Vector3(-totalWidth * uniformScale * offs.x + Mathf.Lerp(margin.Left, -margin.Right, offs.x), -totalHeight * uniformScale * offs.y - Mathf.Lerp(margin.Top, -margin.Bottom, offs.y), 0f); }
void DestoryBillboard(BillboardText t) { t.Recycled = false; Text uiText = t.UIText; TextDirection d = t.Direction; if (uiText != null && uiText.gameObject != null) { ChartCommon.SafeDestroy(uiText.gameObject); } if (d != null && d.gameObject != null) { ChartCommon.SafeDestroy(d.gameObject); } if (t != null) { ChartCommon.SafeDestroy(t.gameObject); } }
protected virtual void ClearChart() { mHovered.Clear(); if (TextController != null) { TextController.DestroyAll(); TextController.transform.SetParent(transform, false); } ChartItem[] children = GetComponentsInChildren <ChartItem>(); for (int i = 0; i < children.Length; ++i) { if (children[i] != null) { RectMask2D mask = children[i].GetComponent <RectMask2D>(); if (mask != null) { Debug.Log(mask.gameObject); } if (TextController != null && children[i].gameObject == TextController.gameObject) { continue; } if (children[i].gameObject != gameObject) { ChartCommon.SafeDestroy(children[i].gameObject); } } } EnsureTextController(); for (int i = 0; i < mAxis.Count; i++) { if (mAxis[i] != null && mAxis[i].This() != null) { ChartCommon.SafeDestroy(mAxis[i].GetGameObject()); } } mAxis.Clear(); }
protected override void ClearChart() { base.ClearChart(); foreach (BarObject bar in mBars.Values) { if (bar != null) { if (bar.Bar != null) { bar.Bar.Clear(); MonoBehaviour b = bar.Bar as MonoBehaviour; if (b != null) { ChartCommon.SafeDestroy(b.gameObject); } } if (bar.TopObject != null) { ChartCommon.SafeDestroy(bar.TopObject); } } } mBars.Clear(); }
/// <summary> /// override this method in a dervied class to add custom clearing for any chart type. default implementation deletes all chartItem components from this transform /// </summary> protected virtual void ClearChart() { //#if UNITY_2018_3_OR_NEWER //#if UNITY_EDITOR // // if (Application.isEditor == true && Application.isPlaying == false) // // { // var path = UnityEditor.PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(gameObject); // if (!(path == null || path.Trim().Length == 0)) // { // // Load the contents of the Prefab Asset. // GameObject contentsRoot = UnityEditor.PrefabUtility.LoadPrefabContents(path); // bool save = false; // // Modify Prefab contents. // foreach (var item in contentsRoot.GetComponentsInChildren<ChartItem>()) // { // if (item == null) // continue; // if (item.gameObject != null) // { // save = true; // DestroyImmediate(item.gameObject); // } // } // if (save) // { // // try // // { // UnityEditor.PrefabUtility.SaveAsPrefabAsset(contentsRoot, path); // // } // // catch (Exception e) // // { // // } // } // UnityEditor.PrefabUtility.UnloadPrefabContents(contentsRoot); // } // // } //#endif //#endif mHovered.Clear(); if (TextController != null) // destroy all child text object { TextController.DestroyAll(); TextController.transform.SetParent(transform, false); // the text controller my not be a direct child of this gameobject , make it so that it is. } // destroy all child ChartItem objects ChartItem[] children = GetComponentsInChildren <ChartItem>(); for (int i = 0; i < children.Length; ++i) { if (children[i] != null) { RectMask2D mask = children[i].GetComponent <RectMask2D>(); if (mask != null) { // Debug.Log(mask.gameObject); } if (TextController != null && children[i].gameObject == TextController.gameObject) { continue; } if (children[i].gameObject.GetComponent <ChartItemNoDelete>() != null) { continue; } if (children[i].gameObject.GetComponentInParent <AnyChart>() != this) { continue; } if (children[i].gameObject != gameObject) { ChartCommon.SafeDestroy(children[i].gameObject); } } } // ensure the text controller has been created ( it is generated only when the graph chart is first created) EnsureTextController(); //destroy all axis components in this chart for (int i = 0; i < mAxis.Count; i++) { if (mAxis[i] != null && mAxis[i].This() != null) { ChartCommon.SafeDestroy(mAxis[i].GetGameObject()); } } mAxis.Clear(); }
protected override void OnDisable() { base.OnDisable(); ChartCommon.SafeDestroy(mCachedMaterial); }
void FitCanvas() { RectTransform trans = GetComponent <RectTransform>(); mLastSetSize = trans.rect.size; if (ShouldFitCanvas == false) { return; } // if (FitAspectCanvas == FitType.None) // return; ChartMagin margin = MarginLink; if (mFixPosition != null) { ChartCommon.SafeDestroy(mFixPosition); } GameObject fixPosition = new GameObject(); var fixRect = fixPosition.AddComponent <RectTransform>(); mFixPosition = fixPosition; ChartCommon.HideObject(fixPosition, hideHierarchy); fixPosition.AddComponent <ChartItem>(); float totalWidth = TotalWidthLink; // + margin.Left + margin.Right; float totalHeight = TotalHeightLink; // + margin.Top + margin.Bottom; fixRect.SetParent(transform, false); fixRect.localPosition = Vector3.zero; fixRect.anchorMin = new Vector2(0f, 0f); fixRect.anchorMax = new Vector2(0f, 0f); fixRect.pivot = new Vector2(0f, 0f); fixRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, totalWidth); fixRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, totalHeight); float xAnchor = 0.5f; float yAnchor = 0.5f; if (FitAlignCanvas == FitAlign.StartXCenterY || FitAlignCanvas == FitAlign.StartXStartY) { xAnchor = 0f; } if (FitAlignCanvas == FitAlign.CenterXStartY || FitAlignCanvas == FitAlign.StartXStartY) { yAnchor = 0f; } fixPosition.transform.localScale = new Vector3(1f, 1f, 1f); fixPosition.transform.SetSiblingIndex(0); toMove.Clear(); for (int i = 0; i < gameObject.transform.childCount; i++) { var child = trans.GetChild(i).gameObject; if (child == null) { continue; } if (child == fixPosition) { continue; } if (child.GetComponent <AnyChart>() != null) { continue; } if (child.GetComponent <ChartItem>() == null) { continue; } toMove.Add(child); } foreach (GameObject obj in toMove) { obj.transform.SetParent(fixPosition.transform, false); } toMove.Clear(); fixRect.anchorMin = new Vector2(xAnchor, yAnchor); fixRect.anchorMax = new Vector2(xAnchor, yAnchor); fixRect.pivot = new Vector2(xAnchor, yAnchor); if (totalWidth <= 0 || TotalHeight <= 0) { return; } float widthScale = (trans.rect.size.x - margin.Left - margin.Right) / totalWidth; float heightScale = (trans.rect.size.y - margin.Top - margin.Bottom) / totalHeight; float uniformScale = Math.Min(widthScale, heightScale); if (FitAspectCanvas == FitType.Height) { uniformScale = heightScale; } else if (FitAspectCanvas == FitType.Width) { uniformScale = widthScale; } else if (FitAspectCanvas == FitType.None) { uniformScale = 1f; } fixRect.localScale = new Vector3(uniformScale, uniformScale, 1f); if (MaintainLabelSize) { TextController.SetInnerScale(1f / uniformScale); } else { TextController.SetInnerScale(1f); } fixRect.anchoredPosition = new Vector3(Mathf.Lerp(margin.Left, -margin.Right, xAnchor), Mathf.Lerp(margin.Bottom, -margin.Top, yAnchor), 0f); }
public void Clear() { ChartCommon.SafeDestroy(mCandle); ChartCommon.SafeDestroy(mLine); ChartCommon.SafeDestroy(mOutline); }
private void GeneratePyramid(bool update) { if (update == false) { ClearChart(); } else { EnsureTextController(); } if (((IInternalPyramidData)Data).InternalDataSource == null) { return; } double[,] data = ((IInternalPyramidData)Data).InternalDataSource.getRawData(); int rowCount = data.GetLength(0); int columnCount = data.GetLength(1); if (rowCount != 1) // row count for pie must be 1 { return; } double total = 0.0; for (int i = 0; i < columnCount; ++i) { double val = Math.Max(data[0, i], 0); total += val; } var rectTrans = GetComponent <RectTransform>(); totalHeight = rectTrans.rect.height; totalWidth = rectTrans.rect.width; float baseX1 = 0; float baseX2 = totalWidth; float accumilatedHeight = 0; float?firstCenterHeight = null; float acummilatedWeight = 0; for (int i = 0; i < columnCount; ++i) { object userData = ((IInternalPyramidData)Data).InternalDataSource.Columns[i].UserData; var categoryData = ((PyramidData.CategoryData)userData); string name = ((IInternalPyramidData)Data).InternalDataSource.Columns[i].Name; double amount = Math.Max(data[0, i], 0); if (amount == 0f) { continue; } float weight = (float)(amount / total); float actualHeight = totalHeight * weight; float slopeRight = categoryData.RightSlope; float slopeLeft = categoryData.LeftSlope; float atan; switch (slope) { case SlopeType.Center: atan = -Mathf.Atan2(totalHeight, totalWidth * 0.5f) * Mathf.Rad2Deg + 90; slopeRight = atan; slopeLeft = atan; break; case SlopeType.Left: atan = -Mathf.Atan2(totalHeight, totalWidth) * Mathf.Rad2Deg + 90; slopeLeft = 0; slopeRight = atan; break; case SlopeType.Right: atan = -Mathf.Atan2(totalHeight, totalWidth) * Mathf.Rad2Deg + 90; slopeLeft = atan; slopeRight = 0; break; default: break; } GameObject pyramidObject = null; GameObject pyramidBackObject = null; IPyramidGenerator generator = null; IPyramidGenerator backgenerator = null; PyramidObject dataObject; float centerHeight = actualHeight * 0.5f + accumilatedHeight; float unblendedHeight = centerHeight; if (firstCenterHeight.HasValue == false) { firstCenterHeight = centerHeight; } centerHeight = Mathf.Lerp(firstCenterHeight.Value, centerHeight, categoryData.PositionBlend); if (mPyramids.TryGetValue(name, out dataObject)) { pyramidBackObject = dataObject.backObject; pyramidObject = dataObject.pyramidObject; backgenerator = dataObject.BackGenerator; generator = dataObject.Generator; generator.SetParams(baseX1, baseX2, totalWidth, slopeLeft, slopeRight, actualHeight, inset, 0f, 1f); if (backgenerator != null) { backgenerator.SetParams(baseX1, baseX2, totalWidth, slopeLeft, slopeRight, actualHeight, 0f, acummilatedWeight, acummilatedWeight + weight); } if (dataObject.ItemLabel) { Vector3 labelPos = AlignTextPosition(mItemLabels, dataObject, generator, centerHeight); dataObject.ItemLabel.transform.localPosition = labelPos; ChartCommon.UpdateTextParams(dataObject.ItemLabel.UIText, categoryData.Title); } } else { dataObject = new PyramidObject(); if (backMaterial != null) { var backGenerator = PreparePyramidObject(out pyramidBackObject); backGenerator.SetParams(baseX1, baseX2, totalWidth, slopeLeft, slopeRight, actualHeight, 0f, acummilatedWeight, acummilatedWeight + weight); dataObject.backObject = pyramidBackObject; dataObject.BackGenerator = backGenerator; ChartCommon.HideObject(pyramidBackObject, hideHierarchy); pyramidBackObject.transform.SetParent(transform, false); ChartCommon.EnsureComponent <ChartItem>(pyramidBackObject); ChartMaterialController backcontrol = ChartCommon.EnsureComponent <ChartMaterialController>(pyramidBackObject); backcontrol.Materials = new ChartDynamicMaterial(backMaterial); foreach (var itemEffect in pyramidBackObject.GetComponents <ChartItemEffect>()) { ChartCommon.SafeDestroy(itemEffect); } ChartCommon.SafeDestroy(backGenerator.ContainerObject); } generator = PreparePyramidObject(out pyramidObject); generator.SetParams(baseX1, baseX2, totalWidth, slopeLeft, slopeRight, actualHeight, inset, 0f, 1f); ChartCommon.HideObject(pyramidObject, hideHierarchy); pyramidObject.transform.SetParent(transform, false); ChartCommon.EnsureComponent <ChartItem>(pyramidObject); ChartMaterialController control = ChartCommon.EnsureComponent <ChartMaterialController>(pyramidObject); control.Materials = Data.GetMaterial(name); control.Refresh(); dataObject.Generator = generator; dataObject.category = name; dataObject.pyramidObject = pyramidObject; mPyramids.Add(name, dataObject); CharItemEffectController effect = ChartCommon.EnsureComponent <CharItemEffectController>(pyramidObject); effect.WorkOnParent = false; effect.InitialScale = false; ChartItemEvents[] events = pyramidObject.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 = dataObject; } if (mItemLabels != null) { Vector3 labelPos = AlignTextPosition(mItemLabels, dataObject, generator, 0f); float angle = justification == JustificationType.LeftAligned ? -180f : 180f; BillboardText billboard = ChartCommon.CreateBillboardText(null, mItemLabels.TextPrefab, dataObject.pyramidObject.transform, categoryData.Title, labelPos.x, labelPos.y, labelPos.z, angle, null, hideHierarchy, mItemLabels.FontSize, mItemLabels.FontSharpness); dataObject.ItemLabel = billboard; dataObject.ItemLabel.transform.localPosition = labelPos; TextController.AddText(billboard); } } dataObject.Text = categoryData.Text; dataObject.Title = categoryData.Title; if (IsCanvas) { if (pyramidObject != null) { Vector2 actualPosition = new Vector2(0.5f, centerHeight) + categoryData.Shift; actualPosition = new Vector2(actualPosition.x, actualPosition.y / TotalHeight); var objectRect = pyramidObject.GetComponent <RectTransform>(); objectRect.pivot = new Vector2(0.5f, 0.5f); objectRect.anchorMin = actualPosition; objectRect.anchorMax = actualPosition; objectRect.anchoredPosition = new Vector2(); objectRect.sizeDelta = new Vector2(totalWidth, actualHeight); } if (pyramidBackObject != null) { Vector2 actualPosition = new Vector2(0.5f, unblendedHeight); actualPosition = new Vector2(actualPosition.x, actualPosition.y / TotalHeight); var objectRect = pyramidBackObject.GetComponent <RectTransform>(); objectRect.pivot = new Vector2(0f, 0f); objectRect.anchorMin = actualPosition; objectRect.anchorMax = actualPosition; objectRect.anchoredPosition = new Vector2(); } } accumilatedHeight += actualHeight; acummilatedWeight += weight; if (backgenerator != null) { backgenerator.Generate(); } generator.Generate(); generator.GetUpperBase(out baseX1, out baseX2); generator.ApplyInfo(categoryData.Title, categoryData.Text, categoryData.Image, categoryData.Scale); generator.SetAlpha(categoryData.Alpha); } }