Exemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        if (aiUnits == null)
        {
            aiUnits = new List <AIUnitScript>();

            aiUnitToGameObjectMap = new Dictionary <AIUnitScript, GameObject>();
        }

        currentAICreation = AIEnemyCreation.AIEnemyTheFirst;
        enemyCount        = 0;
        instance          = this;
        GenerateMap();
        UnitScript unit = new UnitScript();

        SpawnUnitAt(unit, unitPlumberPrefab, 10, 10);
        AIUnitScript aiUnit  = new AIUnitScript();
        AIUnitScript aiUnit2 = new AIUnitScript();
        AIUnitScript aiUnit3 = new AIUnitScript();

        SpawnAIUnitAt(aiUnit, unitPlumberPrefab, 17, 17);
        currentAICreation = AIEnemyCreation.AIEnemyTheSecond;
        SpawnAIUnitAt(aiUnit2, unitPlumberPrefab, 2, 17);
        currentAICreation = AIEnemyCreation.AIEnemyTheThird;
        SpawnAIUnitAt(aiUnit3, unitPlumberPrefab, 17, 2);

        foreach (var item in aiUnits)
        {
            Debug.LogError(item);
        }

        //Debug.LogError(-Mathf.Infinity);
    }
Exemplo n.º 2
0
    public void SpawnAIUnitAt(AIUnitScript aiUnit, GameObject prefab, int q, int r)
    {
        #region Attempt at Spawning procedures
        if (currentAICreation == AIEnemyCreation.AIEnemyTheFirst)
        {
            AIUnitScript aiUnitTheFirst = aiUnit;
            GameObject   myHex_go       = hexToGameObjectMap[GetHexAt(q, r)];
            aiUnitTheFirst.SetHex(GetHexAt(q, r));
            GameObject unitPlumberTheFirst_go = (GameObject)Instantiate(prefab, new Vector3(myHex_go.transform.position.x, 1, myHex_go.transform.position.z), Quaternion.identity, myHex_go.transform);
            aiUnitTheFirst.OnUnitMoved    += unitPlumberTheFirst_go.GetComponent <UnitViewScript>().OnUnitMoved;
            aiUnitTheFirst.ReceivedName   += unitPlumberTheFirst_go.GetComponent <UnitViewScript>().ReceiveName;
            aiUnitTheFirst.ReceivedNumber += unitPlumberTheFirst_go.GetComponent <UnitViewScript>().ReceiveNumber;
            aiUnitTheFirst.name            = "AIAggressivePlumber";
            aiUnitTheFirst.SetName();
            aiUnitTheFirst.enemyNumber = 1;
            aiUnitTheFirst.SetNumber();

            aiUnits.Insert(enemyCount, aiUnitTheFirst);
            //aiUnitGameObjects.Add(unitPlumber_go);

            aiUnitToGameObjectMapList.Add(unitPlumberTheFirst_go);
            //aiUnitToGameObjectMap.Add(aiUnitTheFirst, unitPlumberTheFirst_go);

            enemyCount++;
            currentAICreation = AIEnemyCreation.Stalling;
        }

        if (currentAICreation == AIEnemyCreation.AIEnemyTheSecond)
        {
            List <AIUnitScript> test2           = aiUnits;
            AIUnitScript        aiUnitTheSecond = aiUnit;
            GameObject          myHex_go        = hexToGameObjectMap[GetHexAt(q, r)];
            aiUnitTheSecond.SetHex(GetHexAt(q, r));
            GameObject unitPlumberTheSecond_go = (GameObject)Instantiate(prefab, new Vector3(myHex_go.transform.position.x, 1, myHex_go.transform.position.z), Quaternion.identity, myHex_go.transform);
            aiUnitTheSecond.OnUnitMoved    += unitPlumberTheSecond_go.GetComponent <UnitViewScript>().OnUnitMoved;
            aiUnitTheSecond.ReceivedName   += unitPlumberTheSecond_go.GetComponent <UnitViewScript>().ReceiveName;
            aiUnitTheSecond.ReceivedNumber += unitPlumberTheSecond_go.GetComponent <UnitViewScript>().ReceiveNumber;
            aiUnitTheSecond.name            = "AIDocilePlumber";
            aiUnitTheSecond.SetName();
            List <AIUnitScript> test = aiUnits;
            aiUnitTheSecond.enemyNumber = 2;
            aiUnitTheSecond.SetNumber();


            aiUnits.Insert(enemyCount, aiUnitTheSecond);
            //aiUnitGameObjects.Add(unitPlumber_go);

            aiUnitToGameObjectMapList.Add(unitPlumberTheSecond_go);
            //aiUnitToGameObjectMap.Add(aiUnitTheSecond, unitPlumberTheSecond_go);

            enemyCount++;
            currentAICreation = AIEnemyCreation.Stalling;
        }

        if (currentAICreation == AIEnemyCreation.AIEnemyTheThird)
        {
            if (currentAICreation == AIEnemyCreation.AIEnemyTheThird)
            {
                AIUnitScript aiUnitTheThird = aiUnit;
                GameObject   myHex_go       = hexToGameObjectMap[GetHexAt(q, r)];
                aiUnitTheThird.SetHex(GetHexAt(q, r));
                GameObject unitPlumberTheFirst_go = (GameObject)Instantiate(prefab, new Vector3(myHex_go.transform.position.x, 1, myHex_go.transform.position.z), Quaternion.identity, myHex_go.transform);
                aiUnitTheThird.OnUnitMoved    += unitPlumberTheFirst_go.GetComponent <UnitViewScript>().OnUnitMoved;
                aiUnitTheThird.ReceivedName   += unitPlumberTheFirst_go.GetComponent <UnitViewScript>().ReceiveName;
                aiUnitTheThird.ReceivedNumber += unitPlumberTheFirst_go.GetComponent <UnitViewScript>().ReceiveNumber;
                aiUnitTheThird.name            = "AIDesperatePlumber";
                aiUnitTheThird.SetName();
                aiUnitTheThird.enemyNumber = 3;
                aiUnitTheThird.SetNumber();

                aiUnits.Insert(enemyCount, aiUnitTheThird);
                //aiUnitGameObjects.Add(unitPlumber_go);

                aiUnitToGameObjectMapList.Add(unitPlumberTheFirst_go);
                //aiUnitToGameObjectMap.Add(aiUnitTheFirst, unitPlumberTheFirst_go);

                enemyCount++;
                currentAICreation = AIEnemyCreation.Stalling;
            }
        }

        if (currentAICreation == AIEnemyCreation.AIEnemyTheFourth)
        {
            GameObject myHex_go = hexToGameObjectMap[GetHexAt(q, r)];
            aiUnit.SetHex(GetHexAt(q, r));
            GameObject unitPlumberTheFourth_go = (GameObject)Instantiate(prefab, new Vector3(myHex_go.transform.position.x, 1, myHex_go.transform.position.z), Quaternion.identity, myHex_go.transform);
            aiUnit.OnUnitMoved    += unitPlumberTheFourth_go.GetComponent <UnitViewScript>().OnUnitMoved;
            aiUnit.ReceivedName   += unitPlumberTheFourth_go.GetComponent <UnitViewScript>().ReceiveName;
            aiUnit.ReceivedNumber += unitPlumberTheFourth_go.GetComponent <UnitViewScript>().ReceiveNumber;
            aiUnit.name            = "AIDesperatePlumber";
            aiUnit.SetName();
            aiUnit.enemyNumber = 4;
            aiUnit.SetNumber();

            aiUnits.Add(aiUnit);
            //aiUnitGameObjects.Add(unitPlumber_go);

            AIUnitScript aiUnitTheFourth = aiUnit;
            aiUnitToGameObjectMapList.Add(unitPlumberTheFourth_go);
            //aiUnitToGameObjectMap.Add(aiUnitTheFourth, unitPlumberTheFourth_go);

            currentAICreation = AIEnemyCreation.Stalling;
        }
        #endregion
        #region attempt 2
        //if (aiUnits == null)
        //{
        //    aiUnits = new HashSet<AIUnitScript>();

        //    aiUnitToGameObjectMap = new Dictionary<AIUnitScript, GameObject>();
        //}

        //GameObject myHex_go = hexToGameObjectMap[GetHexAt(q, r)];
        //aiUnit.SetHex(GetHexAt(q, r));
        //GameObject unitPlumber_go = (GameObject)Instantiate(prefab, new Vector3(myHex_go.transform.position.x, 1, myHex_go.transform.position.z), Quaternion.identity, myHex_go.transform);
        //aiUnit.OnUnitMoved += unitPlumber_go.GetComponent<UnitViewScript>().OnUnitMoved;
        //aiUnit.ReceivedName += unitPlumber_go.GetComponent<UnitViewScript>().ReceiveName;
        //aiUnit.ReceivedNumber += unitPlumber_go.GetComponent<UnitViewScript>().ReceiveNumber;
        //aiUnit.name = "AIDesperatePlumber";
        //aiUnit.SetName();
        //aiUnit.enemyNumber = enemyCount;
        //aiUnit.SetNumber();

        //aiUnits.Add(aiUnit);
        //aiUnitToGameObjectMapList.Add(unitPlumber_go);
        #endregion
    }