public Unit(GameObject unitObject, AgentBase unitAgentBase, Health unitHealth, UnitSpellHandler unitSpellHandler)
 {
     obj        = unitObject;
     agentB     = unitAgentBase;
     health     = unitHealth;
     unitSpellH = unitSpellHandler;
 }
    void CreateObjectPool()
    {
        for (int i = 0; i < maxUnitsOut; i++)
        {
            GameObject       temp             = Instantiate(spawnUnit.gameObject);
            AgentBase        agentBase        = temp.GetComponent <AgentBase>();
            Health           unitHealth       = temp.GetComponent <Health>();
            UnitSpellHandler unitSpellHandler = temp.GetComponent <UnitSpellHandler>();

            temp.layer = thisTransform.gameObject.layer;
            //agentBase.GetFriendsAndFoes();
            unitHealth.Init();
            agentBase.Init();
            unitSpellHandler.Init();
            //temp.transform.parent = thisTransform;
            temp.SetActive(false);

            Unit tempUnit = new Unit(temp, agentBase, unitHealth, unitSpellHandler);
            unitPool.Add(tempUnit);

            //GameObject temp = Instantiate(spawnUnit.gameObject);
            //Transform unitTransform = temp.transform.transform.GetChild(0); //första barnet
            //AgentBase agentBase = unitTransform.GetComponent<AgentBase>();
            //Health unitHealth = unitTransform.GetComponent<Health>();
            //unitTransform.gameObject.layer = thisTransform.gameObject.layer;

            //Unit tempUnit = new Unit(temp, agentBase, unitHealth);

            //agentBase.GetFriendsAndFoes();
            //temp.transform.parent = thisTransform;
            //temp.SetActive(false);
            //unitPool.Add(tempUnit);
        }
    }
示例#3
0
 public virtual void Init()
 {
     initializedTimes++;
     id = nrAI;
     nrAI++;
     thisTransform    = this.transform;
     unitSpellHandler = thisTransform.GetComponent <UnitSpellHandler>();
     GetFriendsAndFoes();
     ClearCommands();
     attackerIDs.Clear();
     LoadValidSpellIndexes();
 }
示例#4
0
    public void Init()
    {
        initializedTimes++;
        if (damageHandler == null)
        {
            damageHandler = GameObject.FindGameObjectWithTag("DamageHandler").GetComponent <DamageHandler>();
        }

        thisTransform = this.transform;
        thisRenderer  = GetComponentsInChildren <Renderer>();

        if (thisTransform.GetComponent <UnitSpellHandler>() != null)
        {
            unitSpellHandler = thisTransform.GetComponent <UnitSpellHandler>();
        }

        if (thisTransform.GetComponent <AIBase>() != null)
        {
            aiBase = thisTransform.GetComponent <AIBase>();
        }
        //if (thisRenderer == null)
        //{
        //    thisRenderer = thisTransform.GetComponent<Renderer>();
        //}
        int i = 0;

        foreach (Renderer re in thisRenderer)
        {
            //Debug.Log(re.material.name);
            thisMaterial.Add(re.material);
            i++;
        }

        if (deathParticleSystemObj != null)
        {
            deathParticleSystemSpawned = Instantiate(deathParticleSystemObj.gameObject);
            deathParticleSystemSpawned.SetActive(false);
        }

        if (aiBase != null)
        {
            animationObj = aiBase.animationObject;
        }

        mainCamera = Camera.main;

        maxHealth  = startHealth; //maxHealth kan påverkas av andra faktorer also
        currHealth = maxHealth;

        healthRegAmount = startHealthRegAmount;

        ToggleSelMarker(false);
    }
