コード例 #1
0
        protected void AddBillboardText(string cat, int index, BillboardText text)
        {
            if (text.UIText != null)
            {
                ChartCommon.MakeMaskable(text.UIText, false);
            }
            Dictionary <int, BillboardText> addTo;

            if (mTexts.TryGetValue(cat, out addTo) == false)
            {
                addTo = new Dictionary <int, BillboardText>(ChartCommon.DefaultIntComparer);
                mTexts.Add(cat, addTo);
            }
            addTo.Add(index, text);
        }
コード例 #2
0
ファイル: CanvasCandle.cs プロジェクト: hsinpa/IdleGame_Space
        private CanvasCandleGraphic CreateCandleGraphic()
        {
            GameObject          obj     = ChartCommon.CreateCanvasChartItem();
            CanvasCandleGraphic graphic = obj.AddComponent <CanvasCandleGraphic>();

            graphic.maskable = true;
            RectTransform rect = obj.GetComponent <RectTransform>();

            rect.SetParent(transform, false);
            rect.anchoredPosition = Vector3.zero;
            rect.rotation         = Quaternion.identity;
            rect.localScale       = new Vector3(1f, 1f, 1f);
            HookEventsForGraphic(graphic);
            return(graphic);
        }
        protected RadarFill CreateFillObject(GameObject conatiner)
        {
            GameObject obj = ChartCommon.CreateCanvasChartItem();

            ChartCommon.HideObject(obj, hideHierarchy);
            obj.AddComponent <ChartItem>();
            obj.AddComponent <CanvasRenderer>();
            RadarFill fill = obj.AddComponent <RadarFill>();

            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);
        }
コード例 #4
0
        IEnumerable <UIVertex> getDotVeritces()
        {
            if (mLines == null)
            {
                yield break;
            }
            float z        = 0f;
            float halfSize = mPointSize * 0.5f;

            for (int i = 0; i < mLines.Count; ++i)
            {
                LineSegement seg   = mLines[i];
                int          total = seg.PointCount;
                for (int j = mMinModifyIndex; j < total; ++j)
                {
                    Vector4 magPoint = seg.getPoint(j);
                    if (magPoint.w == 0f)
                    {
                        continue;
                    }

                    Vector3 point = (Vector3)magPoint;
                    halfSize = mPointSize * 0.5f;
                    ProcesssPoint(ref magPoint, ref halfSize);
                    Vector3 p1  = point + new Vector3(-halfSize, -halfSize, 0f);
                    Vector3 p2  = point + new Vector3(halfSize, -halfSize, 0f);
                    Vector3 p3  = point + new Vector3(-halfSize, halfSize, 0f);
                    Vector3 p4  = point + new Vector3(halfSize, halfSize, 0f);
                    Vector2 uv1 = new Vector2(0f, 0f);
                    Vector2 uv2 = new Vector2(1f, 0f);
                    Vector2 uv3 = new Vector2(0f, 1f);
                    Vector2 uv4 = new Vector2(1f, 1f);

                    UIVertex v1 = ChartCommon.CreateVertex(p1, uv1, z);
                    UIVertex v2 = ChartCommon.CreateVertex(p2, uv2, z);
                    UIVertex v3 = ChartCommon.CreateVertex(p3, uv3, z);
                    UIVertex v4 = ChartCommon.CreateVertex(p4, uv4, z);

                    yield return(v1);

                    yield return(v2);

                    yield return(v3);

                    yield return(v4);
                }
            }
        }
コード例 #5
0
 private CanvasLines AddLineRenderer(GameObject topObject, CanvasLines.LineSegement line)
 {
     GameObject obj = ChartCommon.CreateCanvasChartItem();
     obj.transform.SetParent(topObject.transform);
     obj.transform.localScale = new Vector3(1f, 1f, 1f);
     obj.transform.localPosition = new Vector3(0f, 0f, 0f);
     obj.transform.localRotation = Quaternion.identity;
     CanvasLines lines = obj.AddComponent<CanvasLines>();
     lines.raycastTarget = false;
     var lst = new List<CanvasLines.LineSegement>();
     lst.Add(line);
     lines.SetLines(lst);
     lines.Thickness = LineThicknessLink;
     lines.material = LineMaterialLink;
     return lines;
 }
