Пример #1
0
        public static void Add()
        {
            if (inprogress)
            {
                return;
            }
            inprogress = true;
            GameObject go;

            if (Selection.gameObjects.Length >= 1)
            {
                var parent = Selection.gameObjects[0];
                go = GameObjectEx.InstantiateEmptyToChild <AtlasImage>(parent, "AtlasButton").gameObject;
            }
            else
            {
                go = GameObjectEx.InstantiateEmptyToRoot <AtlasImage>("AtlasButton").gameObject;
            }
            go.GetRectTransform().sizeDelta = new Vector2(160, 30);
            go.AddComponent <Button>();
            var text = GameObjectEx.InstantiateEmptyToChild <Text>(go, "Text");

            text.text      = "Button";
            text.alignment = TextAnchor.MiddleCenter;
            text.color     = new Color(50f / 255f, 50f / 255f, 50f / 255f, 255);
            var textRT = text.rectTransform;

            textRT.sizeDelta = Vector2.zero;
            textRT.anchorMin = Vector2.zero;
            textRT.anchorMax = Vector2.one;
            Selection.SetActiveObjectWithContext(go, null);
            inprogress = false;
        }
Пример #2
0
        public static void Add()
        {
            if (inprogress)
            {
                return;
            }
            inprogress = true;
            GameObject go;

            if (Selection.gameObjects.Length >= 1)
            {
                var parent = Selection.gameObjects[0];
                go = GameObjectEx.InstantiateEmptyToChild <AtlasImage>(parent, "AtlasImage").gameObject;
            }
            else
            {
                go = GameObjectEx.InstantiateEmptyToRoot <AtlasImage>("AtlasImage").gameObject;
            }
            Selection.SetActiveObjectWithContext(go, null);
            inprogress = false;
        }
Пример #3
0
//		[SerializeField]
//		Material graphMaterial;

        protected override IEnumerator UpdateCoroutine()
        {
            do
            {
                Spy.StopwatchesStart("LineGraph.UpdateCoroutine() A");
                needUpdate = false;
                var cornersArray = new Vector3[4];
                viewRTF.GetWorldCorners(cornersArray);
                viewMinXGlobal = cornersArray[0].x;
                viewMaxXGlobal = cornersArray[2].x;
#if DEBUG_DETAIL
                paramMemo += "viewMinXGlobal:" + viewMinXGlobal + "\n";
                paramMemo += "viewMaxXGlobal:" + viewMaxXGlobal + "\n";
//				Debug.LogWarning("@@@@@@@@viewMinXGlobal:" + viewMinXGlobal);
//				Debug.LogWarning("@@@@@@@@viewMaxXGlobal:" + viewMaxXGlobal);
#endif
                // scrollRectを求める.
                //  viewRTFよりも枠線分小さくする.
                var scrollRect = new Rect(
                    hMainAxisConfig.lineThickness * 0.5f,
                    vMainAxisConfig.lineThickness * 0.5f,
                    (viewRTF.rect.width - hMainAxisConfig.lineThickness) * scaleH + hMainAxisConfig.lineThickness,
                    (viewRTF.rect.height - vMainAxisConfig.lineThickness) * scaleV + vMainAxisConfig.lineThickness);
                var graphWidth  = scrollRect.width - hMainAxisConfig.lineThickness;
                var graphHeight = scrollRect.height - vMainAxisConfig.lineThickness;

                var valueHDiff = (valueHMax - valueHMin);
//				Debug.LogWarning("@@@@@@@@valueHMin:" + valueHMin.ToString("MM / dd HH: mm"));
//				Debug.LogWarning("@@@@@@@@valueHMax:" + valueHMax.ToString("MM / dd HH: mm"));
//				Debug.LogWarning("@@@@@@@@TotalDays:" + valueHDiff.TotalDays);
//				Debug.LogWarning("@@@@@@@@Days:" + valueHDiff.Days);
//				Debug.LogWarning("@@@@@@@@m:" + valueHDiff.TotalMinutes);
                var valueVDiff = (valueVMax - valueVMin);
                graphScrollRect.content.pivot = Vector2.zero;
                graphScrollRect.content.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollRect.width);
                graphScrollRect.content.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, scrollRect.height);
                // hTextScrollRectの位置調整.
                hTextScrollRect.content.pivot = Vector2.zero;
                hTextScrollRect.content.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollRect.width);
                var hTextScrollRectRTF = hTextScrollRect.transform as RectTransform;
                hTextScrollRectRTF.offsetMin = new Vector2(viewRTF.offsetMin.x, 0);
                hTextScrollRectRTF.offsetMax = new Vector2(viewRTF.offsetMax.x, viewRTF.offsetMax.y - viewRTF.rect.height);
                // vTextScrollRectの位置調整.
                vTextScrollRect.content.pivot = Vector2.zero;
                vTextScrollRect.content.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, scrollRect.height);
                var vTextScrollRectRTF = vTextScrollRect.transform as RectTransform;
                vTextScrollRectRTF.offsetMin = new Vector2(0, viewRTF.offsetMin.y);
                vTextScrollRectRTF.offsetMax = new Vector2(viewRTF.offsetMax.x - viewRTF.rect.width, viewRTF.offsetMax.y);
                var valueHMaxTick = valueHMax.Ticks;

                Spy.StopwatchesStop("LineGraph.UpdateCoroutine() A");
                Spy.StopwatchesStart("LineGraph.UpdateCoroutine() CreateHorizontal");
