Esempio n. 1
0
    public void AddNewBuilding()
    {
        GameObject emptyGO = new GameObject();

        AssetDatabase.CreateFolder("Assets/Prefabs", nameUnit);
        GameObject tmp = PrefabUtility.CreatePrefab("Assets/Prefabs/" + nameUnit + "/" + nameUnit + ".prefab", emptyGO);

        tmp.AddComponent <Animator>();
        tmp.AddComponent <Rigidbody>();
        tmp.AddComponent <BoxCollider>();

        CreationBuilding building = tmp.AddComponent <CreationBuilding>();

        building.NameGo             = nameUnit;
        building.UnitType           = unitType;
        building.DefaultMaterial    = defaultMaterial;
        building.RegenManaPerSecond = regenManaPerSecond;
        Material   inAreaUnit     = (Material)AssetDatabase.LoadAssetAtPath("Assets/Prefabs/Skills/InAreaUnit.mat", typeof(Material));
        GameObject smallHealthBar = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/Prefabs/HealthBar/HealthBar.prefab", typeof(GameObject));

        building.InAreaMaterial       = inAreaUnit;
        building.SmallHealthBarPrefab = smallHealthBar;
        building.HealthMax            = healthMax;
        building.ManaMax      = manaMax;
        building.Cost         = cost;
        building.XpValue      = xpValue;
        building.Creations    = new WalkingUnit[1];
        building.Creations[0] = creation;

        // Create the building ghost and save it at the same folder as the original building
        GameObject emptyBuildingGhost = new GameObject();
        GameObject tmpBuildingGhost   = PrefabUtility.CreatePrefab("Assets/Prefabs/" + nameUnit + "/" + nameUnit + "Ghost.prefab", emptyBuildingGhost);

        tmpBuildingGhost.AddComponent <BuildingGhost>();
        tmpBuildingGhost.AddComponent <BoxCollider>();

        GameObject instantiatedTmpBuildingGhost = Instantiate(tmpBuildingGhost);

        //GameObject emptySkin = new GameObject();
        //emptySkin.transform.SetParent(tmpBuildingGhost.transform);
        //instantiatedTmpBuildingGhost.AddComponent<MeshFilter>();
        //if(skin)
        //    instantiatedTmpBuildingGhost.GetComponent<MeshFilter>().mesh =
        //GameObject skinInstantiated = null;
        //if (skin)
        //    skinInstantiated = Instantiate(skin, instantiatedTmpBuildingGhost.transform);
        //if (skinInstantiated && skinInstantiated.GetComponent<MeshRenderer>())
        //    skinInstantiated.GetComponent<MeshRenderer>().sharedMaterials[0] = ghostMaterial;


        PrefabUtility.ReplacePrefab(instantiatedTmpBuildingGhost, tmpBuildingGhost);

        building.BuildingGhost = tmpBuildingGhost;

        GameObject instantiatedTmp = Instantiate(tmp);

        if (skin)
        {
            Instantiate(skin, instantiatedTmp.transform);
        }

        GameObject projector = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/Prefabs/Projector/ProjectorPrefab.prefab", typeof(GameObject));

        if (!projector)
        {
            Debug.LogError("No aggro or projector or triggerXpArea object");
            return;
        }
        Instantiate(projector, instantiatedTmp.transform);

        PrefabUtility.ReplacePrefab(instantiatedTmp, tmp);
        DestroyImmediate(instantiatedTmp);

        DestroyImmediate(emptyGO);
    }
Esempio n. 2
0
    public void UpdateEveryFields()
    {
        GameObject tmpShit = (GameObject)AssetDatabase.LoadAssetAtPath(search_results[indexGO], typeof(GameObject));

        if (unitType.Equals(UnitType.AttackingUnit))
        {
            AttackingUnit unit = tmpShit.GetComponent <AttackingUnit>();

            nameUnit        = unit.NameGo;
            unitType        = unit.UnitType;
            defaultMaterial = unit.DefaultMaterial;
            //GameObject tmpSkin = new GameObject();
            //tmpSkin.AddComponent<MeshFilter>();
            //tmpSkin.GetComponent<MeshFilter>().mesh = unit.GetComponent<MeshFilter>().mesh;
            //skin = tmpSkin;
            //DestroyImmediate(tmpSkin);
            //skin
            regenManaPerSecond = unit.RegenManaPerSecond;
            healthMax          = unit.HealthMax;
            manaMax            = unit.ManaMax;
            cost    = unit.Cost;
            xpValue = unit.XpValue;

            bool inventoryEmpty = true;
            for (int i = 0; i < unit.Inventory.Length; i++)
            {
                if (unit.Inventory[i] != null)
                {
                    inventoryEmpty = false;
                }
            }

            if (!inventoryEmpty)
            {
                for (int i = 0; i < unit.Inventory.Length; i++)
                {
                    inventory[i] = unit.Inventory[i];
                }
            }

            creationTime         = unit.CreationTime;
            attackSpeed          = unit.AttackSpeed;
            damage               = unit.Damage;
            range                = unit.Range;
            defense              = unit.Defense;
            rangeAggroWhenAttack = unit.RangeAggroWhenAttack;
            moveSpeed            = unit.MoveSpeed;
        }
        else if (unitType.Equals(UnitType.Building))
        {
            CreationBuilding unit = tmpShit.GetComponent <CreationBuilding>();

            nameUnit        = unit.NameGo;
            unitType        = unit.UnitType;
            defaultMaterial = unit.DefaultMaterial;
            healthMax       = unit.HealthMax;
            manaMax         = unit.ManaMax;
            cost            = unit.Cost;
            xpValue         = unit.XpValue;
            creation        = unit.Creations[0];
            //bool creationsEmpties = true;
            //for (int i = 0; i < unit.Creations.Length; i++)
            //{
            //    if (unit.Creations[i] != null)
            //        creationsEmpties = false;
            //}
            //if (!creationsEmpties)
            //{
            //    for (int i = 0; i < unit.Creations.Length; i++)
            //    {
            //        if (unit.Creations[i] != null)
            //            creations[i] = unit.Creations[i];
            //    }
            //}
        }
    }