// --------------------------------------------------------------------------------------------------------------------
//
// HiddenMonk
// http://answers.unity3d.com/users/496850/hiddenmonk.html
//
// Johannes Deml
// send@johannesdeml.com
//
// --------------------------------------------------------------------------------------------------------------------
namespace VRTK.Supyrb
{
using System;
using UnityEngine;
using UnityEditor;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
///
/// Extension class for SerializedProperties
/// See also: http://answers.unity3d.com/questions/627090/convert-serializedproperty-to-custom-class.html
///
public static class SerializedPropertyExtensions
{
///
/// Get the object the serialized property holds by using reflection
///
/// The object type that the property contains
///
/// Returns the object type T if it is the type the property actually contains
public static T GetValue(this SerializedProperty property)
{
return GetNestedObject(property.propertyPath, GetSerializedPropertyRootComponent(property));
}
///
/// Set the value of a field of the property with the type T
///
/// The type of the field that is set
/// The serialized property that should be set
/// The new value for the specified property
/// Returns if the operation was successful or failed
public static bool SetValue(this SerializedProperty property, T value)
{
object obj = GetSerializedPropertyRootComponent(property);
//Iterate to parent object of the value, necessary if it is a nested object
string[] fieldStructure = property.propertyPath.Split('.');
for (int i = 0; i < fieldStructure.Length - 1; i++)
{
obj = GetFieldOrPropertyValue