//				List<Vector2> lineListMain = new List<Vector2>();
//				List<Vector2> lineListSub = new List<Vector2>();
                List <UILines.UILineData> lineData = new List <UILines.UILineData>();
                {                   // Create horizontal objects.
                    var divisions = hMainDivisions * hSubDivisions * scaleH;
                    for (var idx = 0; idx < divisions + 1; ++idx)
                    {
                        var        posH = scrollRect.x + (graphWidth / divisions) * idx;
                        AxisConfig ac   = (idx % hSubDivisions == 0) ? hMainAxisConfig : hSubAxisConfig;
//						if (ac.linePrefabPool != null)
                        {                           // Line.
#if true
                            // Add horizontal line data.(縦線データの追加.)
                            var ld = new UILines.UILineData(
                                new Vector2(posH, 0),
                                new Vector2(posH, scrollRect.height),
                                ac.lineThickness,
                                ac.lineColor);
                            lineData.Add(ld);
#else
                            // Create horizontal line.(縦線.)
                            var lineRTF = ac.linePrefabPool.Rent() as RectTransform;
                            lineRTF.anchorMin        = Vector2.zero;
                            lineRTF.anchorMax        = Vector2.zero;
                            lineRTF.pivot            = new Vector2(0.5f, 0.0f);
                            lineRTF.anchoredPosition = new Vector2(posH, 0);
                            lineRTF.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, ac.lineThickness);
                            lineRTF.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, scrollRect.height);
                            lineRTF.eulerAngles = Vector3.zero;
                            lineRTF.GetComponent <Image>().color = ac.lineColor;
#endif
                        }
                        if (ac.textPrefabPool != null)
                        {                           // Text.
                            // Create horizontal text.
                            var val     = valueHMin.Ticks + (long)(valueHDiff.Ticks / divisions) * idx;
                            var textRTF = ac.textPrefabPool.Rent() as RectTransform;
                            textRTF.anchorMin        = Vector2.up;
                            textRTF.anchorMax        = Vector2.up;
                            textRTF.pivot            = new Vector2(0.5f, 1.0f);
                            textRTF.anchoredPosition = new Vector2(posH + ac.textOffset.x, ac.textOffset.y);
                            var text = textRTF.GetComponent <Text>();
                            text.text = new DateTime(val).Round(new TimeSpan(0, 1, 0)).ToString("MM/dd HH:mm");                                 // 分で丸める.
                            if (textRTF.position.x < viewMinXGlobal - H_TEXT_COLOR_CHANGE_OFFSET ||
                                viewMaxXGlobal + H_TEXT_COLOR_CHANGE_OFFSET < textRTF.position.x)
                            {
                                text.color = new Color(ac.textColor.r, ac.textColor.g, ac.textColor.b, 0.0f);
                            }
                            else
                            {
                                text.color = ac.textColor;
                            }
                            hTextTFList.Add(textRTF);
                        }
                    }
