private void Update()
        {
            Dictionary <EquipSlot, Item> Equips = Inventory.Drive.GetEquippedItems();

            for (int i = 0; i < Slots.Length; i++)
            {
                bool Equipped     = Equips.ContainsKey(Slots[i].Slot);
                bool LastEquipped = LastEquips.ContainsKey(Slots[i].Slot);
                // Check if this slot needs to be changed
                if (Equipped != LastEquipped || (Equipped && Equips[Slots[i].Slot] != LastEquips[Slots[i].Slot]))
                {
                    // Clear slot
                    for (int j = 0; j < Slots[i].Transform.childCount; j++)
                    {
                        Destroy(Slots[i].Transform.GetChild(j).gameObject);
                    }
                    if (!Equipped)
                    {
                        // Nothing is equipped
                        LastEquips.Remove(Slots[i].Slot);
                    }
                    else
                    {
                        // Something is equipped
                        Item Item = Equips[Slots[i].Slot];
                        PrefabDB.Create(Item.ModelID, Slots[i].Transform);
                        LastEquips[Slots[i].Slot] = Item;
                    }
                }
            }
        }
Exemple #2
0
 private void SetPreviewItem(Item item)
 {
     ItemPreviewSpinner.Spinning = item != null;
     if (item != null && PreviewModelID != item.ModelID)
     {
         for (int j = 0; j < ItemPreview.childCount; j++)
         {
             DestroyImmediate(ItemPreview.GetChild(j).gameObject);
         }
         GameObject ItemObject = PrefabDB.Create(item.ModelID, ItemPreview);
         MeshUtil.SetMaterial(ItemObject, ItemPreviewHologramMaterial);
         PreviewModelID = item.ModelID;
     }
     FixMeshScaling(ItemPreview, 0.35f * PreviewVisibility);
 }
Exemple #3
0
        private void RebuildItemGrid(int focused)
        {
            bool ItemFound = false;

            for (int y = 0; y < ItemGridDimensions.y; y++)
            {
                for (int x = 0; x < ItemGridDimensions.x; x++)
                {
                    // Find the item and mesh
                    int  i    = x + y * (int)ItemGridDimensions.x;
                    Item Item = Inventory.Drive.GetItemAt(x + y * (int)ItemGridDimensions.x);
                    if (Item != null && (!ItemGridContainedItems.ContainsKey(i) || ItemGridContainedItems[i] != Item))
                    {
                        // Clear cell
                        for (int j = 0; j < ItemGridCells[i].childCount; j++)
                        {
                            DestroyImmediate(ItemGridCells[i].GetChild(j).gameObject);
                        }

                        // Add new item
                        GameObject ItemObject = PrefabDB.Create(Item.ModelID, ItemGridCells[i]);
                        MeshUtil.SetMaterial(ItemObject, ItemGridHologramMaterial);
                        ItemGridContainedItems[i] = Item;
                    }
                    else if (Item == null && ItemGridContainedItems.ContainsKey(i))
                    {
                        for (int j = 0; j < ItemGridCells[i].childCount; j++)
                        {
                            Destroy(ItemGridCells[i].GetChild(j).gameObject);
                        }
                        ItemGridContainedItems.Remove(i);
                    }

                    // Set the base scale and spin status
                    float Scale    = 0.13f;
                    bool  Spinning = false;

                    if (focused == i || ItemGridSelectedIndex == i)
                    {
                        // Item is selected or hovered, animate
                        Scale    = 0.16f;
                        Spinning = true;
                    }

                    if (ItemGridSelectedIndex == i)
                    {
                        // Set preview information
                        if (ItemGridCells[i].childCount > 0)
                        {
                            SetPreviewItem(Item);
                        }
                        TextTextureProperties NameProps        = ItemNameText.TextProperties;
                        TextTextureProperties DescriptionProps = ItemDescriptionText.TextProperties;
                        if (Item != null)
                        {
                            NameProps.Text        = Item.Name;
                            DescriptionProps.Text = Item.Description;
                            ItemFound             = true;
                        }
                        else
                        {
                            NameProps.Text        = "";
                            DescriptionProps.Text = "";
                        }
                        ItemNameText.SetTextProperties(NameProps);
                        ItemDescriptionText.SetTextProperties(DescriptionProps);

                        // Move selector
                        if ((ItemGridSelector.position - ItemGridCells[i].position).magnitude < 0.01f)
                        {
                            ItemGridSelector.position = ItemGridCells[i].position;
                        }
                        else
                        {
                            ItemGridSelector.position =
                                Vector3.Lerp(ItemGridSelector.position,
                                             ItemGridCells[i].position, 10f * Time.deltaTime);
                        }
                        Vector3 NewRot = ItemGridSelector.localEulerAngles;
                        NewRot.z = 0;
                        ItemGridSelector.localEulerAngles = NewRot;
                    }

                    if (!Spinning)
                    {
                        // Not selected, reset rotation
                        if (ItemGridCells[i].childCount > 0)
                        {
                            Transform ItemTransform = ItemGridCells[i].GetChild(0);
                            ItemTransform.LookAt(Camera.transform);
                            Vector3 NewRot = ItemTransform.localEulerAngles;
                            NewRot.z  = 0;
                            NewRot.y += 90;
                            ItemTransform.localEulerAngles = NewRot;
                        }
                    }

                    // Update spinning status and scaling
                    ItemGridCells[i].GetComponent <Spinner>().Spinning = Spinning;
                    if (ItemGridCells[i].childCount > 0)
                    {
                        FixMeshScaling(ItemGridCells[i].GetChild(0), Scale);
                    }
                }
            }

            // Hide the selector if nothing is selected
            ItemGridSelector.gameObject.SetActive(ItemGridSelectedIndex >= 0);

            // Clean up the preview screen if there was no item
            if (!ItemFound)
            {
                SetPreviewItem(null);
                TextTextureProperties NameProps        = ItemNameText.TextProperties;
                TextTextureProperties DescriptionProps = ItemDescriptionText.TextProperties;
                NameProps.Text        = "";
                DescriptionProps.Text = "";
                ItemNameText.SetTextProperties(NameProps);
                ItemDescriptionText.SetTextProperties(DescriptionProps);
                PreviewVisibility = Mathf.Lerp(PreviewVisibility, 0f, 10f * Time.deltaTime);
            }
            else
            {
                PreviewVisibility = Mathf.Lerp(PreviewVisibility, 1f, 10f * Time.deltaTime);
            }
        }