public void Set(BuildTargetGroup g, object value)
        {
            if (value == null)
            {
                Remove(g);
                return;
            }

            bool defaultNeedsUpdate = false;

            if (m_className != value.GetType().AssemblyQualifiedName)
            {
                m_values.Clear();
                m_className        = value.GetType().AssemblyQualifiedName;
                defaultNeedsUpdate = true;
            }

            int i    = m_values.FindIndex(v => v.targetGroup == g);
            var json = CustomScriptUtility.EncodeString(JsonUtility.ToJson(value));

            if (i >= 0)
            {
                m_values [i].value    = json;
                m_values [i].instance = value;
            }
            else
            {
                m_values.Add(new Entry(g, json, value));
                if (defaultNeedsUpdate && g != BuildTargetUtility.DefaultTarget)
                {
                    m_values.Add(new Entry(BuildTargetUtility.DefaultTarget, json, value));
                }
            }
        }
Example #2
0
            public void Restore(GameObject o)
            {
                UnityEngine.Assertions.Assert.IsNotNull(m_typeInfo);

                if (m_componentType == null)
                {
                    m_componentType = Type.GetType(m_typeInfo);
                }
                UnityEngine.Assertions.Assert.IsNotNull(m_componentType);

                m_component = o.GetComponent(m_componentType);
                if (m_component == null)
                {
                    m_component = o.AddComponent(m_componentType);
                    if (m_componentData != null)
                    {
                        EditorJsonUtility.FromJsonOverwrite(CustomScriptUtility.DecodeString(m_componentData), m_component);
                    }
                }

                if (m_componentEditor == null)
                {
                    m_componentEditor = Editor.CreateEditor(m_component);
                }
            }
        public T Get <T>(BuildTargetGroup g)
        {
            if (m_className == null)
            {
                return(default(T));
            }
            int i = m_values.FindIndex(v => v.targetGroup == g);

            if (i >= 0)
            {
                Type t = Type.GetType(m_className);

                if (t == null)
                {
                    LogUtility.Logger.LogFormat(LogType.Warning, "Could not retrieve Type info from classname:{0}", m_className);
                    return(default(T));
                }
                Assertions.Assert.IsTrue(typeof(T).IsAssignableFrom(t));

                if (m_values [i].instance == null)
                {
                    m_values [i].instance = JsonUtility.FromJson(CustomScriptUtility.DecodeString(m_values [i].value), t);
                }

                return((T)m_values [i].instance);
            }
            else
            {
                return(GetDefaultValue <T>());
            }
        }
Example #4
0
        public SerializedInstance(T obj)
        {
            UnityEngine.Assertions.Assert.IsNotNull(obj);

            m_className    = obj.GetType().AssemblyQualifiedName;
            m_instanceData = CustomScriptUtility.EncodeString(JsonUtility.ToJson(obj));
        }
Example #5
0
 public void Save()
 {
     if (m_component != null)
     {
         m_componentData = CustomScriptUtility.EncodeString(EditorJsonUtility.ToJson(m_component));
     }
 }
        private void Deserialize()
        {
            m_gameObject           = new GameObject();
            m_gameObject.hideFlags = HideFlags.HideInHierarchy | HideFlags.DontSave;
            m_gameObject.name      = (string.IsNullOrEmpty(m_newGameObjectName)) ? "New GameObject" : m_newGameObjectName;

            if (!string.IsNullOrEmpty(m_instanceData))
            {
                var decoded = CustomScriptUtility.DecodeString(m_instanceData);
                EditorJsonUtility.FromJsonOverwrite(decoded, m_gameObject);
            }

            if (m_attachedComponents == null)
            {
                m_attachedComponents = new List <ComponentInfo> ();
            }
            SortComponents();

            foreach (var info in m_attachedComponents)
            {
                info.Restore(m_gameObject);
            }

            if (m_gameObjectEditor == null)
            {
                m_gameObjectEditor = Editor.CreateEditor(m_gameObjectEditor);
            }
        }
Example #7
0
 public void Save()
 {
     if (m_object != null)
     {
         m_className    = m_object.GetType().AssemblyQualifiedName;
         m_instanceData = CustomScriptUtility.EncodeString(JsonUtility.ToJson(m_object));
     }
 }
 public SerializableMultiTargetInstance(string assemblyQualifiedName, SerializableMultiTargetString instanceData)
 {
     m_className = assemblyQualifiedName;
     m_values    = new List <Entry>(instanceData.Values.Count);
     foreach (var v in instanceData.Values)
     {
         m_values.Add(new Entry(v.targetGroup, CustomScriptUtility.EncodeString(v.value), null));
     }
 }
            public T Get <T> ()
            {
                if (instance == null)
                {
                    instance = JsonUtility.FromJson(CustomScriptUtility.DecodeString(value), typeof(T));
                }

                return((T)instance);
            }
Example #10
0
 public void Save()
 {
     if (m_gameObject != null)
     {
         m_instanceData = CustomScriptUtility.EncodeString(EditorJsonUtility.ToJson(m_gameObject));
     }
     foreach (var info in m_attachedComponents)
     {
         info.Save();
     }
 }
Example #11
0
		private T Deserialize() {
			Type instanceType = null;
			if(!string.IsNullOrEmpty(m_className)) {
				instanceType = Type.GetType(m_className);
			}

			if(!string.IsNullOrEmpty(m_instanceData) && instanceType != null) {
				string data = CustomScriptUtility.DecodeString(m_instanceData);
				return (T)JsonUtility.FromJson(data, instanceType);
			}

			return default(T);
		}
Example #12
0
        private GameObject Deserialize()
        {
            var obj = new GameObject();

            obj.hideFlags = HideFlags.HideInHierarchy | HideFlags.DontSave;
            obj.name      = "Attaching Component";

            if (!string.IsNullOrEmpty(m_instanceData))
            {
                var decoded = CustomScriptUtility.DecodeString(m_instanceData);
                EditorJsonUtility.FromJsonOverwrite(decoded, obj);
            }

            foreach (var info in m_attachedComponents)
            {
                info.Restore(obj);
            }

            return(obj);
        }