コード例 #6
0
        protected CanvasLines CreateLinesObject(GameObject conatiner)
        {
            GameObject obj = ChartCommon.CreateCanvasChartItem();

            ChartCommon.HideObject(obj, hideHierarchy);
            obj.AddComponent <ChartItem>();
            var rend = obj.AddComponent <CanvasRenderer>();

            rend.cullTransparentMesh = false;
            CanvasLines lines = obj.AddComponent <CanvasLines>();

            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(lines);
        }
コード例 #7
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);
        }
コード例 #8
0
        /// <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 != 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();
        }
コード例 #9
0
        protected void TransformPoints(IList <DoubleVector3> points, Rect viewRect, DoubleVector3 min, DoubleVector3 max)
        {
            DoubleVector3 range = max - min;

            if (range.x <= 0.0001f || range.y < 0.0001f)
            {
                return;
            }
            double radiusMultiplier = Math.Min(viewRect.width / range.x, viewRect.height / range.y);

            for (int i = 0; i < points.Count; i++)
            {
                DoubleVector3 point = points[i];
                DoubleVector4 res   = ChartCommon.interpolateInRect(viewRect, new DoubleVector3((point.x - min.x) / range.x, (point.y - min.y) / range.y));
                res.z     = point.z * radiusMultiplier;
                points[i] = res.ToDoubleVector3();
            }
        }
コード例 #10
0
        private void HandleMouseDrag()
        {
            if (verticalPanning == false && horizontalPanning == false)
            {
                return;
            }
            mCaster = GetComponentInParent <GraphicRaycaster>();
            if (mCaster == null)
            {
                return;
            }
            if (Application.isPlaying == false)
            {
                return;
            }

            Vector2 mousePos;
            var     chart   = GetComponentInParent <AnyChart>();
            var     pointer = ChartCommon.EnsureComponent <CustomChartPointer>(chart.gameObject);

            if (pointer == null)
            {
                return;
            }
            Vector3 checkMousePos = pointer.ScreenPosition;

            RectTransformUtility.ScreenPointToLocalPointInRectangle(transform as RectTransform, checkMousePos, mCaster.eventCamera, out mousePos);
            var  cam     = mCaster.eventCamera;
            bool mouseIn = RectTransformUtility.RectangleContainsScreenPoint(transform as RectTransform, checkMousePos, cam);

            if (((pointer != null && pointer.IsMouseDown)) && mouseIn)
            {
                if (mLastPosition.HasValue)
                {
                    Vector2 delta = mousePos - mLastPosition.Value;
                    MouseDraged(delta);
                }
                mLastPosition = mousePos;
            }
            else
            {
                mLastPosition = null;
            }
        }
コード例 #11
0
        void Update()
        {
            float opTime = Time.time - mStartTime;

            opTime *= TimeScale;
            float val;

            switch (Operation)
            {
            case GrowOp:
                FixEaseFunction(GrowEaseFunction);
                val = GrowEaseFunction.Evaluate(opTime);
                mScaleMultiplier = ChartCommon.SmoothLerp(mStartValue, GrowMultiplier, val);
                if (CheckAnimationEnded(opTime, GrowEaseFunction))
                {
                    Operation        = NoOp;
                    mScaleMultiplier = GrowMultiplier;
                }
                break;

            case ShrinkOp:
                FixEaseFunction(ShrinkEaseFunction);
                val = ShrinkEaseFunction.Evaluate(opTime);
                mScaleMultiplier = ChartCommon.SmoothLerp(mStartValue, 1f, val);
                if (CheckAnimationEnded(opTime, ShrinkEaseFunction))
                {
                    Operation        = NoOp;
                    mScaleMultiplier = 1f;
                }
                break;

            case GrowShrinkOp:
                FixEaseFunction(GrowEaseFunction);
                val = GrowEaseFunction.Evaluate(opTime);
                mScaleMultiplier = ChartCommon.SmoothLerp(mStartValue, GrowMultiplier, val);
                if (CheckAnimationEnded(opTime, GrowEaseFunction))
                {
                    mScaleMultiplier = GrowMultiplier;
                    Shrink();
                }
                break;
            }
        }
コード例 #12
0
        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);
            }
        }
