Пример #1
0
        //method to spawn a specific gem
        void SpawnGem(MineralItem gemChosen)
        {
            float valueMod = 1.0f - (gemChosen.Value / 1000.0f);

            //instantiate gem object
            GemBehavior thisGem = Instantiate(gemPrefab, voxelGrid.transform).GetComponent <GemBehavior>();

            //generate random position and normalize it
            Vector3 gemPosition = new Vector3(
                Random.Range(-1.0f, 1.0f),
                Random.Range(-1.0f, 1.0f),
                Random.Range(-1.0f, 1.0f)).normalized;

            //place position within specified range of origin
            float rangePercentage = Random.Range(valueMod / 2.0f, valueMod) * range;

            gemPosition = gemPosition * rangePercentage + gemOrigin;

            //correct for floating gems
            gemPosition = PullToRock(gemPosition);

            //set the gem's position
            thisGem.transform.position = gemPosition;

            // Set the gem's internal data
            thisGem.name = "Gem (" + gemChosen.ItemName + ")";
            thisGem.Initialize(gemChosen);
        }
Пример #2
0
        public MineralItem GetMineralData()
        {
            MineralItem i = ScriptableObject.CreateInstance <MineralItem>();

            i.SetValues(itemName, itemText, value, spriteName, modelName, new Color(colorR, colorG, colorB, 1.0f));

            return(i);
        }
Пример #3
0
        public SaveItem(InventoryItem item)
        {
            if (item is ToolItem)
            {
                type = ItemType.TOOL;
            }
            else if (item is MineralItem)
            {
                type = ItemType.MINERAL;
            }
            else if (item is ConsumableItem)
            {
                type = ItemType.CONSUMABLE;
            }
            else
            {
                type = ItemType.OTHER;
            }

            itemName   = item.ItemName;
            itemText   = item.ItemText;
            value      = item.Value;
            spriteName = item.SpriteName;

            switch (type)
            {
            case ItemType.TOOL:
                ToolItem t = item as ToolItem;

                toolType  = t.Type;
                inputType = t.InputType;
                power     = t.Power;
                precision = t.Precision;
                sustainedBreakCooldown = t.SustainedBreakCooldown;
                breakRadius            = t.BreakRadius;
                break;

            case ItemType.MINERAL:
                MineralItem m = item as MineralItem;

                modelName = m.ModelName;
                colorR    = m.Color.r;
                colorG    = m.Color.g;
                colorB    = m.Color.b;
                break;

            case ItemType.CONSUMABLE:
                ConsumableItem c = item as ConsumableItem;

                consumableType = c.Type;
                strength       = c.Strength;
                duration       = c.Duration;
                break;
            }
        }
Пример #4
0
        //generate a number of gems
        public void GenerateGems()
        {
            ResetGemerationValues();

            do
            {
                //randomly choose a gem
                MineralItem gemChosen = gemObjects[Random.Range(0, gemObjects.Count)];

                SpawnGem(gemChosen);

                //subtract from total value
                totalRockValue -= gemChosen.Value;
            } while (totalRockValue > 0);
        }
Пример #5
0
 public void Initialize(MineralItem item)
 {
     textMesh.color = item.Color;
     textMesh.text  = string.Format("${0:n0}", item.Value);
 }
Пример #6
0
        public void SpawnFloatingText(Vector3 position, MineralItem item)
        {
            TextFade text = Instantiate(FloatingText, position, Quaternion.identity).GetComponent <TextFade>();

            text.Initialize(item);
        }