Creating several buttons on the bottom of a video app player with the following code. The touch input works on android and on macOS build, but touch input is ignored on iPhone ios. Please see the code below. The button width and height are fixed but the position is calculated based on the screen width=1920 and height=1080
The code is below
for (int i = 0; i < mViewCount; i++)
{
GameObject lViewInstance = GameObject.Instantiate(mViewButtonTemplate);
lViewInstance.name = "ViewButton " + i;
Debug.Log ("Adding buttons");
RectTransform lViewTransform = lViewInstance.transform as RectTransform;
lViewTransform.SetParent(mViewButtonTemplate.transform.parent);
Image lViewImage = lViewTransform.GetChild(0).GetComponent();
lViewImage.rectTransform.sizeDelta = new Vector2(ViewButton.WIDTH, ViewButton.HEIGHT);
if (!InvertVideo())
{
lViewImage.rectTransform.rotation = Quaternion.AngleAxis(180f, lViewImage.rectTransform.right);
}
lViewTransform.localScale = Vector3.one;
lViewTransform.anchoredPosition = lViewTemplateTransform.anchoredPosition;
lViewTransform.anchorMin = lViewTemplateTransform.anchorMin;
lViewTransform.anchorMax = lViewTemplateTransform.anchorMax;
lViewTransform.offsetMin = lViewTemplateTransform.offsetMin;
lViewTransform.offsetMax = lViewTemplateTransform.offsetMax;
Vector3 lPosition = lViewTransform.localPosition;
lPosition.x = lPosition.x + (i * (lViewTemplateTransform.rect.width + 10f));
lPosition.y = ((RectTransform)lViewTransform.parent).sizeDelta.y * 0.5f;
lPosition.z = 0f;
lViewTransform.localPosition = lPosition;
ViewButton lViewButton = lViewInstance.GetComponent();
lViewButton.Index = i;
lViewButton.Controller = this;
lViewButton.UpdateMaterial(this, i);
mViewButtons.Add(lViewButton);
}
↧