Example #1
0
        public void ApplySaveData(SaveService.SavedGameObject savedData)
        {
            if (savedData.savedData.ContainsKey(TransformSaveData.Key))
            {
                TransformSaveData.ApplySaveData(gameObject.transform, (TransformSaveData)savedData.savedData[TransformSaveData.Key]);
            }
            if (savedData.savedData.ContainsKey(RigidBodySaveData.Key))
            {
                RigidBodySaveData.ApplySaveData(gameObject.GetComponent <Rigidbody>(), (RigidBodySaveData)savedData.savedData[RigidBodySaveData.Key]);
            }
            if (savedData.savedData.ContainsKey(AnimatorSaveData.Key))
            {
                AnimatorSaveData.ApplySaveData(gameObject.GetComponent <Animator>(), (AnimatorSaveData)savedData.savedData[AnimatorSaveData.Key]);
            }

            foreach (ISaveableObject saveObject in GetComponents <ISaveableObject>())
            {
                if (!savedData.savedData.ContainsKey(saveObject.SaveDataKey))
                {
                    continue;
                }

                saveObject.ApplySaveData(savedData.savedData[saveObject.SaveDataKey]);
            }
        }
Example #2
0
        public SaveService.SavedGameObject GameObjectSaveData()
        {
            SaveService.SavedGameObject savedData = new SaveService.SavedGameObject(poolDefinition);

            // Add component data to this object as SaveData objects.
            foreach (ISaveableObject saveObject in GetComponents <ISaveableObject>())
            {
                savedData.savedData[saveObject.SaveDataKey] = saveObject.GetSaveData();
            }

            // Do Unity components manually here. (Transform, Rigidbody, Animator ect.)
            savedData.savedData[TransformSaveData.Key] = new TransformSaveData(transform);

            Rigidbody rb = gameObject.GetComponent <Rigidbody>();

            if (rb != null)
            {
                savedData.savedData[RigidBodySaveData.Key] = new RigidBodySaveData(rb);
            }

            Animator animator = gameObject.GetComponent <Animator>();

            if (animator != null)
            {
                savedData.savedData[AnimatorSaveData.Key] = new AnimatorSaveData(animator);
            }

            return(savedData);
        }