private void OnValidate() { if (!IsPrefabDataValid()) { Debug.LogError($"[{nameof(ObstacleData)}] [{nameof(OnValidate)}] Invalid data. {name}"); return; } if (!IntRangedValue.IsInitialized(_spawnRotation)) { _spawnRotation = GameConstants.Animation.Obstacle.DefaultRotation; UnityEditor.EditorUtility.SetDirty(this); } if (!IntRangedValue.IsInitialized(_targetRotation)) { _targetRotation = _autoCalculateTarget ? FindSafeTarget() : GameConstants.Animation.Obstacle.DefaultRotation; UnityEditor.EditorUtility.SetDirty(this); } if (_autoCalculateTarget && _targetRotation.IsEqualTo(GameConstants.Animation.Obstacle.DefaultRotation)) { _targetRotation = FindSafeTarget(); UnityEditor.EditorUtility.SetDirty(this); } }
private IntRangedValue FindSafeTarget() { var totalObjects = _enabledObjects.Count + _disabledObjects.Count; var isPrevEnabled = _enabledObjects.Contains(0); var currentGapSize = isPrevEnabled ? 0 : 1; var gapStart = currentGapSize == 0 ? -1 : 0; var largestGapRange = new IntRangedValue(gapStart, gapStart, true); var smallestGapRange = new IntRangedValue(0, totalObjects - 1, true); for (var i = 1; i < totalObjects; i++) { var isCurrentEnabled = _enabledObjects.Contains(i); var didChange = isPrevEnabled != isCurrentEnabled; if (!didChange) { if (!isPrevEnabled) { continue; } gapStart = -1; } else { if (isPrevEnabled) { gapStart = i; } else { var gap = new IntRangedValue(gapStart, i - 1, true); if (gap.Interval > largestGapRange.Interval && IsGapValid(gap)) { largestGapRange = gap; } if (gap.Interval < smallestGapRange.Interval && IsGapValid(gap)) { smallestGapRange = gap; } } } isPrevEnabled = isCurrentEnabled; } const float resolution = GameConstants.Animation.Obstacle.Resolution; const float buffer = GameConstants.Animation.Obstacle.MinGapSize * (360f / resolution); var safeRange = new IntRangedValue((int)(90 + buffer), (int)(270 - buffer)); var largestGapAngle = new IntRangedValue((int)(largestGapRange.Min / resolution * 360f), (int)(largestGapRange.Max / resolution * 360f)); var targetRotation = new IntRangedValue(safeRange.Min - largestGapAngle.Max, safeRange.Max - largestGapAngle.Min); return(targetRotation); }
private void OnGameStart(object[] obj) { _groupRange = _levelDataManager.CurrentLevelData.Grouping; _groupCount = -1; _obstacleId = -1; _groupColorIndex = -1; _shuffleBag = new ShuffleBag(_data.Length); }
private static bool IsGapValid(IntRangedValue gap) { return(gap.Interval >= GameConstants.Animation.Obstacle.MinGapSize); }
public bool IsEqualTo(IntRangedValue other) { return(other != null && other.Min == _min && other._max == _max && other.Interval == Interval); }
public int Next(IntRangedValue val) => _random.Next(val.Min, val.Max);