Esempio n. 1
0
        public MapView(Game game)
            : base(game)
        {
            PlayerList players = ((XnaUITestGame)game).Model.GetScenario().GetGameWorld().GetPlayerList();

            foreach (PlayerComponent player in players.GetChildren())
            {
                UnitList unitList = player.GetUnitList();
                unitList.UnitAddedEvent   += onUnitAdded;
                unitList.UnitRemovedEvent += onUnitRemoved;
                ZRTSCompositeViewUIFactory factory = ZRTSCompositeViewUIFactory.Instance;
                foreach (UnitComponent unit in unitList.GetChildren())
                {
                    UnitUI unitUI = factory.BuildUnitUI(unit);
                    unitUI.DrawBox = new Rectangle((int)(unit.PointLocation.X * cellDimension), (int)(unit.PointLocation.Y * cellDimension), unitUI.DrawBox.Width, unitUI.DrawBox.Height);
                    AddChild(unitUI);
                    componentToUI.Add(unit, unitUI);
                    unit.MovedEventHandlers     += updateLocationOfUnit;
                    unit.HPChangedEventHandlers += killUnit;
                }
                BuildingList buildingList = player.BuildingList;
                foreach (Building b in buildingList.GetChildren())
                {
                    BuildingUI buildingUI = factory.BuildBuildingUI(b);
                    buildingUI.DrawBox = new Rectangle((int)b.PointLocation.X * cellDimension, (int)b.PointLocation.Y * cellDimension, buildingUI.DrawBox.Width, buildingUI.DrawBox.Height);
                    AddChild(buildingUI);
                }
                buildingList.BuildingAddedEventHandlers += this.onBuildingAdded;
            }
            leftButtonStrategy = new DrawSelectionBoxStrategy(this);
            OnClick           += moveSelectedUnits;
        }
        public void Awake()
        {
            _currentStatPanel = Instantiate(unitUI, container.transform);

            _currentStatPanel.gameObject.SetActive(false);
            traitManager.Hide();
        }
 public void UnselectUnit()
 {
     if (selectedUnit != null)
     {
         Destroy(selectedUnit.gameObject);
         selectedUnit = null;
     }
 }
Esempio n. 4
0
    public void AddUnitUI(Transform canvasTransform)
    {
        hasUI = true;
        UnitUI unitui = Instantiate(unitUIPrefab, Camera.main.WorldToScreenPoint(transform.position), Quaternion.identity, canvasTransform);

        unitui.gameObject.name = "SelectedUnitUI";
        unitui.Init(this);
    }
    /**
     * <summary>
     * Set health
     * </summary>
     *
     * <param name="health">Health</param>
     *
     * <returns>
     * void
     * </returns>
     */
    public void SetHealth(float health)
    {
        this.health = health;

        UnitUI unitUI = this.UI.GetComponent <UnitUI>();

        unitUI.SetHealth(health, this.maxHealth);
    }
Esempio n. 6
0
    public void ShowUnitUI()
    {
        if (unitUI == null)
        {
            unitUI = gameObject.GetComponentInChildren <UnitUI>();
        }

        unitUI.EnableUnitUI();
    }
Esempio n. 7
0
    public void OnTurnEnd()
    {
        UnitUI uUI = game.GetUnitUI(this);

        CheckCountStatus();
        UpdateAllUnitStatus();
        UpdateUnitStatus();
        CheckHealthUnit();
    }
Esempio n. 8
0
    public Coroutine UnitHeal(Unit source, Unit target)
    {
        UnitUI sourceUI = FindUnitUI(source);
        UnitUI targetUI = FindUnitUI(target);

        return(StartCoroutine(ParallelCoroutine(
                                  () => sourceUI.AttackMove((targetUI.transform.position - sourceUI.transform.position).normalized),
                                  () => targetUI.HealEffect()
                                  )));
    }
Esempio n. 9
0
    void UpdateHealthBar()
    {
        UnitUI uUI = game.GetUnitUI(this);

        if (uUI == null)
        {
            return;
        }
        uUI.health_bar.fillAmount = _current_hp / max_hp;
    }
