예제 #1
0
        /// <summary>
        /// Finds the serialized property starting from the root object (the Monobehaviour or the ScriptableObject) and
        /// going down through every composed fields (custom serializable class and struct).
        /// </summary>
        private void FindSerializedProperty()
        {
            serializedProperty = FieldInfoHelper.GetSerializedPropertyFromPath(entityInfo.propertyPath,
                                                                               serializedObject,
                                                                               out directParentSerializedObject);

            if (serializedProperty == null)
            {
                string path = FieldInfoHelper.GetFieldInfoPath(entityInfo.fieldInfo, serializedObject.targetObject.GetType());
                if (!string.IsNullOrEmpty(path))
                {
                    string[] pathTable = path.Split('.');
                    if (pathTable.Length > 0)
                    {
                        serializedProperty = serializedObject.FindProperty(pathTable [0]);
                        for (int i = 1; i < pathTable.Length; i++)
                        {
                            serializedProperty = serializedProperty.FindPropertyRelative(pathTable [i]);
                        }
                    }
                }
                else
                {
                    Debug.LogWarning("The field info " + entityInfo.fieldInfo.Name + " you initialized this renderer with cannot be found in the children properties of the target.");
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Gets the custom class reference from the source object containing it. The custom class is
        /// not necessarily a direct member of the source object.
        /// </summary>
        /// <returns>The custom class reference.</returns>
        /// <param name="fieldInfo">Field info representing the custom class.</param>
        /// <param name="sourceObject">Source object.</param>
        public static object GetCustomClassReference(FieldInfo fieldInfo, object sourceObject)
        {
            object result = null;

            string path = FieldInfoHelper.GetFieldInfoPath(fieldInfo, sourceObject.GetType());

            if (!string.IsNullOrEmpty(path))
            {
                result = sourceObject;
                string[] pathTable = path.Split('.');
                for (int i = 0; i < pathTable.Length; i++)
                {
                    result = FieldInfoHelper.GetFieldReferenceFromName(pathTable [i], BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, result);
                }
            }

            return(result);
        }