Exemplo n.º 1
0
        public virtual void Load(StringReaderEx str, object obj)
        {
            Type t = obj.GetType();

            var fields = t.GetFields(getFieldFlags).Where(f => f.GetCustomAttributes(typeof(StoreThis), true).Length > 0).ToArray();

            int len = str.ReadLineInt();

            if (fields.Length != len)
            {
                throw new UnityException("Incorrect save file");
            }

            for (int i = 0; i < len; i++)
            {
                string fieldName = str.ReadLine();
                string fieldData = str.ReadLine();

                //Debug.Log("    > Loading field "+fieldName);
                FieldInfo finfo = fields.Where(f => f.Name == fieldName).First();
                if (finfo == null)
                {
                    continue;
                }
                StoreBase.LoadField(finfo, obj, fieldData);
            }
        }
Exemplo n.º 2
0
    public static void LoadObject(StringReaderEx str, GameObject obj)
    {
        Component[] components = obj.GetComponents <Component>();
        Dictionary <string, Component> byName = new Dictionary <string, Component>();

        foreach (Component c in components)
        {
            byName[c.GetType().Name] = c;
        }

        bool isActive = str.ReadLineBool();

        int len = str.ReadLineInt();

        for (int i = 0; i < len; i++)
        {
            string name    = str.ReadLine();
            bool   enabled = str.ReadLineBool();
            if (byName.ContainsKey(name))
            {
                Component c = byName[name];
                if (c is Behaviour)
                {
                    (c as Behaviour).enabled = enabled;
                }

                LoadComponent(str, c);
                //LoadClass<Component>(str,c);
            }
        }

        obj.SetActive(isActive);
    }
Exemplo n.º 3
0
        public override void Load(StringReaderEx str, object obj)
        {
            Rigidbody2D r = obj as Rigidbody2D;

            r.isKinematic  = str.ReadLineBool();
            r.gravityScale = str.ReadLineFloat();
        }
Exemplo n.º 4
0
    void Update()
    {
        if (!PlayerPrefs.HasKey(CheckpointName))
        {
            GameObject.Destroy(gameObject);
            return;
        }

        try
        {
            StringReaderEx str = new StringReaderEx(PlayerPrefs.GetString(CheckpointName));

            int enemiesCount = str.ReadLineInt();
            Debug.Log("Load: enemies = " + enemiesCount);
            for (int i = 0; i < enemiesCount; i++)
            {
                string prefabName = str.ReadLine();
                string path       = prefabName;


                GameObject prefab = (GameObject)Resources.Load(path, typeof(GameObject));
                Debug.Log("path: " + path + ", val=" + (prefab == null));
                EnemyShipController ship = ((GameObject)GameObject.Instantiate(prefab)).GetComponent <EnemyShipController>();
                ship.PrefabName = prefabName;
                //ship.transform.position = str.ReadLineVector3();
                //LoadObject(str,ship.gameObject);
                ObjectSerializer.LoadObject(str, ship.gameObject);
                //LoadClass<EnemyShipController>(str,ship);
                //EnemyShipController enemy = GameObject.Instantiate()
            }

            PlanetController planet = GameObject.FindGameObjectWithTag("Planet").GetComponent <PlanetController>();

            ObjectSerializer.LoadObject(str, planet.gameObject);
            ObjectSerializer.LoadObject(str, planet.Gun.gameObject);

            UIController ui = GameObject.Find("UICanvas").GetComponent <UIController>();;

            ObjectSerializer.LoadComponent(str, ui.HpBar);
            ObjectSerializer.LoadComponent(str, ui.Score);
            ObjectSerializer.LoadComponent(str, planet.Multiplier.Indicator);

            EnemyGeneratorController eg = GameObject.Find("EnemyGenerator").GetComponent <EnemyGeneratorController>();

            ObjectSerializer.LoadComponent(str, eg);
            StageController[] stages = eg.GetComponentsInChildren <StageController>(true);

            foreach (StageController s in stages)
            {
                ObjectSerializer.LoadObject(str, s.gameObject);
            }
        }
        catch (Exception e)
        {
            Debug.LogError("Exception while trying to load level: " + e.ToString());
        }

        GameObject.Destroy(gameObject);
    }
Exemplo n.º 5
0
        public override void Load(StringReaderEx str, object obj)
        {
            Transform tr = obj as Transform;

            tr.position   = str.ReadLineVector3();
            tr.localScale = str.ReadLineVector3();
            tr.rotation   = Quaternion.Euler(str.ReadLineVector3());
        }
Exemplo n.º 6
0
    public static void LoadComponent(StringReaderEx str, Component c)
    {
        GetClassSerializer(c).Load(str, c);

        Type t = c.GetType();

        MethodInfo[] methods = t.GetMethods(getFieldFlags).Where(i => (i.GetCustomAttributes(typeof(ExecuteAfterLoad), true).Length > 0)).ToArray();

        foreach (MethodInfo m in methods)
        {
            m.Invoke(c, null);
        }
    }
Exemplo n.º 7
0
        public override void Load(StringReaderEx str, object obj)
        {
            Animator a = obj as Animator;

            a.Play(str.ReadLineInt(), 0, str.ReadLineFloat());
        }