コード例 #13
0
        public virtual BillboardText AddText(AnyChart chart, MonoBehaviour prefab, Transform parentTransform, int fontSize, float fontSharpness, string text, float x, float y, float z, float angle, object userData)
        {
            BillboardText recycled = null;

            if (RecycleText == true)
            {
                if (mRecycled.TryGetValue(text, out recycled))
                {
                    recycled.SetVisible(true);
                    recycled.Recycled = false;
                    mRecycled.Remove(text);
                }
                else
                {
                    if (mCached.Count > 0)
                    {
                        recycled = mCached[mCached.Count - 1];
                        recycled.SetVisible(true);
                        recycled.Recycled = false;
                        mCached.RemoveAt(mCached.Count - 1);
                    }
                    else
                    {
                        recycled = null;
                    }
                }
            }

            BillboardText billboardText = ChartCommon.CreateBillboardText(recycled, prefab, parentTransform, text, x, y, z, angle, null, ((IInternalUse)chart).HideHierarchy, fontSize, fontSharpness);

            if (billboardText == null)
            {
                return(null);
            }
            billboardText.Recycled = false;
            billboardText.UserData = userData;
            if (recycled == null)
            {
                mText.Add(billboardText);
            }
            mCurrentTexts.Add(billboardText);
            return(billboardText);
        }
コード例 #14
0
        private CanvasCandle CreateDataObject(CandleChartData.CategoryData data, GameObject rectMask)
        {
            GameObject obj = new GameObject("Candles", typeof(RectTransform));

            ChartCommon.HideObject(obj, hideHierarchy);
            obj.AddComponent <ChartItem>();
            RectTransform t = obj.GetComponent <RectTransform>();

            obj.AddComponent <CanvasRenderer>();
            CanvasCandle candles = obj.AddComponent <CanvasCandle>();

            t.SetParent(rectMask.transform, false);
            t.localScale       = new Vector3(1f, 1f, 1f);
            t.anchorMin        = new Vector2(0f, 0f);
            t.anchorMax        = new Vector2(0f, 0f);
            t.anchoredPosition = Vector3.zero;
            t.localRotation    = Quaternion.identity;
            return(candles);
        }
コード例 #15
0
        void PickLine(Vector3 mouse, out int segment, out int line)
        {
            float minDist = Mathf.Infinity;

            segment = -1;
            line    = -1;

            if (mLines == null)
            {
                return;
            }
            for (int i = 0; i < mLines.Count; ++i)
            {
                LineSegement seg   = mLines[i];
                int          total = seg.LineCount;
                for (int j = 0; j < total; ++j)
                {
                    Vector3 from;
                    Vector3 to;
                    seg.GetLine(j, out from, out to);
                    float dist = ChartCommon.SegmentPointSqrDistance(from, to, mouse);
                    if (dist < minDist)
                    {
                        minDist = dist;
                        segment = i;
                        line    = j;
                    }
                }
            }
            float sensitivity = 10f;

            if (mControl != null)
            {
                sensitivity = mControl.Sensitivity;
            }
            float thresh = (Thickness + sensitivity);

            if ((ViewRect.HasValue && !ViewRect.Value.Contains(mouse)) || minDist > thresh * thresh)
            {
                segment = -1;
                line    = -1;
            }
        }
コード例 #16
0
        public void Generate(float startAngle, float angleSpan, float radius, float innerRadius, int segments, float outerDepth, float innerDepth)
        {
            WorldSpaceChartMesh mesh = new WorldSpaceChartMesh(1);
            float maxDepth           = Mathf.Max(outerDepth, innerDepth);

            if (maxDepth <= 0f)
            {
                PieMesh.Generate2dMesh(mesh, startAngle, angleSpan, radius, innerRadius, segments);
            }
            else
            {
                PieMesh.Generate3dMesh(mesh, startAngle, angleSpan, radius, innerRadius, segments, outerDepth, innerDepth);
            }

            if (mCleanMesh != null)
            {
                mCleanMesh.Clear();
                mesh.ApplyToMesh(mCleanMesh);
                MeshCollider collider = ChartCommon.EnsureComponent <MeshCollider>(gameObject);
                if (collider != null)
                {
                    collider.sharedMesh = null;
                    collider.sharedMesh = mCleanMesh;
                }
            }
            else
            {
                Mesh newMesh = mesh.Generate();
                newMesh.hideFlags = HideFlags.DontSave;
                if (mFilter == null)
                {
                    mFilter = GetComponent <MeshFilter>();
                }
                mFilter.sharedMesh = newMesh;
                MeshCollider collider = ChartCommon.EnsureComponent <MeshCollider>(gameObject);
                if (collider != null)
                {
                    collider.sharedMesh = newMesh;
                }
                ChartCommon.CleanMesh(newMesh, ref mCleanMesh);
            }
        }
