public static MonoBehaviourData MonoBehaviourDataFromSource(MonoBehaviour target, Hammurabi serializer)
        {
            MonoBehaviourData data = new MonoBehaviourData();

            data.n = "MonoBehaviour";
            SerializedObject serializableTarget = new SerializedObject(target);

            UnityEditor.SerializedProperty unityProperty  = serializableTarget.GetIterator();
            List <SerializedProperty>      propertiesList = new List <SerializedProperty>();

            while (unityProperty.NextVisible(true))
            {
                if (unityProperty.type == "int")
                {
                    SerializedProperty property = new SerializedProperty();
                    property.k = unityProperty.name;
                    property.t = SerializablePropertyType.Number;
                    property.v = unityProperty.intValue;
                    propertiesList.Add(property);
                }
                else if (unityProperty.type == "PPtr<MonoScript>")
                {
                    MonoScript script = unityProperty.objectReferenceValue as MonoScript;
                    serializer.LinkScript(script);
                    data.n = script.name;
                }
            }
            data.properties = propertiesList.ToArray();
            return(data);
        }
Esempio n. 2
0
 public static ComponentData ComponentDataFromSource(Component target, Hammurabi serializer)
 {
     if (target is Transform)
     {
         return(TransformData.TransformDataFromSource(target as Transform));
     }
     if (target is Camera)
     {
         return(CameraData.CameraDataFromSource(target as Camera));
     }
     if (target is Light)
     {
         return(LightData.LightDataFromSource(target as Light));
     }
     if (target is MeshFilter)
     {
         return(MeshFilterData.MeshFilterDataFromSource(target as MeshFilter));
     }
     if (target is MeshRenderer)
     {
         return(MeshRendererData.MeshRendererDataFromSource(target as MeshRenderer));
     }
     if (target is Rigidbody)
     {
         return(RigidbodyData.RigidbodyDataFromSource(target as Rigidbody));
     }
     if (target is BoxCollider)
     {
         return(BoxColliderData.BoxColliderDataFromSource(target as BoxCollider));
     }
     if (target is MonoBehaviour)
     {
         return(MonoBehaviourData.MonoBehaviourDataFromSource(target as MonoBehaviour, serializer));
     }
     return(new ComponentData());
 }