public void ShowLevelSelection(List <LocalLevelData> data)
 {
     if (data != null)
     {
         int new_panels = data.Count - levelContent.childCount;
         for (int i = 0; i < new_panels; i++)
         {
             Instantiate(levelPrefab, levelContent).gameObject.SetActive(false);
         }
         int total         = levelContent.childCount;
         int index_counter = 0;
         for (int i = 0; i < total; i++)
         {
             Transform child = levelContent.GetChild(i);
             if (data.Count > index_counter)
             {
                 LevelHolder holder = child.GetComponent <LevelHolder>();
                 if (holder != null)
                 {
                     holder.RenderLevelBox(data[index_counter]);
                     index_counter++;
                 }
             }
         }
         gameObject.SetActive(true);
     }
     else
     {
         Debug.LogError("Level data list is null");
         gameObject.SetActive(false);
     }
 }
Beispiel #2
0
    public static void CreateLevelAsset()
    {
        int         nextLevel = CountFilesInPathWithExt(levelDirPath, "asset") + 1;
        LevelHolder lh        = ScriptableObject.CreateInstance <LevelHolder>();

        AssetDatabase.CreateAsset(lh, levelDirPath + "/Level" + nextLevel + ".asset");
        AssetDatabase.SaveAssets();
    }
Beispiel #3
0
 public void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
 }
    public static void CreateLevelHolder()
    {
        LevelHolder levelHolder = ScriptableObject.CreateInstance <LevelHolder> ();

        AssetDatabase.CreateAsset(levelHolder, "Assets/LevelHolder.asset");
        AssetDatabase.SaveAssets();

        EditorUtility.FocusProjectWindow();

        Selection.activeObject = levelHolder;
    }
Beispiel #5
0
    public static void Save()
    {
        LevelHolder lh = new LevelHolder();

        lh.oldlevels = new bool[11];
        for (int i = 0; i < 11; i++)
        {
            lh.oldlevels[i] = SingleGameManager.Levels[i];
        }

        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(Application.persistentDataPath + "/savedLevels.gd");

        bf.Serialize(file, (LevelHolder)lh);
        file.Close();
    }
        public void Initialize(OpponentsData opponentData, LevelData levelData)
        {
            if (_initialized)
            {
                return;
            }
            data              = opponentData.Clone();
            levelHolder       = levelData.levelHolder;
            data.defaultSpeed = opponentData.defaultSpeed + Random.Range(-1, 1) + Time.realtimeSinceStartup % 3 * Random.Range(-1, 1);

            _actualSpeed          = data.defaultSpeed - 2f;
            _desiredSpeed         = data.defaultSpeed;
            _follower.computer    = levelHolder._lines[currentRoadId];
            _follower.followSpeed = data.defaultSpeed;
            SetupOffset();
            ChangeSpeed();
            _initialized = true;
        }
Beispiel #7
0
    public bool Load()
    {
        if (File.Exists(Application.persistentDataPath + "/savedLevels.gd"))
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath + "/savedLevels.gd", FileMode.Open);
            LevelHolder     lh   = (LevelHolder)bf.Deserialize(file);
            file.Close();

            setLevels(lh);

            return(true);
        }
        else
        {
            return(false);
        }
    }
Beispiel #8
0
 public MemoryGeneralGame()
 {
     unitsInRoster      = new List <Unit>();
     unitsInParty       = new List <Unit>();
     itemsOwned         = new EquipmentOwned();
     shopWares          = new ShopWares();
     enemiesInMaps      = new EnemiesInMap();
     levelHolder        = new LevelHolder();
     levelCompletion    = new LevelCompletion();
     currentLevels      = new List <CurrentLevel>();
     heldGameType       = new AreaGroupHolder();
     humanClassProgress = new UnitHumanClass();
     impClassProgress   = new UnitImpClass();
     viraClassProgress  = new UnitViraClass();
     TheDemonKing       = new CurrentLevel();
     currentLevelID     = "";
     doISave            = "";
     gold = 0;
 }