Esempio n. 10
0
        /// <summary>
        /// Trigger fucntion in the event of new unit being added
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void onUnitAdded(object sender, UnitAddedEventArgs e)
        {
            ZRTSCompositeViewUIFactory factory = ZRTSCompositeViewUIFactory.Instance;
            UnitUI unitUI = factory.BuildUnitUI(e.Unit);

            unitUI.DrawBox = new Rectangle((int)(e.Unit.PointLocation.X * cellDimension), (int)(e.Unit.PointLocation.Y * cellDimension), unitUI.DrawBox.Width, unitUI.DrawBox.Height);
            AddChild(unitUI);
            componentToUI.Add(e.Unit, unitUI);
            e.Unit.MovedEventHandlers     += updateLocationOfUnit;
            e.Unit.HPChangedEventHandlers += killUnit;
        }
Esempio n. 11
0
    public Coroutine UnitDamage(Unit source, Unit target, int damageAmount)
    {
        UnitUI sourceUI = FindUnitUI(source);
        UnitUI targetUI = FindUnitUI(target);

        targetUI.RenderUnit();

        return(StartCoroutine(ParallelCoroutine(
                                  () => sourceUI.AttackMove(AttackDirection(Lane.GetLaneSidePosOf(source, Driver.instance.gameManager.Lanes).Item2)),
                                  () => damageTextManager.DamageTextPopup(targetUI.transform.position, $"-{damageAmount}")
                                  )));
    }
Esempio n. 12
0
    public Coroutine TowerUnitDamage(Unit target, int damageAmount)
    {
        (int laneIndex, int sideIndex, int positionIndex) = GetPositionIdentifier(target);
        TowerUI sourceUI = towerManagers[1 - sideIndex].towerUIs[laneIndex];
        UnitUI  targetUI = FindUnitUI(target);

        return(StartCoroutine(SerialCoroutine(
                                  () => sourceUI.Attack(targetUI.transform.position),
                                  () => { targetUI.RenderUnit(); return null; },
                                  () => damageTextManager.DamageTextPopup(targetUI.transform.position, $"-{damageAmount}")
                                  )));
    }
Esempio n. 13
0
    void UpdateUnitStatus()
    {
        UnitUI uUI = game.GetUnitUI(this);

        if (uUI != null)
        {
            uUI.UpdateUnitStatus();
        }
        else
        {
            uUI.UpdateUnitStatus();
        }
    }
    /**
     * <summary>
     * Select a unit
     * </summary>
     *
     * <returns>
     * void
     * </returns>
     */
    public static void Select(GameObject unit)
    {
        if (unit.GetComponent <UnitBehaviour>() == null)
        {
            throw new Exception(unit.name + " " + "is not a unit type");
        }

        // Clear previous units
        UnitsManagerBehaviour.UnselectGameObjects();

        // Unselect resource
        if (ResourcesManagerBehaviour.SelectedResource != null)
        {
            ResourcesManagerBehaviour.UnselectResource();
        }

        UnitBehaviour unitBehaviour = unit.GetComponent <UnitBehaviour>();

        if (unitBehaviour is ISelectableUnit)
        {
            UnitsManagerBehaviour.SelectedUnits.Add(unit);
            unitBehaviour.SetSelect(true);

            Self.infoComponentPanel.SetActive(true);

            // Show info component panel
            Self.infoComponentPanel
            .transform
            .Find("Single")
            .gameObject
            .SetActive(true);

            // Hide multiple
            Self.infoComponentPanel
            .transform
            .Find("Multiple")
            .gameObject
            .SetActive(false);

            UnitUI unitUI = unitBehaviour.GetUI().GetComponent <UnitUI>();

            InfoComponentPanelUI infoComponentPanelUI = Self.infoComponentPanel.GetComponent <InfoComponentPanelUI>();
            infoComponentPanelUI.SetName(unit.name);
            infoComponentPanelUI.SetHealth(unitBehaviour.GetHealth(), unitBehaviour.GetMaxHealth());
            infoComponentPanelUI.SetIcon(unitUI.GetIcon());

            // Show action component panel
            Self.actionComponentPanel.SetActive(true);
        }
    }
Esempio n. 15
0
    public GameObject InstantiateUnit(UnitCard cardData)
    {
        GameObject unitObject = Instantiate(unitPrefab, transform);

        UnitUI unitUI = unitObject.GetComponent <UnitUI>();

        unitUI.cardData = cardData;

        HoverCardOverlay cardHover = unitObject.GetComponent <HoverCardOverlay>();

        cardHover.hoverParent = hoverParent;

        return(unitObject);
    }