#if true
                    /*					var graphLineRTF = graphLinePrefabPool.Rent() as RectTransform;
                     * graphLineRTF.SetParent(graphScrollRect.content, false);
                     * graphLineRTF.anchorMin = Vector2.zero;
                     * graphLineRTF.anchorMax = Vector2.zero;
                     * graphLineRTF.pivot = Vector2.zero;
                     * graphLineRTF.anchoredPosition = Vector2.zero;
                     * var polygonalLine = graphLineRTF.GetComponent<UIPolygonalMesh>();
                     * polygonalLine.width = lineThickness;
                     * polygonalLine.color = lineColor;
                     * polygonalLine.points = lineList.ToArray();
                     */
#endif
                }
                Spy.StopwatchesStop("LineGraph.UpdateCoroutine() CreateHorizontal");
                Spy.StopwatchesStart("LineGraph.UpdateCoroutine() CreateVertical");
                {                   // Create vertical objects.
                    /*					if(true)
                     *                                      {
                     *                                              var graphRenderer = GameObjectEx.InstantiateEmptyToChild<UIPolygonalLineFast>(gameObject);
                     *                                              graphRenderer.material = graphMaterial;
                     *                                              graphRenderer.width = 10;
                     *                                              graphRenderer.points = new List<Vector2>();
                     *                                              var corners = new Vector3[4];
                     *                                              viewRTF.GetLocalCorners(corners);
                     *                                              graphRenderer.points.Add(corners[0]);
                     *                                              graphRenderer.points.Add(corners[1]);
                     *                                              graphRenderer.points.Add(corners[2]);
                     *                                              graphRenderer.points.Add(corners[3]);
                     *                                      }*/

                    var divisions = vMainDivisions * vSubDivisions;
                    for (var idx = 0; idx < divisions + 1; ++idx)
                    {
                        var        posV = scrollRect.y + (graphHeight / divisions) * idx;
                        AxisConfig ac   = (idx % vSubDivisions == 0) ? vMainAxisConfig : vSubAxisConfig;
//						if (ac.linePrefabPool != null)
                        {                           // Line.
                            // Add vertical line data.(横線データの追加.)
                            var ld = new UILines.UILineData(
                                new Vector2(0, posV),
                                new Vector2(scrollRect.width, posV),
                                ac.lineThickness,
                                ac.lineColor);
                            lineData.Add(ld);
                        }
                        if (ac.textPrefabPool != null)
                        {                           // Text.
                            // Create vertical text.
                            var val     = valueVMin + (valueVDiff / divisions) * idx;
                            var textRTF = ac.textPrefabPool.Rent() as RectTransform;
                            textRTF.anchorMin        = Vector2.right;
                            textRTF.anchorMax        = Vector2.right;
                            textRTF.pivot            = Vector2.right;
                            textRTF.anchoredPosition = new Vector2(ac.textOffset.x, posV + ac.textOffset.y);
                            var text = textRTF.GetComponent <Text>();
                            text.text  = val.ToString("0." + new string('0', ac.fractionalDigits));
                            text.color = ac.textColor;
                        }
                    }
                }
                Spy.StopwatchesStop("LineGraph.UpdateCoroutine() CreateVertical");
                Spy.StopwatchesStart("LineGraph.UpdateCoroutine() CreatePosArray");
                var posArray = new Vector2[valList.Count];
                {
                    for (var idx = 0; idx < valList.Count; ++idx)
                    {
                        var val  = valList[idx];
                        var valH = val.Key;
                        var valV = val.Value;
                        posArray[idx] = new Vector2(
                            scrollRect.y + (graphWidth / valueHDiff.Ticks) * (valH.Ticks - valueHMin.Ticks),
                            scrollRect.y + (graphHeight / valueVDiff) * (valV - valueVMin));
                    }
                }
                Spy.StopwatchesStop("LineGraph.UpdateCoroutine() CreatePosArray");



                //				Debug.Log("posArray.Length :"+ posArray.Length);
                //					posArray = posArray.ToList().GetRange(169, 14).ToArray();



                Spy.StopwatchesStart("LineGraph.UpdateCoroutine() CreateBackLine");
                if (lineData.Count != 0)
                {
                    var uiLines = GameObjectEx.InstantiateEmptyToChild <UILines>(graphScrollRect.content.gameObject);
                    uiLines.lineDataArray = lineData.ToArray();
                    uiLines.raycastTarget = false;
                    var polygonalRTF = uiLines.rectTransform;
                    polygonalRTF.anchorMin        = Vector2.zero;
                    polygonalRTF.anchorMax        = Vector2.zero;
                    polygonalRTF.pivot            = Vector2.zero;
                    polygonalRTF.anchoredPosition = Vector2.zero;
                }
                Spy.StopwatchesStop("LineGraph.UpdateCoroutine() CreateBackLine");

                Spy.StopwatchesStart("LineGraph.UpdateCoroutine() CreateLine");
