Example #1
0
    public GameObject GetPickable(HorseItem.Type type, bool showName = false, bool destroyOnPick = true)
    {
        HorseItem item = Get(type);

        if (!item)
        {
            return(null);
        }

        GameObject go = Instantiate(pickablePrefab.gameObject);

        go.name                    = type.ToString();
        go.transform.parent        = null;
        go.transform.position      = Vector3.zero;
        go.transform.localRotation = Quaternion.identity;
        go.transform.localScale    = Vector3.one;
        go.AddComponent <InteractionType>().type = InteractionType.Type.pickableHorse;
        HorseItem.Copy(item, go.AddComponent <HorseItem>());
        go.SetActive(true);

        SkinnedMeshRenderer        skin     = item.gameObject.GetComponent <SkinnedMeshRenderer>();
        SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();

        pickable.textmesh.text = go.name;
        if (go.name.Length >= 8)
        {
            pickable.textmesh.characterSize *= 0.5f;
        }
        pickable.itemMesh.gameObject.SetActive(false);
        pickable.body.gameObject.SetActive(false);

        pickable.horse.gameObject.SetActive(true);
        if (skin)
        {
            BodySlot.CopySkinnedMesh(skin, pickable.horse);
        }
        else
        {
            pickable.horse.gameObject.SetActive(false);
        }

        pickable.textmesh.gameObject.SetActive(showName);
        go.GetComponent <Item>().destroyOnPick = destroyOnPick;

        return(go);
    }
