示例#1
0
        /// <summary>
        /// 指定された名前の子を検索します。取得できなかった場合はログを出力します
        /// </summary>
        public static GameObject FindGameObjectWithLog(this GameObject self, string name)
        {
            var transform = self.transform.Find(name);

            if (transform == null)
            {
                OnFailureFind?.Invoke(nameof(FindGameObjectWithLog), self, name);
            }

            return(transform != null ? transform.gameObject : null);
        }
示例#2
0
        /// <summary>
        /// 指定された名前の子を検索します。取得できなかった場合はログを出力します
        /// </summary>
        public static GameObject FindDeepWithLog(this GameObject self, string name, bool includeInactive)
        {
            var transforms = self.GetComponentsInChildren <Transform>(includeInactive);

            for (var i = 0; i < transforms.Length; i++)
            {
                var transform = transforms[i];
                if (transform.name != name)
                {
                    continue;
                }
                return(transform.gameObject);
            }

            OnFailureFind?.Invoke(nameof(FindDeepWithLog), self, name);

            return(null);
        }
示例#3
0
        /// <summary>
        /// 指定された名前の子からコンポーネントを検索します。取得できなかった場合はログを出力します
        /// </summary>
        public static T FindComponentWithLog <T>(this GameObject self, string name) where T : Component
        {
            var transform = self.transform.Find(name);

            if (transform == null)
            {
                OnFailureFind?.Invoke(nameof(FindComponentWithLog), self, name);
                return(null);
            }

            var component = transform.GetComponent <T>();

            if (component == null)
            {
                OnFailureGetComponent?.Invoke(nameof(FindComponentWithLog), self, typeof(T));
            }

            return(component);
        }