private void CreateBarrier()
    {
        var minNumber    = LEVEL_BARRIER_MIN[difficulty];
        var maxNumber    = LEVEL_BARRIER_MAX[difficulty];
        var wayDict      = WorldHelper.RandomFixedXS(minNumber, maxNumber);
        var blockMinimum = 2;
        var blockCount   = 0;

        foreach (var kv in wayDict)
        {
            var way  = kv.Key;
            var x    = kv.Value;
            var type = EBarrierType.BLOCK;
            if (++blockCount > blockMinimum)
            {
                type = (EBarrierType)MathKit.RandomType(CREATE_BARRIER_PROBS);
            }

            var gameObject = Object.Instantiate(stage.barrierPrefab, stage.barrierCanvas.transform);
            gameObject.transform.position = new Vector3(x, Screen.height + 100, 0);

            var barrier = gameObject.GetComponent <Barrier>();
            barrier.Way = way;
            barrier.Morph(type);
            world.BarrierManager.Add(barrier);
        }
    }
Пример #2
0
        void Update()
        {
            OnUpdate(Time.unscaledDeltaTime);

            if (_progress < 1f)
            {
                _progress = Mathf.Clamp01(_progress + Time.unscaledDeltaTime / _tweenDuration);
                SetBorderWorldRect(MathKit.Lerp(_start, _target, Mathf.SmoothStep(0, 1, _progress)));
            }
        }
Пример #3
0
        /// <summary>
        /// 拖动鼠标以修改数值
        /// </summary>
        public static float DragValue(Rect rect, GUIContent content, float value, float step, GUIStyle style, bool horizontal = true)
        {
            int controlID = GUIUtility.GetControlID(FocusType.Passive);

            switch (Event.current.GetTypeForControl(controlID))
            {
            case EventType.Repaint:
            {
                GUI.Label(rect, content, style);
                break;
            }

            case EventType.MouseDown:
            {
                if (Event.current.button == 0 && rect.Contains(Event.current.mousePosition))
                {
                    GUIUtility.hotControl = controlID;
                }
                break;
            }

            case EventType.MouseUp:
            {
                if (GUIUtility.hotControl == controlID)
                {
                    GUIUtility.hotControl = 0;
                }
                break;
            }
            }

            if (Event.current.isMouse && GUIUtility.hotControl == controlID)
            {
                if (Event.current.type == EventType.MouseDrag)
                {
                    if (horizontal)
                    {
                        value += Event.current.delta.x * step;
                    }
                    else
                    {
                        value -= Event.current.delta.y * step;
                    }
                    value = MathKit.RoundToSignificantDigitsFloat(value);

                    GUI.changed = true;
                }

                Event.current.Use();
            }

            return(value);
        }
    private void CreateByDistance()
    {
        var type = ECreateDistance.NONE;

        do
        {
            type = (ECreateDistance)MathKit.RandomType(CREATE_DISTANCE_PROBS);
            if (type == lastCreateDistanceType)
            {
                ++lastCreateDistanceCount;
            }
            else
            {
                lastCreateDistanceType  = type;
                lastCreateDistanceCount = 1;
            }
        } while (lastCreateDistanceCount > 2);

        switch (type)
        {
        case ECreateDistance.ENEMY:
            CreateBarrier();
            break;

        case ECreateDistance.BARRIER:
            CreateBarrier();
            break;

        case ECreateDistance.ROLLING:
            CreateBarrier();
            break;

        default:
            break;
        }
    }
Пример #5
0
        /// <summary>
        /// 拖动鼠标以修改数值
        /// </summary>
        public static float DragValue(Rect rect, GUIContent content, float value, float step, GUIStyle style, bool horizontal = true)
        {
            int controlID = GUIUtility.GetControlID(FocusType.Passive);

            switch (Event.current.GetTypeForControl(controlID))
            {
            case EventType.Repaint:
            {
                GUI.Label(rect, content, style);
                break;
            }

            case EventType.MouseDown:
            {
                if (Event.current.button == 0 && rect.Contains(Event.current.mousePosition))
                {
                    GUIUtility.hotControl = controlID;
                }
                break;
            }

            case EventType.MouseUp:
            {
                if (GUIUtility.hotControl == controlID)
                {
                    GUIUtility.hotControl = 0;
                    UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
                }
                break;
            }
            }

            if (GUIUtility.hotControl == controlID)
            {
                if (Event.current.isMouse)
                {
                    if (Event.current.type == EventType.MouseDrag)
                    {
                        if (horizontal)
                        {
                            value += Event.current.delta.x * step;
                        }
                        else
                        {
                            value -= Event.current.delta.y * step;
                        }
                        value = MathKit.RoundToSignificantDigitsFloat(value);

                        GUI.changed = true;
                    }

                    Event.current.Use();
                }

                rect.size   = new Vector2(1000, 1000);
                rect.center = Event.current.mousePosition;
            }

            EditorGUIUtility.AddCursorRect(rect, horizontal ? MouseCursor.ResizeHorizontal : MouseCursor.ResizeVertical);

            return(value);
        }
 public static List <int> FilterFixedWays(List <int> excludes)
 {
     return(MathKit.FilterValues(Constant.FIXED_WAYS, excludes));
 }
    public static List <int> RandomFixedIndexes(int min, int max)
    {
        var number = MathKit.RandomRange(min, max);

        return(MathKit.RandomValues <int>(Constant.FIXED_INDEXES, number));
    }