Exemple #1
0
    //string text = "Paste JSON here";

    void OnGUI()
    {
        if (GUILayout.Button("Instantiate Ragdoll"))
        {
            guids  = new Dictionary <string, UnityEngine.Object>();
            fields = new Dictionary <Action <UnityEngine.Object>, string>();

            string      text     = File.ReadAllText(@"C:\Program Files (x86)\Steam\SteamApps\common\Human Fall Flat\prefab.json");
            var         s        = new fsSerializer();
            fsData      data     = fsJsonParser.Parse(text);
            JGameObject instance = new JGameObject();
            s.TryDeserialize <JGameObject>(data, ref instance);
            instance.Instantiate(null);

            foreach (var a in fields.Keys)
            {
                string g = fields[a];
                if (guids.ContainsKey(g))
                {
                    a.Invoke(guids[g]);
                }
                else
                {
                    Debug.Log("Missing GUID " + g);
                }
            }
        }

        if (GUILayout.Button("Instantiate Player"))
        {
            guids  = new Dictionary <string, UnityEngine.Object>();
            fields = new Dictionary <Action <UnityEngine.Object>, string>();

            string      text     = File.ReadAllText(@"C:\Program Files (x86)\Steam\SteamApps\common\Human Fall Flat\playerPrefab.json");
            var         s        = new fsSerializer();
            fsData      data     = fsJsonParser.Parse(text);
            JGameObject instance = new JGameObject();
            s.TryDeserialize <JGameObject>(data, ref instance);
            instance.Instantiate(null);

            foreach (var a in fields.Keys)
            {
                string g = fields[a];
                if (guids.ContainsKey(g))
                {
                    a.Invoke(guids[g]);
                }
                else
                {
                    Debug.Log("Missing GUID " + g);
                }
            }
        }

        //text = EditorGUILayout.TextArea(text);
    }
Exemple #2
0
        public static void Load()
        {
            gameObject = new UnityEngine.GameObject();
            gameObject.AddComponent <Cheat>();
            UnityEngine.Object.DontDestroyOnLoad(gameObject);

            UnityEngine.Debug.Log("swag");
            UnityEngine.Debug.Log("wew");

            try
            {
                Game       game         = GameObject.FindObjectOfType <Game>();
                GameObject playerPrefab = game.ragdollPrefab.gameObject;

                JGameObject jgo = SerializeGameObject(playerPrefab);
                var         s   = new fsSerializer();
                fsData      data;
                s.TrySerialize <JGameObject>(jgo, out data);

                File.WriteAllText("prefab.json", fsJsonPrinter.PrettyJson(data));
                Debug.Log("saved ragdoll prefab");
            }
            catch (Exception e)
            {
                Debug.Log(e.ToString());
            }


            try
            {
                Game       game         = GameObject.FindObjectOfType <Game>();
                GameObject playerPrefab = game.playerPrefab.gameObject;

                JGameObject jgo = SerializeGameObject(playerPrefab);
                var         s   = new fsSerializer();
                fsData      data;
                s.TrySerialize <JGameObject>(jgo, out data);

                File.WriteAllText("playerPrefab.json", fsJsonPrinter.PrettyJson(data));
                Debug.Log("saved player prefab");
            }
            catch (Exception e)
            {
                Debug.Log(e.ToString());
            }
        }
Exemple #3
0
    private NetworkDto AppendObjectToMessage()
    {
        var obj = new JGameObject()
        {
            Id         = transform.name,
            Position   = new JVector3(transform.localPosition.x, transform.localPosition.y, transform.localPosition.z),
            Scale      = new JVector3(transform.localScale.x, transform.localScale.y, transform.localScale.z),
            EulerAngle = new JVector3(transform.localEulerAngles.x, transform.localEulerAngles.y, transform.localEulerAngles.z),
            Rotation   = new JVector4(transform.localRotation.x, transform.localRotation.y, transform.localRotation.z, transform.localRotation.w),
            Type       = JGameObjectType.Existed_Rotation
        };

        var dto = new NetworkDto()
        {
            Msg = obj
        };

        return(dto);
    }
Exemple #4
0
        private static JGameObject SerializeGameObject(GameObject go)
        {
            JGameObject jgo;

            jgo.name     = go.name;
            jgo.positon  = go.transform.localPosition;
            jgo.rotation = go.transform.localEulerAngles;
            jgo.scale    = go.transform.localScale;
            int nchildren = go.transform.childCount;

            JGameObject[] jgos = new JGameObject[nchildren];
            for (int i = 0; i < nchildren; i++)
            {
                jgos[i] = SerializeGameObject(go.transform.GetChild(i).gameObject);
            }
            Component[]  c     = go.GetComponents <Component>();
            JComponent[] comps = new JComponent[c.Length];
            for (int i = 0; i < c.Length; i++)
            {
                JComponent jc;
                Component  co   = c[i];
                Type       type = co.GetType();

                jc.type = type.AssemblyQualifiedName;
                FieldInfo[]   fields  = type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetField | BindingFlags.SetField);
                List <JField> jfields = new List <JField>();
                foreach (FieldInfo fi in fields)
                {
                    bool flag = false;
                    foreach (Attribute attr in fi.GetCustomAttributes(true))
                    {
                        if (attr is HideInInspector || attr is ObsoleteAttribute)
                        {
                            flag = true;
                        }
                    }

                    if (flag)
                    {
                        continue;
                    }
                    JField jfield;
                    jfield.name = fi.Name;
                    object field = fi.GetValue(co);
                    if (field != null && typeof(UnityEngine.Object).IsAssignableFrom(fi.FieldType))
                    {
                        field = GetGUID((UnityEngine.Object)field);
                    }
                    jfield.value = field;
                    jfields.Add(jfield);
                }
                jc.fields = jfields.ToArray();


                PropertyInfo[]   props  = type.GetProperties(BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty | BindingFlags.Instance);
                List <JProperty> jprops = new List <JProperty>();
                foreach (PropertyInfo fi in props)
                {
                    bool flag = false;
                    foreach (Attribute attr in fi.GetCustomAttributes(true))
                    {
                        if (attr is HideInInspector || attr is ObsoleteAttribute)
                        {
                            flag = true;
                        }
                    }

                    if (flag)
                    {
                        continue;
                    }
                    try
                    {
                        Type t = fi.PropertyType;
                        //if (t == typeof(string) || t == typeof(int) || t == typeof(float) || t == typeof(double) || t == typeof(Vector3) || t == typeof(Vector2))
                        object value = fi.GetValue(co, null);

                        var    s = new fsSerializer();
                        fsData data;
                        s.TrySerialize(value, out data);
                        fsJsonPrinter.PrettyJson(data);

                        if (value != null && typeof(UnityEngine.Object).IsAssignableFrom(fi.PropertyType))
                        {
                            value = GetGUID((UnityEngine.Object)value);
                        }

                        JProperty jprop;
                        jprop.name  = fi.Name;
                        jprop.value = value;
                        jprops.Add(jprop);
                    } catch (Exception ex)
                    {
                    }
                }
                jc.properties = jprops.ToArray();
                jc.guid       = GetGUID(co);

                comps[i] = jc;
            }
            jgo.components = comps;
            jgo.children   = jgos;
            jgo.guid       = GetGUID(go);

            return(jgo);
        }