public object ResolvedMemberObject() { if (targetObject == null || targetObject.Equals(null)) { return(null); } //if snapshot not null, means at least one time this has been evaluated if (_resolvedMemberObject != null && !_resolvedMemberObject.Equals(null) && snapshot != null) { return(_resolvedMemberObject); } var result = targetObject; //if is gameobject, resolve path and final component type if (targetObject is GameObject) { var leafGameObject = (GameObject)targetObject; if (!string.IsNullOrEmpty(transformHierarchyPath)) { var leafTransform = UnityObjectUtility.ResolveTransformPath(leafGameObject.transform, transformHierarchyPath); leafGameObject = leafTransform != null ? leafTransform.gameObject : null; } result = leafGameObject != null?leafGameObject.GetComponent(declaringType) : null; } result = ReflectionTools.GetRelativeMemberParent(result, parameterName); return(_resolvedMemberObject = result); }
///Pops a menu for animatable properties selection public static void ShowAnimatedPropertySelectionMenu(GameObject root, AnimationDataCollection.AddParameterDelegate callback) { var menu = new GenericMenu(); foreach (var _comp in root.GetComponentsInChildren <Component>(true)) { var comp = _comp; if (comp == null) { continue; } var compType = comp.GetType(); var transformPath = UnityObjectUtility.CalculateTransformPath(root.transform, comp.transform); var displayTransformPath = "Self"; if (comp.gameObject != root) { displayTransformPath = "Children/" + transformPath; } if (comp is Transform) //special treat { menu.AddItem(new GUIContent(displayTransformPath + "/Transform/Position"), false, () => { callback(typeof(Transform), "localPosition", transformPath); }); menu.AddItem(new GUIContent(displayTransformPath + "/Transform/Rotation"), false, () => { callback(typeof(Transform), "localEulerAngles", transformPath); }); menu.AddItem(new GUIContent(displayTransformPath + "/Transform/Scale"), false, () => { callback(typeof(Transform), "localScale", transformPath); }); //if its Transform itself, continue, otherwise append (this is basically done for RectTransform). if (compType == typeof(Transform)) { continue; } } Predicate <Type> shouldInclude = (t) => AnimatedParameter.supportedTypes.Contains(t); Predicate <Type> shouldContinue = (t) => !typeof(UnityEngine.Object).IsAssignableFrom(t) && !t.IsValueType && !t.IsEnum && !typeof(IEnumerable).IsAssignableFrom(t); //TODO: List & Enum support foreach (var path in ReflectionTools.GetMemberPaths(compType, shouldInclude, shouldContinue)) { var finalPath = string.Format("{0}/{1}/{2}", displayTransformPath, compType.Name.SplitCamelCase(), path.Replace('.', '/').SplitCamelCase()); menu.AddItem(new GUIContent(finalPath), false, () => { callback(compType, path, transformPath); }); } } menu.ShowAsContext(); Event.current.Use(); }