Example #1
0
        private void AddKeyButton(Key key, Transform parentArea)
        {
            int w = key.width * width + (key.width - 1) * widthInterval;
            int h = key.height * height + (key.height - 1) * heightInterval;
            int x = startX + key.x * (width + widthInterval) + w / 2;
            int y = startY - key.y * (height + heightInterval) - h / 2;

            GameObject keyObj = Instantiate(keyPrefab) as GameObject;

            keyObj.name = key.text;
            RectTransform keyTrans = keyObj.transform as RectTransform;

            keyTrans.SetParent(parentArea);
            keyTrans.localPosition = new Vector3(x, y, 0);
            keyTrans.localRotation = Quaternion.identity;
            keyTrans.localScale    = Vector3.one;

            CommonButton button = keyObj.GetComponent <CommonButton>();

            button.ButtonName = key.text;
            button.SetSize(w, h);

            button.param         = key.key;
            button.callbackClick = OnClick;
        }