コード例 #17
0
 public virtual void Clear()
 {
     if (RecycleText)
     {
         for (int i = 0; i < mCurrentTexts.Count; i++)
         {
             string key = ChartCommon.GetText(mCurrentTexts[i].UIText);
             mCurrentTexts[i].SetVisible(false);
             mCurrentTexts[i].Recycled = true;
             if (key == null || mRecycled.ContainsKey(key))
             {
                 mCached.Add(mCurrentTexts[i]);
                 continue;
             }
             mRecycled[key] = mCurrentTexts[i];
         }
     }
     mText.Clear();
     mCurrentTexts.Clear();
 }
コード例 #18
0
        protected override IPieGenerator PreparePieObject(out GameObject pieObject)
        {
            if (Prefab == null)
            {
                pieObject = new GameObject();
            }
            else
            {
                pieObject = GameObject.Instantiate(Prefab);
            }
            ChartCommon.EnsureComponent <MeshFilter>(pieObject);
            ChartCommon.EnsureComponent <MeshRenderer>(pieObject);
            IPieGenerator gen = pieObject.GetComponent <IPieGenerator>();

            if (gen != null)
            {
                return(gen);
            }
            return(ChartCommon.EnsureComponent <WorldSpacePieGenerator>(pieObject));
        }
コード例 #19
0
        protected void TransformPoints(IList <DoubleVector4> points, List <Vector4> output, Rect viewRect, DoubleVector3 min, DoubleVector3 max)
        {
            output.Clear();
            DoubleVector3 range = max - min;

            if (Math.Abs(range.x) <= 0.0001f || Math.Abs(range.y) < 0.0001f)
            {
                return;
            }
            double radiusMultiplier = Math.Min(viewRect.width / Math.Abs(range.x), viewRect.height / Math.Abs(range.y));

            for (int i = 0; i < points.Count; i++)
            {
                DoubleVector4 point = points[i];
                DoubleVector4 res   = ChartCommon.interpolateInRect(viewRect, new DoubleVector3((point.x - min.x) / range.x, (point.y - min.y) / range.y));
                res.z = 0.0;
                res.w = point.w * radiusMultiplier;
                output.Add(res.ToVector4());
            }
        }
コード例 #20
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);
        }
コード例 #21
0
ファイル: AxisBase.cs プロジェクト: jalvarez2000/Independence
        /// <summary>
        /// used internally , adds the axis main divisions to the chart mesh
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="parentTransform"></param>
        /// <param name="mesh"></param>
        /// <param name="orientation"></param>

        internal void AddMainDivisionToChartMesh(double scrollOffset, AnyChart parent, Transform parentTransform, IChartMesh mesh, ChartOrientation orientation)
        {
            double maxValue = ((IInternalUse)parent).InternalMaxValue(this);
            double minValue = ((IInternalUse)parent).InternalMinValue(this);
            double range    = maxValue - minValue;
            double?gap      = GetMainGap(parent, range);

            if (gap.HasValue == false)
            {
                return;
            }
            mesh.Tile = ChartCommon.GetTiling(MainDivisions.MaterialTiling);
            if ((MainDivisions.Alignment & ChartDivisionAligment.Opposite) == ChartDivisionAligment.Opposite)
            {
                DrawDivisions(scrollOffset, parent, parentTransform, MainDivisions, mesh, 0, orientation, gap.Value, false, -1);
            }
            if ((MainDivisions.Alignment & ChartDivisionAligment.Standard) == ChartDivisionAligment.Standard)
            {
                DrawDivisions(scrollOffset, parent, parentTransform, MainDivisions, mesh, 0, orientation, gap.Value, true, -1);
            }
        }
コード例 #22
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="t"></param>
        /// <param name="prefab"></param>
        /// <returns></returns>
        ScrollableAxisChart IMixedChartDelegate.CreateCategoryView(Type t, ScrollableAxisChart prefab)
        {
            string type = t.FullName;
            ScrollableAxisChart chart = prefab;

            if (chart == null)
            {
                if (mPrefabs == null || mPrefabs.TryGetValue(type, out chart) == false)
                    return null;
            }

            if (chart.IsCanvas != IsCanvas)
                return null;

            GameObject obj = (GameObject)GameObject.Instantiate(chart.gameObject);
            obj.transform.SetParent(transform);
            ChartCommon.HideObject(obj, true);
            chart = obj.GetComponent<ScrollableAxisChart>();
            mContainedCharts.Add(chart);
            return chart;
        }
