public static DynamicBoneProperties CreateObject(Component component) { var path = PropertyTransformer.TransformToStringPath(component); using (var serializer = new SerializedObject(component)) { return(new DynamicBoneProperties { Colliders = PropertyTransformer.TransformToList(serializer.FindProperty("m_Colliders")).Select(w => ToRelativePath(path, PropertyTransformer.TransformToStringPath(w.objectReferenceValue))).ToList(), Damping = serializer.FindProperty("m_Damping").floatValue, DampingDistrib = serializer.FindProperty("m_DampingDistrib").animationCurveValue, DistanceToObject = serializer.FindProperty("m_DistanceToObject").floatValue, DistantDisable = serializer.FindProperty("m_DistantDisable").boolValue, Elasticity = serializer.FindProperty("m_Elasticity").floatValue, ElasticityDistrib = serializer.FindProperty("m_ElasticityDistrib").animationCurveValue, EndLength = serializer.FindProperty("m_EndLength").floatValue, EndOffset = serializer.FindProperty("m_EndOffset").vector3Value, Exclusion = PropertyTransformer.TransformToList(serializer.FindProperty("m_Exclusions")).Select(w => ToRelativePath(path, PropertyTransformer.TransformToStringPath(w.objectReferenceValue))).ToList(), Force = serializer.FindProperty("m_Force").vector3Value, FreezeAxis = serializer.FindProperty("m_FreezeAxis").enumValueIndex, Gravity = serializer.FindProperty("m_Gravity").vector3Value, Inert = serializer.FindProperty("m_Inert").floatValue, InertDistrib = serializer.FindProperty("m_InertDistrib").animationCurveValue, Radius = serializer.FindProperty("m_Radius").floatValue, RadiusDistrib = serializer.FindProperty("m_RadiusDistrib").animationCurveValue, ReferenceObject = ToRelativePath(path, PropertyTransformer.TransformToStringPath(serializer.FindProperty("m_ReferenceObject").objectReferenceValue)), RootReference = ToRelativePath(path, PropertyTransformer.TransformToStringPath(serializer.FindProperty("m_Root").objectReferenceValue)), Stiffness = serializer.FindProperty("m_Stiffness").floatValue, StiffnessDistrib = serializer.FindProperty("m_StiffnessDistrib").animationCurveValue, UpdateMode = serializer.FindProperty("m_UpdateMode").enumValueIndex, UpdateRate = serializer.FindProperty("m_UpdateRate").floatValue }); } }
private static Transform ToActualObject(string path, string relative, GameObject rootObject) { var absolute = ToAbsolutePath(path, relative).Replace(Path.DirectorySeparatorChar.ToString(), "/"); var transforms = rootObject.GetComponentsInChildren <Transform>(); return(transforms.SingleOrDefault(w => PropertyTransformer.TransformToStringPath(w) == absolute)); }
public void ApplyProperties(Component component, GameObject root) { var path = PropertyTransformer.TransformToStringPath(component); using (var serializer = new SerializedObject(component)) { ApplyArrayToProperty(serializer.FindProperty("m_Colliders"), Colliders.Select(w => ToActualObject(path, w, root)).ToList()); serializer.FindProperty("m_Damping").floatValue = Damping; serializer.FindProperty("m_DampingDistrib").animationCurveValue = DampingDistrib; serializer.FindProperty("m_DistanceToObject").floatValue = DistanceToObject; serializer.FindProperty("m_DistantDisable").boolValue = DistantDisable; serializer.FindProperty("m_Elasticity").floatValue = Elasticity; serializer.FindProperty("m_ElasticityDistrib").animationCurveValue = ElasticityDistrib; serializer.FindProperty("m_EndLength").floatValue = EndLength; serializer.FindProperty("m_EndOffset").vector3Value = EndOffset; ApplyArrayToProperty(serializer.FindProperty("m_Exclusions"), Exclusion.Select(w => ToActualObject(path, w, root)).ToList()); serializer.FindProperty("m_Force").vector3Value = Force; serializer.FindProperty("m_FreezeAxis").enumValueIndex = FreezeAxis; serializer.FindProperty("m_Gravity").vector3Value = Gravity; serializer.FindProperty("m_Inert").floatValue = Inert; serializer.FindProperty("m_InertDistrib").animationCurveValue = InertDistrib; serializer.FindProperty("m_Radius").floatValue = Radius; serializer.FindProperty("m_RadiusDistrib").animationCurveValue = RadiusDistrib; serializer.FindProperty("m_ReferenceObject").objectReferenceValue = ToActualObject(path, ReferenceObject, root); serializer.FindProperty("m_Root").objectReferenceValue = ToActualObject(path, RootReference, root); serializer.FindProperty("m_Stiffness").floatValue = Stiffness; serializer.FindProperty("m_StiffnessDistrib").animationCurveValue = StiffnessDistrib; serializer.FindProperty("m_UpdateMode").enumValueIndex = UpdateMode; serializer.FindProperty("m_UpdateRate").floatValue = UpdateRate; serializer.ApplyModifiedPropertiesWithoutUndo(); } }