Ejemplo n.º 1
0
        public SerializedInstance(T obj)
        {
            UnityEngine.Assertions.Assert.IsNotNull(obj);

            m_className    = obj.GetType().AssemblyQualifiedName;
            m_instanceData = CustomScriptUtility.EncodeString(JsonUtility.ToJson(obj));
        }
        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;
            }
            else
            {
                m_values.Add(new Entry(g, json));
                if (defaultNeedsUpdate && g != BuildTargetUtility.DefaultTarget)
                {
                    m_values.Add(new Entry(BuildTargetUtility.DefaultTarget, json));
                }
            }
        }
        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));
                return((T)JsonUtility.FromJson(CustomScriptUtility.DecodeString(m_values[i].value), t));
            }
            else
            {
                return(GetDefaultValue <T>());
            }
        }
Ejemplo n.º 4
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)));
     }
 }
Ejemplo n.º 6
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));
        }