Example #1
0
        public void SelectPrevious()
        {
            List <CharacterView> characterCollection = GetCharacterCollection().ToList();

            int newIndex = characterCollection.IndexOf(Selection);

            if (newIndex == -1)
            {
                newIndex = characterCollection.Count - 1;
            }
            else
            {
                newIndex -= 1;
                if (newIndex < 0)
                {
                    newIndex = characterCollection.Count - 1;
                }
            }

            Selection = characterCollection.ElementAtOrDefault(newIndex);
        }
Example #2
0
        public void SelectNext()
        {
            List <CharacterView> characterCollection = GetCharacterCollection().ToList();

            int newIndex = characterCollection.IndexOf(Selection);

            if (newIndex == -1)
            {
                newIndex = 0;
            }
            else
            {
                newIndex += 1;
                if (newIndex >= characterCollection.Count)
                {
                    newIndex = 0;
                }
            }

            Selection = characterCollection.ElementAtOrDefault(newIndex);
        }
        public void ApplyModelToScene()
        {
            ResetScene();

            if (String.IsNullOrEmpty(Model.Map) == false)
            {
                GameObject mapPrefab = Resources.Load <GameObject>("Maps/" + Model.Map);
                GameObject mapObject = GameObjectExtensions.Instantiate(mapPrefab, mapGroup);
                mapObject.name = Model.Map;
                mapObject.transform.localPosition = Vector3.zero;
            }

            foreach (PlayerModel playerModel in Model.PlayerCollection)
            {
                PlayerView playerView = GameObjectExtensions.Instantiate(playerPrefab, playerGroup).GetComponent <PlayerView>();
                playerView.Data  = Data.PlayerCollection.Single(p => p.Id == playerModel.Id);
                playerView.Model = playerModel;
                playerView.UpdateFromModel();
                playerCollection.Add(playerView);

                HumanPlayerController playerController
                    = GameObjectExtensions.Instantiate(humanPlayerControllerPrefab, playerView.transform).GetComponent <HumanPlayerController>();
                playerController.Game   = this;
                playerController.Player = playerView;

                playerView.LocalController = playerController.gameObject;
                playerView.Disable();
            }

            foreach (CharacterModel characterModel in Model.CharacterCollection)
            {
                CharacterView characterView = GameObjectExtensions.Instantiate(characterPrefab, characterGroup).GetComponent <CharacterView>();
                characterView.Data  = Data.CharacterCollection.Single(c => c.Id == characterModel.Id);
                characterView.Model = characterModel;
                characterView.UpdateFromModel();
                characterCollection.Add(characterView);
            }

            Debug.LogFormat(this, "[GameView] Applied model to scene");
        }
        private void UpdateCurrentAbility()
        {
            CharacterModel caster = Player.Selection.Model;

            if (autoCurrentAbility)
            {
                RaycastHit2D hit = Physics2D.Raycast(Camera.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
                if (hit.collider != null)
                {
                    CharacterView target = hit.collider.GetComponentInParent <CharacterView>();
                    currentAbility = target != null ? caster.CharacterClass.DefaultAbility : null;
                    if (currentAbility != null)
                    {
                        ClearPath();
                    }
                    abilityCastView.Change(true, caster, currentAbility);
                }
            }

            if (currentAbility == null)
            {
                ShowPath(caster.Position, abilityCastView.TargetPosition.ToModelVector());
            }
        }
Example #5
0
 public void Disable()
 {
     Selection = null;
     LocalController?.SetActive(false);
 }
Example #6
0
 public void Enable()
 {
     LocalController?.SetActive(true);
     Selection = GetCharacterCollection().FirstOrDefault();
 }