Esempio n. 16
0
    private void Start()
    {
        if (!_assignedInteraction)
        {
            _assignedInteraction = GetComponentInChildren <UnitInteraction>() ?? GetComponent <UnitInteraction>();
        }

        if (!_unitSoul)
        {
            _unitSoul = GetComponentInChildren <SoulFighter>() ?? GetComponent <SoulFighter>();
        }

        UnitUI = GetComponent <UnitUI>() ?? GetComponentInChildren <UnitUI>();
    }
Esempio n. 17
0
File: Unit.cs Progetto: KIS02/KIS
    //유닛의 생존 여부



    void Awake()
    {
        Health = MaxHealth;

        Energy = MaxEnergy;

        Speed = InitSpeed;

        m_Anim = GetComponentInChildren <Animation> ();

        m_Transform = GetComponent <Transform> ();
        m_Form      = transform.Find("Form");
        m_UI        = GetComponentInChildren <UnitUI> ();
    }
Esempio n. 18
0
    public void CheckHealthUnit()
    {
        UnitUI uUI = game.GetUnitUI(this);

        if (_current_hp <= 0.0f)
        {
            uUI.GetComponent <Animations>().PlayAnimation(AnimationType.DEAD);
        }
        else
        {
            if (GetStunStatus() == null)
            {
                uUI.GetComponent <Animations>().PlayAnimation(AnimationType.IDLE);
            }
        }
        UpdateHealthBar();
    }
Esempio n. 19
0
    void DamageUnit(Ability ability)
    {
        UnitUI uUI = game.GetUnitUI(this);

        if (ability.type == AbilityType.PROTECTION)
        {
        }
        else if (ability.type == AbilityType.STUN)
        {
            uUI.GetComponent <Animations>().PlayAnimation(AnimationType.STUN);
        }
        else if (ability.type == AbilityType.POISONING)
        {
        }
        else
        {
            if (IsUnitStatuses())
            {
                Ability status_protection = GetProtectionStatus();

                if (status_protection != null)
                {
                    if (ability.type == AbilityType.RECOVERY)
                    {
                        current_hp -= ability.damage;
                    }
                    else
                    {
                        current_hp -= ability.damage / 2;
                    }
                }
                else
                {
                    current_hp -= ability.damage;
                }
            }
            else
            {
                current_hp -= ability.damage;
            }
        }
    }
Esempio n. 20
0
    public void UpdateUnit(int i, Unit u)
    {
        UnitUI ui = _units[i];

        ui.SetKO(u.IsKO());
        ui.SetDefending(u.IsDefending());
        ui.SetPrisoner(u.IsPrisoner());
        ui.SetUpgrade(u.HasUpgrade());
        if (u.IsKO())
        {
            UnitOverview.transform.GetChild(i).GetComponent <Image>().color = Color.clear;
        }
        else if (u.IsDefending())
        {
            UnitOverview.transform.GetChild(i).GetComponent <Image>().color = DefendingColour;
        }
        else
        {
            UnitOverview.transform.GetChild(i).GetComponent <Image>().color = OverviewColour;
        }
    }
Esempio n. 21
0
    public void OnDestroy()
    {
        EventsAggregator.Units.RemoveListener <BaseUnit, HitInfo>(EUnitEvent.HitReceived, OnHitReceived);
        EventsAggregator.Units.RemoveListener <BaseUnit>(EUnitEvent.DeathCame, OnUnitDeath);
        EventsAggregator.Fight.RemoveListener(EFightEvent.Pause, OnFightPause);
        EventsAggregator.Fight.RemoveListener(EFightEvent.Resume, OnFightResume);
        EventsAggregator.Fight.RemoveListener(EFightEvent.MapComplete, OnMapComplete);
        EventsAggregator.Fight.RemoveListener(EFightEvent.MapFail, OnMapFail);

        if (_isAlly && UnitsConfig.Instance != null && UnitsConfig.Instance.IsHero(_unitData.Data.Key))
        {
            EventsAggregator.Units.RemoveListener <ESkillKey>(EUnitEvent.SkillUsage, UseSkill);
        }

        _unitData       = null;
        _lastTargetUnit = _targetUnit = null;
        _unitAttack     = null;
        //_unitPathfinder = null;
        _model = null;
        _ui    = null;
    }
