#define Graph_And_Chart_PRO using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; namespace ChartAndGraph.Axis { /// /// generates an axis mesh from an AxisBase settings instance. /// [RequireComponent(typeof(MeshRenderer))] [RequireComponent(typeof(MeshFilter))] [ExecuteInEditMode] partial class AxisGenerator { MeshRenderer mRenderer; MeshFilter mFilter; Mesh mCleanMesh; List mTexts; AxisBase mAxis; Material mDispose; Material mMaterial; float mTiling=1f; WorldSpaceChartMesh mMesh; Mesh mCreated; double mScroll = 0f; AnyChart mParent = null; ChartOrientation mOrientation = ChartOrientation.Vertical; int mDivType = 0; void Start() { } void OnDestroy() { ChartCommon.CleanMesh(null, ref mCleanMesh); ChartCommon.SafeDestroy(mDispose); } /// /// fix the labels after the axis data is updated /// /// partial void InnerFixLabels(AnyChart parent) { if (mAxis == null) return; if((((ChartMainDivisionInfo) mAxis.MainDivisions).Messure == ChartDivisionInfo.DivisionMessure.DataUnits) || (mDivType == 2)) { SetAxis(mScroll, mParent, mAxis, mOrientation, mDivType); return; } for(int i=0; i /// used internally to get the tiling for a chart axis division /// /// /// /// /// float GetTiling(AnyChart parent, ChartOrientation orientation, ChartDivisionInfo inf) { MaterialTiling tiling = inf.MaterialTiling; if (tiling.EnableTiling == false || tiling.TileFactor <= 0f) return 1f; float length = Math.Abs(ChartCommon.GetAutoLength(parent, orientation, inf)); float backLength = ChartCommon.GetAutoLength(parent, orientation); float depth = ChartCommon.GetAutoDepth(parent, orientation, inf); if (inf.MarkBackLength.Automatic == false) backLength = inf.MarkBackLength.Value; if (backLength != 0 && depth > 0) length += Math.Abs(backLength) + Math.Abs(depth); return length / tiling.TileFactor; } /// /// sets the axis settings. Calling this method will cause the axisgenerator to create the axis mesh /// /// /// /// /// partial void InnerSetAxis(double scrollOffset, AnyChart parent, AxisBase axis, ChartOrientation axisOrientation, int divType) { mScroll = scrollOffset; mParent = parent; mAxis = axis; mOrientation = axisOrientation; mDivType = divType; if (mMesh == null) { mMesh = new WorldSpaceChartMesh(2); mMesh.RecycleText = true; } mMesh.Clear(); mMesh.Orientation = axisOrientation; mAxis = axis; switch(divType) { case 0: axis.AddMainDivisionToChartMesh(scrollOffset, parent, transform, mMesh, axisOrientation); break; case 1: axis.AddSubdivisionToChartMesh(scrollOffset, parent, transform, mMesh, axisOrientation); break; case 2: axis.AddCustomDivisionsToChartMesh(scrollOffset, parent, transform, mMesh, axisOrientation,false); break; case 3: axis.AddCustomDivisionsToChartMesh(scrollOffset, parent, transform, mMesh, axisOrientation,true); break; } if (mMesh.TextObjects != null) { foreach (BillboardText text in mMesh.TextObjects) { ((IInternalUse)parent).InternalTextController.AddText(text); } } mTexts = mMesh.CurrentTextObjects; Mesh newMesh = mMesh.Generate(mCreated); mCreated = newMesh; newMesh.hideFlags = HideFlags.DontSave; if (mFilter == null) mFilter = GetComponent(); mFilter.sharedMesh = newMesh; MeshCollider collider = GetComponent(); if (collider != null) collider.sharedMesh = newMesh; ChartCommon.CleanMesh(newMesh, ref mCleanMesh); MeshRenderer renderer = GetComponent(); if(renderer != null) { Material m = mAxis.MainDivisions.Material; float tiling = GetTiling(parent, axisOrientation, mAxis.MainDivisions); if (divType == 1) { m = mAxis.SubDivisions.Material; tiling = GetTiling(parent, axisOrientation, mAxis.SubDivisions) ; } mMaterial = m; if (m != null) { ChartCommon.SafeDestroy(mDispose); mDispose = new Material(m); mDispose.hideFlags = HideFlags.DontSave; renderer.sharedMaterial = mDispose; mTiling = tiling; if (mDispose.HasProperty("_ChartTiling")) mDispose.SetFloat("_ChartTiling", mTiling); } } mMesh.DestoryRecycled(); } protected virtual void Update() { if (mMaterial != null && mDispose != null && mDispose.HasProperty("_ChartTiling")) { if (mDispose != mMaterial) mDispose.CopyPropertiesFromMaterial(mMaterial); mDispose.SetFloat("_ChartTiling", mTiling); } } } }