public void InitInfo <T>(T classType) { type = classType.GetType().ToString(); if (!initialObjInfoMap.ContainsKey(type)) { var initialObjInfo = new List <RectTrsInfo>(); Transform[] allChildren = transform.GetComponentsInChildren <Transform>(true); var initalChildrenCount = allChildren.Length; foreach (var child in allChildren) { RectTrsInfo info = new RectTrsInfo(); RectTransform rect = child.GetComponent <RectTransform>(); info.objName = child.name; info.isActive = child.gameObject.activeSelf; info.localPosition = rect.localPosition; info.localScale = rect.localScale; info.anchoredPosition = rect.anchoredPosition; info.anchoredMin = rect.anchorMin; info.anchoredMax = rect.anchorMax; info.sizeDelta = rect.sizeDelta; info.pivot = rect.pivot; if (child.GetComponent <Text>() != null) { info.textComponentText = child.GetComponent <Text>().text; info.textComponentColor = child.GetComponent <Text>().color; info.textComponentFontSize = child.GetComponent <Text>().fontSize; info.textComponentFontLineSpacing = child.GetComponent <Text>().lineSpacing; } else { info.textComponentText = "default"; info.textComponentColor = Color.white; } if (child.GetComponent <Outline>() != null) { info.outlineColor = child.GetComponent <Outline>().effectColor; } else { info.outlineColor = Color.black; } if (child.GetComponent <Button>() != null && child.GetComponent <Button>().enabled == true) { info.buttonEnabled = true; } else { info.buttonEnabled = false; } initialObjInfo.Add(info); } initialObjInfoMap.Add(type, initialObjInfo); initalChildrenCountMap.Add(type, initalChildrenCount); } }
public void OnSpawn() { if (initialObjInfoMap.ContainsKey(type)) { var initialObjInfo = initialObjInfoMap[type]; var initalChildrenCount = initalChildrenCountMap[type]; Transform[] allChildren = transform.GetComponentsInChildren <Transform>(true); if (initalChildrenCount != allChildren.Length) { Debug.LogError("回收对象时发现该对象层级关系发生变化!"); return; } for (int i = 0; i < allChildren.Length; i++) { Transform child = allChildren[i]; RectTrsInfo info = initialObjInfo[i]; RectTransform rect = child.GetComponent <RectTransform>(); child.name = info.objName; child.gameObject.SetActive(info.isActive); rect.localPosition = info.localPosition; rect.localScale = info.localScale; rect.anchoredPosition = info.anchoredPosition; rect.anchorMin = info.anchoredMin; rect.anchorMax = info.anchoredMax; rect.sizeDelta = info.sizeDelta; rect.pivot = info.pivot; if (child.GetComponent <Text>() != null) { child.GetComponent <Text>().text = info.textComponentText; child.GetComponent <Text>().color = info.textComponentColor; child.GetComponent <Text>().fontSize = info.textComponentFontSize; child.GetComponent <Text>().lineSpacing = info.textComponentFontLineSpacing; } if (child.GetComponent <Outline>() != null) { child.GetComponent <Outline>().effectColor = info.outlineColor; } if (child.GetComponent <Button>() != null) { child.GetComponent <Button>().enabled = info.buttonEnabled; } } } }
public void InitInfo <T>(T classType) { type = classType.GetType().ToString(); if (!initialObjInfoMap.ContainsKey(type)) { var initialObjInfo = new List <RectTrsInfo>(); Transform[] allChildren = transform.GetComponentsInChildren <Transform>(true); var initalChildrenCount = allChildren.Length; foreach (var child in allChildren) { RectTrsInfo info = new RectTrsInfo(); Transform tras = child.transform; info.objName = child.name; info.isActive = child.gameObject.activeSelf; info.localPosition = tras.localPosition; info.localScale = tras.localScale; initialObjInfo.Add(info); } initialObjInfoMap.Add(type, initialObjInfo); initalChildrenCountMap.Add(type, initalChildrenCount); } }
public void OnSpawn() { if (initialObjInfoMap.ContainsKey(type)) { var initialObjInfo = initialObjInfoMap[type]; var initalChildrenCount = initalChildrenCountMap[type]; Transform[] allChildren = transform.GetComponentsInChildren <Transform>(true); if (initalChildrenCount != allChildren.Length) { Debug.LogError("回收对象时发现该对象层级关系发生变化!"); return; } for (int i = 0; i < allChildren.Length; i++) { Transform child = allChildren[i]; RectTrsInfo info = initialObjInfo[i]; RectTransform rect = child.GetComponent <RectTransform>(); child.name = info.objName; child.gameObject.SetActive(info.isActive); rect.localPosition = info.localPosition; rect.localScale = info.localScale; } } }