Esempio n. 1
0
    private void ApplyConfig(RoomConfig conf)
    {
        if (conf == null)
        {
            return;
        }

        foreach (string dirtyPair in conf.pickedItemsAndVariants)
        {
            string[] strs = dirtyPair.Split('+');
            var      item = ScriptableList <RoomItemConfig> .instance.GetItemByID(strs[0]);

            if (item != null)
            {
                var privewingItems = FindObjectsOfType <IChangable>(); //just tag previewing gameobjects with this
                foreach (var it in privewingItems)
                {
                    if (it.gameObject.name == item.furnitureType.ToString())
                    {
                        var rotation = it.gameObject.transform.rotation; //save starting rotation


                        if (item.mesh != null)
                        {
                            it.gameObject.GetComponent <MeshFilter>().mesh = item.mesh;
                        }
                        it.gameObject.GetComponent <MeshRenderer>().material       = item.material;
                        it.gameObject.GetComponent <MeshRenderer>().material.color = conf.GetActiveVariant(item).color;
                        it.transform.rotation = rotation;
                    }
                }
            }
        }
    }
Esempio n. 2
0
    //show item at model(preview)
    private void OnItemPressed(GameObject item)
    {
        ObjectsPreviewing.Clear();
        var itemCFG = item.GetComponent <RoomItemDisplay>().itemConfig;

        activeVariant = currentRoomConf?.GetActiveVariant(itemCFG);

        foreach (GameObject it in roomItems)
        {
            if (it.name == itemCFG.furnitureType.ToString())
            {
                camMov.target = it.transform;
                ObjectsPreviewing.Add(it);
                if (itemCFG.mesh != null)
                {
                    it.GetComponent <MeshFilter>().mesh = itemCFG.mesh;
                }

                var itemRenderer = it.GetComponent <MeshRenderer>();
                itemRenderer.material       = itemCFG.material;
                itemRenderer.material.color = currentRoomConf?.ItemIsInConfig(itemCFG) == true?
                                              currentRoomConf.GetActiveVariant(itemCFG).color : itemCFG.variants[0].color;
            }
        }
        itemPreviewing = itemCFG;
    }
Esempio n. 3
0
    private void DisplayItem(GameObject itemGO)
    {
        currentRoomConfig = SaveManager.Instance.LoadRoomSet();
        variantSlider.SetActive(true); //activate it just in case


        //display item description
        itemCFG = itemGO.GetComponent <RoomItemDisplay>().itemConfig;
        rightPanel.SetActive(true);
        itemDisplaying = Instantiate(itemGO, rightPanel.transform.position, Quaternion.identity);
        itemDisplaying.transform.SetParent(parentForItem);
        itemDisplaying.GetComponent <RectTransform>().ResetTransform();
        itemDisplaying.GetComponent <RectTransform>().sizeDelta = itemDisplaySize;
        if (shopManager.CheckIfItemIsBought(itemCFG, currentRoomConfig.GetActiveVariant(itemCFG)))
        {
            buyButton.SetActive(false);
        }
        else
        {
            buyButton.SetActive(true);
        }


        //clear all variants
        var children = parentForVariants.GetComponentsInChildren <Transform>();

        foreach (Transform child in children)
        {
            if (child != parentForVariants.transform)
            {
                Destroy(child.gameObject);
            }
        }


        // spawn variants in RightSlider
        if (itemCFG.variants.Count > 1)
        {
            foreach (ItemVariant V in itemCFG.variants)
            {
                var varGroup = parentForVariants.GetComponent <VariantGroup>();
                var variant  = Instantiate(variantPrefab);
                variant.transform.SetParent(parentForVariants);
                var varTab = variant.GetComponent <VariantTab>();
                varTab.group   = varGroup;
                varTab.variant = V;
                varTab.group.Subscribe(varTab);
                varTab.tabBackground.color = V.color;
                bool hasActiveVar;
                if (currentRoomConfig.ItemIsInConfig(itemCFG))
                {
                    hasActiveVar = currentRoomConfig.GetActiveVariant(itemCFG) == V ? true : false;
/*                    Debug.Log("Item: " + itemCFG + ", active variant :" + currentRoomConfig.GetActiveVariant(itemCFG));*/
                }
                else
                {
                    hasActiveVar = V == itemCFG.variants[0] ? true : false;
                }
                varTab.activeIMG.gameObject.SetActive(hasActiveVar);

                bool isActive = currentRoomConfig.ItemAndVarIsInConfig(itemCFG, V) == true ? true : false;
                varTab.activeTick.SetActive(isActive);

                bool isBought = shopManager.CheckIfItemIsBought(itemCFG, V) /* || V.cost == 0*/ == true ? false : true;
                varTab.lockIMG.gameObject.SetActive(isBought);
            }
            ManipulateDisplayingInfo(currentRoomConfig.GetActiveVariant(itemCFG));
        }
        else
        {
            variantSlider.SetActive(false);
            ManipulateDisplayingInfo(itemCFG.variants[0]);
        }

        Destroy(itemDisplaying.GetComponent <ItemClick>());
    }