コード例 #23
0
        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();
        }
コード例 #24
0
#pragma warning restore 0672

        void FillChartMesh(IChartMesh mesh)
        {
            UIVertex v1 = vertices[0];
            UIVertex v2 = vertices[1];
            UIVertex v3 = vertices[2];
            UIVertex v4 = vertices[3];

            v1.position += (Vector3)(normals[0] * mInset);
            v2.position += (Vector3)(normals[1] * mInset);
            v3.position += (Vector3)(normals[2] * mInset);
            v4.position += (Vector3)(normals[3] * mInset);

            Vector2 inter;

            if (ChartCommon.SegmentIntersection(v1.position, v3.position, v2.position, v4.position, out inter))
            {
                v3.position = inter;
                v4.position = inter;
            }

            mesh.AddQuad(v1, v2, v3, v4);
        }
コード例 #25
0
        protected GameObject CreateRectMask(Rect viewRect)
        {
            //GameObject obj = Instantiate(Resources.Load("Chart And Graph/RectMask") as GameObject);
            GameObject obj = ChartCommon.CreateCanvasChartItem();

            obj.name = "rectMask2D";;
            ChartCommon.HideObject(obj, hideHierarchy);
            obj.AddComponent <RectMask2D>();

            //obj.AddComponent<ChartItem>();
            obj.transform.SetParent(transform, false);
            var rectTransform = obj.GetComponent <RectTransform>();

            rectTransform.anchorMin        = new Vector2(0f, 0f);
            rectTransform.anchorMax        = new Vector2(0f, 0f);
            rectTransform.pivot            = new Vector2(0f, 1f);
            rectTransform.sizeDelta        = viewRect.size;
            rectTransform.anchoredPosition = new Vector2(0f, viewRect.size.y);

            mMask = obj;
            return(obj);
        }
コード例 #26
0
        private CanvasLines CreateDataObject(GraphData.CategoryData data, GameObject rectMask, bool mask)
        {
            GameObject obj = new GameObject("Lines", typeof(RectTransform));

            ChartCommon.HideObject(obj, hideHierarchy);
            obj.AddComponent <ChartItem>();

            var rend = obj.AddComponent <CanvasRenderer>();

            rend.cullTransparentMesh = false;

            CenterObject(obj, rectMask.GetComponent <RectTransform>());
            //  Canvas c = obj.AddComponent<Canvas>();

            //c.pixelPerfect = false;
            //obj.AddComponent<GraphicRaycaster>();
            CanvasLines lines = obj.AddComponent <CanvasLines>();

            lines.maskable = true;

            return(lines);
        }
コード例 #27
0
        /// <summary>
        /// Takes a hover object out of the pool , or creates a new one if the pool is empty
        /// </summary>
        /// <param name="index">the index of the data item , this index will be assigned to the returned object</param>
        /// <returns></returns>
        public ChartItemEffect LockHoverObject(int index, int type, object selectionData)
        {
            int             count  = mHoverFreeObjects.Count;
            ChartItemEffect effect = null;

            if (count > 0)
            {
                effect = mHoverFreeObjects[count - 1];
                mHoverFreeObjects.RemoveAt(count - 1);
            }
            else
            {
                if (mHoverPrefab == null)
                {
                    return(null);
                }
                GameObject      obj = GameObject.Instantiate(mHoverPrefab.gameObject);
                MaskableGraphic g   = obj.GetComponent <MaskableGraphic>();
                if (g != null)
                {
                    g.maskable = false;
                }
                ChartCommon.EnsureComponent <ChartItem>(obj);
                Transform parent = transform;
                if (mHoverTransform != null)
                {
                    parent = mHoverTransform;
                }
                obj.transform.SetParent(parent);
                effect             = obj.GetComponent <ChartItemEffect>();
                effect.Deactivate += Effect_Deactivate;
            }

            effect.ItemType  = type;
            effect.ItemIndex = index;
            effect.ItemData  = selectionData;
            mHoverObjectes.Add(effect);
            return(effect);
        }