Beispiel #9
0
    void Awake()
    {
        if (control == null)
        {
            control = this;
            DontDestroyOnLoad(gameObject);
        }
        else if (control != this)
        {
            Destroy(gameObject);
        }

        introMessages.Add("placeholder");
        introMessages.Add("Level 1\n\nRemember, enemies only take damage from the type they are weak against!");
        introMessages.Add("Level 2\n\nGot the hang of it? Let's make sure!");
        introMessages.Add("Level 3\n\nWatch out for Tauros. It's faster and tougher than the rest, but it can be damaged by all types!");

        spawnIntervals = new float[] { 0f, 4f, 3f, 3f };
        timeLimits     = new float[] { 0f, 20f, 30f, 60f };
    }
 private void Start()
 {
     if (levelHolder == null)
     {
         levelHolder = FindObjectOfType <LevelHolder>();
     }
     if (follower == null)
     {
         Debug.LogError("Opponent's brain follower is null");
     }
     RoadEntityData[] roadEntityArray = new RoadEntityData[levelHolder.allEntities.Count];
     entitiesData = new List <RoadEntityData>();
     levelHolder.allEntities.CopyTo(roadEntityArray);
     entitiesData.AddRange(roadEntityArray);
     entitiesData = entitiesData.OrderBy(d => d.percentAtRoad).ToList();
     _nextEntity  = GetNextEntityData();
     racerName   += UnityEngine.Random.Range(0, 100);
     Finish.OnCrossFinishLineEnemy += DisableEnemy;
     RegisterPausable();
 }
 private void Awake()
 {
     RegisterPausable();
     _collider = GetComponent <CapsuleCollider>();
     _defaultColliderHeight = _collider.height;
     if (player == null)
     {
         player = GetComponent <Player>();
     }
     if (_follower == null)
     {
         _follower = GetComponent <SplineFollower>();
     }
     _actualSpeed           = defaultSpeed;
     _desiredSpeed          = defaultSpeed;
     _follower.followSpeed  = defaultSpeed;
     _follower.physicsMode  = SplineTracer.PhysicsMode.Transform;
     _follower.updateMethod = SplineUser.UpdateMethod.LateUpdate;
     levelHolder            = Locator.GetObject <LevelHolder>();
     _animator = GetComponent <PlayerAnimator>();
     _collider = GetComponent <CapsuleCollider>();
     _boosters = new List <IBoostable>();
     _boosters.AddRange(GetComponents <IBoostable>());
 }
 public void SetInternals(SplineComputer spline, LevelHolder levelHolder)
 {
     this.spline           = spline;
     levelData.levelHolder = levelHolder;
 }
Beispiel #13
0
        private void CreateObjects(LevelHolder levelHolder)
        {
            var allEntities = new List <RoadEntityData>();
            var splines     = levelHolder._lines;
            var points      = levelHolder.GetComputer().GetPoints();

            for (var i = 0; i < points.Length; i++)
            {
                for (var j = 0; j < _track[i].Lines.Length; j++)
                {
                    foreach (var item in _track[i].Lines[j].values)
                    {
                        var point = splines[j].Evaluate(splines[j].Project(splines[j].GetPoint(i).position));

                        TrackPrefabs.TrackObject prefab = null;
                        IList <GameObject>       list   = null;
                        switch (item)
                        {
                        case TrackItem.Magnet:
                        {
                            prefab = _prefabs.Magnet;
                            break;
                        }

                        case TrackItem.Obstacle:
                        {
                            prefab = _prefabs.Obstacle;
                            list   = levelHolder.barriers;
                            allEntities.Add(RoadEntityData.CreateBarrier(BarrierType.Ground_SingePath, i / (float)(points.Length - 1), 0.5f, j));
                            break;
                        }

                        case TrackItem.ObstacleHard:
                        {
                            prefab = _prefabs.ObstacleBlock;
                            list   = levelHolder.barriers;
                            allEntities.Add(RoadEntityData.CreateBarrier(BarrierType.Ground_SingePath, i / (float)(points.Length - 1), 1.5f, j));
                            break;
                        }

                        case TrackItem.EnemyGround:
                        {
                            prefab = _prefabs.EnemyGround;
                            list   = levelHolder.enemies;
                            allEntities.Add(RoadEntityData.CreateEnemy(EnemyType.Ground, i / (float)(points.Length - 1), 0.5f, j));
                            break;
                        }

                        case TrackItem.EnemyAir:
                        {
                            prefab = _prefabs.EnemyAir;
                            list   = levelHolder.enemies;
                            allEntities.Add(RoadEntityData.CreateEnemy(EnemyType.Fly, i / (float)(points.Length - 1), 0.5f, j));
                            break;
                        }

                        case TrackItem.Shield:
                        {
                            prefab = _prefabs.Shield;
                            break;
                        }

                        case TrackItem.Accelerator:
                        {
                            prefab = _prefabs.Accelerator;
                            list   = levelHolder.boosters;
                            break;
                        }
                        }
                        if (prefab != null)
                        {
                            var obj = (GameObject)PrefabUtility.InstantiatePrefab(prefab.prefab);
                            obj.transform.rotation = Quaternion.LookRotation(point.direction, point.normal);
                            obj.transform.position = point.position + point.rotation * prefab.offset;
                            obj.transform.parent   = splines[j].transform;
                            list?.Add(obj);
                        }
                        CreateCoins(_track[i].Lines[j].values.Where(t => t == TrackItem.CoinLow || t == TrackItem.CoinMiddle || t == TrackItem.CoinHigh).ToArray(), point, splines[j].transform, levelHolder.money, allEntities, j);
                    }
                    EditorUtility.DisplayProgressBar("Create track objects", $"Line #{j + 1} of {_track[i].Lines.Length} :: Point: {i + 1} of {points.Length}", i / (float)(points.Length - 1));
                }
            }
            levelHolder.allEntities = allEntities;
            EditorUtility.ClearProgressBar();
            eGUI.SetDirty(levelHolder.gameObject);
        }
