void InitActorListButton() { List <GameObject> actorPrefabs = ResLoad.db.actorsPrefabs; List <GameObject> buttonList; buttonList = new List <GameObject>(); Vector3 initPos = actorButton.transform.localPosition; for (int i = 0; i < actorPrefabs.Count; i++) { GameObject newButton = Instantiate <GameObject>(actorButton.gameObject); newButton.transform.SetParent(actorButton.transform.parent); newButton.name = i.ToString(); newButton.transform.localPosition = new Vector3(initPos.x, initPos.y - i * 40, initPos.z); newButton.transform.Find("Text").GetComponent <Text>().text = actorPrefabs[i].name; ClickListener.Get(newButton).onClick = ClickActor; } Transform contentTs = actorButton.transform.parent; RectTransform rectTs = contentTs as RectTransform; Rect rect = rectTs.rect; rect.height = actorPrefabs.Count * 40 + 10; rectTs.sizeDelta = new Vector2(rect.width, rect.height); actorButton.gameObject.SetActive(false); }
void InitCompScrollView() { compButton.gameObject.SetActive(true); //compButton.transform.parent.childCount; Transform parent = compButton.transform.parent; for (int j = 1; j < parent.childCount; j++) { GameObject.Destroy(parent.GetChild(j).gameObject); } Main.ins.currCompIdx = 0; if (Main.ins.currActorGo == null) { return; } Actor actor = Main.ins.currActorGo.GetComponent <Actor>(); var acList = actor.components; List <GameObject> buttonList; buttonList = new List <GameObject>(); Vector3 initPos = compButton.transform.localPosition; for (int i = 0; i < acList.Count; i++) { GameObject newButton; newButton = Instantiate <GameObject>(compButton.gameObject); newButton.transform.SetParent(compButton.transform.parent); newButton.name = i.ToString(); newButton.transform.localPosition = new Vector3(initPos.x, initPos.y - i * 40, initPos.z); newButton.transform.Find("Text").GetComponent <Text>().text = acList[i].name; ClickListener.Get(newButton).onClick = ClickComp; } compButton.gameObject.SetActive(false); }
public void InitAlterCompSV(Actor.ActorComponent ac) { List <string> showList = ac.canSwapList; Transform parent = alterButton.transform.parent; for (int j = 1; j < parent.childCount; j++) { GameObject.Destroy(parent.GetChild(j).gameObject); } List <GameObject> buttonList; buttonList = new List <GameObject>(); alterButton.gameObject.SetActive(true); Vector3 initPos = alterButton.transform.localPosition; for (int i = 0; i < showList.Count; i++) { GameObject newButton = Instantiate <GameObject>(alterButton.gameObject); newButton.transform.SetParent(alterButton.transform.parent); newButton.name = i.ToString(); newButton.transform.localPosition = new Vector3(initPos.x, initPos.y - i * 40, initPos.z); newButton.transform.Find("Text").GetComponent <Text>().text = showList[i]; ClickListener.Get(newButton).onClick = ClickAlter; } Transform contentTs = alterButton.transform.parent; RectTransform rectTs = contentTs as RectTransform; Rect rect = rectTs.rect; rect.height = showList.Count * 40 + 10; //Debug.Log(rect.width); //rectTs.sizeDelta = new Vector2(rect.width, rect.height); alterButton.gameObject.SetActive(false); }