Example #1
0
        // Try Text first, then TextMesh, then child named "Text".  Else error.
        // Return true if text component was found.
        public static bool SetText(GameObject textOwner, string text, string childName = "Text")
        {
            Text textComponent = textOwner.GetComponent <Text>();

            if (textComponent != null)
            {
                textComponent.text = text;
                return(true);
            }
            TextMesh mesh = textOwner.GetComponent <TextMesh>();

            if (mesh != null)
            {
                mesh.text = text;
                return(true);
            }
            GameObject child = SceneNodeView.GetChild(textOwner, childName);

            if (child != null)
            {
                return(SetText(child, text, childName));
            }
            throw new System.InvalidOperationException(
                      "Expected to set Text or TextMesh component on " + textOwner);
        }
Example #2
0
        // Try Text first, then TextMesh, then child named "Text".  Else error.
        // Return true if text component was found.
        public static string GetText(GameObject textOwner, string childName = "Text")
        {
            TextMeshPro tmp = textOwner.GetComponent <TextMeshPro>();

            if (tmp != null)
            {
                return(tmp.text);
            }
            TextMeshProUGUI tmpUI = textOwner.GetComponent <TextMeshProUGUI>();

            if (tmpUI != null)
            {
                return(tmpUI.text);
            }
            Text textComponent = textOwner.GetComponent <Text>();

            if (textComponent != null)
            {
                return(textComponent.text);
            }
            TextMesh mesh = textOwner.GetComponent <TextMesh>();

            if (mesh != null)
            {
                return(mesh.text);
            }
            GameObject child = SceneNodeView.GetChild(textOwner, childName);

            if (child != null)
            {
                return(GetText(child, childName));
            }
            throw new System.InvalidOperationException(
                      "Expected to set Text or TextMesh component on " + textOwner);
        }
Example #3
0
        // namePattern:  Substitute {0} with an index between 0 and to countMax - 1.
        public static List <GameObject> GetChildrenByPattern(GameObject parent, string namePattern, int countMax)
        {
            List <GameObject> children = new List <GameObject>();

            for (int i = 0; i < countMax; i++)
            {
                string     name  = namePattern.Replace("{0}", i.ToString());
                GameObject child = SceneNodeView.GetChild(parent, name);
                children.Add(child);
            }
            return(children);
        }