//graphLinePrefabPool = null;
                if (posArray.Length > 1 && graphLinePrefabPool != null)
                {                                     // Create line.
                    const int MAX_VERTS = 64000 / 10; // 本来65000/9ぐらいだが、バグが怖いので余裕を持っておく.

                    /*
                     * // テスト用に頂点を増やす.
                     *                                              var a2 = new Vector2[posArray.Length];
                     *                                              Array.Copy(posArray, a2, posArray.Length);
                     *                                              var posList = posArray.ToList();
                     *                                              while(posList.Count < MAX_VERTS / 4)
                     *                                              {
                     *                                                      posList.AddRange(a2);
                     *
                     *                                              }
                     *                                              posArray = posList.ToArray();
                     */

                    // 65000頂点までしか対応していない為、分割する.
                    if (posArray.Length < MAX_VERTS)
                    {
                        Spy.StopwatchesStart("LineGraph.UpdateCoroutine() CreateLine A");
                        var graphLineRTF = graphLinePrefabPool.Rent() as RectTransform;
                        graphLineRTF.SetParent(graphScrollRect.content, false);
                        graphLineRTF.anchorMin        = Vector2.zero;
                        graphLineRTF.anchorMax        = Vector2.zero;
                        graphLineRTF.pivot            = Vector2.zero;
                        graphLineRTF.anchoredPosition = Vector2.zero;
                        var polygonalLine = graphLineRTF.GetComponent <UIPolygonalMesh>();
                        polygonalLine.width  = lineThickness;
                        polygonalLine.color  = lineColor;
                        polygonalLine.points = posArray;
                        Spy.StopwatchesStop("LineGraph.UpdateCoroutine() CreateLine A");
                    }
                    else
                    {
                        Spy.StopwatchesStart("LineGraph.UpdateCoroutine() CreateLine B");
                        const int ChunkSize = MAX_VERTS;
                        //						Debug.Log("posArray.Length:" + posArray.Length);
                        var loopNum = (posArray.Length - 1) / ChunkSize + 1;
                        for (var idx = 0; idx < loopNum; ++idx)
                        {
                            var offset = ChunkSize * idx;
                            var count  = (idx + 1 == loopNum) ? (posArray.Length - (idx * ChunkSize)) : ChunkSize;
                            // つなぎ目の描画がきれいになるように2つ分多めに計算する.
                            count = (offset + count + 2 <= posArray.Length) ? (count + 2) : (posArray.Length - offset);
#if false
                            {                               // .Net4.5以前なのでArraySegmentを活用できない.
                                var arraySegment = new ArraySegment <Vector2>(posArray, offset, count);
                                Debug.Log("idx:" + idx + ", arraySegment.Length:" + arraySegment.Count);
                                for (int index = arraySegment.Offset; index <= arraySegment.Offset + arraySegment.Count - 1; index++)
                                {
                                    Debug.Log(" vvv:" + arraySegment.Array[index]);
                                }
                            }
#endif
                            var arraySeg = new Vector2[count];
                            Array.Copy(posArray, offset, arraySeg, 0, count);

                            var graphLineRTF = graphLinePrefabPool.Rent() as RectTransform;
                            graphLineRTF.SetParent(graphScrollRect.content, false);
                            graphLineRTF.anchorMin        = Vector2.zero;
                            graphLineRTF.anchorMax        = Vector2.zero;
                            graphLineRTF.pivot            = Vector2.zero;
                            graphLineRTF.anchoredPosition = Vector2.zero;
                            var polygonalLine = graphLineRTF.GetComponent <UIPolygonalMesh>();
                            polygonalLine.width = lineThickness;
                            polygonalLine.color = lineColor;

                            polygonalLine.points = arraySeg;
                        }
                        Spy.StopwatchesStop("LineGraph.UpdateCoroutine() CreateLine B");
                    }
                }
                Spy.StopwatchesStop("LineGraph.UpdateCoroutine() CreateLine");