コード例 #28
0
ファイル: CandleChart.cs プロジェクト: hsinpa/IdleGame_Space
        public CandleChartData.CandleValue InterpolateCandleInRect(CandleChartData.CandleValue candle, Rect viewRect)
        {
            CandleChartData.CandleValue res = new CandleChartData.CandleValue();
            res.Open  = ChartCommon.interpolateInRectY(viewRect, candle.Open);
            res.Close = ChartCommon.interpolateInRectY(viewRect, candle.Close);
            res.High  = ChartCommon.interpolateInRectY(viewRect, candle.High);
            res.Low   = ChartCommon.interpolateInRectY(viewRect, candle.Low);

            if (res.High < res.Low)
            {
                double tmp = res.High;
                res.High  = res.Low;
                res.Low   = tmp;
                tmp       = res.Open;
                res.Open  = res.Close;
                res.Close = tmp;
            }
            double candleEnd = candle.Start + candle.Duration;

            candleEnd = ChartCommon.interpolateInRectX(viewRect, candleEnd);
            double start    = ChartCommon.interpolateInRectX(viewRect, candle.Start);
            double duration = candleEnd - start;

            if (start > candleEnd)
            {
                double tmp = start;
                start     = candleEnd;
                candleEnd = tmp;
            }
            if (ThicknessMode == CandleThicknessMode.Constant)
            {
                Deflate(ref start, ref duration, ThicknessConstant / duration);
            }

            res.Start    = start;
            res.Duration = duration;

            return(res);
        }
コード例 #29
0
        public static void Generate2dMesh(UIVertex[] mesh, Vector2[] normals, float baseX1, float baseX2, float baseSize, float slopLeft, float slopeRight, float height, float startV, float endV)
        {
            float halfHeight = height * 0.5f;
            float halfWidth  = baseSize * 0.5f;

            slopLeft   = -Mathf.Clamp(slopLeft, -90, 90) + 90;
            slopeRight = Mathf.Clamp(slopeRight, -90, 90) + 90;

            float tanLeft  = (1f / Mathf.Tan(slopLeft * Mathf.Deg2Rad)) * height;
            float tanRight = (1f / Mathf.Tan(slopeRight * Mathf.Deg2Rad)) * height;

            float leftPos  = baseX1 + tanLeft;
            float rightPos = baseX2 + tanRight;

            leftPos  = Mathf.Clamp(leftPos, 0, baseSize);
            rightPos = Mathf.Clamp(rightPos, 0, baseSize);


            if (leftPos > rightPos)
            {
                leftPos = rightPos = Mathf.Clamp(Mathf.Lerp(leftPos, rightPos, 0.5f), 0, baseSize);
            }

            UIVertex v1 = ChartCommon.CreateVertex(new Vector3(baseX1 - halfWidth, -halfHeight), new Vector2(0f, startV));
            UIVertex v2 = ChartCommon.CreateVertex(new Vector3(baseX2 - halfWidth, -halfHeight), new Vector2(1f, startV));
            UIVertex v3 = ChartCommon.CreateVertex(new Vector3(leftPos - halfWidth, halfHeight), new Vector2(0f, endV));
            UIVertex v4 = ChartCommon.CreateVertex(new Vector3(rightPos - halfWidth, halfHeight), new Vector2(1f, endV));

            normals[0] = ((Vector2.up + ChartCommon.Perpendicular(v3.position - v1.position).normalized) * 0.5f).normalized;
            normals[1] = ((Vector2.up + ChartCommon.Perpendicular(v2.position - v4.position).normalized) * 0.5f).normalized;
            normals[2] = ((Vector2.down + ChartCommon.Perpendicular(v3.position - v1.position).normalized) * 0.5f).normalized;
            normals[3] = ((Vector2.down + ChartCommon.Perpendicular(v2.position - v4.position).normalized) * 0.5f).normalized;

            mesh[0] = v1;
            mesh[1] = v2;
            mesh[2] = v3;
            mesh[3] = v4;
        }
コード例 #30
0
ファイル: GraphChart.cs プロジェクト: bigdot-app/BigDOT
        void FitCanvas()
        {
            RectTransform trans       = GetComponent <RectTransform>();
            GameObject    fixPosition = new GameObject();

            mFixPosition = fixPosition;
            ChartCommon.HideObject(fixPosition, hideHierarchy);
            fixPosition.AddComponent <ChartItem>();
            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 widthScale   = trans.rect.size.x / WidthRatio;
            float heightScale  = trans.rect.size.y / HeightRatio;
            float uniformScale = Math.Min(widthScale, heightScale);

            fixPosition.transform.localScale    = new Vector3(uniformScale, uniformScale, uniformScale);
            fixPosition.transform.localPosition = new Vector3(-WidthRatio * uniformScale * 0.5f, -HeightRatio * uniformScale * 0.5f, 0f);
            mLastSetSize = trans.rect.size;
        }