Exemplo n.º 1
0
        private void SerializeUnityObject(UnityEngine.Object obj)
        {
            if (obj == null)
            {
                this.Serialize(null);
                return;
            }
            this.output.Append("{");
            this.QuotedField("Name", obj.name);
            this.output.Append(", ");
            this.QuotedField("Type", obj.GetType().FullName);
            Component  component  = obj as Component;
            GameObject gameObject = obj as GameObject;

            if (component != null || gameObject != null)
            {
                if (component != null && gameObject == null)
                {
                    gameObject = component.gameObject;
                }
                UnityReferenceHelper unityReferenceHelper = gameObject.GetComponent <UnityReferenceHelper>();
                if (unityReferenceHelper == null)
                {
                    Debug.Log("Adding UnityReferenceHelper to Unity Reference '" + obj.name + "'");
                    unityReferenceHelper = gameObject.AddComponent <UnityReferenceHelper>();
                }
                unityReferenceHelper.Reset();
                this.output.Append(", ");
                this.QuotedField("GUID", unityReferenceHelper.GetGUID().ToString());
            }
            this.output.Append("}");
        }
Exemplo n.º 2
0
        public void SerializeUnityObject(Object ob)
        {
            if (ob == null)
            {
                this.writer.Write(2147483647);
                return;
            }
            int        instanceID            = ob.GetInstanceID();
            string     name                  = ob.name;
            string     assemblyQualifiedName = ob.GetType().get_AssemblyQualifiedName();
            string     text                  = string.Empty;
            Component  component             = ob as Component;
            GameObject gameObject            = ob as GameObject;

            if (component != null || gameObject != null)
            {
                if (component != null && gameObject == null)
                {
                    gameObject = component.gameObject;
                }
                UnityReferenceHelper unityReferenceHelper = gameObject.GetComponent <UnityReferenceHelper>();
                if (unityReferenceHelper == null)
                {
                    Debug.Log("Adding UnityReferenceHelper to Unity Reference '" + ob.name + "'");
                    unityReferenceHelper = gameObject.AddComponent <UnityReferenceHelper>();
                }
                unityReferenceHelper.Reset();
                text = unityReferenceHelper.GetGUID();
            }
            this.writer.Write(instanceID);
            this.writer.Write(name);
            this.writer.Write(assemblyQualifiedName);
            this.writer.Write(text);
        }
Exemplo n.º 3
0
 public void SerializeUnityObject(UnityEngine.Object ob)
 {
     if (ob == null)
     {
         this.writer.Write(0x7fffffff);
     }
     else
     {
         int        instanceID            = ob.GetInstanceID();
         string     name                  = ob.name;
         string     assemblyQualifiedName = ob.GetType().AssemblyQualifiedName;
         string     gUID                  = string.Empty;
         Component  component             = ob as Component;
         GameObject gameObject            = ob as GameObject;
         if ((component != null) || (gameObject != null))
         {
             if ((component != null) && (gameObject == null))
             {
                 gameObject = component.gameObject;
             }
             UnityReferenceHelper helper = gameObject.GetComponent <UnityReferenceHelper>();
             if (helper == null)
             {
                 Debug.Log("Adding UnityReferenceHelper to Unity Reference '" + ob.name + "'");
                 helper = gameObject.AddComponent <UnityReferenceHelper>();
             }
             helper.Reset();
             gUID = helper.GetGUID();
         }
         this.writer.Write(instanceID);
         this.writer.Write(name);
         this.writer.Write(assemblyQualifiedName);
         this.writer.Write(gUID);
     }
 }
Exemplo n.º 4
0
        public override Dictionary <string, object> WriteJson(Type type, object value)
        {
            Object @object = (Object)value;
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            if (value == null)
            {
                dictionary.Add("Name", null);
                return(dictionary);
            }
            dictionary.Add("Name", @object.name);
            dictionary.Add("Type", @object.GetType().AssemblyQualifiedName);
            Component  component  = value as Component;
            GameObject gameObject = value as GameObject;

            if (component != null || gameObject != null)
            {
                if (component != null && gameObject == null)
                {
                    gameObject = component.gameObject;
                }
                UnityReferenceHelper unityReferenceHelper = gameObject.GetComponent <UnityReferenceHelper>();
                if (unityReferenceHelper == null)
                {
                    Debug.Log("Adding UnityReferenceHelper to Unity Reference '" + @object.name + "'");
                    unityReferenceHelper = gameObject.AddComponent <UnityReferenceHelper>();
                }
                unityReferenceHelper.Reset();
                dictionary.Add("GUID", unityReferenceHelper.GetGUID());
            }
            return(dictionary);
        }
