コード例 #1
0
    public void SelectItem(PickableMat mat)
    {
        CurrentPickableMat = mat;
        Value = mat.index;
        Image current_img = CurrentMaterial.GetComponent <Image>();

        current_img.sprite = mat.GetSprite();
        current_img.color  = mat.GetColor();

        HideList();
        if (onUpdateEvent != null)
        {
            onUpdateEvent.Invoke();
        }
    }
コード例 #2
0
    // Start is called before the first frame update
    void Start()
    {
        CurrentMaterial    = transform.Find("CurrentMaterial").gameObject;
        MaterialList       = transform.Find("MaterialList").gameObject;
        MaterialContainer  = MaterialList.transform.Find("MaterialContainer").gameObject;
        CurrentPickableMat = MATERIALS[0];
        Image current_img = CurrentMaterial.GetComponent <Image>();

        current_img.color = MATERIALS[0].GetColor();


        MaterialList.SetActive(false);
        foreach (PickableMat mat in MATERIALS)
        {
            GameObject go  = Instantiate(Resources.Load <GameObject>("PickableButton"), Vector3.zero, Quaternion.identity);
            Image      img = go.GetComponent <Image>();
            img.sprite = mat.GetSprite();
            img.color  = mat.GetColor();
            Button btn = go.GetComponent <Button>();
            btn.onClick.AddListener(delegate { SelectItem(mat); });
            go.transform.SetParent(MaterialContainer.transform);
        }
    }