Пример #1
0
        /// <summary>
        /// Initializes the level and creates all necessary nodes. No geometry is loaded yet
        /// </summary>
        /// <param name="scenario">The scenario that constitutes the level</param>
        public void Initialize(Scenario scenario)
        {
            _scenario = scenario;

            var levelGameObject = new GameObject("Level", typeof(View.Level.Level));

            Level = levelGameObject.GetComponent <View.Level.Level>();

            Camera = Object.FindObjectOfType <CameraController>();

            LevelNodeController previous = new LevelNodeController();

            _nodes.AddLast(previous);
            //create new controllers for each step in the scenario
            foreach (var scenarioStep in _scenario.Steps)
            {
                var levelNodeController = new LevelNodeController(previous, scenarioStep);
                levelNodeController.OnFinished      += OnNodeFinished;
                levelNodeController.OnLengthChanged += Level.OnNodeChangedLength;
                previous = levelNodeController;
                _nodes.AddLast(levelNodeController);
            }
            _currentListNode = _nodes.First;

            Level.RebuildSplinePoints();

            // instantly enable the first levelcontroller
            Debug.Assert(_currentListNode != null, "No Nodes in List! Are there any steps loaded?");
            CurrentNode.Enable();
        }
        public LevelNodeController(LevelNodeController previous, Scenario.IScenarioStep step)
        {
            Previous = previous;
            _step    = step;
            _length  = step.DefaultLength;

            //instantiate the corresponding LevelNode for the step by calling Level's templated method via reflection
            Type type = ScenarioStepToLevelNodeTypeDictionary[step.GetType()];

            Debug.Assert(type.IsSubclassOf(typeof(LevelNode)));
            // ReSharper disable once PossibleNullReferenceException
            var genericMethod = typeof(View.Level.Level).GetMethod("CreateLevelNode").MakeGenericMethod(type);

            _levelNode       = (LevelNode)genericMethod.Invoke(World.Instance.Level, new object[] { this });
            OnLengthChanged += _levelNode.OnPreviousNodeChangedLength;
        }
Пример #3
0
 public void OnNodeFinished(LevelNodeController nodeController)
 {
     Debug.Assert(CurrentNode == nodeController, "Finished node is not the current one!");
     _currentListNode = _currentListNode.Next;
 }