Exemplo n.º 1
0
        /// <summary>
        /// 寻找GameObject
        /// </summary>
        /// <param name="type"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        protected GameObject SearchGameObject(Type type, AutoSearch search)
        {
            var searchPath = search != null ? search.path : string.Empty;
            var flag       = search != null ? search.autoSearchFlag : AutoSearchFlag.Local;

            if (flag == AutoSearchFlag.Local)
            {
                return(transform.Find(searchPath).gameObject);
            }
            else
            {
                if (string.IsNullOrEmpty(searchPath))
                {
                    return(FindObjectOfType(type) as GameObject);
                }
                var go = GameObject.Find(searchPath);
                return(go);
            }
        }
Exemplo n.º 2
0
        protected Component SearchComponent(Type type, AutoSearch search)
        {
            var searchPath = search != null ? search.path : string.Empty;
            var flag       = search != null ? search.autoSearchFlag : AutoSearchFlag.Local;

            if (flag == HMLFramwork.Mono.AutoSearchFlag.Local)
            {
                if (string.IsNullOrEmpty(searchPath))
                {
                    return(transform.GetComponentInChildren(type));
                }
                return(transform.FindFirstComponentInChild(type, searchPath));
            }
            else
            {
                if (string.IsNullOrEmpty(searchPath))
                {
                    return(FindObjectOfType(type) as Component);
                }
                var go = GameObject.Find(searchPath);
                return(go ? go.GetComponent(type) as Component : null);
            }
        }