Esempio n. 22
0
    public void Setup(BaseUnit unitData, Dictionary <ESkillKey, BaseUnitSkill> skills, string tag, GameObject uiResource, int unitNumber)
    {
        _unitData      = unitData;
        gameObject.tag = tag;
        _isAlly        = gameObject.CompareTag(GameConstants.Tags.UNIT_ALLY);

        _attackTime           = FightManager.SceneInstance.AttackInterval;// 1f / unitData.AttackSpeed;
        _cachedWaitForSeconds = new WaitForSeconds(_attackTime - _model.ShootPositionTimeOffset);

        _skills = skills != null ? skills : new Dictionary <ESkillKey, BaseUnitSkill>();

        if (_isAlly && UnitsConfig.Instance.IsHero(_unitData.Data.Key))
        {
            EventsAggregator.Units.AddListener <ESkillKey>(EUnitEvent.SkillUsage, UseSkill);
        }

        if (_ui == null)
        {
            _ui = (GameObject.Instantiate(uiResource) as GameObject).GetComponent <UnitUI>();
            _ui.transform.SetParent(transform, false);
            _ui.transform.localPosition = _healthBarPosition;
            _ui.transform.localRotation = Quaternion.Euler(GameConstants.CAMERA_ROTATION);
        }
        else
        {
            _ui.Reset();
        }

        if (unitData.DamageTaken > 0)
        {
            _ui.UpdateHealthBar(Mathf.Max(unitData.HealthPoints - unitData.DamageTaken, 0) / (unitData.HealthPoints * 1f));
        }

        if (_isStarted)
        {
            EventsAggregator.Units.Broadcast <BaseUnitBehaviour>(EUnitEvent.ReadyToFight, this);
        }
        //_unitPathfinder.UnitNumber = unitNumber;
    }
Esempio n. 23
0
    public UnitUI GetUnitUI(Unit _unit)
    {
        for (int i = 0; i < evil_units_ui.transform.childCount; i++)
        {
            UnitUI unitUI = evil_units_ui.transform.GetChild(i).GetComponent <UnitUI>();
            if (unitUI.unit == _unit)
            {
                return(unitUI);
            }
        }

        for (int i = 0; i < good_units_ui.transform.childCount; i++)
        {
            UnitUI unitUI = good_units_ui.transform.GetChild(i).GetComponent <UnitUI>();
            if (unitUI.unit == _unit)
            {
                return(unitUI);
            }
        }

        return(null);
    }
Esempio n. 24
0
    public void AddUnit(Unit u)
    {
        GameObject obj = Instantiate(UnitPrefab);

        obj.transform.SetParent(UnitList.transform);
        obj.transform.localScale = Vector3.one;
        UnitUI ui = obj.GetComponent <UnitUI> ();

        ui.SetImage(getSprite(u.Type));
        ui.SetKO(u.IsKO());
        ui.SetIndex(_units.Count);
        ui.SetUpgrade(u.HasUpgrade());
        ui.SetDefending(u.IsDefending());
        ui.SetPrisoner(u.IsPrisoner());
        ui.OnClick += _clickUnit;
        if (_selectMode)
        {
            ui.EnableSelection();
        }
        _units.Add(ui);
        GameObject g     = new GameObject();
        Image      image = g.AddComponent <Image> ();

        g.transform.SetParent(UnitOverview.transform);
        g.transform.localScale = Vector3.one;
        if (u.IsKO())
        {
            image.color = Color.clear;
        }
        else if (u.IsDefending())
        {
            image.color = DefendingColour;
        }
        else
        {
            image.color = OverviewColour;
        }
    }
