public static IOutput <T> FromBehaviour <T>(string propertyPath, MonoBehaviour behaviour) { var path = propertyPath.Split('.'); var gameObject = behaviour.gameObject; while (gameObject != null) { var components = gameObject.GetComponents <IContext>(); foreach (var component in components) { var output = ResolveInObject <T>(path, component); if (output != null) { return(output); } } gameObject = gameObject.transform.parent?.gameObject; } var roots = GroveRoot.GetInstances(); foreach (var root in roots) { var output = ResolveInObject <T>(path, root); if (output != null) { return(output); } } throw new Exception($"Cannot resolve {propertyPath} from {behaviour}"); }
private void DrawRoots() { var roots = GroveRoot.EditorGetInstances(); if (roots == null) { return; } EditorGUILayout.Separator(); EditorGUILayout.LabelField($"Roots #{roots.Count}"); foreach (var root in roots) { var info = root != null ? root.GetHashCode().ToString() : "null"; EditorGUILayout.BeginHorizontal(); EditorGUILayout.ObjectField(root, typeof(GroveRoot), false); EditorGUILayout.LabelField(info); EditorGUILayout.EndHorizontal(); } }