Exemplo n.º 5
0
        public override Dictionary <string, object> WriteJson(System.Type type, object value)
        {
            UnityEngine.Object          obj2       = (UnityEngine.Object)value;
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            if (value == null)
            {
                dictionary.Add("Name", null);
                return(dictionary);
            }
            dictionary.Add("Name", obj2.name);
            dictionary.Add("Type", obj2.GetType().AssemblyQualifiedName);
            Component  component  = value as Component;
            GameObject gameObject = value as GameObject;

            if ((component != null) || (gameObject != null))
            {
                if ((component != null) && (gameObject == null))
                {
                    gameObject = component.gameObject;
                }
                UnityReferenceHelper helper = gameObject.GetComponent <UnityReferenceHelper>();
                if (helper == null)
                {
                    Debug.Log("Adding UnityReferenceHelper to Unity Reference '" + obj2.name + "'");
                    helper = gameObject.AddComponent <UnityReferenceHelper>();
                }
                helper.Reset();
                dictionary.Add("GUID", helper.GetGUID());
            }
            return(dictionary);
        }
Exemplo n.º 6
0
        public void SerializeUnityObject(UnityEngine.Object ob)
        {
            if (ob == null)
            {
                writer.Write(int.MaxValue);
                return;
            }

            int    inst = ob.GetInstanceID();
            string name = ob.name;
            string type = ob.GetType().AssemblyQualifiedName;
            string guid = "";

            //Write scene path if the object is a Component or GameObject
            Component  component = ob as Component;
            GameObject go        = ob as GameObject;

            if (component != null || go != null)
            {
                if (component != null && go == null)
                {
                    go = component.gameObject;
                }

                UnityReferenceHelper helper = go.GetComponent <UnityReferenceHelper>();

                if (helper == null)
                {
                    Debug.Log("Adding UnityReferenceHelper to Unity Reference '" + ob.name + "'");
                    helper = go.AddComponent <UnityReferenceHelper>();
                }

                //Make sure it has a unique GUID
                helper.Reset();

                guid = helper.GetGUID();
            }


            writer.Write(inst);
            writer.Write(name);
            writer.Write(type);
            writer.Write(guid);
        }
Exemplo n.º 7
0
        public override Dictionary <string, object> WriteJson(Type type, object value)
        {
            UnityEngine.Object obj = (UnityEngine.Object)value;


            Dictionary <string, object> dict = new Dictionary <string, object>();


            if (value == null)
            {
                dict.Add("Name", null);
                return(dict);
            }

            dict.Add("Name", obj.name);

            dict.Add("Type", obj.GetType().AssemblyQualifiedName);

            //Write scene path if the object is a Component or GameObject
            Component  component = value as Component;
            GameObject go        = value as GameObject;

            if (component != null || go != null)
            {
                if (component != null && go == null)
                {
                    go = component.gameObject;
                }

                UnityReferenceHelper helper = go.GetComponent <UnityReferenceHelper>();

                if (helper == null)
                {
                    Debug.Log("Adding UnityReferenceHelper to Unity Reference '" + obj.name + "'");
                    helper = go.AddComponent <UnityReferenceHelper>();
                }

                //Make sure it has a unique GUID
                helper.Reset();

                dict.Add("GUID", helper.GetGUID());
            }
            return(dict);
        }
        private UnityEngine.Object DeserializeUnityObjectInner()
        {
            string a = this.EatField();

            if (a == "InstanceID")
            {
                this.EatField();
                a = this.EatField();
            }
            if (a != "Name")
            {
                throw new Exception("Expected 'Name' field");
            }
            string text = this.EatField();

            if (text == null)
            {
                return(null);
            }
            if (this.EatField() != "Type")
            {
                throw new Exception("Expected 'Type' field");
            }
            string text2 = this.EatField();

            if (text2.IndexOf(',') != -1)
            {
                text2 = text2.Substring(0, text2.IndexOf(','));
            }
            Type type = WindowsStoreCompatibility.GetTypeInfo(typeof(AstarPath)).Assembly.GetType(text2);

            type = (type ?? WindowsStoreCompatibility.GetTypeInfo(typeof(Transform)).Assembly.GetType(text2));
            if (object.Equals(type, null))
            {
                Debug.LogError("Could not find type '" + text2 + "'. Cannot deserialize Unity reference");
                return(null);
            }
            this.EatWhitespace();
            if ((ushort)this.reader.Peek() == 34)
            {
                if (this.EatField() != "GUID")
                {
                    throw new Exception("Expected 'GUID' field");
                }
                string b = this.EatField();
                UnityReferenceHelper[] array = UnityEngine.Object.FindObjectsOfType <UnityReferenceHelper>();
                int i = 0;
                while (i < array.Length)
                {
                    UnityReferenceHelper unityReferenceHelper = array[i];
                    if (unityReferenceHelper.GetGUID() == b)
                    {
                        if (object.Equals(type, typeof(GameObject)))
                        {
                            return(unityReferenceHelper.gameObject);
                        }
                        return(unityReferenceHelper.GetComponent(type));
                    }
                    else
                    {
                        i++;
                    }
                }
            }
            UnityEngine.Object[] array2 = Resources.LoadAll(text, type);
            for (int j = 0; j < array2.Length; j++)
            {
                if (array2[j].name == text || array2.Length == 1)
                {
                    return(array2[j]);
                }
            }
            return(null);
        }