Example #2
0
    private void InstanciateShop()
    {
        GameObject shopContainer = new GameObject("shopContainer");

        shopContainer.transform.parent        = transform;
        shopContainer.transform.localPosition = Vector3.zero;
        shopContainer.transform.localRotation = Quaternion.identity;
        shopContainer.transform.localScale    = Vector3.one;
        shopContainer.SetActive(true);

        if (export_csv)
        {
            file_csv += "Arsenal items\n" +
                        "Name;Load;Dammage;Armor;Capacity;Wood;Wheat;Stone;Iron;Gold;Crystal\n";
        }

        // backpack
        Vector3 position = Vector3.zero;

        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = BackpackItem.Type.None.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = new Vector3(-2 * gap, position.y, position.z);
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableBackpack;
            go.AddComponent <BackpackItem>();
            go.SetActive(true);
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            pickable.body.gameObject.SetActive(false);

            if (export_csv)
            {
                file_csv += "\nbackpack items\n";
            }
        }
        foreach (KeyValuePair <BackpackItem.Type, BackpackItem> item in backpackDictionary)
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = item.Key.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = position;
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableBackpack;
            BackpackItem.Copy(item.Value, go.AddComponent <BackpackItem>());
            go.SetActive(true);

            MeshFilter mf = item.Value.gameObject.GetComponent <MeshFilter>();
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            if (mf)
            {
                pickable.itemMesh.mesh = mf.mesh;
            }
            else
            {
                pickable.itemMesh.gameObject.SetActive(false);
            }
            pickable.body.gameObject.SetActive(false);

            if (createIcons)
            {
                pickable.textmesh.gameObject.SetActive(false);
                pickable.transform.localEulerAngles = new Vector3(0, 15, 0);
                cameraPivot.position = go.transform.position + new Vector3(-0.13f, 0.6f, 1.1f);

                if (item.Key == BackpackItem.Type.AdventureBackpack)
                {
                    pickable.transform.localEulerAngles = new Vector3(0, 90, 0);
                    cameraPivot.position = go.transform.position + new Vector3(0f, 0.7f, 0.9f);
                }

                CreateIcon(iconFolderPath + "/Backpacks/" + go.name + ".png");
            }
            if (export_csv)
            {
                ItemCost cost = GetCost(item.Value.crafting);
                file_csv += item.Key.ToString() + ";" +
                            item.Value.load.ToString() + ";0;0;" + item.Value.capacity.ToString() + ";" +
                            cost.wood.ToString() + ";" + cost.wheat.ToString() + ";" + cost.stone.ToString() + ";" + cost.iron.ToString() + ";" + cost.gold.ToString() + ";" + cost.crystal.ToString() + "\n";
            }
            position.x += gap;
        }

        // shields
        position.x = 0; position.z -= gap; position.y += gapY;
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = ShieldItem.Type.None.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = new Vector3(-2 * gap, position.y, position.z);
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableShield;
            go.AddComponent <ShieldItem>();
            go.SetActive(true);
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            pickable.body.gameObject.SetActive(false);

            if (export_csv)
            {
                file_csv += "\nshield items\n";
            }
        }
        foreach (KeyValuePair <ShieldItem.Type, ShieldItem> item in shieldDictionary)
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = item.Key.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = position;
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableShield;
            ShieldItem.Copy(item.Value, go.AddComponent <ShieldItem>());
            go.SetActive(true);

            MeshFilter mf = item.Value.gameObject.GetComponent <MeshFilter>();
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            if (mf)
            {
                pickable.itemMesh.mesh = mf.mesh;
            }
            else
            {
                pickable.itemMesh.gameObject.SetActive(false);
            }
            pickable.body.gameObject.SetActive(false);

            if (createIcons)
            {
                pickable.textmesh.gameObject.SetActive(false);
                pickable.transform.localEulerAngles = new Vector3(0, 30, 0);
                cameraPivot.position = go.transform.position + new Vector3(0f, 0.6f, 1.3f);
                CreateIcon(iconFolderPath + "/Shields/" + go.name + ".png");
            }
            if (export_csv)
            {
                ItemCost cost = GetCost(item.Value.crafting);
                file_csv += item.Key.ToString() + ";" +
                            item.Value.load.ToString() + ";0;" + item.Value.armor.ToString() + ";0;" +
                            cost.wood.ToString() + ";" + cost.wheat.ToString() + ";" + cost.stone.ToString() + ";" + cost.iron.ToString() + ";" + cost.gold.ToString() + ";" + cost.crystal.ToString() + "\n";
            }
            position.x += gap;
        }

        // second hand
        position.x = 0; position.z -= gap; position.y += gapY;
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = SecondItem.Type.None.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = new Vector3(-2 * gap, position.y, position.z);
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableSecond;
            go.AddComponent <SecondItem>();
            go.SetActive(true);
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            pickable.body.gameObject.SetActive(false);

            if (export_csv)
            {
                file_csv += "\nsecond hand items\n";
            }
        }
        foreach (KeyValuePair <SecondItem.Type, SecondItem> item in secondDictionary)
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = item.Key.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = position;
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableSecond;
            SecondItem.Copy(item.Value, go.AddComponent <SecondItem>());
            go.SetActive(true);

            MeshFilter mf = item.Value.gameObject.GetComponent <MeshFilter>();
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            if (mf)
            {
                pickable.itemMesh.mesh = mf.mesh;
            }
            else
            {
                pickable.itemMesh.gameObject.SetActive(false);
            }
            pickable.body.gameObject.SetActive(false);

            if (createIcons)
            {
                pickable.textmesh.gameObject.SetActive(false);
                pickable.transform.localEulerAngles = new Vector3(0, 0, -42);
                cameraPivot.position = go.transform.position + new Vector3(0.3f, 0.45f, 1.5f);
                CreateIcon(iconFolderPath + "/SecondHands/" + go.name + ".png");
            }
            if (export_csv)
            {
                ItemCost cost = GetCost(item.Value.crafting);
                file_csv += item.Key.ToString() + ";" +
                            item.Value.load.ToString() + ";" + item.Value.dammage.ToString() + ";0;0;" +
                            cost.wood.ToString() + ";" + cost.wheat.ToString() + ";" + cost.stone.ToString() + ";" + cost.iron.ToString() + ";" + cost.gold.ToString() + ";" + cost.crystal.ToString() + "\n";
            }
            position.x += gap;
        }

        // weapons
        position.x = 0; position.z -= gap; position.y += gapY;
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = WeaponItem.Type.None.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = new Vector3(-2 * gap, position.y, position.z);
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableWeapon;
            go.AddComponent <WeaponItem>();
            go.SetActive(true);
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            pickable.body.gameObject.SetActive(false);
            if (export_csv)
            {
                file_csv += "\nweapon items\n";
            }
        }
        foreach (KeyValuePair <WeaponItem.Type, WeaponItem> item in weaponDictionary)
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = item.Key.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = position;
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableWeapon;
            WeaponItem.Copy(item.Value, go.AddComponent <WeaponItem>());
            go.SetActive(true);

            MeshFilter mf = item.Value.gameObject.GetComponent <MeshFilter>();
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            if (mf)
            {
                pickable.itemMesh.mesh = mf.mesh;
            }
            else
            {
                pickable.itemMesh.gameObject.SetActive(false);
            }
            pickable.body.gameObject.SetActive(false);

            if (createIcons)
            {
                pickable.textmesh.gameObject.SetActive(false);
                pickable.transform.localEulerAngles = new Vector3(0, 0, -42);
                cameraPivot.position = go.transform.position + new Vector3(0.3f, 0.6f, 1.5f);

                if (item.Key == WeaponItem.Type.FireSword)
                {
                    pickable.itemMesh.gameObject.transform.Find("swordFireEffect").gameObject.SetActive(true);
                }
                else if (item.Key == WeaponItem.Type.ElectricSword)
                {
                    pickable.itemMesh.gameObject.transform.Find("swordElectricEffect").gameObject.SetActive(true);
                }

                CreateIcon(iconFolderPath + "/Weapons/" + go.name + ".png");
            }
            if (export_csv)
            {
                ItemCost cost = GetCost(item.Value.crafting);
                file_csv += item.Key.ToString() + ";" +
                            item.Value.load.ToString() + ";" + item.Value.dammage.ToString() + ";0;0;" +
                            cost.wood.ToString() + ";" + cost.wheat.ToString() + ";" + cost.stone.ToString() + ";" + cost.iron.ToString() + ";" + cost.gold.ToString() + ";" + cost.crystal.ToString() + "\n";
            }
            position.x += gap;
        }

        // heads
        position.x = 0; position.z -= gap; position.y += gapY;

        if (export_csv)
        {
            file_csv += "\nhead items\n";
        }
        foreach (KeyValuePair <HeadItem.Type, HeadItem> item in headDictionary)
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = item.Key.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = position;
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableHead;
            HeadItem.Copy(item.Value, go.AddComponent <HeadItem>());
            go.SetActive(true);

            MeshFilter mf = item.Value.gameObject.GetComponent <MeshFilter>();
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            if (mf)
            {
                pickable.itemMesh.mesh = mf.mesh;
            }
            else
            {
                pickable.itemMesh.gameObject.SetActive(false);
            }
            pickable.body.gameObject.SetActive(false);

            if (createIcons)
            {
                pickable.textmesh.gameObject.SetActive(false);
                pickable.transform.localEulerAngles = new Vector3(0, 15, 0);
                cameraPivot.position = go.transform.position + new Vector3(0, 0.6f, 1f);
                CreateIcon(iconFolderPath + "/Heads/" + go.name + ".png");
            }
            if (export_csv)
            {
                ItemCost cost = GetCost(item.Value.crafting);
                file_csv += item.Key.ToString() + ";" +
                            item.Value.load.ToString() + ";0;" + item.Value.armor.ToString() + ";0;" +
                            cost.wood.ToString() + ";" + cost.wheat.ToString() + ";" + cost.stone.ToString() + ";" + cost.iron.ToString() + ";" + cost.gold.ToString() + ";" + cost.crystal.ToString() + "\n";
            }
            position.x += gap;
        }

        // bodies
        position.x = 0; position.z -= gap; position.y += gapY;

        if (export_csv)
        {
            file_csv += "\nbody items\n";
        }
        foreach (KeyValuePair <BodyItem.Type, BodyItem> item in bodyDictionary)
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = item.Key.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = position;
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableBody;
            BodyItem.Copy(item.Value, go.AddComponent <BodyItem>());
            go.SetActive(true);

            SkinnedMeshRenderer        skin     = item.Value.gameObject.GetComponent <SkinnedMeshRenderer>();
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            pickable.itemMesh.gameObject.SetActive(false);

            if (skin)
            {
                BodySlot.CopySkinnedMesh(skin, pickable.body);
            }
            else
            {
                pickable.body.gameObject.SetActive(false);
            }

            if (createIcons)
            {
                pickable.textmesh.gameObject.SetActive(false);
                pickable.transform.localEulerAngles = new Vector3(0, 15, 0);
                cameraPivot.position = go.transform.position + new Vector3(0, 0.5f, 1.5f);
                CreateIcon(iconFolderPath + "/Bodies/" + go.name + ".png");
            }
            if (export_csv)
            {
                ItemCost cost = GetCost(item.Value.crafting);
                file_csv += item.Key.ToString() + ";" +
                            item.Value.load.ToString() + ";0;" + item.Value.armor.ToString() + ";0;" +
                            cost.wood.ToString() + ";" + cost.wheat.ToString() + ";" + cost.stone.ToString() + ";" + cost.iron.ToString() + ";" + cost.gold.ToString() + ";" + cost.crystal.ToString() + "\n";
            }
            position.x += gap;
        }

        // horses
        position.x = 0; position.z -= 2 * gap; position.y += gapY;
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = HorseItem.Type.None.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = new Vector3(-2 * gap, position.y, position.z);
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableHorse;
            go.AddComponent <HorseItem>();
            go.SetActive(true);
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            pickable.body.gameObject.SetActive(false);

            if (export_csv)
            {
                file_csv += "\nhorse items\n";
            }
        }
        foreach (KeyValuePair <HorseItem.Type, HorseItem> item in horseDictionary)
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = item.Key.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = position;
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableHorse;
            HorseItem.Copy(item.Value, go.AddComponent <HorseItem>());
            go.SetActive(true);

            SkinnedMeshRenderer        skin     = item.Value.gameObject.GetComponent <SkinnedMeshRenderer>();
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            pickable.itemMesh.gameObject.SetActive(false);

            if (skin)
            {
                BodySlot.CopySkinnedMesh(skin, pickable.horse);
            }
            else
            {
                pickable.horse.gameObject.SetActive(false);
            }
            pickable.horse.gameObject.SetActive(true);
            pickable.body.gameObject.SetActive(false);

            if (createIcons)
            {
                pickable.textmesh.gameObject.SetActive(false);
                pickable.transform.localEulerAngles = new Vector3(0, 90, 0);
                cameraPivot.position = go.transform.position + new Vector3(0, 1, 3f);
                CreateIcon(iconFolderPath + "/Horses/" + go.name + ".png");
            }
            if (export_csv)
            {
                file_csv += item.Key.ToString() + ";" + item.Value.load.ToString() + ";0;" + item.Value.armor.ToString() + ";0;0;0;0;0;0;0\n";
            }
            position.x += gap;
        }



        if (export_csv)
        {
            StreamWriter writer = new StreamWriter("Assets/Resources/arsenal.csv", false);
            writer.WriteLine(file_csv);
            writer.Close();
        }
    }