/
/
/ "BRO TIGER"2017-10-15 13:15:01
C++ / C#
/ "BRO TIGER", 2017-10-15 13:15:01

How to organize the removal of unnecessary objects with information about the characteristics of the Objects?

Good day Toaster! I thought about adding in my project some characteristics of different parts with different characteristics, I created several scripts: one is tied to the "Content List" inside which all the elements were equal, the second to the "tablet" prefab with an icon, name, and number ...
Made more or less adequate creation of prefabs inside the Content sheet, when the user hovered the mouse over the part of interest, a list of characteristics was displayed, but when hovering over another part, the plates with characteristics remained the same. I thought: How to organize an adequate removal of extra "Tables"? I wanted to create a deletion through a while loop, but ... Windows does not want to digest it and just goes into a knockout))) Do you know how to organize the deletion more adequately?
PS When you move the mouse cursor over an object, the Content Sheet appears, and when the cursor leaves the Content Sheet disappears...

DetailInfo - Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;


[System.Serializable]
public class DetailInfos
{
    public string nameInfoLabel;
    public Sprite infoSorta;
    public int infoCount;
}


public class DetailInfo : MonoBehaviour
{
    public List<DetailInfos> InfoPrefabs;
    public GameObject StatisticPrefab;

    public Text detailName;
    public Text detailInfo;
    public Image sortaImage;

    GameObject currentobject;
    RaycastHit hit;

    GameObject statisticGameObject;
    BuildingSystem buildingSystem;
    BuildingHUB buildingHUB;
    DetailRefs detailRefs;

    bool statisticPrefabSpawned;
    bool readyToClear;


    void Start()
    {
        buildingSystem = Camera.main.GetComponent<BuildingSystem>();
        buildingHUB = GameObject.Find("Building_Manager").GetComponent<BuildingHUB>();
    }


    void Update()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit))
            currentobject = hit.transform.gameObject;

        detailRefs = currentobject.GetComponent<DetailRefs>();

        if (detailRefs.highlight)
        {
            detailName.text = detailRefs.nameLabel;
            detailInfo.text = detailRefs.infoLabel;
            sortaImage.sprite = detailRefs.sortaImage;

            InfoPrefabs = detailRefs.info;

            if (!statisticPrefabSpawned)
            {
                for (int i = 0; i < InfoPrefabs.Count; i++)
                {
                    DetailInfos info = InfoPrefabs[i];

                    statisticGameObject = (GameObject)Instantiate(StatisticPrefab, this.transform);
                    SampleInfoPrefab sampleInfoPrefab = statisticGameObject.GetComponent<SampleInfoPrefab>();
                    sampleInfoPrefab.Setup(info, this);
                }

                statisticPrefabSpawned = true;
            }
        }
    }
}
SampleInfoPrefab - Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;

public class SampleInfoPrefab : MonoBehaviour
{
    public Text nameLabel;
    public Image iconImage;
    public Text countText;

    private DetailInfos info;
    private DetailInfo scrollList;

    public void Setup(DetailInfos currentInfo, DetailInfo currentDetailInfo)
    {
        info = currentInfo;

        nameLabel.text = info.nameInfoLabel;
        iconImage.sprite = info.infoSorta;
        countText.text = info.infoCount.ToString();
        scrollList = currentDetailInfo;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
/
/ "BRO TIGER", 2017-10-17
@BRO_TIGER

After sitting a little over the script and on the project itself, as well as unchecking the SetActive object in the Content List, I noticed that if you uncheck it, the Content List itself will shrink to the desired size ... And I figured out how to make the system without problems ... Just when the object is in a certain sorting, you can turn on a ready-made card through SetActive and it remains only to fill it in ... And I bothered about Instatiate and Destroy thinking that there was no other way ...

A piece of script with changes
if (detailRefs != null)
        {
            detailName.text = detailRefs.nameLabel;
            detailInfo.text = detailRefs.infoLabel;
            sortaImage.sprite = detailRefs.sortaImage;

            if(detailRefs.sort == DetailRefs.objectsorts.hull)
            {
                hullInfo.SetActive(true);
                hardwareInfo.SetActive(false);

                strenght[0].text = detailRefs.strength.ToString();
                mass[0].text = detailRefs.density.ToString();
            }
            else if (detailRefs.sort == DetailRefs.objectsorts.hardware)
            {
                hullInfo.SetActive(false);
                hardwareInfo.SetActive(true);

                strenght[1].text = detailRefs.strength.ToString();
                energy[0].text = detailRefs.energy.ToString();
                mass[1].text = detailRefs.density.ToString();
            }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question