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);
             }
         }
     }
 }
예제 #2
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();
     }
 }
예제 #3
0
    ///<summary>set battleStarted to be True</summary>
    public void startBattle()
    {
        AgentPreset preset;

        initEnemyNumber  = inspector.getCurrentEnemys().Length;
        initKnightNumber = inspector.getCurrentKnights().Length;
        int numberOfSpace = inspector.getCurrentUnits().Length *2;

        foreach (GameObject unit in inspector.getCurrentUnits())
        {
            if (unit.TryGetComponent <AgentPreset>(out preset))
            {
                if (preset.AgentType == "Unit")
                {
                    dynamic obj = preset.refer(numberOfSpace, AcademyInner.resetParameters);
                    unit.SetActive(true);
                    unit.SendMessage("initRefer", obj, SendMessageOptions.RequireReceiver);
                }
                else
                {
                    Type anytype = Type.GetType(preset.AgentType);
                    if (anytype != null)
                    {
                        Component script = unit.AddComponent(anytype);
                        dynamic   obj    = preset.refer(numberOfSpace, AcademyInner.resetParameters);
                        Debug.Log($"{anytype.Name} / {script.name} / {obj}");
                        unit.SetActive(true);
                        script.SendMessage("initRefer", obj, SendMessageOptions.RequireReceiver);
                    }
                    else
                    {
                        Debug.LogError("There was invalid Agent type string which couldn't converted to type object ");
                    }
                }
            }
        }

        print($"Start:{knightUnits.Length}/{enemyUnits.Length}");
        //show the new UI
        cam.onStart();
        StartCoroutine(battleUI());
        battleStarted = true;
        //Hardcoded rewarding algorithm, need to be adjusted
        AllInitLives = 0;
    }