Beispiel #14
0
        private void CreateLines(LevelHolder levelHolder)
        {
            var spline   = levelHolder.GetComputer();
            var deviance = new float[_lines];
            var points   = spline.GetPoints();
            var tracks   = new SplinePoint[_lines][];

            // calc line deviance from center
            for (var i = 0; i < _lines; i++)
            {
                deviance[i] = _linesInterval * (i - (_lines - 1) / 2f);
                tracks[i]   = new SplinePoint[points.Length];
            }

            var trackSurfaces = new List <TrackInterval> [_lines];

            for (var i = 0; i < _lines; i++)
            {
                trackSurfaces[i] = new List <TrackInterval>();
            }

            var offset = new Vector3[_lines];

            // create points for lines & calc intervals for mesh
            for (var i = 0; i < points.Length; i++)
            {
                EditorUtility.DisplayProgressBar("Create points for lines & calc intervals for mesh", $" Point {i + 1} of {points.Length}", i / (float)(points.Length - 1));
                for (var line = 0; line < _lines; line++)
                {
                    var currSurface = _track[i].Lines[line].surface;
                    if (i == 0)
                    {
                        var ti = new TrackInterval {
                            type     = currSurface,
                            start    = 0,
                            end      = 0,
                            segments = 0
                        };
                        trackSurfaces[line].Add(ti);
                    }
                    else if (i == points.Length - 1)
                    {
                        trackSurfaces[line][trackSurfaces[line].Count - 1].end      = 1d;
                        trackSurfaces[line][trackSurfaces[line].Count - 1].segments = i - trackSurfaces[line][trackSurfaces[line].Count - 1].segments;
                    }
                    else
                    {
                        var prevSurface = _track[i - 1].Lines[line].surface;
                        if (currSurface != prevSurface)
                        {
                            trackSurfaces[line][trackSurfaces[line].Count - 1].end      = (i) / (double)(points.Length - 1);
                            trackSurfaces[line][trackSurfaces[line].Count - 1].segments = i - trackSurfaces[line][trackSurfaces[line].Count - 1].segments;
                            var ti2 = new TrackInterval {
                                start    = i / (double)(points.Length - 1),
                                type     = currSurface,
                                segments = i
                            };
                            trackSurfaces[line].Add(ti2);
                        }
                    }

                    var pos = spline.Project(points[i].position);
                    var p   = spline.Evaluate(pos);

                    foreach (var dir in _track[i].Lines[line].dirs)
                    {
                        switch (dir)
                        {
                        case TrackDir.ShiftLeft:
                            offset[line].x += -_stepHorizontalShift;
                            break;

                        case TrackDir.ShiftRight:
                            offset[line].x += _stepHorizontalShift;
                            break;

                        case TrackDir.ShiftUp:
                            offset[line].y += _stepVerticalShift;
                            break;

                        case TrackDir.ShiftDown:
                            offset[line].y += -_stepVerticalShift;
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    }
                    var p2 = points[i].position + p.right * deviance[line] + (Quaternion.LookRotation(p.direction, p.normal) * offset[line]);
                    tracks[line][i].position = p2;
                    tracks[line][i].size     = _linesInterval;
                    tracks[line][i].normal   = points[i].normal;
                }
                {
                    var p    = spline.Evaluate(spline.Project(points[i].position)).position;
                    var pos0 = tracks[0][i].position - p;
                    var pos1 = tracks[_lines - 1][i].position - p;
                    if (_track[i].dir.Any(t => t == TrackDir.RotateLeft || t == TrackDir.RotateRight))
                    {
                        var dy = Mathf.Max(pos0.y, pos1.y);
                        foreach (var track in tracks)
                        {
                            track[i].position.y += dy;
                        }
                    }
                }
            }

            var splines = new List <SplineComputer>(_lines);

            // create splines from lines & set SplineMesh for road bake
            for (var i = 0; i < _lines; i++)
            {
                var go = new GameObject($"Line_{i}");
                go.transform.parent = spline.gameObject.transform;

                var s = go.AddComponent <SplineComputer>();
                splines.Add(s);

                s.space = SplineComputer.Space.Local;
                s.SetPoints(tracks[i]);
                s.type = Spline.Type.BSpline;
                s.RebuildImmediate();

                var sm = go.AddComponent <SplineMesh>();
                sm.computer = s;
                sm.RemoveChannel(0);

                var divider = int.MaxValue;
                foreach (var interval in trackSurfaces[i])
                {
                    if (divider > interval.segments)
                    {
                        divider = interval.segments;
                    }
                }
                divider = _simplifyTrackMeshes ? divider : 1;

                for (var index = 0; index < trackSurfaces[i].Count; index++)
                {
                    EditorUtility.DisplayProgressBar("Create lines & road bake", $"Line #{i + 1} of {_lines} :: Interval: {index} of {trackSurfaces[i].Count - 1}", index / (float)(trackSurfaces[i].Count - 1));
                    var interval = trackSurfaces[i][index];
                    var md       = interval.type == TrackSurface.Railroad ? _prefabs.Rails : _prefabs.Normal;

                    var channel = sm.AddChannel($"{interval.type}");
                    channel.minScale  = md.scale;
                    channel.maxScale  = md.scale;
                    channel.minOffset = md.offset;
                    channel.maxOffset = md.offset;
                    channel.AddMesh(md.mesh);
                    channel.count    = interval.segments / divider;
                    channel.clipFrom = interval.start;
                    channel.clipTo   = interval.end;
                }
                EditorUtility.DisplayProgressBar("Create lines & road bake", $"Line #{i + 1} of {_lines} :: Build mesh", 0);
                sm.RebuildImmediate(true);
                sm.Rebuild(true);
                var mr = sm.gameObject.GetComponent <MeshRenderer>();
                mr.sharedMaterial       = _prefabs.RoadMaterial;
                mr.shadowCastingMode    = ShadowCastingMode.Off;
                mr.receiveShadows       = false;
                mr.lightProbeUsage      = LightProbeUsage.Off;
                mr.reflectionProbeUsage = ReflectionProbeUsage.Off;
            }
            levelHolder.Init(spline);
            levelHolder.Init(splines.ToArray(), _linesInterval);

            {
                for (var i = 0; i < points.Length; i++)
                {
                    if (_track[i].dir.Any(t => t == TrackDir.Fence))
                    {
                        var p  = splines[0].Evaluate(i);
                        var go = Instantiate(_prefabs.Fence.prefab).transform;
                        go.position   = p.position - p.right * _linesInterval * 0.5f;
                        go.rotation   = p.rotation;
                        go.localScale = Vector3.one * _stepLength;
                        go.parent     = splines[0].transform;

                        p             = splines[_lines - 1].Evaluate(i);
                        go            = Instantiate(_prefabs.Fence.prefab).transform;
                        go.position   = p.position + p.right * _linesInterval * 0.5f;
                        go.rotation   = p.rotation;
                        go.localScale = Vector3.one * _stepLength;
                        go.parent     = splines[_lines - 1].transform;
                    }
                }
            }

            levelHolder.barriers  = new List <GameObject>();
            levelHolder.boosters  = new List <GameObject>();
            levelHolder.enemies   = new List <GameObject>();
            levelHolder.money     = new List <GameObject>();
            levelHolder.intervals = new LevelHolder.TrackSurface[trackSurfaces.Length];
            for (var i = 0; i < trackSurfaces.Length; i++)
            {
                levelHolder.intervals[i] = new LevelHolder.TrackSurface(trackSurfaces[i]);
            }
            CreateObjects(levelHolder);
        }
Beispiel #15
0
 private void Start()
 {
     instance = this;
 }
Beispiel #16
0
 public static void setLevels(LevelHolder lh)
 {
     SingleGameManager.Levels = lh.oldlevels;
 }
Beispiel #17
0
 private void Awake()
 {
     levelHolder = GetComponent <LevelHolder>();
 }