示例#5
0
    void UpdateSpellInfo()
    {
        if (currTargetGroup[0].GetComponent <UnitSpellHandler>() != null)
        {
            UnitSpellHandler tempUSH = currTargetGroup[0].GetComponent <UnitSpellHandler>();
            for (int i = 0; i < spellButtons.Length; i++)
            {
                if (tempUSH.SpellIndexExists(i))
                {
                    //spellButtons[i].GetComponent<Tooltip>().tooltip = "<b>" + tempUSH.allAbilities[i].name+ "</b>" + "\n" + tempUSH.allAbilities[i].tooltip; tooltips updateras i sin egen funktion
                    Image spellButtonImage = spellButtons[i].GetComponent <Image>();
                    spellButtonImage.sprite = tempUSH.allAbilities[i].abilitySprite;

                    if (tempUSH.autoCast[i] == true && tempUSH.allAbilities[i].GetComponent <CastAbility>() == true)
                    {
                        spellButtons[i].image.color = autoCastColor;
                    }
                    else
                    {
                        spellButtons[i].image.color = normalColor;
                    }

                    float bestCooldown = 0.0f; //displaya den bästa cooldownen hos gruppen, castspell kommer ändå kanske alla som är redo
                    for (int y = 0; y < currTargetGroup.Count; y++)
                    {
                        float currCooldown = currTargetGroup[y].GetComponent <UnitSpellHandler>().allAbilities[i].GetPercentageCooldownFinished();
                        if (bestCooldown < currCooldown)
                        {
                            bestCooldown = currCooldown;
                        }
                    }
                    spellButtonImage.fillAmount = bestCooldown;
                }
                else
                {
                    spellButtons[i].GetComponent <Image>().sprite = spellMissingSprite;
                    spellButtons[i].image.color = normalColor;
                    spellButtons[i].GetComponent <Image>().fillAmount = 1;
                }
            }
        }
        else
        {
            for (int i = 0; i < spellButtons.Length; i++)
            {
                spellButtons[i].GetComponent <Tooltip>().tooltip = ""; //den kommer inte visa någon bar ifall det är "" (y)
                spellButtons[i].GetComponent <Image>().sprite    = spellMissingSprite;
            }
        }
    }
示例#6
0
    public void ToggleAutoCast(int spellIndexBut)
    {
        if (currTargetGroup[0].GetComponent <UnitSpellHandler>() == null)
        {
            return;
        }
        UnitSpellHandler firstSpellHandler = currTargetGroup[0].GetComponent <UnitSpellHandler>();

        if (!firstSpellHandler.SpellIndexExists(spellIndexBut))
        {
            return;
        }
        bool newAutocastSetting = !firstSpellHandler.autoCast[spellIndexBut];

        for (int i = 0; i < currTargetGroup.Count; i++)
        {
            currTargetGroup[i].GetComponent <UnitSpellHandler>().autoCast[spellIndexBut] = newAutocastSetting;
        }
    }
示例#7
0
    void UpdateToolTips()
    {
        //updatera tooltips till dessa nya units!
        if (currTargetGroup.Count == 0)
        {
            return;
        }
        if (currTargetGroup[0].GetComponent <UnitSpellHandler>() != null)
        {
            UnitSpellHandler tempUSH = currTargetGroup[0].GetComponent <UnitSpellHandler>();
            for (int i = 0; i < spellButtons.Length; i++)
            {
                if (tempUSH.SpellIndexExists(i))
                {
                    //spellButtons[i].GetComponent<Tooltip>().ChangeToolTip(GetSpellToolTip(i)); //updatera spelltooltipen
                    spellButtons[i].GetComponent <Tooltip>().tooltip = "<b>" + tempUSH.allAbilities[i].name + "</b>" + "\n" + tempUSH.allAbilities[i].tooltip; //spell tooltips!
                }
                else
                {
                    spellButtons[i].GetComponent <Tooltip>().tooltip = ""; //den kommer inte visa någon bar ifall det är "" (y)
                }
            }
        }

        string armorTypeToolTip = damageHandler.GetArmorToolTip(currTargetGroup[0].GetComponent <Health>().armorType);

        if (currTargetGroup[0].GetComponent <AIBase>() != null)
        {
            string damageTypeToolTip = damageHandler.GetDamageToolTip(currTargetGroup[0].GetComponent <AIBase>().damageType);
            damageTypeImage.gameObject.GetComponent <Tooltip>().ChangeToolTip(damageTypeToolTip);
        }
        else
        {
            damageTypeImage.gameObject.GetComponent <Tooltip>().ChangeToolTip("N/A");
        }
        armorTypeImage.gameObject.GetComponent <Tooltip>().ChangeToolTip(armorTypeToolTip);

        //namn och tooltip på unitet
        Health ct = currTargetGroup[0].GetComponent <Health>();

        unitPortrait.GetComponent <Tooltip>().ChangeToolTip("<b>" + ct.name + "</b>\n" + ct.tooltip);
    }