Esempio n. 25
0
    public Coroutine UnitTowerDamage(Tower target, int damageAmount)
    {
        (int laneIndex, int sideIndex) = GetPositionIdentifier(target);
        TowerUI targetUI = towerManagers[sideIndex].towerUIs[laneIndex];

        UnitUI[] attackers = new UnitUI[] {
            FindUnitUI(gameManager.Lanes[laneIndex].Units[1 - sideIndex, 0]),
            FindUnitUI(gameManager.Lanes[laneIndex].Units[1 - sideIndex, 1])
        }.Where(unitUI => unitUI != null).ToArray();

        List <Func <Coroutine> > callbacks = new List <Func <Coroutine> >();

        callbacks.Add(() => damageTextManager.DamageTextPopup(
                          targetUI.transform.position,
                          $"-{damageAmount}"
                          ));
        callbacks.AddRange(
            attackers.Select <UnitUI, Func <Coroutine> >(attacker => () => attacker.AttackMove(AttackDirection(1 - sideIndex)))
            );

        targetUI.RenderTower();
        return(StartCoroutine(ParallelCoroutine(callbacks.ToArray())));
    }
Esempio n. 26
0
    private void Awake()
    {
        hexGrid        = FindObjectOfType <HexGrid>();
        HUDUI          = FindObjectOfType <HUD>();
        Behaviour      = gameObject.AddComponent <UnitBehaviour>();
        GameController = FindObjectOfType <GameController>();
        unitUI         = Instantiate(unitUiPrefab).GetComponent <UnitUI>();
        hexVision      = gameObject.AddComponent <HexVision>();
        abilities      = GetComponent <Abilities>();
        unitUI.Unit    = this;
        hexVision.AddVisibleObject(unitUI.gameObject);
        if (hexUnit.GetMesh())
        {
            hexVision.AddVisibleObject(hexUnit.GetMesh());
        }
        hexUnit.HexVision = hexVision;
        gameController.VisionSystem.AddHexVision(hexVision);
        AudioSource audioSource = gameObject.AddComponent <AudioSource>();

        audioSource.spatialBlend = 1;
        audioSource.minDistance  = 10;
        Setup();
    }
Esempio n. 27
0
    private void SpawnUnit(IUnit data)
    {
        UnitUI newUnitUI = Instantiate(_prefabUnitUI, transform);

        _controller.SetUpUnitUI(newUnitUI, data);
    }
 public static void AddUnitSprite(UnitUI unitSprite)
 {
     UnitUIList.Add(unitSprite);
 }
Esempio n. 29
0
 // Start is called before the first frame update
 void Start()
 {
     unitUI = gameObject.GetComponentInChildren <UnitUI>();
     SetupUI();
 }
Esempio n. 30
0
    public void OnDestroy()
    {
        EventsAggregator.Units.RemoveListener<BaseUnit, HitInfo>(EUnitEvent.HitReceived, OnHitReceived);
        EventsAggregator.Units.RemoveListener<BaseUnit>(EUnitEvent.DeathCame, OnUnitDeath);
        EventsAggregator.Fight.RemoveListener(EFightEvent.Pause, OnFightPause);
        EventsAggregator.Fight.RemoveListener(EFightEvent.Resume, OnFightResume);
        EventsAggregator.Fight.RemoveListener(EFightEvent.MapComplete, OnMapComplete);
        EventsAggregator.Fight.RemoveListener(EFightEvent.MapFail, OnMapFail);

        if (_isAlly && UnitsConfig.Instance != null && UnitsConfig.Instance.IsHero(_unitData.Data.Key)) {
            EventsAggregator.Units.RemoveListener<ESkillKey>(EUnitEvent.SkillUsage, UseSkill);
        }

        _unitData = null;
        _lastTargetUnit = _targetUnit = null;
        _unitAttack = null;
        //_unitPathfinder = null;
        _model = null;
        _ui = null;
    }
