Example #1
0
 void EndEpisode()
 {
     GameObject[] Remained = inspector.getCurrentUnits();
     foreach (GameObject unit in Remained)
     {
         if (inspector.setScriptsFrom(unit))
         {
             if (inspector.getScriptType() == "Unit")
             {
                 inspector.removeFrom(unit);
                 Destroy(unit);
             }
             else if (inspector.getScriptType() == "AgentScript")
             {
                 Debug.LogWarning("Agent Remained after episode ends");
             }
         }
     }
     sys.battleStarted = false;
     System.Array.Resize(ref sys.knightUnits, 0);
     System.Array.Resize(ref sys.enemyUnits, 0);
     foreach (GameObject unit in inspector.getInstantiatedUnits())
     {
         Destroy(unit);
     }
     foreach (GameObject corpe in GameObject.FindGameObjectsWithTag("Ragdoll"))
     {
         corpe.GetComponent <DeleteParticles>().DestroyMe();
     }
 }
 public void onStart()
 {
     if (Dict != null)
     {
         foreach (Healthbar pair in Dict.Values)
         {
             Destroy(pair.gameObject);
         }
     }
     Dict = new Dictionary <GameObject, Healthbar>();
     if (characterPlacer.showhp)
     {
         GameObject[] units = inspector.getCurrentUnits();
         for (int i = 1; i <= units.Length; i++)
         {
             if (inspector.setScriptsFrom(units[i - 1]))
             {
                 GameObject obj = Instantiate(HpBar);
                 Healthbar  bar = obj.GetComponent <Healthbar>();
                 bar.SetDesc(inspector.getScriptType());
                 bar.SetColorTag(units[i - 1].tag);
                 bar.maximumHealth = inspector.getInitialLives();
                 obj.transform.SetParent(HpBarParent);
                 obj.transform.localPosition = new Vector3(87, i * (-34) - 38, 30);
                 obj.transform.localScale    = new Vector3(1f, 0.2f, 0.2f);
                 Dict.Add(units[i - 1], bar);
             }
         }
     }
 }
Example #3
0
    public void enableUnit(GameObject unit)
    {
        //enable all the components
        unit.GetComponent <NavMeshAgent>().enabled = true;
        unit.GetComponent <Collider>().enabled     = true;
        unit.GetComponent <AudioSource>().Play();
        if (inspector.setScriptsFrom(unit))
        {
            inspector.setEnable(true);
        }
        if (inspector.getScriptType() == "AgentScript")
        {
            inspector.setInitAgent(brain);
        }
        if (unit.GetComponent <Archer>())
        {
            unit.GetComponent <Archer>().enabled = true;
        }

        unit.transform.Find("Health").gameObject.SetActive(true);

        //show particles
        foreach (ParticleSystem particles in unit.GetComponentsInChildren <ParticleSystem>())
        {
            particles.gameObject.SetActive(true);
        }

        //start the animators
        foreach (Animator animator in unit.GetComponentsInChildren <Animator>())
        {
            animator.SetBool("Start", true);
        }
    }
 /// <summary>set Debuginfo from given unit</summary>
 /// <param name="unit">lolsbarry</param>
 public void setFromUnit(GameObject unit)
 {
     if (i.setScriptsFrom(unit))
     {
         initialLives   = i.getInitialLives();
         currentLives   = i.getLives();
         defaultDammage = i.getDamage();
         attackTag      = i.getAttackTag();
         range          = i.getRange();
         unitType       = i.getScriptType();
         //needAction=i.getNeedAction();
     }
 }
Example #5
0
    public override void RewardAtEpisodeEnds(UnitInspect inspector, GameSystem sys)
    {
        float AllDamaged = (inspector.getCurrentEnemys().Length <= 0)?0:inspector.AvgLives(inspector.getCurrentEnemys());

        //Rewarding globally
        foreach (GameObject knight in inspector.getInstantiatedKnights())
        {
            inspector.setScriptsFrom(knight);
            if (inspector.isScriptValid() && inspector.getScriptType() == "AgentScript")
            {
                BagReset();
                AddReward((1 - ((AllDamaged) / sys.AllInitLives)) * 2f);
                Apply(inspector.AgentScript);
            }
        }

        /*
         * //Rewarding reamined units
         * foreach(GameObject knight in inspector.getCurrentKnights()) {
         *  inspector.AgentAddRewardDircetly(1f);
         * }
         */
    }