Ejemplo n.º 1
0
    /// <summary>
    /// Adds - if not present - a SaveLoadBehavior-Component to the specified GameObject
    /// and sets the Savable-State accordingly.
    /// </summary>
    /// <param name="gameobject">The GameObject you want to set to be savable</param>
    /// <param name="isSavable">Setting the savable-State to true will enable saving of the GameObjects' data</param>
    /// <returns>The SaveLoad-Component of the GameObject. It is not advisable to manually change any data though!</returns>
    static public SaveLoadBehavior SetSavableStatus(GameObject gameobject, bool isSavable)
    {
        SaveLoadBehavior saveload = gameobject.GetComponent <SaveLoadBehavior>() as SaveLoadBehavior;

        if (saveload == null)
        {
            saveload = gameobject.AddComponent <SaveLoadBehavior>();
        }

        saveload.IsSavable = isSavable;

        return(saveload);
    }
Ejemplo n.º 2
0
    void EntityFinishedLoading(GameObject loadedAsset)
    {
        if (loadedAsset == null)
        {
            Debug.Log("Scene Manager: Something very, very wrong happened!");
            _entitiesToLoad = 0;

            return;
        }

        SaveLoadBehavior slb = loadedAsset.GetComponent <SaveLoadBehavior>();

        if (slb == null)
        {
            Debug.Log("Scene Manager: Something very, very, very wrong happened!");
        }

        // Grab one of the SaveData from the Cache and apply the changes to the gameobject
        if (_entityCache.ContainsKey(slb.AssetBundleName))
        {
            SaveData data;

            while (_entityCache[slb.AssetBundleName].Count > 0)
            {
                data = _entityCache[slb.AssetBundleName][0];
                _entityCache[slb.AssetBundleName].RemoveAt(0);

                GameObject assetCopy = GameObject.Instantiate(loadedAsset);
                data.Deserialize(assetCopy);

                if (OnAssetLoaded != null)
                {
                    OnAssetLoaded(assetCopy);
                }

                _entitiesToLoad--;
            }

            _entityCache[slb.AssetBundleName] = null;
            Destroy(loadedAsset);
        }
    }