//================================================================================ // GetComponentInParent //================================================================================ /// <summary> /// 自分自身もしくは親からコンポーネントを取得します。取得できなかった場合はログを出力します /// </summary> public static T GetComponentInParentWithLog <T>(this GameObject self) where T : Component { var component = self.GetComponentInParent <T>(); if (component == null) { OnFailureGetComponent?.Invoke(nameof(GetComponentInParentWithLog), self, typeof(T)); } return(component); }
/// <summary> /// 自分自身もしくは子からコンポーネントを取得します。取得できなかった場合はログを出力します /// </summary> public static T GetComponentInChildrenWithLog <T>(this GameObject self, bool includeInactive) where T : Component { var component = self.GetComponentInChildren <T>(includeInactive); if (component == null) { OnFailureGetComponent?.Invoke(nameof(GetComponentInChildrenWithLog), self, typeof(T)); } return(component); }
/// <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); }
/// <summary> /// 子からコンポーネントを取得します。取得できなかった場合はログを出力します /// </summary> public static T GetComponentInChildrenWithoutSelfWithLog <T>(this GameObject self, bool includeInactive) where T : Component { var components = self.GetComponentsInChildren <T>(includeInactive); for (var i = 0; i < components.Length; i++) { var component = components[i]; if (component == null) { continue; } if (component.gameObject == self) { continue; } return(component); } OnFailureGetComponent?.Invoke(nameof(GetComponentInChildrenWithoutSelfWithLog), self, typeof(T)); return(null); }