示例#1
0
    private void UpdateVisual()
    {
        //Clean up old keys
        foreach (Transform child in container)
        {
            if (child == keyTemplate)
            {
                continue;
            }
            {
                Destroy(child.gameObject);
            }
        }

        //Instantiate current key list
        List <KeyScript.KeyType> keyList = keyHolder.GetKeyList();

        for (int i = 0; i < keyList.Count; i++)
        {
            KeyScript.KeyType keyType      = keyList[i];
            Transform         keyTransform = Instantiate(keyTemplate, container);
            keyTemplate.gameObject.SetActive(true);
            keyTransform.GetComponent <RectTransform>().anchoredPosition = new Vector2(50 * 1, 0);
            Image keyImage = keyTransform.Find("Image").GetComponent <Image>();
            switch (keyType)
            {
            default:
            case KeyScript.KeyType.Red: keyImage.color = Color.red; break;

            case KeyScript.KeyType.Green: keyImage.color = Color.red; break;

            case KeyScript.KeyType.Blue: keyImage.color = Color.red; break;
            }
        }
    }
 public bool ContainsKey(KeyScript.KeyType keyType)
 {
     return(keyList.Contains(keyType));
 }
 public void RemoveKey(KeyScript.KeyType keyType)
 {
     keyList.Remove(keyType);
     OnKeysChanged?.Invoke(this, EventArgs.Empty);
 }
 public void AddKey(KeyScript.KeyType keyType)
 {
     keyList.Add(keyType);
     OnKeysChanged?.Invoke(this, EventArgs.Empty);
 }