Esempio n. 1
0
        public void SetAbility(Ability ability, bool shouldBePresent, AbilityViewState newState)
        {
            bool alreadyPresent = _abilityViewsByOrder[ability.Order] != null;

            if (alreadyPresent && !shouldBePresent)
            {
                AbilityView viewToRemove = _abilityViewsByOrder[ability.Order];
                _abilityViewsByOrder[ability.Order] = null;
                PoolingManager.Free(PoolingManager.AbilityView, viewToRemove.gameObject);
            }
            else if (!alreadyPresent && shouldBePresent)
            {
                AbilityView newView = PoolingManager.Fetch <AbilityView>(PoolingManager.AbilityView, Vector3.zero,
                                                                         Quaternion.identity, transform);
                _abilityViewsByOrder[ability.Order] = newView;
                newView.InitializeWith(ability, newState);

                AdjustViewOrder(ability, newView);
            }
            else if (alreadyPresent)
            {
                AbilityView viewToChange = _abilityViewsByOrder[ability.Order];
                viewToChange.UpdateForState(newState);
            }
        }
Esempio n. 2
0
        public IViewController InitializeViewForEntity(GameEntity entity)
        {
            EntityViewBehaviour instantiatedEntityView = PoolingManager.Fetch(PoolingManager.EntityView).GetComponent <EntityViewBehaviour>();

            instantiatedEntityView.Entity = entity;
            entity.ReplaceView(instantiatedEntityView);

            _entityViewBehaviourInitializer.Initialize(instantiatedEntityView);

            return(instantiatedEntityView);
        }
Esempio n. 3
0
        private PositionEffect FetchPositionEffectAtPosition(Position position)
        {
            if (_positionEffectPrefab == null)
            {
                _positionEffectPrefab = Resources.Load <PositionEffect>("Prefabs/UI/" + nameof(PositionEffect));
            }
            Vector3        position3            = _unityGridInfoProvider.GetCellCenterWorld(position);
            GameObject     positionEffectObject = PoolingManager.Fetch(PoolingManager.PositionEffect, position3, Quaternion.identity);
            PositionEffect positionEffect       = positionEffectObject.GetComponent <PositionEffect>();

            return(positionEffect);
        }
Esempio n. 4
0
        public void SetStatus(ViewStatusClass viewStatusClass, ActorStatusDefinition statusDefinition)
        {
            Image statusImage;

            if (_classesToStatusImages.ContainsKey(viewStatusClass))
            {
                statusImage = _classesToStatusImages[viewStatusClass];
            }
            else
            {
                statusImage = PoolingManager.Fetch(PoolingManager.StatusImage, _statusesGroup.transform.position,
                                                   Quaternion.identity, _statusesGroup.transform)
                              .GetComponent <Image>();
                _classesToStatusImages[viewStatusClass] = statusImage;
            }
            statusImage.sprite = statusDefinition.Icon;
            statusImage.transform.localPosition = Vector3.zero;
            statusImage.transform.localScale    = new Vector3(1, 1, 1);
            LayoutRebuilder.ForceRebuildLayoutImmediate(_statusesGroup.GetComponent <RectTransform>());            // prevents statuses from laying one on top of another
        }