Пример #1
0
        public override void OnInspectorGUI()
        {
            using (new UndoScope(serializedObject))
            {
                EditorGUILayout.Space();
                EditorGUILayout.PropertyField(_begin);
                EditorGUILayout.PropertyField(_path);
            }

            if (_pathController.Path.UsePathfinding)
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    var pathfinding = ComponentHelper.GetComponentInScene <Pathfinding>(_pathController.gameObject.scene.buildIndex, false);
                    if (pathfinding == null)
                    {
                        EditorGUILayout.HelpBox("In order to use pathfinding this scene's map object must have a pathfinding component attached", MessageType.Warning, true);

                        if (GUILayout.Button(_createPathfindingContent, GUILayout.Height(39)))
                        {
                            var properties = ComponentHelper.GetComponentInScene <MapProperties>(_pathController.gameObject.scene.buildIndex, false);
                            if (properties)
                            {
                                var path = Undo.AddComponent <Pathfinding>(properties.gameObject);
                                path.RegenerateNodes();
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        protected override void Teardown()
        {
            if (HideWorld)
            {
                var camera = ComponentHelper.GetComponentInScene <Camera>(WorldManager.Instance.gameObject.scene.buildIndex, true);
                camera.gameObject.SetActive(true);
            }

            base.Teardown();
        }
Пример #3
0
        protected override void Setup()
        {
            base.Setup();

            if (HideWorld)
            {
                var camera = ComponentHelper.GetComponentInScene <Camera>(WorldManager.Instance.gameObject.scene.buildIndex, false);
                camera.gameObject.SetActive(false);
            }

            foreach (var display in CreatureDisplays)
            {
                display.SetCreature(null);
            }
        }
Пример #4
0
        private void OnSceneGUI()
        {
            if (_pathController.Path.Nodes.Length > 0)
            {
                var lineColor         = Color.cyan;
                var fillColor         = new Color(0.0f, 1.0f, 1.0f, 0.2f);
                var mover             = _pathController.GetComponent <Mover>();
                var pathfinding       = ComponentHelper.GetComponentInScene <Pathfinding>(_pathController.gameObject.scene.buildIndex, false);
                var transformPosition = _pathController.Path.UseAbsolutePositioning ? Vector2.zero : (Vector2)_pathController.transform.position;

                if (_pathController.Path.Nodes.Length > 2 && _pathController.Path.Type == Path.PathType.Loop)
                {
                    var first = _pathController.Path.Nodes[0];
                    var last  = _pathController.Path.Nodes[_pathController.Path.Nodes.Length - 1];

                    var firstPosition = GetPosition(first.Position, _pathController.transform.position, Mover.PositionOffset);
                    var lastPosition  = GetPosition(last.Position, transformPosition, Mover.PositionOffset);

                    if (_pathController.Path.UsePathfinding && pathfinding)
                    {
                        var pathFrom = GetPathPosition(first.Position, _pathController.transform.position);
                        var pathTo   = GetPathPosition(last.Position, transformPosition);
                        var path     = pathfinding.GetPath(mover.MovementLayer, pathFrom, pathTo, false);

                        if (path.Count > 1)
                        {
                            for (var n = 1; n < path.Count; n++)
                            {
                                var node     = path[n];
                                var position = node + Mover.PositionOffset;

                                HandleHelper.DrawLine(position, firstPosition, lineColor);

                                firstPosition = position;
                            }
                        }
                    }
                    else
                    {
                        HandleHelper.DrawLine(lastPosition, firstPosition, lineColor);
                    }
                }

                for (var i = 1; i < _pathController.Path.Nodes.Length; i++)
                {
                    var previous = _pathController.Path.Nodes[i - 1];
                    var current  = _pathController.Path.Nodes[i];

                    var previousPosition = GetPosition(previous.Position, i == 1 ? (Vector2)_pathController.transform.position : transformPosition, Mover.PositionOffset);
                    var currentPosition  = GetPosition(current.Position, transformPosition, Mover.PositionOffset);

                    if (_pathController.Path.UsePathfinding && pathfinding)
                    {
                        var pathFrom = GetPathPosition(previous.Position, i == 1 ? (Vector2)_pathController.transform.position : transformPosition);
                        var pathTo   = GetPathPosition(current.Position, transformPosition);
                        var path     = pathfinding.GetPath(mover.MovementLayer, pathFrom, pathTo, false);

                        if (path.Count > 1)
                        {
                            for (var n = 1; n < path.Count; n++)
                            {
                                var node     = path[n];
                                var position = node + Mover.PositionOffset;

                                HandleHelper.DrawLine(position, previousPosition, lineColor);

                                previousPosition = position;
                            }
                        }
                    }
                    else
                    {
                        HandleHelper.DrawLine(currentPosition, previousPosition, Color.cyan);
                    }
                }

                for (var i = 0; i < _pathController.Path.Nodes.Length; i++)
                {
                    var node             = _pathController.Path.Nodes[i];
                    var position         = GetPosition(node.Position, i == 0 ? (Vector2)_pathController.transform.position : transformPosition, Mover.PositionOffset);
                    var selectedPosition = HandleHelper.MoveHandle(position, Vector2.one, lineColor, fillColor, 0.25f);

                    if (i != 0 && position != selectedPosition)
                    {
                        selectedPosition -= transformPosition;

                        using (new UndoScope(_pathController, true))
                            _pathController.Path.Nodes[i].Position = Vector2Int.FloorToInt(selectedPosition);
                    }

                    if (node.Delay > 0 && node.Direction != MovementDirection.None)
                    {
                        HandleHelper.DrawArrow(selectedPosition, Direction.GetVector(node.Direction), 0.25f, Color.white);
                    }

                    HandleHelper.DrawText(new Vector2(selectedPosition.x, selectedPosition.y + 0.05f), i.ToString(), TextAnchor.MiddleCenter, Color.white);
                }
            }
        }
Пример #5
0
        private IEnumerator Load(LoadInformation info, GameSaveData game, string filename)
        {
            info.UpdateProgress(LoadState.ReadingData, 0.0f);

            var data = new SaveData();

            if (!string.IsNullOrEmpty(filename))
            {
                Read(info, filename, data);
            }

            if (info.State == LoadState.Error)
            {
                yield break;
            }

            game = game ?? data.Game;
            var worldData  = data.World ?? new WorldSaveData();
            var playerData = data.Player ?? new PlayerSaveData();

            info.UpdateProgress(LoadState.LoadingWorld, 0.1f);

            var mainLoader = string.IsNullOrEmpty(game.MainScene) ? null : SceneManager.LoadSceneAsync(game.MainScene);

            if (mainLoader == null)
            {
                info.SetError(string.Format(_missingMainSceneError, game.MainScene));
                yield break;
            }

            while (!mainLoader.isDone)
            {
                yield return(null);
            }

            if (WorldManager.Instance == null)
            {
                info.SetError(string.Format(_missingWorldManagerError, game.MainScene));
                yield break;
            }

            if (WorldManager.Instance.World == null)
            {
                info.SetError(string.Format(_missingWorldAssetError, game.MainScene));
                yield break;
            }

            if (InstructionManager.Instance == null)
            {
                info.SetError(string.Format(_missingCompositionManagerError, game.MainScene));
                yield break;
            }

            if (Player.Instance == null)
            {
                info.SetError(string.Format(_missingPlayerError, game.MainScene));
                yield break;
            }

            var camera = ComponentHelper.GetComponentInScene <Camera>(WorldManager.Instance.gameObject.scene.buildIndex, false);

            if (camera == null)
            {
                info.SetError(string.Format(_missingCameraError, game.MainScene));
                yield break;
            }

            var zone = WorldManager.Instance.World.GetZoneByName(game.StartingZone);

            if (zone == null)
            {
                info.SetError(string.Format(_invalidZoneError, game.StartingZone, game.MainScene));
                yield break;
            }

            info.UpdateProgress(LoadState.LoadingUi, 0.2f);

            yield return(WorldManager.Instance.LoadUi());

            info.UpdateProgress(LoadState.LoadingZones, 0.4f);

            WorldManager.Instance.Load(filename, worldData);
            Player.Instance.Load(playerData);

            WorldManager.Instance.TransitionZone(zone, game.PlayerSpawn, null);

            while (WorldManager.Instance.IsTransitioning)
            {
                yield return(null);
            }

            info.SetComplete();
        }