コード例 #1
0
        //public static void Test(object o)
        //{
        //	try
        //	{
        //		string a = UON.ToUON(o);
        //		Debug.Log(a);
        //		object c = UON.FromUON(a);
        //		string b = UON.ToUON(c);
        //		Debug.Log(b);
        //		Debug.Log(b.Equals(a) == true ? "<color=green>VALID</color>" : "<color=red>FAILED</color>");
        //	}
        //	catch (Exception ex)
        //	{
        //		Debug.LogException(ex);
        //	}
        //}

        /// <summary>Converts <paramref name="instance"/> into UON.</summary>
        /// <param name="instance">Can be of any types, Unity Object, array, list, struct or class.</param>
        /// <returns>A UON of the given <paramref name="instance"/>.</returns>
        public static string    ToUON(object instance)
        {
            if (instance == null)
            {
                return("[]");
            }

            SerializationData data = new SerializationData()
            {
                workingType = instance.GetType()
            };

            data.registeredTypes.Add(instance.GetType());

            for (int i = 0; i < UON.types.Length; i++)
            {
                if (UON.types[i] is UnityObjectUON)
                {
                    continue;
                }

                if (UON.types[i].Can(data.workingType) == true)
                {
                    return(data.Generate(UON.types[i].Serialize(data, instance)));
                }
            }

            throw new UnhandledTypeException("Object of type " + instance.GetType().FullName + " not handled.");
        }