Ejemplo n.º 1
0
 public SerializedGameObject(SerializationInfo info, StreamingContext context)
 {
     _name     = (string)info.GetValue("Name", typeof(string));
     _tr       = (SerializedTransform)info.GetValue("Tr", typeof(SerializedTransform));
     _metadata = (SerializedMetaData)info.GetValue("Metadata", typeof(SerializedMetaData));
     if (_metadata == null || !_metadata.HasValidSerializedId)
     {
         _components = (List <IUnitySerializable>)info.GetValue("Components", typeof(List <IUnitySerializable>));
     }
     _children = (List <SerializedGameObject>)info.GetValue("Children", typeof(List <SerializedGameObject>));
 }
Ejemplo n.º 2
0
        private void SetupCreated(GameObject root)
        {
            var wc = root.AddComponent <PrefabEntity>();

            wc.SetStatic();
            _metadata           = wc.Metadata;
            _metadata.AssetType = AssetType.Scene;
            foreach (var c in root.GetComponents <Component>())
            {
                if (c == null ||
                    c is Transform ||
                    c.GetType().GetCustomAttributes(true).Any(x => x is IgnoreFileSerialization))
                {
                    continue;
                }
                _components.Add(Serializer.CreateSerializableObject(c));
            }
        }
Ejemplo n.º 3
0
        public SerializedGameObject(GameObject root, PrefabEntity dataHolder)
        {
            _name       = root.name;
            _components = new List <IUnitySerializable>();
            if (dataHolder == null)
            {
                SetupCreated(root);
            }
            else
            {
                _metadata = dataHolder.Metadata;
                _metadata.SetDatabaseEntry(dataHolder);
            }
            _metadata.UpdateSerializedId();
            _tr = new SerializedTransform();
            _tr.Set(root.transform);
            _children = new List <SerializedGameObject>();
            foreach (Transform child in root.transform)
            {
                if (!child.gameObject.activeSelf)
                {
                    continue;
                }
                var entity = child.GetComponent <PrefabEntity>();
                if (entity == null)
                {
                    continue;
                }
                _children.Add(new SerializedGameObject(child.gameObject, entity));
            }
            if (Application.isPlaying)
            {
                var savedData = root.GetComponentsInChildren <ISavedData>();
                for (int i = 0; i < savedData.Length; i++)
                {
                    savedData[i].SaveMetaData(_metadata);
                }
            }
#if UNITY_EDITOR
            if (Application.isPlaying || UnityEditor.PrefabUtility.GetPrefabType(root) == PrefabType.None)
            {
                return;
            }
            var mods = UnityEditor.PrefabUtility.GetPropertyModifications(root);
            if (mods == null)
            {
                return;
            }
            for (int i = 0; i < mods.Length; i++)
            {
                var component = mods[i].target as Component;
                if (component == null || component is Transform || ReflectionHelper.HasIgnoredAttribute(component.GetType()) ||
                    Serializer.RestrictedTypes.Contains(component.GetType()))
                {
                    continue;
                }
                if (mods[i].objectReference != null)
                {
                    _metadata.ComponentDiff.SetDiff(component, mods[i].propertyPath, mods[i].objectReference);
                }
                else
                {
                    _metadata.ComponentDiff.SetDiff(component, mods[i].propertyPath, mods[i].value);
                }
            }
#endif
        }