Hi, not sure if this is the right section for my question, but if anyone can help it will be very much appreciated.
We are in the works of making a trading card game.
What we would like to know is, how do we create a dynamic grid-view with this layout? (4 x 5 stored in json)
Cards will be placed and removed here as players buy and sell cards. Each page will contain 20 cards etc.
Hi there!
I would use Unity.UI to do this.
Would make a container object which holds an array/grid of slots for cards, the container can be made resizeable to it will fit on diffirent mobile screens so i would focus on making a small script that in editor mode nad playmode would layout the children into the positions inthe grid by setting anchorMin/anchorMax of each child as well as setting the heigh tof th echildren based on a aspect ratio and resetting the offset.
The following code is an example of a somewhat similar concept i made for a UI framework that I use, it does abit what you want to do but it only does it on the XAxis.
using UnityEngine;
using System.Collections;
[UnityEngine.ExecuteInEditMode]
public class UIHorizontal : MonoBehaviour {
// Update is called once per frame
void Update () {
float offx=0f;
for(int i=0; i<this.transform.childCount; i++ ) {
var ch = this.transform.GetChild(i);
var tf = ch.GetComponent<RectTransform>();
// they should be of X in size
float width = 1f / this.transform.childCount;
var amin = tf.anchorMin;
amin.x = offx;
amin.y = 0f;
var amax = tf.anchorMax;
amax.x = amin.x + width;
amax.y = 1f;
tf.anchorMin = amin;
tf.anchorMax = amax;
tf.offsetMin = tf.offsetMax = Vector2.zero;
offx += width;
}
}
public void OnHorizontalRefit() {
Update();
}
}
Hope this helps,
Cheers