Esempio n. 31
0
    public void Setup(BaseUnit unitData, Dictionary<ESkillKey, BaseUnitSkill> skills, string tag, GameObject uiResource, int unitNumber)
    {
        _unitData = unitData;
        gameObject.tag = tag;
        _isAlly = gameObject.CompareTag(GameConstants.Tags.UNIT_ALLY);

        _attackTime = FightManager.SceneInstance.AttackInterval;// 1f / unitData.AttackSpeed;
        _cachedWaitForSeconds = new WaitForSeconds(_attackTime - _model.ShootPositionTimeOffset);

        _skills = skills != null ? skills : new Dictionary<ESkillKey, BaseUnitSkill>();

        if (_isAlly && UnitsConfig.Instance.IsHero(_unitData.Data.Key)) {
            EventsAggregator.Units.AddListener<ESkillKey>(EUnitEvent.SkillUsage, UseSkill);
        }

        if (_ui == null) {
            _ui = (GameObject.Instantiate(uiResource) as GameObject).GetComponent<UnitUI>();
            _ui.transform.SetParent(transform, false);
            _ui.transform.localPosition = _healthBarPosition;
            _ui.transform.localRotation = Quaternion.Euler(GameConstants.CAMERA_ROTATION);
        } else {
            _ui.Reset();
        }

        if (unitData.DamageTaken > 0) {
            _ui.UpdateHealthBar(Mathf.Max(unitData.HealthPoints - unitData.DamageTaken, 0) / (unitData.HealthPoints * 1f));
        }

        if (_isStarted) {
            EventsAggregator.Units.Broadcast<BaseUnitBehaviour>(EUnitEvent.ReadyToFight, this);
        }
        //_unitPathfinder.UnitNumber = unitNumber;
    }
Esempio n. 32
0
        /// <summary>
        /// Trigger function in the event of unit moving across the screen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void updateLocationOfUnit(Object sender, UnitMovedEventArgs e)
        {
            UnitUI ui = componentToUI[e.Unit] as UnitUI;

            ui.DrawBox = new Rectangle((int)(e.NewPoint.X * cellDimension) - ui.DrawBox.Width / 2, (int)(e.NewPoint.Y * cellDimension) - ui.DrawBox.Height / 2, ui.DrawBox.Width, ui.DrawBox.Height);
        }
Esempio n. 33
0
    IEnumerator PerformMove(Quaternion oldOrientation, Vector3 newPos)
    {
        GameController.Instance.SwitchAction(true);

        GetComponent <UnitUI>().ShowMarkers(false);

        StartCoroutine(PlayMoveSound(true));

        var targetRotation = Quaternion.LookRotation(new Vector3(newPos.x, transform.position.y, newPos.z) - transform.position);

        targetRotation.eulerAngles = new Vector3(0, targetRotation.eulerAngles.y, targetRotation.eulerAngles.z);

        //this is offset for Jumpship
        Vector3 offset = transform.position + Vector3.up / 2;

        //this is only for the Grunt model, usually unit.Model is declared as Animator
        Animation anim = unit.Model.GetComponent <Animation>();

        if (anim != null && anim.GetClipCount() > 1)
        {
            unit.Model.GetComponent <Animation>().CrossFade("walk_forward");
        }

        while (Mathf.Abs(transform.rotation.eulerAngles.y - targetRotation.eulerAngles.y) > 1)
        {
            transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, Time.deltaTime * (unit.RotationSpeed * 10));

            if (unit.Type == Unit.UnitType.Jumpship)
            {
                transform.position = Vector3.MoveTowards(transform.position, offset, Time.deltaTime);
            }

            yield return(null);
        }

        while (Vector3.Distance(transform.position, newPos) > 0.01f)
        {
            transform.position = Vector3.MoveTowards(transform.position, newPos, Time.deltaTime * (unit.MovemenSpeed / 10));
            yield return(null);
        }

        if (anim != null && anim.GetClipCount() > 1)
        {
            unit.Model.GetComponent <Animation>().CrossFade("idle");
        }

        targetRotation = oldOrientation;

        while (Mathf.Abs(transform.rotation.eulerAngles.y - targetRotation.eulerAngles.y) > 1)
        {
            transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, Time.deltaTime * (unit.RotationSpeed * 10));
            yield return(null);
        }

        StartCoroutine(PlayMoveSound(false));

        GameController.Instance.SwitchAction(false);

        if (unit.Type == Unit.UnitType.Drone)
        {
            GameController.Instance.CheckEndGame();
        }

        UnitUI unitUI = GetComponent <UnitUI>();

        if (!unit.CanAttack || GetComponent <UnitAttack>().GetAttackTiles(BoardManager.Instance.GetPositionOfUnit(unit), true, BoardManager.TileType.Attack).Count == 0)
        {
            unitUI.ShowActionMarker(false);
            unitUI.ShowTeamIndicator(true);
        }
        else
        {
            unitUI.ShowMarkers(true);
        }
    }