/*
 *                              Spy.StopwatchesStart("LineGraph.UpdateCoroutine() CreatePoints");
 *                              // Create points.
 *                              if (pointPrefabPool != null)
 *                              {
 *                                      foreach (var pos in posArray)
 *                                      {
 *                                              var pointRTF = pointPrefabPool.Rent() as RectTransform;
 *                                              pointRTF.anchorMin = Vector2.zero;
 *                                              pointRTF.anchorMax = Vector2.zero;
 *                                              pointRTF.pivot = new Vector2(0.5f, 0.5f);
 *                                              pointRTF.anchoredPosition = pos;
 *                                              pointRTF.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, pointSize);
 *                                              pointRTF.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, pointSize);
 *                                              pointRTF.GetComponent<Image>().color = pointColor;
 #if UNITY_EDITOR
 *                                              pointRTF.GetComponent<Image>().color = ColorEx.Random;
 #endif
 *                                      }
 *                              }
 *                              Spy.StopwatchesStop("LineGraph.UpdateCoroutine() CreatePoints");
 */

                // 開始時のスクロールバーの位置を設定する.
                graphScrollRect.normalizedPosition = Vector2.right;
                hTextScrollRect.normalizedPosition = Vector2.right;

//				Debug.Log("scrollRect.width:" + scrollRect.width);
//				Debug.Log("scrollRect.x:" + scrollRect.x);
//				Debug.Log("graphWidth:" + graphWidth);
//				Debug.Log("posArray[posArray.Length-1].x:" + posArray[posArray.Length-1].x);
//				Debug.Log("viewRTF:" + viewRTF.rect.xMin + ", " + viewRTF.rect.xMax);
//				Debug.Log("viewRTF.rect.width:" + viewRTF.rect.width);

                var r = (posArray[posArray.Length - 1].x - viewRTF.rect.width) / (scrollRect.width - viewRTF.rect.width);
                var normalizedPosition = new Vector2(r, 0);
                //				Debug.Log("r:" + r);
                graphScrollRect.normalizedPosition = normalizedPosition;
                hTextScrollRect.normalizedPosition = normalizedPosition;
            } while (needUpdate);
            updateCoroutine = null;
            yield break;
        }