plantilla base para movimiento básico
This commit is contained in:
Robii Aragon
2026-02-05 05:07:55 -08:00
parent ed7b223c04
commit fd87a6ffd5
14441 changed files with 13711084 additions and 20 deletions

View File

@@ -0,0 +1,343 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System;
public class saveDialogInfo : saveGameInfo
{
public dialogManager mainDialogManager;
public string mainDialogManagerName = "Dialog Manager";
[Space]
[Header ("Debug")]
[Space]
public List<persistanceDialogContentInfo> persistanceInfoList;
public persistancePlayerDialogContentInfo temporalPersistancePlayerDialogContentInfo;
public override void saveGame (int saveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
saveGameContent (saveNumber, playerID, currentSaveDataPath, showDebugInfo, savingGameToChangeScene);
}
public override void loadGame (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
loadGameContent (saveNumberToLoad, playerID, currentSaveDataPath, showDebugInfo);
}
public void saveGameContent (int currentSaveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
getMainManager ();
if (mainDialogManager == null) {
return;
}
if (!mainDialogManager.dialogSystemEnabled) {
return;
}
if (!mainDialogManager.saveCurrentDialogContentToSaveFile) {
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Saving dialog");
}
bool saveLocated = false;
bool playerLocated = false;
int saveSlotIndex = -1;
int listIndex = -1;
BinaryFormatter bf = new BinaryFormatter ();
FileStream file;
persistancePlayerDialogContentInfo dialogContentToSave = getPersistanceList (playerID, showDebugInfo);
persistanceDialogContentListBySaveSlotInfo newPersistanceDialogContentListBySaveSlotInfo = new persistanceDialogContentListBySaveSlotInfo ();
List<persistanceDialogContentListBySaveSlotInfo> infoListToSave = new List<persistanceDialogContentListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToSave = currentData as List<persistanceDialogContentListBySaveSlotInfo>;
file.Close ();
}
int infoListToSaveCount = infoListToSave.Count;
for (int j = 0; j < infoListToSaveCount; j++) {
if (infoListToSave [j].saveNumber == currentSaveNumber) {
newPersistanceDialogContentListBySaveSlotInfo = infoListToSave [j];
saveLocated = true;
saveSlotIndex = j;
}
}
if (saveLocated) {
int playerDialogContentListCount = newPersistanceDialogContentListBySaveSlotInfo.playerDialogContentList.Count;
for (int j = 0; j < playerDialogContentListCount; j++) {
if (newPersistanceDialogContentListBySaveSlotInfo.playerDialogContentList [j].playerID == dialogContentToSave.playerID) {
playerLocated = true;
listIndex = j;
}
}
}
if (showDebugInfo) {
print ("\n\n");
print ("EXTRA INFO\n");
print ("Number of elements on scene: " + dialogContentToSave.dialogContentList.Count);
print ("Current Save Number " + currentSaveNumber);
print ("Save Located " + saveLocated);
print ("Player Located " + playerLocated);
print ("Player ID " + dialogContentToSave.playerID);
print ("Scene Index " + menuPause.getCurrentActiveSceneIndex ());
}
int currentSceneIndex = menuPause.getCurrentActiveSceneIndex ();
//if the save is located, check if the player id exists
if (saveLocated) {
//if player id exists, overwrite it
if (playerLocated) {
int elementOnSceneListCount = infoListToSave [saveSlotIndex].playerDialogContentList [listIndex].dialogContentList.Count;
for (int i = elementOnSceneListCount - 1; i >= 0; i--) {
if (currentSceneIndex == infoListToSave [saveSlotIndex].playerDialogContentList [listIndex].dialogContentList [i].dialogContentScene) {
infoListToSave [saveSlotIndex].playerDialogContentList [listIndex].dialogContentList.RemoveAt (i);
}
}
infoListToSave [saveSlotIndex].playerDialogContentList [listIndex].dialogContentList.AddRange (dialogContentToSave.dialogContentList);
} else {
infoListToSave [saveSlotIndex].playerDialogContentList.Add (dialogContentToSave);
}
} else {
newPersistanceDialogContentListBySaveSlotInfo.saveNumber = currentSaveNumber;
newPersistanceDialogContentListBySaveSlotInfo.playerDialogContentList.Add (dialogContentToSave);
infoListToSave.Add (newPersistanceDialogContentListBySaveSlotInfo);
}
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.OpenOrCreate);
bf.Serialize (file, infoListToSave);
file.Close ();
if (showDebugInfo) {
print ("\n\n");
print ("Saving Dialogs ");
print ("Number of dialog: " + dialogContentToSave.dialogContentList.Count);
for (int j = 0; j < dialogContentToSave.dialogContentList.Count; j++) {
persistanceDialogContentInfo currentPersistanceDialogContentInfo = dialogContentToSave.dialogContentList [j];
if (currentPersistanceDialogContentInfo.dialogContentScene == currentSceneIndex) {
showDetailedDebugInfo (currentPersistanceDialogContentInfo);
}
}
}
}
public void loadGameContent (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
getMainManager ();
if (mainDialogManager == null) {
return;
}
if (!mainDialogManager.dialogSystemEnabled) {
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Loading dialog");
}
persistanceInfoList = new List<persistanceDialogContentInfo> ();
//need to store and check the current slot saved and the player which is saving, to get that concrete info
List<persistanceDialogContentListBySaveSlotInfo> infoListToLoad = new List<persistanceDialogContentListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToLoad = currentData as List<persistanceDialogContentListBySaveSlotInfo>;
file.Close ();
}
if (saveNumberToLoad > -1) {
persistanceDialogContentListBySaveSlotInfo newPersistanceDialogContentListBySaveSlotInfo = new persistanceDialogContentListBySaveSlotInfo ();
int infoListToLoadCount = infoListToLoad.Count;
for (int j = 0; j < infoListToLoadCount; j++) {
if (infoListToLoad [j].saveNumber == saveNumberToLoad) {
newPersistanceDialogContentListBySaveSlotInfo = infoListToLoad [j];
}
}
int listIndex = -1;
int playerDialogContentListCount = newPersistanceDialogContentListBySaveSlotInfo.playerDialogContentList.Count;
for (int j = 0; j < playerDialogContentListCount; j++) {
if (newPersistanceDialogContentListBySaveSlotInfo.playerDialogContentList [j].playerID == playerID) {
listIndex = j;
}
}
if (listIndex > -1) {
int currentSceneIndex = menuPause.getCurrentActiveSceneIndex ();
temporalPersistancePlayerDialogContentInfo = newPersistanceDialogContentListBySaveSlotInfo.playerDialogContentList [listIndex];
int elementOnSceneListCount = temporalPersistancePlayerDialogContentInfo.dialogContentList.Count;
if (showDebugInfo) {
print ("\n\n");
print ("Total number of elements saved in game " + elementOnSceneListCount);
}
for (int j = 0; j < elementOnSceneListCount; j++) {
if (currentSceneIndex == temporalPersistancePlayerDialogContentInfo.dialogContentList [j].dialogContentScene) {
persistanceInfoList.Add (temporalPersistancePlayerDialogContentInfo.dialogContentList [j]);
}
}
}
}
if (showDebugInfo) {
print ("\n\n");
print ("Dialogs Loaded in Save Number " + saveNumberToLoad);
print ("Number of dialog: " + persistanceInfoList.Count);
print ("Scene Index " + menuPause.getCurrentActiveSceneIndex ());
print ("\n\n");
for (int j = 0; j < persistanceInfoList.Count; j++) {
print ("\n\n");
persistanceDialogContentInfo currentPersistanceDialogContentInfo = persistanceInfoList [j];
showDetailedDebugInfo (currentPersistanceDialogContentInfo);
}
}
loadInfoOnMainComponent ();
}
public persistancePlayerDialogContentInfo getPersistanceList (int playerID, bool showDebugInfo)
{
persistancePlayerDialogContentInfo newPersistancePlayerDialogContentInfo = new persistancePlayerDialogContentInfo ();
newPersistancePlayerDialogContentInfo.playerID = playerID;
List<persistanceDialogContentInfo> newPersistanceDialogContentInfoList = new List<persistanceDialogContentInfo> ();
List<dialogContentSystem> dialogContentSystemList = mainDialogManager.dialogContentSystemList;
int dialogContentSystemListCount = dialogContentSystemList.Count;
for (int k = 0; k < dialogContentSystemListCount; k++) {
dialogContentSystem currentDialogContentSystem = dialogContentSystemList [k];
if (currentDialogContentSystem != null) {
persistanceDialogContentInfo newPersistanceDialogContentInfo = new persistanceDialogContentInfo ();
newPersistanceDialogContentInfo.dialogContentID = currentDialogContentSystem.getDialogContentID ();
newPersistanceDialogContentInfo.dialogContentScene = currentDialogContentSystem.getDialogContentScene ();
newPersistanceDialogContentInfo.currentDialogIndex = currentDialogContentSystem.getCurrentDialogIndex ();
newPersistanceDialogContentInfoList.Add (newPersistanceDialogContentInfo);
}
}
newPersistancePlayerDialogContentInfo.dialogContentList = newPersistanceDialogContentInfoList;
return newPersistancePlayerDialogContentInfo;
}
void loadInfoOnMainComponent ()
{
if (persistanceInfoList != null && persistanceInfoList.Count > 0) {
int persistanceInfoListCount = persistanceInfoList.Count;
for (int i = 0; i < persistanceInfoListCount; i++) {
persistanceDialogContentInfo currentPersistanceDialogContentInfo = persistanceInfoList [i];
dialogContentSystem currentDialogContentSystem = mainDialogManager.getDialogContentSystem (currentPersistanceDialogContentInfo.dialogContentID,
currentPersistanceDialogContentInfo.dialogContentScene);
if (currentDialogContentSystem != null) {
currentDialogContentSystem.setCompleteDialogIndex (currentPersistanceDialogContentInfo.currentDialogIndex);
}
}
}
}
void showDetailedDebugInfo (persistanceDialogContentInfo currentPersistanceDialogContentInfo)
{
print ("Dialog Content ID " + currentPersistanceDialogContentInfo.dialogContentID);
print ("Dialog Scene " + currentPersistanceDialogContentInfo.dialogContentScene);
print ("Dialog Index " + currentPersistanceDialogContentInfo.currentDialogIndex);
print ("\n\n");
}
void getMainManager ()
{
bool mainDialogManagerLocated = mainDialogManager != null;
if (!mainDialogManagerLocated) {
mainDialogManager = dialogManager.Instance;
mainDialogManagerLocated = mainDialogManager != null;
}
if (!mainDialogManagerLocated) {
GKC_Utils.instantiateMainManagerOnSceneWithTypeOnApplicationPlaying (dialogManager.getMainManagerName (), typeof (dialogManager), true);
mainDialogManager = dialogManager.Instance;
mainDialogManagerLocated = mainDialogManager != null;
}
if (!mainDialogManagerLocated) {
mainDialogManager = FindObjectOfType<dialogManager> ();
mainDialogManagerLocated = mainDialogManager != null;
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: b2159d06282132b4eb1ac92408f92418
timeCreated: 1602213732
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Save System/Custom Class To Save/saveDialogInfo.cs
uploadId: 814740

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 7b3e2665ca071144d9f3190e9fad41f0
timeCreated: 1650494788
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Save System/Custom Class To Save/saveElementsOnSceneInfo.cs
uploadId: 814740

View File

@@ -0,0 +1,70 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class saveGameInfo : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool gameSavedOnHomeMenu;
[Space]
public bool ignorePlayerIDOnSaveLoadInfo;
public bool ignoreSaveNumberOnSaveLoadInfo;
public int saveNumberToIgnoreSaveLoadInfo = -1;
[Space]
[Space]
public bool saveInfoOnRegularTxtFile;
public string saveInfoOnRegulaFileName;
public string loadInfoOnRegulaFileName;
public virtual void saveGame (int saveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
}
public virtual void loadGame (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
}
public virtual void saveGameFromEditor (int saveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
}
public virtual void initializeValuesOnComponent ()
{
}
public virtual void deleteGameInfo (int saveNumberToDelete, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
}
public virtual void copyGameInfo (int saveNumberToStoreDuplicate, int saveNumberToDuplicate, int playerID,
string currentSaveDataPath, bool copyAllInfoWithoutChecks, bool showDebugInfo)
{
}
public virtual void showSaveInfoDebug (int saveNumberToShow, int playerID, string currentSaveDataPath,
bool showAllGameInfoDebug, bool showDebugInfo)
{
}
public virtual void checkSaveInfoToLoadOnStartOnAllScenes (int saveNumberToLoad, int playerID,
string currentSaveDataPath, bool showDebugInfo)
{
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 0be5476b1d980a94fb9b648aaffb1d24
timeCreated: 1602145496
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Save System/Custom Class To Save/saveGameInfo.cs
uploadId: 814740

View File

@@ -0,0 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class saveInfo
{
public string Name;
public bool saveInfoEnabled = true;
public bool loadInfoEnabled = true;
public string saveFileName;
public bool showDebugInfo;
public saveGameInfo mainSaveGameInfo;
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: b9ba533f9bc4b734eb01145cf6a89094
timeCreated: 1602147267
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Save System/Custom Class To Save/saveInfo.cs
uploadId: 814740

View File

@@ -0,0 +1,406 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System;
public class saveInventoryBankInfo : saveGameInfo
{
public inventoryBankManager mainInventoryBankManager;
public string mainInventoryManagerName = "Main Inventory Manager";
List<inventoryListElement> persistanceInfoList;
public override void saveGame (int saveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
saveGameContent (saveNumber, playerID, currentSaveDataPath, showDebugInfo, savingGameToChangeScene);
}
public override void loadGame (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
loadGameContent (saveNumberToLoad, playerID, currentSaveDataPath, showDebugInfo);
}
public override void saveGameFromEditor (int saveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
saveGameContentFromEditor (saveNumber, playerID, currentSaveDataPath, showDebugInfo);
}
public void saveGameContent (int currentSaveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
getMainManager ();
if (mainInventoryBankManager == null) {
return;
}
if (!mainInventoryBankManager.saveCurrentBankInventoryToSaveFile) {
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Saving inventory bank");
}
bool saveLocated = false;
bool playerLocated = false;
int saveSlotIndex = -1;
int listIndex = -1;
BinaryFormatter bf = new BinaryFormatter ();
FileStream file;
persistanceInventoryListByPlayerInfo vendorToSave = getPersistanceList (playerID, showDebugInfo);
persistanceInventoryListBySaveSlotInfo newPersistanceInventoryListBySaveSlotInfo = new persistanceInventoryListBySaveSlotInfo ();
List<persistanceInventoryListBySaveSlotInfo> infoListToSave = new List<persistanceInventoryListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToSave = currentData as List<persistanceInventoryListBySaveSlotInfo>;
file.Close ();
}
int infoListToSaveCount = infoListToSave.Count;
for (int j = 0; j < infoListToSaveCount; j++) {
if (saveSlotIndex == -1) {
persistanceInventoryListBySaveSlotInfo currentSlot = infoListToSave [j];
if (currentSlot.saveNumber == currentSaveNumber) {
newPersistanceInventoryListBySaveSlotInfo = currentSlot;
saveLocated = true;
saveSlotIndex = j;
}
}
}
if (showDebugInfo) {
print ("\n\n");
print ("INVENTORY BANK");
print ("Number of objects: " + vendorToSave.inventoryObjectList.Count);
print ("Current Save Number " + currentSaveNumber);
print ("Save Located " + saveLocated);
}
if (saveLocated) {
if (newPersistanceInventoryListBySaveSlotInfo.playerInventoryList.Count > 0) {
playerLocated = true;
listIndex = 0;
}
}
//if the save is located, check if the bank exists
if (saveLocated) {
//if player id exists, overwrite it
if (playerLocated) {
infoListToSave [saveSlotIndex].playerInventoryList [listIndex].inventoryObjectList = vendorToSave.inventoryObjectList;
} else {
infoListToSave [saveSlotIndex].playerInventoryList.Add (vendorToSave);
}
} else {
newPersistanceInventoryListBySaveSlotInfo.saveNumber = currentSaveNumber;
newPersistanceInventoryListBySaveSlotInfo.playerInventoryList.Add (vendorToSave);
infoListToSave.Add (newPersistanceInventoryListBySaveSlotInfo);
}
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.OpenOrCreate);
bf.Serialize (file, infoListToSave);
file.Close ();
}
public void loadGameContent (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
getMainManager ();
if (mainInventoryBankManager == null) {
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Loading inventory bank");
}
//need to store and check the current slot saved and the player which is saving, to get that concrete info
persistanceInfoList = new List<inventoryListElement> ();
List<persistanceInventoryListBySaveSlotInfo> infoListToLoad = new List<persistanceInventoryListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToLoad = currentData as List<persistanceInventoryListBySaveSlotInfo>;
file.Close ();
}
if (saveNumberToLoad > -1) {
persistanceInventoryListBySaveSlotInfo newPersistanceInventoryListBySaveSlotInfo = new persistanceInventoryListBySaveSlotInfo ();
int infoListToLoadCount = infoListToLoad.Count;
bool slotLocated = false;
for (int j = 0; j < infoListToLoadCount; j++) {
if (!slotLocated) {
persistanceInventoryListBySaveSlotInfo currentSlot = infoListToLoad [j];
if (currentSlot.saveNumber == saveNumberToLoad) {
newPersistanceInventoryListBySaveSlotInfo = currentSlot;
slotLocated = true;
}
}
}
int bankInventoryIndex = 0;
if (newPersistanceInventoryListBySaveSlotInfo.playerInventoryList.Count > 0) {
persistanceInventoryListByPlayerInfo bankInventoryListToLoad = newPersistanceInventoryListBySaveSlotInfo.playerInventoryList [bankInventoryIndex];
int inventoryObjectListCount = bankInventoryListToLoad.inventoryObjectList.Count;
for (int j = 0; j < inventoryObjectListCount; j++) {
inventoryListElement newInventoryListElement = new inventoryListElement ();
persistanceInventoryObjectInfo currentInventorInfo = bankInventoryListToLoad.inventoryObjectList [j];
newInventoryListElement.Name = currentInventorInfo.Name;
newInventoryListElement.amount = currentInventorInfo.amount;
newInventoryListElement.infiniteAmount = currentInventorInfo.infiniteAmount;
newInventoryListElement.inventoryObjectName = currentInventorInfo.inventoryObjectName;
newInventoryListElement.categoryIndex = currentInventorInfo.categoryIndex;
newInventoryListElement.elementIndex = currentInventorInfo.elementIndex;
persistanceInfoList.Add (newInventoryListElement);
}
}
}
if (showDebugInfo) {
print ("\n\n");
print ("INVENTORY BANK");
print ("Inventory Bank Loaded in Save Number " + saveNumberToLoad);
print ("Number of objects: " + persistanceInfoList.Count);
for (int j = 0; j < persistanceInfoList.Count; j++) {
inventoryListElement currentElement = persistanceInfoList [j];
print ("Object Name: " + currentElement.Name + " Amount: " + currentElement.amount);
}
}
loadInfoOnMainComponent ();
}
public persistanceInventoryListByPlayerInfo getPersistanceList (int playerID, bool showDebugInfo)
{
persistanceInventoryListByPlayerInfo newPersistanceInventoryListByPlayerInfo = new persistanceInventoryListByPlayerInfo ();
newPersistanceInventoryListByPlayerInfo.playerID = playerID;
List<persistanceInventoryObjectInfo> newPersistanceInventoryObjectInfoList = new List<persistanceInventoryObjectInfo> ();
List<inventoryInfo> bankInventoryList = mainInventoryBankManager.bankInventoryList;
int bankInventoryListCount = bankInventoryList.Count;
for (int k = 0; k < bankInventoryListCount; k++) {
persistanceInventoryObjectInfo newPersistanceInventoryObjectInfo = new persistanceInventoryObjectInfo ();
inventoryInfo currentInventoryInfo = bankInventoryList [k];
newPersistanceInventoryObjectInfo.Name = currentInventoryInfo.Name;
newPersistanceInventoryObjectInfo.amount = currentInventoryInfo.amount;
newPersistanceInventoryObjectInfo.infiniteAmount = currentInventoryInfo.infiniteAmount;
newPersistanceInventoryObjectInfo.inventoryObjectName = currentInventoryInfo.Name;
newPersistanceInventoryObjectInfo.categoryIndex = currentInventoryInfo.categoryIndex;
newPersistanceInventoryObjectInfo.elementIndex = currentInventoryInfo.elementIndex;
newPersistanceInventoryObjectInfoList.Add (newPersistanceInventoryObjectInfo);
}
newPersistanceInventoryListByPlayerInfo.inventoryObjectList = newPersistanceInventoryObjectInfoList;
return newPersistanceInventoryListByPlayerInfo;
}
void loadInfoOnMainComponent ()
{
if (persistanceInfoList != null && persistanceInfoList.Count > 0) {
mainInventoryBankManager.setNewInventoryListManagerList (persistanceInfoList);
}
}
void getMainManager ()
{
if (mainInventoryBankManager == null) {
inventoryListManager mainInventoryListManager = inventoryListManager.Instance;
bool mainInventoryManagerLocated = mainInventoryListManager != null;
if (!mainInventoryManagerLocated) {
GKC_Utils.instantiateMainManagerOnSceneWithTypeOnApplicationPlaying (inventoryListManager.getMainManagerName (), typeof(inventoryListManager), true);
mainInventoryListManager = inventoryListManager.Instance;
mainInventoryManagerLocated = (mainInventoryListManager != null);
}
if (!mainInventoryManagerLocated) {
mainInventoryListManager = FindObjectOfType<inventoryListManager> ();
mainInventoryManagerLocated = mainInventoryListManager != null;
}
if (mainInventoryManagerLocated) {
mainInventoryBankManager = mainInventoryListManager.getMainInventoryBankManager ();
}
}
}
public void saveGameContentFromEditor (int currentSaveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
getMainManager ();
if (mainInventoryBankManager == null) {
return;
}
bool saveLocated = false;
bool playerLocated = false;
int saveSlotIndex = -1;
int listIndex = -1;
BinaryFormatter bf = new BinaryFormatter ();
FileStream file;
persistanceInventoryListByPlayerInfo vendorToSave = getPersistanceVendorListElement (playerID, showDebugInfo);
persistanceInventoryListBySaveSlotInfo newPersistanceInventoryListBySaveSlotInfo = new persistanceInventoryListBySaveSlotInfo ();
List<persistanceInventoryListBySaveSlotInfo> infoListToSave = new List<persistanceInventoryListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToSave = currentData as List<persistanceInventoryListBySaveSlotInfo>;
file.Close ();
}
int infoListToSaveCount = infoListToSave.Count;
for (int j = 0; j < infoListToSaveCount; j++) {
if (saveSlotIndex == -1) {
persistanceInventoryListBySaveSlotInfo currentSlot = infoListToSave [j];
if (currentSlot.saveNumber == currentSaveNumber) {
newPersistanceInventoryListBySaveSlotInfo = currentSlot;
saveLocated = true;
saveSlotIndex = j;
}
}
}
if (showDebugInfo) {
print ("\n\n");
print ("INVENTORY BANK");
print ("Number of objects: " + vendorToSave.inventoryObjectList.Count);
print ("Current Save Number " + currentSaveNumber);
print ("Save Located " + saveLocated);
}
if (saveLocated) {
if (newPersistanceInventoryListBySaveSlotInfo.playerInventoryList.Count > 0) {
playerLocated = true;
listIndex = 0;
}
}
//if the save is located, check if the bank exists
if (saveLocated) {
//if player id exists, overwrite it
if (playerLocated) {
infoListToSave [saveSlotIndex].playerInventoryList [listIndex].inventoryObjectList = vendorToSave.inventoryObjectList;
} else {
infoListToSave [saveSlotIndex].playerInventoryList.Add (vendorToSave);
}
} else {
newPersistanceInventoryListBySaveSlotInfo.saveNumber = currentSaveNumber;
newPersistanceInventoryListBySaveSlotInfo.playerInventoryList.Add (vendorToSave);
infoListToSave.Add (newPersistanceInventoryListBySaveSlotInfo);
}
bf = new BinaryFormatter ();
file = File.Create (currentSaveDataPath);
bf.Serialize (file, infoListToSave);
file.Close ();
}
public persistanceInventoryListByPlayerInfo getPersistanceVendorListElement (int playerID, bool showDebugInfo)
{
persistanceInventoryListByPlayerInfo newPersistanceInventoryListByPlayerInfo = new persistanceInventoryListByPlayerInfo ();
newPersistanceInventoryListByPlayerInfo.playerID = playerID;
List<persistanceInventoryObjectInfo> newPersistanceInventoryObjectInfoList = new List<persistanceInventoryObjectInfo> ();
List<inventoryListElement> inventoryListManagerList = mainInventoryBankManager.inventoryListManagerList;
int inventoryListManagerListCount = inventoryListManagerList.Count;
for (int k = 0; k < inventoryListManagerListCount; k++) {
persistanceInventoryObjectInfo newPersistanceInventoryObjectInfo = new persistanceInventoryObjectInfo ();
inventoryListElement currentElement = inventoryListManagerList [k];
newPersistanceInventoryObjectInfo.Name = currentElement.Name;
newPersistanceInventoryObjectInfo.amount = currentElement.amount;
newPersistanceInventoryObjectInfo.infiniteAmount = currentElement.infiniteAmount;
newPersistanceInventoryObjectInfo.inventoryObjectName = currentElement.inventoryObjectName;
newPersistanceInventoryObjectInfo.elementIndex = currentElement.elementIndex;
newPersistanceInventoryObjectInfo.categoryIndex = currentElement.categoryIndex;
if (showDebugInfo) {
print (newPersistanceInventoryObjectInfo.Name + " " + newPersistanceInventoryObjectInfo.amount);
}
newPersistanceInventoryObjectInfoList.Add (newPersistanceInventoryObjectInfo);
}
newPersistanceInventoryListByPlayerInfo.inventoryObjectList = newPersistanceInventoryObjectInfoList;
return newPersistanceInventoryListByPlayerInfo;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: fe215edec7ef2ce44810f69dc762d3df
timeCreated: 1602224062
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Save System/Custom Class To Save/saveInventoryBankInfo.cs
uploadId: 814740

View File

@@ -0,0 +1,313 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System;
public class saveMeleeWeaponsInfo : saveGameInfo
{
public meleeWeaponsGrabbedManager mainMeleeWeaponsGrabbedManager;
List<persistanceMeleeInfo> persistanceInfoList;
bool valuesInitializedOnLoad;
public override void saveGame (int saveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
saveGameContent (saveNumber, playerID, currentSaveDataPath, showDebugInfo, savingGameToChangeScene);
}
public override void loadGame (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
loadGameContent (saveNumberToLoad, playerID, currentSaveDataPath, showDebugInfo);
}
public override void initializeValuesOnComponent ()
{
initializeValues ();
}
public void saveGameContent (int currentSaveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
if (mainMeleeWeaponsGrabbedManager == null) {
return;
}
if (!mainMeleeWeaponsGrabbedManager.meleeWeaponsGrabbedManagerEnabled) {
return;
}
if (!mainMeleeWeaponsGrabbedManager.saveCurrentMeleeWeaponListToSaveFile) {
return;
}
if (mainMeleeWeaponsGrabbedManager.storePickedWeaponsOnInventory) {
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Saving melee weapons");
}
bool saveLocated = false;
bool playerLocated = false;
int saveSlotIndex = -1;
int listIndex = -1;
BinaryFormatter bf = new BinaryFormatter ();
FileStream file;
persistanceMeleeWeaponInfo meleeWeaponsToSave = getPersistanceList (playerID, showDebugInfo);
persistanceMeleeWeaponListBySaveSlotInfo newPersistanceMeleeWeaponListBySaveSlotInfo = new persistanceMeleeWeaponListBySaveSlotInfo ();
List<persistanceMeleeWeaponListBySaveSlotInfo> infoListToSave = new List<persistanceMeleeWeaponListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToSave = currentData as List<persistanceMeleeWeaponListBySaveSlotInfo>;
file.Close ();
}
int infoListToSaveCount = infoListToSave.Count;
for (int j = 0; j < infoListToSaveCount; j++) {
if (infoListToSave [j].saveNumber == currentSaveNumber) {
newPersistanceMeleeWeaponListBySaveSlotInfo = infoListToSave [j];
saveLocated = true;
saveSlotIndex = j;
}
}
if (saveLocated) {
int meleeWeaponListCount = newPersistanceMeleeWeaponListBySaveSlotInfo.meleeWeaponList.Count;
for (int j = 0; j < meleeWeaponListCount; j++) {
if (newPersistanceMeleeWeaponListBySaveSlotInfo.meleeWeaponList [j].playerID == meleeWeaponsToSave.playerID) {
playerLocated = true;
listIndex = j;
}
}
}
//if the save is located, check if the player id exists
if (saveLocated) {
//if player id exists, overwrite it
if (playerLocated) {
infoListToSave [saveSlotIndex].meleeWeaponList [listIndex].meleeList = meleeWeaponsToSave.meleeList;
} else {
infoListToSave [saveSlotIndex].meleeWeaponList.Add (meleeWeaponsToSave);
}
} else {
newPersistanceMeleeWeaponListBySaveSlotInfo.saveNumber = currentSaveNumber;
newPersistanceMeleeWeaponListBySaveSlotInfo.meleeWeaponList.Add (meleeWeaponsToSave);
infoListToSave.Add (newPersistanceMeleeWeaponListBySaveSlotInfo);
}
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.OpenOrCreate);
bf.Serialize (file, infoListToSave);
file.Close ();
if (showDebugInfo) {
print ("\n\n");
print ("Melee Weapons Saved in Save Number " + currentSaveNumber);
}
}
public void loadGameContent (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
if (mainMeleeWeaponsGrabbedManager == null) {
return;
}
if (!mainMeleeWeaponsGrabbedManager.meleeWeaponsGrabbedManagerEnabled) {
return;
}
if (mainMeleeWeaponsGrabbedManager.storePickedWeaponsOnInventory) {
return;
}
initializeValues ();
if (showDebugInfo) {
print ("\n\n");
print ("Loading melee weapons");
}
//need to store and check the current slot saved and the player which is saving, to get that concrete info
persistanceInfoList = new List<persistanceMeleeInfo> ();
List<persistanceMeleeWeaponListBySaveSlotInfo> infoListToLoad = new List<persistanceMeleeWeaponListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToLoad = currentData as List<persistanceMeleeWeaponListBySaveSlotInfo>;
file.Close ();
}
if (saveNumberToLoad > -1) {
persistanceMeleeWeaponListBySaveSlotInfo newPersistanceMeleeWeaponListBySaveSlotInfo = new persistanceMeleeWeaponListBySaveSlotInfo ();
int infoListToLoadCount = infoListToLoad.Count;
for (int j = 0; j < infoListToLoadCount; j++) {
if (infoListToLoad [j].saveNumber == saveNumberToLoad) {
newPersistanceMeleeWeaponListBySaveSlotInfo = infoListToLoad [j];
}
}
int listIndex = -1;
int meleeWeaponListCount = newPersistanceMeleeWeaponListBySaveSlotInfo.meleeWeaponList.Count;
for (int j = 0; j < meleeWeaponListCount; j++) {
if (newPersistanceMeleeWeaponListBySaveSlotInfo.meleeWeaponList [j].playerID == playerID) {
listIndex = j;
}
}
if (listIndex > -1) {
persistanceInfoList.AddRange (newPersistanceMeleeWeaponListBySaveSlotInfo.meleeWeaponList [listIndex].meleeList);
}
}
if (showDebugInfo) {
print ("\n\n");
print ("Melee Weapons Loaded in Save Number " + saveNumberToLoad);
print ("Number of Melee Weapons: " + persistanceInfoList.Count);
}
loadInfoOnMainComponent ();
}
persistanceMeleeWeaponInfo getPersistanceList (int playerID, bool showDebugInfo)
{
persistanceMeleeWeaponInfo newPersistanceMeleeWeaponInfo = new persistanceMeleeWeaponInfo ();
newPersistanceMeleeWeaponInfo.playerID = playerID;
List<persistanceMeleeInfo> newPersistanceMeleeInfoList = new List<persistanceMeleeInfo> ();
List<meleeWeaponsGrabbedManager.meleeWeaponGrabbedInfo> meleeWeaponGrabbedInfoList = mainMeleeWeaponsGrabbedManager.meleeWeaponGrabbedInfoList;
int meleeWeaponGrabbedInfoListCount = meleeWeaponGrabbedInfoList.Count;
for (int k = 0; k < meleeWeaponGrabbedInfoListCount; k++) {
persistanceMeleeInfo newPersistanceMeleeInfo = new persistanceMeleeInfo ();
meleeWeaponsGrabbedManager.meleeWeaponGrabbedInfo currentWeapon = meleeWeaponGrabbedInfoList [k];
newPersistanceMeleeInfo.weaponActiveIndex = currentWeapon.weaponPrefabIndex;
newPersistanceMeleeInfo.isCurrentWeapon = currentWeapon.isCurrentWeapon;
newPersistanceMeleeInfoList.Add (newPersistanceMeleeInfo);
if (showDebugInfo) {
print ("Weapon " + currentWeapon.Name + " " + currentWeapon.weaponPrefabIndex + " " + currentWeapon.isCurrentWeapon);
}
}
newPersistanceMeleeWeaponInfo.meleeList = newPersistanceMeleeInfoList;
return newPersistanceMeleeWeaponInfo;
}
void loadInfoOnMainComponent ()
{
valuesInitializedOnLoad = true;
initializeValues ();
if (persistanceInfoList != null && persistanceInfoList.Count > 0) {
List<meleeWeaponsGrabbedManager.meleeWeaponPrefabInfo> meleeWeaponPrefabInfoList = mainMeleeWeaponsGrabbedManager.meleeWeaponPrefabInfoList;
List<meleeWeaponsGrabbedManager.meleeWeaponGrabbedInfo> meleeWeaponGrabbedInfoList = mainMeleeWeaponsGrabbedManager.meleeWeaponGrabbedInfoList;
int persistanceInfoListCount = persistanceInfoList.Count;
for (int i = 0; i < persistanceInfoListCount; i++) {
persistanceMeleeInfo currentPersistanceMeleeInfo = persistanceInfoList [i];
meleeWeaponsGrabbedManager.meleeWeaponPrefabInfo currentMeleeWeaponPrefabInfo = meleeWeaponPrefabInfoList [currentPersistanceMeleeInfo.weaponActiveIndex];
if (currentMeleeWeaponPrefabInfo != null) {
meleeWeaponsGrabbedManager.meleeWeaponGrabbedInfo newMeleeWeaponGrabbedInfo = new meleeWeaponsGrabbedManager.meleeWeaponGrabbedInfo ();
newMeleeWeaponGrabbedInfo.Name = currentMeleeWeaponPrefabInfo.Name;
newMeleeWeaponGrabbedInfo.weaponPrefabIndex = currentMeleeWeaponPrefabInfo.weaponPrefabIndex;
meleeWeaponGrabbedInfoList.Add (newMeleeWeaponGrabbedInfo);
if (currentPersistanceMeleeInfo.isCurrentWeapon) {
mainMeleeWeaponsGrabbedManager.currentWeaponIndex = currentMeleeWeaponPrefabInfo.weaponPrefabIndex;
}
}
}
if (!mainMeleeWeaponsGrabbedManager.isGrabObjectsEnabled ()) {
return;
}
int meleeWeaponGrabbedInfoListCount = meleeWeaponGrabbedInfoList.Count;
for (int k = 0; k < meleeWeaponGrabbedInfoListCount; k++) {
meleeWeaponsGrabbedManager.meleeWeaponGrabbedInfo currentMeleeWeaponGrabbedInfo = meleeWeaponGrabbedInfoList [k];
currentMeleeWeaponGrabbedInfo.weaponInstantiated = true;
meleeWeaponsGrabbedManager.meleeWeaponPrefabInfo currentMeleeWeaponPrefabInfo = mainMeleeWeaponsGrabbedManager.getWeaponPrefabByName (currentMeleeWeaponGrabbedInfo.Name);
if (currentMeleeWeaponPrefabInfo != null) {
currentMeleeWeaponGrabbedInfo.weaponStored = (GameObject)Instantiate (currentMeleeWeaponPrefabInfo.weaponPrefab, Vector3.up * 1000, Quaternion.identity);
currentMeleeWeaponGrabbedInfo.weaponPrefabIndex = currentMeleeWeaponPrefabInfo.weaponPrefabIndex;
mainMeleeWeaponsGrabbedManager.checkObjectMeshToEnableOrDisable (!currentMeleeWeaponGrabbedInfo.hideWeaponMeshWhenNotUsed, currentMeleeWeaponGrabbedInfo);
currentMeleeWeaponGrabbedInfo.weaponStored.SetActive (false);
}
}
mainMeleeWeaponsGrabbedManager.isLoadingGame = true;
}
mainMeleeWeaponsGrabbedManager.initializeMeleeManagerValues ();
}
void initializeValues ()
{
mainMeleeWeaponsGrabbedManager.isLoadingGame = false;
if (!valuesInitializedOnLoad) {
mainMeleeWeaponsGrabbedManager.initializeMeleeManagerValues ();
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 6717e2fa25602b84dab33238db4d3bf2
timeCreated: 1602147456
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Save System/Custom Class To Save/saveMeleeWeaponsInfo.cs
uploadId: 814740

View File

@@ -0,0 +1,426 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System;
public class saveMissionsInfo : saveGameInfo
{
public objectiveLogSystem mainObjectiveLogSystem;
List<persistanceMissionInfo> persistanceInfoList;
bool showCurrentDebugInfo;
public override void saveGame (int saveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
saveGameContent (saveNumber, playerID, currentSaveDataPath, showDebugInfo, savingGameToChangeScene);
}
public override void loadGame (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
loadGameContent (saveNumberToLoad, playerID, currentSaveDataPath, showDebugInfo);
}
public override void initializeValuesOnComponent ()
{
initializeValues ();
}
public void saveGameContent (int currentSaveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
getMainManager ();
if (mainObjectiveLogSystem == null) {
return;
}
if (!mainObjectiveLogSystem.isObjectiveMenuActive ()) {
return;
}
if (!mainObjectiveLogSystem.saveCurrentPlayerMissionsToSaveFile) {
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Saving missions");
}
bool saveLocated = false;
bool playerLocated = false;
int saveSlotIndex = -1;
int listIndex = -1;
BinaryFormatter bf = new BinaryFormatter ();
FileStream file;
persistancePlayerMissionInfo missionsToSave = getPersistanceList (playerID, showDebugInfo);
persistancePlayerMissionsListBySaveSlotInfo newPersistancePlayerMissionsListBySaveSlotInfo = new persistancePlayerMissionsListBySaveSlotInfo ();
List<persistancePlayerMissionsListBySaveSlotInfo> infoListToSave = new List<persistancePlayerMissionsListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToSave = currentData as List<persistancePlayerMissionsListBySaveSlotInfo>;
file.Close ();
}
int infoListToSaveCount = infoListToSave.Count;
for (int j = 0; j < infoListToSaveCount; j++) {
if (infoListToSave [j].saveNumber == currentSaveNumber) {
newPersistancePlayerMissionsListBySaveSlotInfo = infoListToSave [j];
saveLocated = true;
saveSlotIndex = j;
}
}
if (saveLocated) {
int playerMissionsListCount = newPersistancePlayerMissionsListBySaveSlotInfo.playerMissionsList.Count;
for (int j = 0; j < playerMissionsListCount; j++) {
if (newPersistancePlayerMissionsListBySaveSlotInfo.playerMissionsList [j].playerID == missionsToSave.playerID) {
playerLocated = true;
listIndex = j;
}
}
}
if (showDebugInfo) {
print ("\n\n");
print ("EXTRA INFO\n");
print ("Number of missions: " + missionsToSave.missionsList.Count);
print ("Current Save Number " + currentSaveNumber);
print ("Save Located " + saveLocated);
print ("Player Located " + playerLocated);
print ("Player ID " + missionsToSave.playerID);
}
//if the save is located, check if the player id exists
if (saveLocated) {
//if player id exists, overwrite it
if (playerLocated) {
infoListToSave [saveSlotIndex].playerMissionsList [listIndex].missionsList = missionsToSave.missionsList;
} else {
infoListToSave [saveSlotIndex].playerMissionsList.Add (missionsToSave);
}
} else {
newPersistancePlayerMissionsListBySaveSlotInfo.saveNumber = currentSaveNumber;
newPersistancePlayerMissionsListBySaveSlotInfo.playerMissionsList.Add (missionsToSave);
infoListToSave.Add (newPersistancePlayerMissionsListBySaveSlotInfo);
}
if (showDebugInfo) {
print ("\n\n");
for (int j = 0; j < missionsToSave.missionsList.Count; j++) {
persistanceMissionInfo currentPersistanceMissionInfo = missionsToSave.missionsList [j];
showDetailedDebugInfo (currentPersistanceMissionInfo);
}
}
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.OpenOrCreate);
bf.Serialize (file, infoListToSave);
file.Close ();
}
public void loadGameContent (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
getMainManager ();
if (mainObjectiveLogSystem == null) {
return;
}
if (!mainObjectiveLogSystem.isObjectiveMenuActive ()) {
return;
}
if (!mainObjectiveLogSystem.saveCurrentPlayerMissionsToSaveFile) {
initializeValues ();
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Loading missions");
}
//need to store and check the current slot saved and the player which is saving, to get that concrete info
persistanceInfoList = new List<persistanceMissionInfo> ();
List<persistancePlayerMissionsListBySaveSlotInfo> infoListToLoad = new List<persistancePlayerMissionsListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToLoad = currentData as List<persistancePlayerMissionsListBySaveSlotInfo>;
file.Close ();
}
if (saveNumberToLoad > -1) {
persistancePlayerMissionsListBySaveSlotInfo newPersistancePlayerMissionsListBySaveSlotInfo = new persistancePlayerMissionsListBySaveSlotInfo ();
int infoListToLoadCount = infoListToLoad.Count;
for (int j = 0; j < infoListToLoadCount; j++) {
if (infoListToLoad [j].saveNumber == saveNumberToLoad) {
newPersistancePlayerMissionsListBySaveSlotInfo = infoListToLoad [j];
}
}
int listIndex = -1;
int playerMissionsListCount = newPersistancePlayerMissionsListBySaveSlotInfo.playerMissionsList.Count;
for (int j = 0; j < playerMissionsListCount; j++) {
if (newPersistancePlayerMissionsListBySaveSlotInfo.playerMissionsList [j].playerID == playerID) {
listIndex = j;
}
}
if (listIndex > -1) {
persistanceInfoList.AddRange (newPersistancePlayerMissionsListBySaveSlotInfo.playerMissionsList [listIndex].missionsList);
}
}
if (showDebugInfo) {
print ("\n\n");
print ("Missions Loaded in Save Number " + saveNumberToLoad);
print ("Number of missions: " + persistanceInfoList.Count);
print ("\n\n");
for (int j = 0; j < persistanceInfoList.Count; j++) {
print ("\n\n");
persistanceMissionInfo currentPersistanceMissionInfo = persistanceInfoList [j];
showDetailedDebugInfo (currentPersistanceMissionInfo);
}
}
showCurrentDebugInfo = showDebugInfo;
loadInfoOnMainComponent ();
}
public persistancePlayerMissionInfo getPersistanceList (int playerID, bool showDebugInfo)
{
persistancePlayerMissionInfo newMissionsList = new persistancePlayerMissionInfo ();
newMissionsList.playerID = playerID;
List<persistanceMissionInfo> newPersistanceMissionInfoList = new List<persistanceMissionInfo> ();
List<objectiveLogSystem.objectiveSlotInfo> objectiveSlotInfoList = mainObjectiveLogSystem.objectiveSlotInfoList;
int objectiveSlotInfoListCount = objectiveSlotInfoList.Count;
for (int k = 0; k < objectiveSlotInfoListCount; k++) {
persistanceMissionInfo newPersistanceMissionInfo = new persistanceMissionInfo ();
objectiveLogSystem.objectiveSlotInfo currentSlotInfo = objectiveSlotInfoList [k];
newPersistanceMissionInfo.missionScene = currentSlotInfo.missionScene;
newPersistanceMissionInfo.missionID = currentSlotInfo.missionID;
newPersistanceMissionInfo.disableObjectivePanelOnMissionComplete = currentSlotInfo.disableObjectivePanelOnMissionComplete;
newPersistanceMissionInfo.addObjectiveToPlayerLogSystem = currentSlotInfo.addObjectiveToPlayerLogSystem;
newPersistanceMissionInfo.missionComplete = currentSlotInfo.missionComplete;
newPersistanceMissionInfo.missionInProcess = currentSlotInfo.missionInProcess;
newPersistanceMissionInfo.rewardObtained = currentSlotInfo.rewardObtained;
newPersistanceMissionInfo.missionAccepted = currentSlotInfo.missionAccepted;
newPersistanceMissionInfo.objectiveName = currentSlotInfo.objectiveName;
newPersistanceMissionInfo.objectiveDescription = currentSlotInfo.objectiveDescription;
newPersistanceMissionInfo.objectiveFullDescription = currentSlotInfo.objectiveFullDescription;
newPersistanceMissionInfo.objectiveLocation = currentSlotInfo.objectiveLocation;
newPersistanceMissionInfo.objectiveRewards = currentSlotInfo.objectiveRewards;
newPersistanceMissionInfo.subObjectiveCompleteList = currentSlotInfo.subObjectiveCompleteList;
if (showDebugInfo) {
debugMissionInfo (newPersistanceMissionInfo);
}
newPersistanceMissionInfoList.Add (newPersistanceMissionInfo);
}
newMissionsList.missionsList = newPersistanceMissionInfoList;
return newMissionsList;
}
void loadInfoOnMainComponent ()
{
initializeValues ();
if (persistanceInfoList != null && persistanceInfoList.Count > 0) {
int persistanceInfoListCount = persistanceInfoList.Count;
for (int k = 0; k < persistanceInfoListCount; k++) {
persistanceMissionInfo currentPersistanceMissionInfo = persistanceInfoList [k];
//Seach the objective event system, the mission it self, in the main objective manager, to see the info needed on it
objectiveEventSystem currentObjectiveEventSystem =
mainObjectiveLogSystem.getObjectiveEventSystem (currentPersistanceMissionInfo.missionID, currentPersistanceMissionInfo.missionScene);
//if the current mission to search is found in the level, assign the info and set its state, including to add the log info on the player's menu
if (currentObjectiveEventSystem != null) {
if (showCurrentDebugInfo) {
debugMissionInfo (currentPersistanceMissionInfo);
}
currentObjectiveEventSystem.setCurrentPlayer (mainObjectiveLogSystem.playerControllerGameObject);
bool updateSubobjectivesCompleteOnMission = currentPersistanceMissionInfo.missionInProcess ||
currentObjectiveEventSystem.updateSubobjectivesCompleteOnLoadGame;
if (updateSubobjectivesCompleteOnMission) {
if (currentPersistanceMissionInfo.subObjectiveCompleteList.Count > 0) {
currentObjectiveEventSystem.setSubObjectiveCompleteListState (currentPersistanceMissionInfo.subObjectiveCompleteList);
}
currentObjectiveEventSystem.initializeNumberOfObjectives ();
}
bool resumeMissionOnLoadGameIfNotComplete = !currentPersistanceMissionInfo.missionComplete &&
(currentObjectiveEventSystem.resumeMissionOnLoadGameIfNotComplete ||
currentPersistanceMissionInfo.missionInProcess);
if (resumeMissionOnLoadGameIfNotComplete) {
currentObjectiveEventSystem.startObjective ();
} else {
currentObjectiveEventSystem.addObjectiveToPlayerLogMenu ();
if (currentPersistanceMissionInfo.missionComplete) {
currentObjectiveEventSystem.setObjectiveAsCompleteOnLoad (currentPersistanceMissionInfo.rewardObtained);
}
}
} else {
//If the mission system is not found, it means the mission is assigned in other level, so just assign the info in the player's log
mainObjectiveLogSystem.addObjective (currentPersistanceMissionInfo.objectiveName,
currentPersistanceMissionInfo.objectiveDescription,
currentPersistanceMissionInfo.objectiveFullDescription,
currentPersistanceMissionInfo.objectiveLocation,
currentPersistanceMissionInfo.objectiveRewards,
null,
currentPersistanceMissionInfo.addObjectiveToPlayerLogSystem);
objectiveLogSystem.objectiveSlotInfo currentobjectiveSlotInfo =
mainObjectiveLogSystem.objectiveSlotInfoList [mainObjectiveLogSystem.objectiveSlotInfoList.Count - 1];
currentobjectiveSlotInfo.missionScene = currentPersistanceMissionInfo.missionScene;
currentobjectiveSlotInfo.missionID = currentPersistanceMissionInfo.missionID;
currentobjectiveSlotInfo.disableObjectivePanelOnMissionComplete = currentPersistanceMissionInfo.disableObjectivePanelOnMissionComplete;
currentobjectiveSlotInfo.addObjectiveToPlayerLogSystem = currentPersistanceMissionInfo.addObjectiveToPlayerLogSystem;
currentobjectiveSlotInfo.missionComplete = currentPersistanceMissionInfo.missionComplete;
currentobjectiveSlotInfo.missionInProcess = currentPersistanceMissionInfo.missionInProcess;
currentobjectiveSlotInfo.rewardObtained = currentPersistanceMissionInfo.rewardObtained;
currentobjectiveSlotInfo.missionAccepted = currentPersistanceMissionInfo.missionAccepted;
if (currentobjectiveSlotInfo.missionComplete) {
mainObjectiveLogSystem.updateObjectiveCompleteSlotInfo (mainObjectiveLogSystem.objectiveSlotInfoList.Count - 1);
} else {
if (currentPersistanceMissionInfo.subObjectiveCompleteList.Count > 0) {
mainObjectiveLogSystem.updateSubObjectiveCompleteListSlotInfo (mainObjectiveLogSystem.objectiveSlotInfoList.Count - 1,
currentPersistanceMissionInfo.subObjectiveCompleteList);
}
}
}
mainObjectiveLogSystem.updateUIElements ();
}
}
}
void getMainManager ()
{
if (mainObjectiveLogSystem == null) {
mainObjectiveLogSystem = FindObjectOfType<objectiveLogSystem> ();
}
}
void initializeValues ()
{
mainObjectiveLogSystem.initializeMissionValues ();
}
public void debugMissionInfo (persistanceMissionInfo missinInfo)
{
print (
missinInfo.missionScene + " " +
missinInfo.missionID + " " +
missinInfo.disableObjectivePanelOnMissionComplete + " " +
missinInfo.addObjectiveToPlayerLogSystem + " " +
missinInfo.missionComplete + " " +
missinInfo.missionInProcess + " " +
missinInfo.rewardObtained + " " +
missinInfo.missionAccepted + " " +
missinInfo.objectiveName + " " +
missinInfo.objectiveDescription + " " +
missinInfo.objectiveFullDescription + " " +
missinInfo.objectiveRewards
);
}
void showDetailedDebugInfo (persistanceMissionInfo currentPersistanceMissionInfo)
{
print ("Mission Scene " + currentPersistanceMissionInfo.missionScene);
print ("Mission ID " + currentPersistanceMissionInfo.missionID);
print ("Disable Panel On Mission Complete " + currentPersistanceMissionInfo.disableObjectivePanelOnMissionComplete);
print ("Add Objective To Player Log System " + currentPersistanceMissionInfo.addObjectiveToPlayerLogSystem);
print ("Mission Complete " + currentPersistanceMissionInfo.missionComplete);
print ("Mission In Process " + currentPersistanceMissionInfo.missionInProcess);
print ("Mission Reward Obtained " + currentPersistanceMissionInfo.rewardObtained);
print ("Mission Accepted " + currentPersistanceMissionInfo.missionAccepted);
print ("Objective Name " + currentPersistanceMissionInfo.objectiveName);
print ("Objective Description " + currentPersistanceMissionInfo.objectiveDescription);
print ("Full Description " + currentPersistanceMissionInfo.objectiveFullDescription);
print ("Objective Location " + currentPersistanceMissionInfo.objectiveLocation);
print ("Objective Rewards " + currentPersistanceMissionInfo.objectiveRewards);
print ("Sub Objectives Complete\n");
for (int j = 0; j < currentPersistanceMissionInfo.subObjectiveCompleteList.Count; j++) {
print (currentPersistanceMissionInfo.subObjectiveCompleteList [j]);
}
print ("\n\n");
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: ea7d764431e170d41ade3fecdc16ad18
timeCreated: 1602221056
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Save System/Custom Class To Save/saveMissionsInfo.cs
uploadId: 814740

View File

@@ -0,0 +1,317 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System;
public class savePlayerBlendshapesInfo : saveGameInfo
{
public characterCustomizationBlendshapesHelper mainCharacterCustomizationBlendshapesHelper;
List<persistanceBlendshapesInfo> persistanceInfoList;
List<string> accessoriesList = new List<string> ();
public override void saveGame (int saveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
saveGameContent (saveNumber, playerID, currentSaveDataPath, showDebugInfo, savingGameToChangeScene);
}
public override void loadGame (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
loadGameContent (saveNumberToLoad, playerID, currentSaveDataPath, showDebugInfo);
}
public override void initializeValuesOnComponent ()
{
initializeValues ();
}
public void saveGameContent (int currentSaveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
if (mainCharacterCustomizationBlendshapesHelper == null) {
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Saving player blendshapes");
}
bool saveLocated = false;
bool playerLocated = false;
int saveSlotIndex = -1;
int listIndex = -1;
BinaryFormatter bf = new BinaryFormatter ();
FileStream file;
mainCharacterCustomizationBlendshapesHelper.storeBlendshapesCustomization ();
persistancePlayerBlendshapesInfo blendShapeListToSave = getPersistanceList (playerID, showDebugInfo);
persistanceBlendshapesListBySaveSlotInfo newPersistanceListBySaveSlotInfo = new persistanceBlendshapesListBySaveSlotInfo ();
List<persistanceBlendshapesListBySaveSlotInfo> infoListToSave = new List<persistanceBlendshapesListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToSave = currentData as List<persistanceBlendshapesListBySaveSlotInfo>;
file.Close ();
}
if (showDebugInfo) {
print ("Number of save list for player blendshapes " + infoListToSave.Count);
}
int infoListToSaveCount = infoListToSave.Count;
for (int j = 0; j < infoListToSaveCount; j++) {
if (saveSlotIndex == -1) {
persistanceBlendshapesListBySaveSlotInfo currentSlot = infoListToSave [j];
if (ignoreSaveNumberOnSaveLoadInfo || currentSlot.saveNumber == currentSaveNumber) {
newPersistanceListBySaveSlotInfo = currentSlot;
saveLocated = true;
saveSlotIndex = j;
}
}
}
if (saveLocated) {
int listCount = newPersistanceListBySaveSlotInfo.playerBlendshapesList.Count;
int playerIDToSearch = blendShapeListToSave.playerID;
for (int j = 0; j < listCount; j++) {
if (listIndex == -1) {
if (ignorePlayerIDOnSaveLoadInfo ||
newPersistanceListBySaveSlotInfo.playerBlendshapesList [j].playerID == playerIDToSearch) {
playerLocated = true;
listIndex = j;
}
}
}
}
if (showDebugInfo) {
print ("\n\n");
print ("EXTRA INFO\n");
print ("PLAYER BLENDSHAPES");
print ("Number of blendshpaes: " + blendShapeListToSave.blendshapesList.Count);
print ("Current Save Number " + currentSaveNumber);
print ("Save Located " + saveLocated);
print ("Player Located " + playerLocated);
print ("Save List Index " + listIndex);
}
//if the save is located, check if the player id exists
if (saveLocated) {
//if player id exists, overwrite it
if (playerLocated) {
infoListToSave [saveSlotIndex].playerBlendshapesList [listIndex] = blendShapeListToSave;
} else {
infoListToSave [saveSlotIndex].playerBlendshapesList.Add (blendShapeListToSave);
}
} else {
newPersistanceListBySaveSlotInfo.saveNumber = currentSaveNumber;
newPersistanceListBySaveSlotInfo.playerBlendshapesList.Add (blendShapeListToSave);
infoListToSave.Add (newPersistanceListBySaveSlotInfo);
}
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.OpenOrCreate);
bf.Serialize (file, infoListToSave);
file.Close ();
}
public void loadGameContent (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
if (mainCharacterCustomizationBlendshapesHelper == null) {
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Loading player blendshapes with PLAYER ID " + playerID);
}
persistanceInfoList = new List<persistanceBlendshapesInfo> ();
List<persistanceBlendshapesListBySaveSlotInfo> infoListToLoad = new List<persistanceBlendshapesListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToLoad = currentData as List<persistanceBlendshapesListBySaveSlotInfo>;
file.Close ();
}
if (saveNumberToLoad > -1) {
if (showDebugInfo) {
print (infoListToLoad.Count);
}
persistanceBlendshapesListBySaveSlotInfo newPersistanceListBySaveSlotInfo = new persistanceBlendshapesListBySaveSlotInfo ();
int infoListToLoadCount = infoListToLoad.Count;
bool slotLocated = false;
for (int j = 0; j < infoListToLoadCount; j++) {
if (!slotLocated) {
persistanceBlendshapesListBySaveSlotInfo currentSlot = infoListToLoad [j];
bool checkSlot = false;
if (ignoreSaveNumberOnSaveLoadInfo) {
checkSlot = true;
}
if (saveNumberToIgnoreSaveLoadInfo == saveNumberToLoad && saveNumberToIgnoreSaveLoadInfo > -1) {
checkSlot = true;
}
if (currentSlot.saveNumber == saveNumberToLoad) {
checkSlot = true;
}
if (checkSlot) {
newPersistanceListBySaveSlotInfo = currentSlot;
slotLocated = true;
}
}
}
int listIndex = -1;
int listCount = newPersistanceListBySaveSlotInfo.playerBlendshapesList.Count;
for (int j = 0; j < listCount; j++) {
if (listIndex == -1) {
bool checkSlot = false;
if (ignorePlayerIDOnSaveLoadInfo) {
checkSlot = true;
}
if (saveNumberToIgnoreSaveLoadInfo == saveNumberToLoad && saveNumberToIgnoreSaveLoadInfo > -1) {
checkSlot = true;
}
if (newPersistanceListBySaveSlotInfo.playerBlendshapesList [j].playerID == playerID) {
checkSlot = true;
}
if (checkSlot) {
listIndex = j;
}
}
}
if (listIndex > -1) {
persistancePlayerBlendshapesInfo blendshapeListToLoad = newPersistanceListBySaveSlotInfo.playerBlendshapesList [listIndex];
persistanceInfoList.AddRange (newPersistanceListBySaveSlotInfo.playerBlendshapesList [listIndex].blendshapesList);
accessoriesList.AddRange (newPersistanceListBySaveSlotInfo.playerBlendshapesList [listIndex].accessoriesList);
}
}
if (showDebugInfo) {
print ("\n\n");
print ("PLAYER BLENDSHAPES");
print ("Blendshapes Loaded in Save Number " + saveNumberToLoad);
print ("Number of objects: " + persistanceInfoList.Count);
for (int j = 0; j < persistanceInfoList.Count; j++) {
persistanceBlendshapesInfo currentPersistanceBlendshapesInfo = persistanceInfoList [j];
print (currentPersistanceBlendshapesInfo.Name + " " + currentPersistanceBlendshapesInfo.blendShapeValue);
}
}
loadInfoOnMainComponent ();
}
public persistancePlayerBlendshapesInfo getPersistanceList (int playerID, bool showDebugInfo)
{
persistancePlayerBlendshapesInfo newPersistancePlayerBlendshapesInfo = new persistancePlayerBlendshapesInfo ();
newPersistancePlayerBlendshapesInfo.playerID = playerID;
List<persistanceBlendshapesInfo> newPersistanceBlendshapesInfoList = new List<persistanceBlendshapesInfo> ();
List<characterCustomizationManager.temporalBlendshapeInfo> temporalBlendshapeInfoList = mainCharacterCustomizationBlendshapesHelper.temporalBlendshapeInfoList;
int temporalBlendshapeInfoListCount = temporalBlendshapeInfoList.Count;
for (int k = 0; k < temporalBlendshapeInfoListCount; k++) {
persistanceBlendshapesInfo newPersistanceBlendshapesInfo = new persistanceBlendshapesInfo ();
characterCustomizationManager.temporalBlendshapeInfo currentBlendshape = temporalBlendshapeInfoList [k];
newPersistanceBlendshapesInfo.Name = currentBlendshape.Name;
newPersistanceBlendshapesInfo.blendShapeValue = currentBlendshape.blendShapeValue;
newPersistanceBlendshapesInfoList.Add (newPersistanceBlendshapesInfo);
}
newPersistancePlayerBlendshapesInfo.blendshapesList = newPersistanceBlendshapesInfoList;
newPersistancePlayerBlendshapesInfo.accessoriesList = mainCharacterCustomizationBlendshapesHelper.temporalCurrentAccessoriesList;
return newPersistancePlayerBlendshapesInfo;
}
void loadInfoOnMainComponent ()
{
initializeValues ();
if (persistanceInfoList != null && persistanceInfoList.Count > 0) {
int persistanceInfoListCount = persistanceInfoList.Count;
for (int i = 0; i < persistanceInfoListCount; i++) {
persistanceBlendshapesInfo currentPersistanceBlendshapesInfo = persistanceInfoList [i];
characterCustomizationManager.temporalBlendshapeInfo newBlendshape = new characterCustomizationManager.temporalBlendshapeInfo ();
newBlendshape.Name = currentPersistanceBlendshapesInfo.Name;
newBlendshape.blendShapeValue = currentPersistanceBlendshapesInfo.blendShapeValue;
mainCharacterCustomizationBlendshapesHelper.temporalBlendshapeInfoList.Add (newBlendshape);
}
mainCharacterCustomizationBlendshapesHelper.temporalCurrentAccessoriesList.AddRange (accessoriesList);
mainCharacterCustomizationBlendshapesHelper.setBlendshapeList ();
}
}
void initializeValues ()
{
mainCharacterCustomizationBlendshapesHelper.checkMainCHaracterCustomizatationManager ();
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 8c65dcaf87d9b89438fe77f4bf770ddf
timeCreated: 1640422152
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Save System/Custom Class To Save/savePlayerBlendshapesInfo.cs
uploadId: 814740

View File

@@ -0,0 +1,696 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System;
public class savePlayerInventoryInfo : saveGameInfo
{
[Space]
[Header ("Other Options")]
[Space]
public bool ignoreAssignLoadedInventoryIfEmpty;
[Space]
[Header ("Debug")]
[Space]
public List<inventoryListElement> persistanceInfoList;
[Space]
[Header ("Components")]
[Space]
public inventoryManagerInfo mainInventoryManager;
bool lastGameSavedOnHomeMenuValue;
public override void saveGame (int saveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
saveGameContent (saveNumber, playerID, currentSaveDataPath, showDebugInfo, savingGameToChangeScene);
}
public override void loadGame (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
loadGameContent (saveNumberToLoad, playerID, currentSaveDataPath, showDebugInfo);
}
public override void saveGameFromEditor (int saveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
saveGameContentFromEditor (saveNumber, playerID, currentSaveDataPath, showDebugInfo);
}
public override void initializeValuesOnComponent ()
{
initializeValues ();
}
public void saveGameContent (int currentSaveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
if (mainInventoryManager == null) {
return;
}
if (!mainInventoryManager.isSaveCurrentPlayerInventoryToSaveFileActive ()) {
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Saving player inventory");
}
bool saveLocated = false;
bool playerLocated = false;
int saveSlotIndex = -1;
int listIndex = -1;
BinaryFormatter bf = new BinaryFormatter ();
FileStream file;
persistanceInventoryListByPlayerInfo inventoryListToSave = getPersistanceList (playerID, showDebugInfo);
persistanceInventoryListBySaveSlotInfo newPersistanceInventoryListBySaveSlotInfo = new persistanceInventoryListBySaveSlotInfo ();
List<persistanceInventoryListBySaveSlotInfo> infoListToSave = new List<persistanceInventoryListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToSave = currentData as List<persistanceInventoryListBySaveSlotInfo>;
file.Close ();
}
if (showDebugInfo) {
print ("Number of save list for player inventory " + infoListToSave.Count);
}
int infoListToSaveCount = infoListToSave.Count;
for (int j = 0; j < infoListToSaveCount; j++) {
if (saveSlotIndex == -1) {
persistanceInventoryListBySaveSlotInfo currentSlot = infoListToSave [j];
if (currentSlot.saveNumber == currentSaveNumber) {
newPersistanceInventoryListBySaveSlotInfo = currentSlot;
saveLocated = true;
saveSlotIndex = j;
}
}
}
if (saveLocated) {
int playerInventoryListCount = newPersistanceInventoryListBySaveSlotInfo.playerInventoryList.Count;
int playerIDToSearch = inventoryListToSave.playerID;
for (int j = 0; j < playerInventoryListCount; j++) {
if (listIndex == -1) {
if (newPersistanceInventoryListBySaveSlotInfo.playerInventoryList [j].playerID == playerIDToSearch) {
playerLocated = true;
listIndex = j;
}
}
}
}
if (showDebugInfo) {
print ("\n\n");
print ("EXTRA INFO\n");
print ("PLAYER INVENTORY");
print ("Number of objects: " + inventoryListToSave.inventoryObjectList.Count);
print ("Current Save Number " + currentSaveNumber);
print ("Save Located " + saveLocated);
print ("Player Located " + playerLocated);
print ("Player ID " + inventoryListToSave.playerID);
print ("Save List Index " + listIndex);
}
//if the save is located, check if the player id exists
if (saveLocated) {
//if player id exists, overwrite it
if (playerLocated) {
// infoListToSave [saveSlotIndex].playerInventoryList [listIndex].inventoryObjectList = inventoryListToSave.inventoryObjectList;
infoListToSave [saveSlotIndex].playerInventoryList [listIndex] = inventoryListToSave;
} else {
infoListToSave [saveSlotIndex].playerInventoryList.Add (inventoryListToSave);
}
} else {
newPersistanceInventoryListBySaveSlotInfo.saveNumber = currentSaveNumber;
newPersistanceInventoryListBySaveSlotInfo.gameSavedOnHomeMenu = gameSavedOnHomeMenu;
newPersistanceInventoryListBySaveSlotInfo.playerInventoryList.Add (inventoryListToSave);
infoListToSave.Add (newPersistanceInventoryListBySaveSlotInfo);
if (showDebugInfo) {
if (gameSavedOnHomeMenu) {
print ("Game saved on home menu");
print ("\n\n");
}
}
}
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.OpenOrCreate);
bf.Serialize (file, infoListToSave);
file.Close ();
}
public void loadGameContent (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
if (mainInventoryManager == null) {
return;
}
if (!mainInventoryManager.isLoadCurrentPlayerInventoryFromSaveFileActive ()) {
initializeValues ();
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Loading player inventory with PLAYER ID " + playerID + " and saveNumberToLoad " + saveNumberToLoad);
}
//need to store and check the current slot saved and the player which is saving, to get that concrete info
persistanceInfoList = new List<inventoryListElement> ();
List<persistanceInventoryListBySaveSlotInfo> infoListToLoad = new List<persistanceInventoryListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToLoad = currentData as List<persistanceInventoryListBySaveSlotInfo>;
file.Close ();
if (showDebugInfo) {
print ("Save File located " + currentSaveDataPath);
print ("\n\n");
}
} else {
if (showDebugInfo) {
print ("Save File not located " + currentSaveDataPath);
print ("\n\n");
}
}
lastGameSavedOnHomeMenuValue = false;
if (saveNumberToLoad > -1) {
if (showDebugInfo) {
print (infoListToLoad.Count);
}
bool removeSaveInfo = false;
persistanceInventoryListBySaveSlotInfo newPersistanceInventoryListBySaveSlotInfo = new persistanceInventoryListBySaveSlotInfo ();
int infoListToLoadCount = infoListToLoad.Count;
bool slotLocated = false;
for (int j = 0; j < infoListToLoadCount; j++) {
if (!slotLocated) {
persistanceInventoryListBySaveSlotInfo currentSlot = infoListToLoad [j];
bool checkSlot = false;
// if (ignoreSaveNumberOnSaveLoadInfo) {
// checkSlot = true;
// }
if (saveNumberToIgnoreSaveLoadInfo == saveNumberToLoad && saveNumberToIgnoreSaveLoadInfo > -1 && currentSlot.gameSavedOnHomeMenu) {
removeSaveInfo = true;
checkSlot = true;
}
if (currentSlot.saveNumber == saveNumberToLoad) {
checkSlot = true;
}
if (checkSlot) {
newPersistanceInventoryListBySaveSlotInfo = currentSlot;
slotLocated = true;
}
}
}
//print ("number " + newPersistanceInventoryListBySaveSlotInfo.playerInventoryList.Count);
int listIndex = -1;
int playerInventoryListCount = newPersistanceInventoryListBySaveSlotInfo.playerInventoryList.Count;
for (int j = 0; j < playerInventoryListCount; j++) {
// print (newPersistanceInventoryListBySaveSlotInfo.playerInventoryList [j].playerID + " " +
// newPersistanceInventoryListBySaveSlotInfo.playerInventoryList [j].inventorySlotAmount);
//
if (listIndex == -1) {
bool checkSlot = false;
// if (ignorePlayerIDOnSaveLoadInfo) {
// checkSlot = true;
// }
if (saveNumberToIgnoreSaveLoadInfo == saveNumberToLoad && saveNumberToIgnoreSaveLoadInfo > -1) {
checkSlot = true;
}
if (newPersistanceInventoryListBySaveSlotInfo.playerInventoryList [j].playerID == playerID) {
checkSlot = true;
}
if (checkSlot) {
listIndex = j;
}
}
}
//print ("index " + listIndex);
if (listIndex > -1) {
lastGameSavedOnHomeMenuValue = newPersistanceInventoryListBySaveSlotInfo.gameSavedOnHomeMenu;
persistanceInventoryListByPlayerInfo playerInventoryListToLoad = newPersistanceInventoryListBySaveSlotInfo.playerInventoryList [listIndex];
int inventoryObjectListCount = playerInventoryListToLoad.inventoryObjectList.Count;
for (int j = 0; j < inventoryObjectListCount; j++) {
inventoryListElement newInventoryListElement = new inventoryListElement ();
persistanceInventoryObjectInfo currentInventoryInfo = playerInventoryListToLoad.inventoryObjectList [j];
newInventoryListElement.Name = currentInventoryInfo.Name;
newInventoryListElement.amount = currentInventoryInfo.amount;
newInventoryListElement.infiniteAmount = currentInventoryInfo.infiniteAmount;
newInventoryListElement.inventoryObjectName = currentInventoryInfo.inventoryObjectName;
newInventoryListElement.categoryIndex = currentInventoryInfo.categoryIndex;
newInventoryListElement.elementIndex = currentInventoryInfo.elementIndex;
newInventoryListElement.isEquipped = currentInventoryInfo.isEquipped;
newInventoryListElement.quickAccessSlotIndex = currentInventoryInfo.quickAccessSlotIndex;
newInventoryListElement.useDurability = currentInventoryInfo.useDurability;
newInventoryListElement.durabilityAmount = currentInventoryInfo.durabilityAmount;
newInventoryListElement.maxDurabilityAmount = currentInventoryInfo.maxDurabilityAmount;
newInventoryListElement.objectIsBroken = currentInventoryInfo.objectIsBroken;
newInventoryListElement.isWeapon = currentInventoryInfo.isWeapon;
newInventoryListElement.isMeleeWeapon = currentInventoryInfo.isMeleeWeapon;
newInventoryListElement.projectilesInMagazine = currentInventoryInfo.projectilesInMagazine;
persistanceInfoList.Add (newInventoryListElement);
}
int inventorySlotAmount = playerInventoryListToLoad.inventorySlotAmount;
if (inventorySlotAmount > -1) {
mainInventoryManager.setInventorySlotAmountValue (inventorySlotAmount);
}
mainInventoryManager.setInventoryWasEmptyWhenSavedState (playerInventoryListToLoad.inventoryWasEmptyWhenSaved);
if (mainInventoryManager.isSetInfiniteSlotValuesOnSaveLoadActive ()) {
mainInventoryManager.setInfiniteSlotsState (playerInventoryListToLoad.infiniteSlots);
}
if (playerInventoryListToLoad.useOnlyBlueprintsUnlocked) {
GKC_Utils.setUseOnlyBlueprintsUnlockedState (mainInventoryManager.gameObject, true);
GKC_Utils.setBlueprintsUnlockedListValue (mainInventoryManager.gameObject, playerInventoryListToLoad.blueprintsUnlockedList);
}
if (playerInventoryListToLoad.anyObjectToCraftInTimeActive) {
GKC_Utils.setCraftObjectInTimeInfoList (mainInventoryManager.gameObject, playerInventoryListToLoad.craftObjectInTimeSimpleInfoList);
}
if (playerInventoryListToLoad.objectCategoriesToCraftAvailableAtAnyMoment != null && playerInventoryListToLoad.objectCategoriesToCraftAvailableAtAnyMoment.Count > 0) {
GKC_Utils.setObjectCategoriesToCraftAvailableAtAnyMomentValue (mainInventoryManager.gameObject, playerInventoryListToLoad.objectCategoriesToCraftAvailableAtAnyMoment);
}
mainInventoryManager.setLastWeaponCarriedOnHandsName (playerInventoryListToLoad.lastWeaponCarriedOnHandsName);
if (showDebugInfo) {
print ("\n\n");
print ("Number of inventory slots available: " + playerInventoryListToLoad.inventorySlotAmount);
print ("\n\n");
if (playerInventoryListToLoad.useOnlyBlueprintsUnlocked) {
print ("\n\n");
print ("Use only blueprints unlocked active with the amount: " + playerInventoryListToLoad.blueprintsUnlockedList.Count);
print ("\n\n");
}
}
if (removeSaveInfo) {
infoListToLoad.Remove (newPersistanceInventoryListBySaveSlotInfo);
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Create (currentSaveDataPath);
bf.Serialize (file, infoListToLoad);
file.Close ();
if (showDebugInfo) {
print ("REMOVE SLOT FROM INITIAL INVENTORY ON NEW GAME");
}
}
}
}
if (showDebugInfo) {
print ("\n\n");
print ("PLAYER INVENTORY");
print ("Inventory Loaded in Save Number " + saveNumberToLoad);
print ("Number of objects: " + persistanceInfoList.Count);
for (int j = 0; j < persistanceInfoList.Count; j++) {
inventoryListElement currentElement = persistanceInfoList [j];
print ("Object Name: " + currentElement.Name + " Amount: " + currentElement.amount);
if (currentElement.isWeapon && !currentElement.isMeleeWeapon) {
print ("Object is weapon with " + currentElement.projectilesInMagazine + " projectiles in the magazine");
}
}
}
loadInfoOnMainComponent ();
}
public persistanceInventoryListByPlayerInfo getPersistanceList (int playerID, bool showDebugInfo)
{
persistanceInventoryListByPlayerInfo newPersistanceInventoryListByPlayerInfo = new persistanceInventoryListByPlayerInfo ();
newPersistanceInventoryListByPlayerInfo.playerID = playerID;
mainInventoryManager.updateDurabilityAmountStateOnAllInventoryObjects ();
int inventorySlotAmount = mainInventoryManager.getInventorySlotAmount ();
newPersistanceInventoryListByPlayerInfo.inventorySlotAmount = inventorySlotAmount;
newPersistanceInventoryListByPlayerInfo.infiniteSlots = mainInventoryManager.isInfiniteSlotsActive ();
//Crafting elements
newPersistanceInventoryListByPlayerInfo.useOnlyBlueprintsUnlocked = GKC_Utils.isUseOnlyBlueprintsUnlockedActive (mainInventoryManager.gameObject);
if (newPersistanceInventoryListByPlayerInfo.useOnlyBlueprintsUnlocked) {
List<string> blueprintsUnlockedList = GKC_Utils.getBlueprintsUnlockedListValue (mainInventoryManager.gameObject);
if (blueprintsUnlockedList != null) {
newPersistanceInventoryListByPlayerInfo.blueprintsUnlockedList = new List<string> (blueprintsUnlockedList);
}
}
newPersistanceInventoryListByPlayerInfo.anyObjectToCraftInTimeActive = GKC_Utils.anyObjectToCraftInTimeActive (mainInventoryManager.gameObject);
if (newPersistanceInventoryListByPlayerInfo.anyObjectToCraftInTimeActive) {
newPersistanceInventoryListByPlayerInfo.craftObjectInTimeSimpleInfoList = GKC_Utils.getCraftObjectInTimeInfoList (mainInventoryManager.gameObject);
}
newPersistanceInventoryListByPlayerInfo.objectCategoriesToCraftAvailableAtAnyMoment = GKC_Utils.getObjectCategoriesToCraftAvailableAtAnyMomentValue (mainInventoryManager.gameObject);
newPersistanceInventoryListByPlayerInfo.lastWeaponCarriedOnHandsName = mainInventoryManager.getLastWeaponCarriedOnHandsName ();
if (showDebugInfo) {
print ("\n\n");
print ("Number of inventory slots available: " + inventorySlotAmount);
print ("\n\n");
if (newPersistanceInventoryListByPlayerInfo.useOnlyBlueprintsUnlocked) {
print ("\n\n");
print ("Use only blueprints unlocked active with the amount: " + newPersistanceInventoryListByPlayerInfo.blueprintsUnlockedList.Count);
print ("\n\n");
}
}
List<persistanceInventoryObjectInfo> newPersistanceInventoryObjectInfoList = new List<persistanceInventoryObjectInfo> ();
List<inventoryInfo> inventoryList = mainInventoryManager.getInventoryList ();
int inventoryListCount = inventoryList.Count;
bool inventoryWasEmptyWhenSaved = true;
for (int k = 0; k < inventoryListCount; k++) {
inventoryInfo currentInventoryInfo = inventoryList [k];
if (currentInventoryInfo.amount > 0) {
persistanceInventoryObjectInfo newPersistanceInventoryObjectInfo = new persistanceInventoryObjectInfo ();
newPersistanceInventoryObjectInfo.Name = currentInventoryInfo.Name;
newPersistanceInventoryObjectInfo.amount = currentInventoryInfo.amount;
newPersistanceInventoryObjectInfo.infiniteAmount = currentInventoryInfo.infiniteAmount;
newPersistanceInventoryObjectInfo.inventoryObjectName = currentInventoryInfo.Name;
newPersistanceInventoryObjectInfo.categoryIndex = currentInventoryInfo.categoryIndex;
newPersistanceInventoryObjectInfo.elementIndex = currentInventoryInfo.elementIndex;
newPersistanceInventoryObjectInfo.isEquipped = currentInventoryInfo.isEquipped;
newPersistanceInventoryObjectInfo.quickAccessSlotIndex = currentInventoryInfo.quickAccessSlotIndex;
newPersistanceInventoryObjectInfo.useDurability = currentInventoryInfo.useDurability;
newPersistanceInventoryObjectInfo.durabilityAmount = currentInventoryInfo.durabilityAmount;
newPersistanceInventoryObjectInfo.maxDurabilityAmount = currentInventoryInfo.maxDurabilityAmount;
newPersistanceInventoryObjectInfo.objectIsBroken = currentInventoryInfo.objectIsBroken;
newPersistanceInventoryObjectInfo.isWeapon = currentInventoryInfo.isWeapon;
newPersistanceInventoryObjectInfo.isMeleeWeapon = currentInventoryInfo.isMeleeWeapon;
if (newPersistanceInventoryObjectInfo.isWeapon && !newPersistanceInventoryObjectInfo.isMeleeWeapon) {
if (currentInventoryInfo.mainWeaponObjectInfo != null) {
newPersistanceInventoryObjectInfo.projectilesInMagazine = currentInventoryInfo.mainWeaponObjectInfo.getProjectilesInWeaponMagazine ();
}
}
newPersistanceInventoryObjectInfoList.Add (newPersistanceInventoryObjectInfo);
inventoryWasEmptyWhenSaved = false;
}
}
newPersistanceInventoryListByPlayerInfo.inventoryWasEmptyWhenSaved = inventoryWasEmptyWhenSaved;
if (showDebugInfo) {
print ("\n\n");
for (int j = 0; j < newPersistanceInventoryObjectInfoList.Count; j++) {
persistanceInventoryObjectInfo currentInfo = newPersistanceInventoryObjectInfoList [j];
print ("Object Name: " + currentInfo.Name + " Amount: " + currentInfo.amount + " category index " +
currentInfo.categoryIndex + " element index " + currentInfo.elementIndex);
if (currentInfo.isWeapon && !currentInfo.isMeleeWeapon) {
print ("Object is weapon with " + currentInfo.projectilesInMagazine + " projectiles in the magazine");
}
}
}
newPersistanceInventoryListByPlayerInfo.inventoryObjectList = newPersistanceInventoryObjectInfoList;
return newPersistanceInventoryListByPlayerInfo;
}
void loadInfoOnMainComponent ()
{
mainInventoryManager.setIsLoadingGameState (true);
initializeValues ();
if (persistanceInfoList != null) {
bool sendNewInventoryResult = true;
//when loading, it can be from a new game or from a continue/load action, so if the loaded inventory is an
//empty list, then:
//-when doing a new game, it should allow to use the initial inventory if configured
//-when loading/continuing a game, it should load the inventory list saved, even if empty
//check the state also when the player options menu is used on home menu
if (ignoreAssignLoadedInventoryIfEmpty) {
if (persistanceInfoList.Count == 0 && !mainInventoryManager.getInventoryWasEmptyWhenSaved ()) {
sendNewInventoryResult = false;
}
if (persistanceInfoList.Count == 0 && mainInventoryManager.getInventoryWasEmptyWhenSaved () && lastGameSavedOnHomeMenuValue) {
sendNewInventoryResult = false;
}
}
//print (persistanceInfoList.Count + " " + mainInventoryManager.getInventoryWasEmptyWhenSaved () + " " + lastGameSavedOnHomeMenuValue + " " +
//sendNewInventoryResult);
if (sendNewInventoryResult) {
mainInventoryManager.setNewInventoryListManagerList (persistanceInfoList);
}
}
}
void initializeValues ()
{
mainInventoryManager.initializeInventoryValues ();
}
public void saveGameContentFromEditor (int currentSaveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
if (mainInventoryManager == null) {
return;
}
bool saveLocated = false;
bool playerLocated = false;
int saveSlotIndex = -1;
int listIndex = -1;
BinaryFormatter bf = new BinaryFormatter ();
FileStream file;
persistanceInventoryListByPlayerInfo inventoryListToSave = getPersistanceInventoryListElement (playerID, showDebugInfo);
persistanceInventoryListBySaveSlotInfo newPersistanceInventoryListBySaveSlotInfo = new persistanceInventoryListBySaveSlotInfo ();
List<persistanceInventoryListBySaveSlotInfo> infoListToSave = new List<persistanceInventoryListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToSave = currentData as List<persistanceInventoryListBySaveSlotInfo>;
file.Close ();
}
int infoListToSaveCount = infoListToSave.Count;
for (int j = 0; j < infoListToSaveCount; j++) {
if (saveSlotIndex == -1) {
persistanceInventoryListBySaveSlotInfo currentSlot = infoListToSave [j];
if (currentSlot.saveNumber == currentSaveNumber) {
newPersistanceInventoryListBySaveSlotInfo = currentSlot;
saveLocated = true;
saveSlotIndex = j;
}
}
}
if (saveLocated) {
int playerInventoryListCount = newPersistanceInventoryListBySaveSlotInfo.playerInventoryList.Count;
int playerIDToSearch = inventoryListToSave.playerID;
for (int j = 0; j < playerInventoryListCount; j++) {
if (listIndex == -1 && newPersistanceInventoryListBySaveSlotInfo.playerInventoryList [j].playerID == playerIDToSearch) {
playerLocated = true;
listIndex = j;
}
}
}
if (showDebugInfo) {
print ("\n\n");
print ("EXTRA INFO\n");
print ("PLAYER INVENTORY");
print ("Number of objects: " + inventoryListToSave.inventoryObjectList.Count);
print ("Current Save Number " + currentSaveNumber);
print ("Save Located " + saveLocated);
print ("Player Located " + playerLocated);
print ("Player ID " + inventoryListToSave.playerID);
}
//if the save is located, check if the player id exists
if (saveLocated) {
//if player id exists, overwrite it
if (playerLocated) {
infoListToSave [saveSlotIndex].playerInventoryList [listIndex].inventoryObjectList = inventoryListToSave.inventoryObjectList;
} else {
infoListToSave [saveSlotIndex].playerInventoryList.Add (inventoryListToSave);
}
} else {
newPersistanceInventoryListBySaveSlotInfo.saveNumber = currentSaveNumber;
newPersistanceInventoryListBySaveSlotInfo.playerInventoryList.Add (inventoryListToSave);
infoListToSave.Add (newPersistanceInventoryListBySaveSlotInfo);
}
bf = new BinaryFormatter ();
file = File.Create (currentSaveDataPath);
bf.Serialize (file, infoListToSave);
file.Close ();
}
public persistanceInventoryListByPlayerInfo getPersistanceInventoryListElement (int playerID, bool showDebugInfo)
{
persistanceInventoryListByPlayerInfo newPersistanceInventoryListByPlayerInfo = new persistanceInventoryListByPlayerInfo ();
newPersistanceInventoryListByPlayerInfo.playerID = playerID;
List<persistanceInventoryObjectInfo> newPersistanceInventoryObjectInfoList = new List<persistanceInventoryObjectInfo> ();
List<inventoryListElement> inventoryListManagerList = mainInventoryManager.getCurrentInventoryListManagerList ();
int inventoryListManagerListCount = inventoryListManagerList.Count;
for (int k = 0; k < inventoryListManagerListCount; k++) {
persistanceInventoryObjectInfo newPersistanceInventoryObjectInfo = new persistanceInventoryObjectInfo ();
inventoryListElement currentElement = inventoryListManagerList [k];
newPersistanceInventoryObjectInfo.Name = currentElement.Name;
newPersistanceInventoryObjectInfo.amount = currentElement.amount;
newPersistanceInventoryObjectInfo.infiniteAmount = currentElement.infiniteAmount;
newPersistanceInventoryObjectInfo.inventoryObjectName = currentElement.inventoryObjectName;
newPersistanceInventoryObjectInfo.elementIndex = currentElement.elementIndex;
newPersistanceInventoryObjectInfo.categoryIndex = currentElement.categoryIndex;
if (showDebugInfo) {
print (newPersistanceInventoryObjectInfo.Name + " " + newPersistanceInventoryObjectInfo.amount);
}
newPersistanceInventoryObjectInfoList.Add (newPersistanceInventoryObjectInfo);
}
newPersistanceInventoryListByPlayerInfo.inventoryObjectList = newPersistanceInventoryObjectInfoList;
return newPersistanceInventoryListByPlayerInfo;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: e702c9927f6168046b43a73301c640c8
timeCreated: 1602224180
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Save System/Custom Class To Save/savePlayerInventoryInfo.cs
uploadId: 814740

View File

@@ -0,0 +1,442 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System;
public class savePlayerOptionsInfo : saveGameInfo
{
[Header ("Custom Settings")]
[Space]
public playerOptionsEditorSystem mainPlayerOptionsEditorSystem;
List<persistanceOptionsInfo> persistanceInfoList;
public override void saveGame (int saveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
saveGameContent (saveNumber, playerID, currentSaveDataPath, showDebugInfo, savingGameToChangeScene);
}
public override void loadGame (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
loadGameContent (saveNumberToLoad, playerID, currentSaveDataPath, showDebugInfo);
}
public void saveGameContent (int currentSaveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
if (mainPlayerOptionsEditorSystem == null) {
return;
}
if (!mainPlayerOptionsEditorSystem.playerOptionsEditorEnabled) {
return;
}
if (!mainPlayerOptionsEditorSystem.saveCurrentPlayerOptionsToSaveFile) {
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Saving player options");
}
bool saveLocated = false;
bool playerLocated = false;
int saveSlotIndex = -1;
int listIndex = -1;
BinaryFormatter bf = new BinaryFormatter ();
FileStream file;
persistancePlayerOptionsInfo playerOptionsToSave = getPersistanceList (playerID, showDebugInfo);
persistancePlayerOptionsListBySaveSlotInfo newPersistancePlayerOptionsListBySaveSlotInfo = new persistancePlayerOptionsListBySaveSlotInfo ();
List<persistancePlayerOptionsListBySaveSlotInfo> infoListToSave = new List<persistancePlayerOptionsListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToSave = currentData as List<persistancePlayerOptionsListBySaveSlotInfo>;
file.Close ();
}
int infoListToSaveCount = infoListToSave.Count;
for (int j = 0; j < infoListToSaveCount; j++) {
if (!saveLocated) {
if (ignoreSaveNumberOnSaveLoadInfo || infoListToSave [j].saveNumber == currentSaveNumber) {
newPersistancePlayerOptionsListBySaveSlotInfo = infoListToSave [j];
saveLocated = true;
saveSlotIndex = j;
}
}
}
if (saveLocated) {
int playerOptionsListCount = newPersistancePlayerOptionsListBySaveSlotInfo.playerOptionsList.Count;
for (int j = 0; j < playerOptionsListCount; j++) {
if (!playerLocated) {
if (ignorePlayerIDOnSaveLoadInfo ||
newPersistancePlayerOptionsListBySaveSlotInfo.playerOptionsList [j].playerID == playerOptionsToSave.playerID) {
playerLocated = true;
listIndex = j;
}
}
}
}
if (showDebugInfo) {
print ("\n\n");
print ("EXTRA INFO\n");
print ("Number of options: " + playerOptionsToSave.optionsList.Count);
print ("Current Save Number " + currentSaveNumber);
print ("Save Located " + saveLocated);
print ("Player Located " + playerLocated);
print ("Player ID " + playerOptionsToSave.playerID);
showDetailedDebugInfo ();
}
//if the save is located, check if the player id exists
if (saveLocated) {
//if player id exists, overwrite it
if (playerLocated) {
infoListToSave [saveSlotIndex].playerOptionsList [listIndex].optionsList = playerOptionsToSave.optionsList;
} else {
infoListToSave [saveSlotIndex].playerOptionsList.Add (playerOptionsToSave);
}
} else {
newPersistancePlayerOptionsListBySaveSlotInfo.saveNumber = currentSaveNumber;
newPersistancePlayerOptionsListBySaveSlotInfo.playerOptionsList.Add (playerOptionsToSave);
infoListToSave.Add (newPersistancePlayerOptionsListBySaveSlotInfo);
}
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.OpenOrCreate);
bf.Serialize (file, infoListToSave);
file.Close ();
if (saveInfoOnRegularTxtFile) {
writeDetailedDebugInfo (false);
}
}
public void loadGameContent (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
if (mainPlayerOptionsEditorSystem == null) {
return;
}
if (!mainPlayerOptionsEditorSystem.playerOptionsEditorEnabled) {
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Loading player options");
}
persistanceInfoList = new List<persistanceOptionsInfo> ();
//need to store and check the current slot saved and the player which is saving, to get that concrete info
List<persistancePlayerOptionsListBySaveSlotInfo> infoListToLoad = new List<persistancePlayerOptionsListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToLoad = currentData as List<persistancePlayerOptionsListBySaveSlotInfo>;
file.Close ();
}
if (saveNumberToLoad > -1) {
persistancePlayerOptionsListBySaveSlotInfo newPersistancePlayerOptionsListBySaveSlotInfo = new persistancePlayerOptionsListBySaveSlotInfo ();
int infoListToLoadCount = infoListToLoad.Count;
bool saveLocated = false;
for (int j = 0; j < infoListToLoadCount; j++) {
if (!saveLocated) {
if (ignoreSaveNumberOnSaveLoadInfo || infoListToLoad [j].saveNumber == saveNumberToLoad) {
newPersistancePlayerOptionsListBySaveSlotInfo = infoListToLoad [j];
saveLocated = true;
}
}
}
int listIndex = -1;
int playerOptionsListCount = newPersistancePlayerOptionsListBySaveSlotInfo.playerOptionsList.Count;
bool playerLocated = false;
for (int j = 0; j < playerOptionsListCount; j++) {
if (!playerLocated) {
if (ignorePlayerIDOnSaveLoadInfo || newPersistancePlayerOptionsListBySaveSlotInfo.playerOptionsList [j].playerID == playerID) {
listIndex = j;
playerLocated = true;
}
}
}
if (listIndex > -1) {
persistanceInfoList.AddRange (newPersistancePlayerOptionsListBySaveSlotInfo.playerOptionsList [listIndex].optionsList);
}
}
if (showDebugInfo) {
print ("\n\n");
print ("Player Options Loaded in Save Number " + saveNumberToLoad);
print ("Number of Player Options: " + persistanceInfoList.Count);
showDetailedDebugInfo ();
}
loadInfoOnMainComponent ();
if (saveInfoOnRegularTxtFile) {
writeDetailedDebugInfo (true);
}
}
public persistancePlayerOptionsInfo getPersistanceList (int playerID, bool showDebugInfo)
{
persistancePlayerOptionsInfo newPersistancePlayerOptionsInfo = new persistancePlayerOptionsInfo ();
newPersistancePlayerOptionsInfo.playerID = playerID;
List<persistanceOptionsInfo> newPersistanceOptionsInfoList = new List<persistanceOptionsInfo> ();
List<playerOptionsEditorSystem.optionInfo> optionInfoList = mainPlayerOptionsEditorSystem.optionInfoList;
int optionInfoListCount = optionInfoList.Count;
for (int k = 0; k < optionInfoListCount; k++) {
persistanceOptionsInfo newPersistanceOptionsInfo = new persistanceOptionsInfo ();
playerOptionsEditorSystem.optionInfo currentOptionInfo = optionInfoList [k];
newPersistanceOptionsInfo.optionName = currentOptionInfo.Name;
newPersistanceOptionsInfo.currentScrollBarValue = currentOptionInfo.currentScrollBarValue;
newPersistanceOptionsInfo.currentSliderValue = currentOptionInfo.currentSliderValue;
newPersistanceOptionsInfo.currentToggleValue = currentOptionInfo.currentToggleValue;
newPersistanceOptionsInfo.currentDropDownValue = currentOptionInfo.currentDropDownValue;
newPersistanceOptionsInfoList.Add (newPersistanceOptionsInfo);
}
newPersistancePlayerOptionsInfo.optionsList = newPersistanceOptionsInfoList;
return newPersistancePlayerOptionsInfo;
}
void loadInfoOnMainComponent ()
{
if (persistanceInfoList != null && persistanceInfoList.Count > 0) {
List<playerOptionsEditorSystem.optionInfo> optionInfoList = mainPlayerOptionsEditorSystem.optionInfoList;
int persistanceInfoListCount = persistanceInfoList.Count;
for (int i = 0; i < persistanceInfoListCount; i++) {
persistanceOptionsInfo currentPersistanceOptionsInfo = persistanceInfoList [i];
int currentOptionIndex = optionInfoList.FindIndex (s => s.Name.Equals (currentPersistanceOptionsInfo.optionName));
if (currentOptionIndex > -1) {
playerOptionsEditorSystem.optionInfo currentOptionInfo = optionInfoList [currentOptionIndex];
if (currentOptionInfo.useScrollBar) {
currentOptionInfo.currentScrollBarValue = currentPersistanceOptionsInfo.currentScrollBarValue;
}
if (currentOptionInfo.useSlider) {
currentOptionInfo.currentSliderValue = currentPersistanceOptionsInfo.currentSliderValue;
}
if (currentOptionInfo.useToggle) {
currentOptionInfo.currentToggleValue = currentPersistanceOptionsInfo.currentToggleValue;
}
if (currentOptionInfo.useDropDown) {
currentOptionInfo.currentDropDownValue = currentPersistanceOptionsInfo.currentDropDownValue;
}
}
}
mainPlayerOptionsEditorSystem.setIsLoadingGameState (true);
}
}
public override void checkSaveInfoToLoadOnStartOnAllScenes (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
if (showDebugInfo) {
print (saveNumberToLoad + " " + playerID + " " + currentSaveDataPath + " " + showDebugInfo);
}
if (File.Exists (currentSaveDataPath)) {
loadGameContent (saveNumberToLoad, playerID, currentSaveDataPath, showDebugInfo);
if (showDebugInfo) {
print ("save filed found, loading");
}
} else {
if (mainPlayerOptionsEditorSystem == null) {
return;
}
if (!mainPlayerOptionsEditorSystem.playerOptionsEditorEnabled) {
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Checking info to load on start on all scenes for player options");
print ("no save file found, loading values from inspector");
}
mainPlayerOptionsEditorSystem.setIsLoadingGameState (true);
}
}
void showDetailedDebugInfo ()
{
List<playerOptionsEditorSystem.optionInfo> optionInfoList = mainPlayerOptionsEditorSystem.optionInfoList;
if (optionInfoList != null && optionInfoList.Count > 0 && persistanceInfoList != null && persistanceInfoList.Count > 0) {
int persistanceInfoListCount = persistanceInfoList.Count;
for (int i = 0; i < persistanceInfoListCount; i++) {
persistanceOptionsInfo currentPersistanceOptionsInfo = persistanceInfoList [i];
int currentOptionIndex = optionInfoList.FindIndex (s => s.Name.Equals (currentPersistanceOptionsInfo.optionName));
if (currentOptionIndex > -1) {
playerOptionsEditorSystem.optionInfo currentOptionInfo = optionInfoList [currentOptionIndex];
print (currentOptionInfo.Name + " " + currentOptionInfo.useScrollBar + " " + currentPersistanceOptionsInfo.currentScrollBarValue);
print (currentOptionInfo.Name + " " + currentOptionInfo.useSlider + " " + currentPersistanceOptionsInfo.currentSliderValue);
print (currentOptionInfo.Name + " " + currentOptionInfo.useToggle + " " + currentPersistanceOptionsInfo.currentToggleValue);
print (currentOptionInfo.Name + " " + currentOptionInfo.useDropDown + " " + currentPersistanceOptionsInfo.currentDropDownValue);
}
}
print ("\n\n");
}
}
void writeDetailedDebugInfo (bool loadingFile)
{
string filePath = GKC_Utils.getMainDataPath ();
string newContent = "";
List<playerOptionsEditorSystem.optionInfo> optionInfoList = mainPlayerOptionsEditorSystem.optionInfoList;
if (loadingFile) {
int persistanceInfoListCount = persistanceInfoList.Count;
for (int i = 0; i < persistanceInfoListCount; i++) {
persistanceOptionsInfo currentPersistanceOptionsInfo = persistanceInfoList [i];
int currentOptionIndex = optionInfoList.FindIndex (s => s.Name.Equals (currentPersistanceOptionsInfo.optionName));
if (currentOptionIndex > -1) {
playerOptionsEditorSystem.optionInfo currentOptionInfo = optionInfoList [currentOptionIndex];
newContent += currentOptionInfo.Name;
if (currentOptionInfo.useScrollBar) {
newContent += " " + currentPersistanceOptionsInfo.currentScrollBarValue + " " + currentOptionInfo.currentScrollBarValue;
}
if (currentOptionInfo.useSlider) {
newContent += " " + currentPersistanceOptionsInfo.currentSliderValue + " " + currentOptionInfo.currentSliderValue;
}
if (currentOptionInfo.useToggle) {
newContent += " " + currentPersistanceOptionsInfo.currentToggleValue + " " + currentOptionInfo.currentToggleValue;
}
if (currentOptionInfo.useDropDown) {
newContent += " " + currentPersistanceOptionsInfo.currentDropDownValue + " " + currentOptionInfo.currentDropDownValue;
}
newContent += ("\n\n");
}
}
} else {
for (int i = 0; i < optionInfoList.Count; i++) {
playerOptionsEditorSystem.optionInfo currentOptionInfo = optionInfoList [i];
newContent += currentOptionInfo.Name;
if (currentOptionInfo.useScrollBar) {
newContent += " " + currentOptionInfo.currentScrollBarValue;
}
if (currentOptionInfo.useSlider) {
newContent += " " + currentOptionInfo.currentSliderValue;
}
if (currentOptionInfo.useToggle) {
newContent += " " + currentOptionInfo.currentToggleValue;
}
if (currentOptionInfo.useDropDown) {
newContent += " " + currentOptionInfo.currentDropDownValue;
}
newContent += ("\n\n");
}
}
if (loadingFile) {
filePath += loadInfoOnRegulaFileName + ".txt";
} else {
filePath += saveInfoOnRegulaFileName + ".txt";
}
File.WriteAllText (filePath, newContent);
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 50d274514d4c6e444bb2fef1f7b9fe44
timeCreated: 1602175129
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Save System/Custom Class To Save/savePlayerOptionsInfo.cs
uploadId: 814740

View File

@@ -0,0 +1,334 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System;
public class savePlayerWeaponsInfo : saveGameInfo
{
public playerWeaponsManager mainPlayerWeaponsManager;
List<persistanceWeaponInfo> persistanceInfoList;
public override void saveGame (int saveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
saveGameContent (saveNumber, playerID, currentSaveDataPath, showDebugInfo, savingGameToChangeScene);
}
public override void loadGame (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
loadGameContent (saveNumberToLoad, playerID, currentSaveDataPath, showDebugInfo);
}
public override void initializeValuesOnComponent ()
{
initializeValues ();
}
public void saveGameContent (int currentSaveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
if (mainPlayerWeaponsManager == null) {
return;
}
if (!mainPlayerWeaponsManager.saveCurrentPlayerWeaponsToSaveFile) {
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Saving player weapons");
}
bool saveLocated = false;
bool playerLocated = false;
int saveSlotIndex = -1;
int listIndex = -1;
BinaryFormatter bf = new BinaryFormatter ();
FileStream file;
persistanceWeaponListByPlayerInfo weaponsToSave = getPersistanceList (playerID, showDebugInfo);
persistanceWeaponListBySaveSlotInfo newPersistanceWeaponListBySaveSlotInfo = new persistanceWeaponListBySaveSlotInfo ();
List<persistanceWeaponListBySaveSlotInfo> infoListToSave = new List<persistanceWeaponListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToSave = currentData as List<persistanceWeaponListBySaveSlotInfo>;
file.Close ();
}
int infoListToSaveCount = infoListToSave.Count;
for (int j = 0; j < infoListToSaveCount; j++) {
if (infoListToSave [j].saveNumber == currentSaveNumber) {
newPersistanceWeaponListBySaveSlotInfo = infoListToSave [j];
saveLocated = true;
saveSlotIndex = j;
}
}
if (saveLocated) {
int playerWeaponListCount = newPersistanceWeaponListBySaveSlotInfo.playerWeaponList.Count;
for (int j = 0; j < playerWeaponListCount; j++) {
if (newPersistanceWeaponListBySaveSlotInfo.playerWeaponList [j].playerID == weaponsToSave.playerID) {
playerLocated = true;
listIndex = j;
}
}
}
if (showDebugInfo) {
print ("\n\n");
print ("Number of weapons: " + weaponsToSave.weaponList.Count);
print ("Current Save Number " + currentSaveNumber);
print ("Save Located " + saveLocated);
print ("Player Located " + playerLocated);
}
//if the save is located, check if the player id exists
if (saveLocated) {
//if player id exists, overwrite it
if (playerLocated) {
infoListToSave [saveSlotIndex].playerWeaponList [listIndex].weaponList = weaponsToSave.weaponList;
} else {
infoListToSave [saveSlotIndex].playerWeaponList.Add (weaponsToSave);
}
} else {
newPersistanceWeaponListBySaveSlotInfo.saveNumber = currentSaveNumber;
newPersistanceWeaponListBySaveSlotInfo.playerWeaponList.Add (weaponsToSave);
infoListToSave.Add (newPersistanceWeaponListBySaveSlotInfo);
}
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.OpenOrCreate);
bf.Serialize (file, infoListToSave);
file.Close ();
}
public void loadGameContent (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
if (mainPlayerWeaponsManager == null) {
return;
}
if (!mainPlayerWeaponsManager.loadWeaponAttachmentsInfoFromSaveFile) {
initializeValues ();
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Loading player weapons");
}
persistanceInfoList = new List<persistanceWeaponInfo> ();
List<persistanceWeaponListBySaveSlotInfo> infoListToLoad = new List<persistanceWeaponListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToLoad = currentData as List<persistanceWeaponListBySaveSlotInfo>;
file.Close ();
}
if (saveNumberToLoad > -1) {
persistanceWeaponListBySaveSlotInfo newPersistanceWeaponListBySaveSlotInfo = new persistanceWeaponListBySaveSlotInfo ();
int infoListToLoadCount = infoListToLoad.Count;
for (int j = 0; j < infoListToLoadCount; j++) {
if (infoListToLoad [j].saveNumber == saveNumberToLoad) {
newPersistanceWeaponListBySaveSlotInfo = infoListToLoad [j];
}
}
int listIndex = -1;
int playerWeaponListCount = newPersistanceWeaponListBySaveSlotInfo.playerWeaponList.Count;
for (int j = 0; j < playerWeaponListCount; j++) {
if (newPersistanceWeaponListBySaveSlotInfo.playerWeaponList [j].playerID == playerID) {
listIndex = j;
}
}
if (listIndex > -1) {
persistanceInfoList = newPersistanceWeaponListBySaveSlotInfo.playerWeaponList [listIndex].weaponList;
}
}
if (showDebugInfo) {
print ("\n\n");
print ("Weapons Loaded in Save Number " + saveNumberToLoad);
print ("Weapons amount: " + persistanceInfoList.Count);
for (int j = 0; j < persistanceInfoList.Count; j++) {
print ("Weapon Name: " + persistanceInfoList [j].Name + " Is Enabled: " + persistanceInfoList [j].isWeaponEnabled +
"Is Current Weapon: " + persistanceInfoList [j].isCurrentWeapon + " Remain Ammo: " + persistanceInfoList [j].remainingAmmo);
}
}
loadInfoOnMainComponent ();
}
public persistanceWeaponListByPlayerInfo getPersistanceList (int playerID, bool showDebugInfo)
{
persistanceWeaponListByPlayerInfo newPersistanceWeaponListByPlayerInfo = new persistanceWeaponListByPlayerInfo ();
newPersistanceWeaponListByPlayerInfo.playerID = playerID;
List<persistanceWeaponInfo> newPersistanceWeaponInfoList = new List<persistanceWeaponInfo> ();
List<IKWeaponSystem> weaponsList = mainPlayerWeaponsManager.weaponsList;
int weaponsListCount = weaponsList.Count;
for (int k = 0; k < weaponsListCount; k++) {
persistanceWeaponInfo newPersistanceWeaponInfo = new persistanceWeaponInfo ();
IKWeaponSystem currentWeapon = weaponsList [k];
newPersistanceWeaponInfo.Name = currentWeapon.getWeaponSystemName ();
newPersistanceWeaponInfo.index = k;
newPersistanceWeaponInfo.isWeaponEnabled = currentWeapon.isWeaponEnabled ();
newPersistanceWeaponInfo.isCurrentWeapon = currentWeapon.isCurrentWeapon ();
newPersistanceWeaponInfo.remainingAmmo = currentWeapon.getWeaponSystemManager ().weaponSettings.remainAmmo + currentWeapon.getWeaponSystemManager ().getWeaponClipSize ();
if (mainPlayerWeaponsManager.saveWeaponAttachmentsInfoToSaveFile) {
if (currentWeapon.weaponUsesAttachment) {
newPersistanceWeaponInfo.weaponUsesAttachment = true;
weaponAttachmentSystem currentWeaponAttachmentSystem = currentWeapon.getWeaponAttachmentSystem ();
if (currentWeaponAttachmentSystem != null) {
newPersistanceWeaponInfo.weaponAttachmentPlaceList = currentWeaponAttachmentSystem.getPersistanceAttachmentWeaponInfoList ();
}
}
newPersistanceWeaponInfoList.Add (newPersistanceWeaponInfo);
}
}
newPersistanceWeaponListByPlayerInfo.weaponList = newPersistanceWeaponInfoList;
return newPersistanceWeaponListByPlayerInfo;
}
void loadInfoOnMainComponent ()
{
initializeValues ();
if (persistanceInfoList != null && persistanceInfoList.Count > 0) {
List<IKWeaponSystem> weaponsList = mainPlayerWeaponsManager.weaponsList;
if (mainPlayerWeaponsManager.storePickedWeaponsOnInventory) {
if (mainPlayerWeaponsManager.loadWeaponAttachmentsInfoFromSaveFile) {
if (mainPlayerWeaponsManager.loadCurrentPlayerWeaponsFromSaveFile) {
int persistanceInfoListCount = persistanceInfoList.Count;
for (int i = 0; i < persistanceInfoListCount; i++) {
persistanceWeaponInfo currentPersistanceWeaponInfo = persistanceInfoList [i];
int currentIndex = currentPersistanceWeaponInfo.index;
if (weaponsList.Count > currentIndex && currentIndex > -1) {
IKWeaponSystem currentIKWeaponToCheck = weaponsList [currentIndex];
if (currentPersistanceWeaponInfo.weaponUsesAttachment) {
weaponAttachmentSystem currentWeaponAttachmentSystem = currentIKWeaponToCheck.getWeaponAttachmentSystem ();
if (currentWeaponAttachmentSystem != null) {
currentWeaponAttachmentSystem.initializeAttachmentValues (currentPersistanceWeaponInfo.weaponAttachmentPlaceList);
}
}
}
}
}
}
return;
}
if (mainPlayerWeaponsManager.loadCurrentPlayerWeaponsFromSaveFile) {
bool thereIsCurrentWeapon = false;
int persistanceInfoListCount = persistanceInfoList.Count;
for (int i = 0; i < persistanceInfoListCount; i++) {
persistanceWeaponInfo currentPersistanceWeaponInfo = persistanceInfoList [i];
int currentIndex = currentPersistanceWeaponInfo.index;
if (weaponsList.Count > currentIndex && currentIndex > -1) {
IKWeaponSystem currentIKWeaponToCheck = weaponsList [currentIndex];
currentIKWeaponToCheck.setWeaponEnabledState (currentPersistanceWeaponInfo.isWeaponEnabled);
currentIKWeaponToCheck.setCurrentWeaponState (currentPersistanceWeaponInfo.isCurrentWeapon);
currentIKWeaponToCheck.weaponSystemManager.weaponSettings.remainAmmo = currentPersistanceWeaponInfo.remainingAmmo
- currentIKWeaponToCheck.weaponSystemManager.getWeaponClipSize ();
if (currentIKWeaponToCheck.isCurrentWeapon ()) {
thereIsCurrentWeapon = true;
}
if (mainPlayerWeaponsManager.loadWeaponAttachmentsInfoFromSaveFile) {
if (currentPersistanceWeaponInfo.weaponUsesAttachment) {
weaponAttachmentSystem currentWeaponAttachmentSystem = currentIKWeaponToCheck.getWeaponAttachmentSystem ();
if (currentWeaponAttachmentSystem != null) {
currentWeaponAttachmentSystem.initializeAttachmentValues (currentPersistanceWeaponInfo.weaponAttachmentPlaceList);
}
}
}
}
}
if (!thereIsCurrentWeapon) {
int weaponsListCount = weaponsList.Count;
for (int k = 0; k < weaponsListCount; k++) {
IKWeaponSystem currentIKWeaponToCheck = weaponsList [k];
if (!thereIsCurrentWeapon && currentIKWeaponToCheck.isWeaponEnabled ()) {
currentIKWeaponToCheck.setCurrentWeaponState (true);
thereIsCurrentWeapon = true;
}
}
}
}
}
}
void initializeValues ()
{
mainPlayerWeaponsManager.initializePlayerWeaponsValues ();
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 5ae017e3ec6c8894d908fdd992e1310e
timeCreated: 1602224300
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Save System/Custom Class To Save/savePlayerWeaponsInfo.cs
uploadId: 814740

View File

@@ -0,0 +1,312 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System;
public class saveSkillsInfo : saveGameInfo
{
public playerSkillsSystem mainPlayerSkillsSystem;
List<persistanceCategorySkillInfo> persistanceInfoList;
bool valuesInitializedOnLoad;
public override void saveGame (int saveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
saveGameContent (saveNumber, playerID, currentSaveDataPath, showDebugInfo, savingGameToChangeScene);
}
public override void loadGame (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
loadGameContent (saveNumberToLoad, playerID, currentSaveDataPath, showDebugInfo);
}
public override void initializeValuesOnComponent ()
{
initializeValues ();
}
public void saveGameContent (int currentSaveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
getMainManager ();
if (mainPlayerSkillsSystem == null) {
return;
}
if (!mainPlayerSkillsSystem.playerSkillsActive) {
return;
}
if (!mainPlayerSkillsSystem.saveCurrentPlayerSkillsToSaveFile) {
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Saving skills");
}
bool saveLocated = false;
bool playerLocated = false;
int saveSlotIndex = -1;
int listIndex = -1;
BinaryFormatter bf = new BinaryFormatter ();
FileStream file;
persistancePlayerCategorySkillInfo skillsToSave = getPersistanceList (playerID, showDebugInfo);
persistancePlayerSkillsListBySaveSlotInfo newPersistancePlayerSkillsListBySaveSlotInfo = new persistancePlayerSkillsListBySaveSlotInfo ();
List<persistancePlayerSkillsListBySaveSlotInfo> infoListToSave = new List<persistancePlayerSkillsListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToSave = currentData as List<persistancePlayerSkillsListBySaveSlotInfo>;
file.Close ();
}
int infoListToSaveCount = infoListToSave.Count;
for (int j = 0; j < infoListToSaveCount; j++) {
if (infoListToSave [j].saveNumber == currentSaveNumber) {
newPersistancePlayerSkillsListBySaveSlotInfo = infoListToSave [j];
saveLocated = true;
saveSlotIndex = j;
}
}
if (saveLocated) {
int playerSkillsListCount = newPersistancePlayerSkillsListBySaveSlotInfo.playerSkillsList.Count;
for (int j = 0; j < playerSkillsListCount; j++) {
if (newPersistancePlayerSkillsListBySaveSlotInfo.playerSkillsList [j].playerID == skillsToSave.playerID) {
playerLocated = true;
listIndex = j;
}
}
}
if (showDebugInfo) {
print ("\n\n");
print ("EXTRA INFO\n");
print ("Number of skills: " + skillsToSave.categorySkillsList.Count);
print ("Current Save Number " + currentSaveNumber);
print ("Save Located " + saveLocated);
print ("Player Located " + playerLocated);
print ("Player ID " + skillsToSave.playerID);
}
//if the save is located, check if the player id exists
if (saveLocated) {
//if player id exists, overwrite it
if (playerLocated) {
infoListToSave [saveSlotIndex].playerSkillsList [listIndex].categorySkillsList = skillsToSave.categorySkillsList;
} else {
infoListToSave [saveSlotIndex].playerSkillsList.Add (skillsToSave);
}
} else {
newPersistancePlayerSkillsListBySaveSlotInfo.saveNumber = currentSaveNumber;
newPersistancePlayerSkillsListBySaveSlotInfo.playerSkillsList.Add (skillsToSave);
infoListToSave.Add (newPersistancePlayerSkillsListBySaveSlotInfo);
}
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.OpenOrCreate);
bf.Serialize (file, infoListToSave);
file.Close ();
}
public void loadGameContent (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
getMainManager ();
if (mainPlayerSkillsSystem == null) {
return;
}
if (!mainPlayerSkillsSystem.playerSkillsActive) {
return;
}
if (!mainPlayerSkillsSystem.saveCurrentPlayerSkillsToSaveFile) {
initializeValues ();
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Loading skills");
}
//need to store and check the current slot saved and the player which is saving, to get that concrete info
persistanceInfoList = new List<persistanceCategorySkillInfo> ();
List<persistancePlayerSkillsListBySaveSlotInfo> infoListToLoad = new List<persistancePlayerSkillsListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToLoad = currentData as List<persistancePlayerSkillsListBySaveSlotInfo>;
file.Close ();
}
if (saveNumberToLoad > -1) {
persistancePlayerSkillsListBySaveSlotInfo newPersistancePlayerSkillsListBySaveSlotInfo = new persistancePlayerSkillsListBySaveSlotInfo ();
int infoListToLoadCount = infoListToLoad.Count;
for (int j = 0; j < infoListToLoadCount; j++) {
if (infoListToLoad [j].saveNumber == saveNumberToLoad) {
newPersistancePlayerSkillsListBySaveSlotInfo = infoListToLoad [j];
}
}
int listIndex = -1;
int playerSkillsListCount = newPersistancePlayerSkillsListBySaveSlotInfo.playerSkillsList.Count;
for (int j = 0; j < playerSkillsListCount; j++) {
if (newPersistancePlayerSkillsListBySaveSlotInfo.playerSkillsList [j].playerID == playerID) {
listIndex = j;
}
}
if (listIndex > -1) {
persistanceInfoList.AddRange (newPersistancePlayerSkillsListBySaveSlotInfo.playerSkillsList [listIndex].categorySkillsList);
}
}
if (showDebugInfo) {
print ("\n\n");
print ("Skills Loaded in Save Number " + saveNumberToLoad);
}
loadInfoOnMainComponent ();
}
public persistancePlayerCategorySkillInfo getPersistanceList (int playerID, bool showDebugInfo)
{
persistancePlayerCategorySkillInfo newSkillsList = new persistancePlayerCategorySkillInfo ();
newSkillsList.playerID = playerID;
List<persistanceCategorySkillInfo> newPersistanceCategorySkillInfoList = new List<persistanceCategorySkillInfo> ();
List<playerSkillsSystem.skillCategoryInfo> skillCategoryInfoList = mainPlayerSkillsSystem.skillCategoryInfoList;
int skillCategoryInfoListCount = skillCategoryInfoList.Count;
for (int i = 0; i < skillCategoryInfoListCount; i++) {
persistanceCategorySkillInfo newPersistanceCategorySkillInfo = new persistanceCategorySkillInfo ();
List<persistanceSkillInfo> newPersistanceSkillInfoList = new List<persistanceSkillInfo> ();
playerSkillsSystem.skillCategoryInfo currentSkillCategory = skillCategoryInfoList [i];
int skillInfoListCount = currentSkillCategory.skillInfoList.Count;
for (int k = 0; k < skillInfoListCount; k++) {
playerSkillsSystem.skillInfo currentSkillInfo = currentSkillCategory.skillInfoList [k];
persistanceSkillInfo newpersistanceSkillInfo = new persistanceSkillInfo ();
newpersistanceSkillInfo.skillUnlocked = currentSkillInfo.skillUnlocked;
newpersistanceSkillInfo.skillActive = currentSkillInfo.skillActive;
newpersistanceSkillInfo.skillComplete = currentSkillInfo.skillComplete;
newpersistanceSkillInfo.currentBoolState = currentSkillInfo.currentBoolState;
newpersistanceSkillInfo.currentValue = currentSkillInfo.currentValue;
newpersistanceSkillInfo.currentSkillLevel = currentSkillInfo.currentSkillLevel;
newPersistanceSkillInfoList.Add (newpersistanceSkillInfo);
}
newPersistanceCategorySkillInfo.skillsList = newPersistanceSkillInfoList;
newPersistanceCategorySkillInfoList.Add (newPersistanceCategorySkillInfo);
}
newSkillsList.categorySkillsList = newPersistanceCategorySkillInfoList;
return newSkillsList;
}
void loadInfoOnMainComponent ()
{
valuesInitializedOnLoad = true;
initializeValues ();
if (persistanceInfoList != null && persistanceInfoList.Count > 0) {
List<playerSkillsSystem.skillCategoryInfo> skillCategoryInfoList = mainPlayerSkillsSystem.skillCategoryInfoList;
int skillCategoryInfoListCount = skillCategoryInfoList.Count;
for (int i = 0; i < skillCategoryInfoListCount; i++) {
playerSkillsSystem.skillCategoryInfo currentSkillCategory = skillCategoryInfoList [i];
int skillInfoListCount = currentSkillCategory.skillInfoList.Count;
for (int k = 0; k < skillInfoListCount; k++) {
playerSkillsSystem.skillInfo currentSkillInfo = currentSkillCategory.skillInfoList [k];
persistanceSkillInfo currentPersistanceSkillInfo = persistanceInfoList [i].skillsList [k];
currentSkillInfo.skillUnlocked = currentPersistanceSkillInfo.skillUnlocked;
currentSkillInfo.skillActive = currentPersistanceSkillInfo.skillActive;
currentSkillInfo.skillComplete = currentPersistanceSkillInfo.skillComplete;
currentSkillInfo.currentBoolState = currentPersistanceSkillInfo.currentBoolState;
currentSkillInfo.currentValue = currentPersistanceSkillInfo.currentValue;
currentSkillInfo.currentSkillLevel = currentPersistanceSkillInfo.currentSkillLevel;
}
}
mainPlayerSkillsSystem.setIsLoadingGameState (true);
}
mainPlayerSkillsSystem.initializeSkillsValues ();
}
void getMainManager ()
{
if (mainPlayerSkillsSystem == null) {
mainPlayerSkillsSystem = FindObjectOfType<playerSkillsSystem> ();
}
}
void initializeValues ()
{
mainPlayerSkillsSystem.setIsLoadingGameState (false);
if (!valuesInitializedOnLoad) {
mainPlayerSkillsSystem.initializeSkillsValues ();
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: e0a9ea24bbaf99c49b6671180fa0ae69
timeCreated: 1602218192
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Save System/Custom Class To Save/saveSkillsInfo.cs
uploadId: 814740

View File

@@ -0,0 +1,299 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System;
public class saveStatsInfo : saveGameInfo
{
public playerStatsSystem mainPlayerStatsSystem;
List<persistanceStatInfo> persistanceInfoList;
bool valuesInitializedOnLoad;
public override void saveGame (int saveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
saveGameContent (saveNumber, playerID, currentSaveDataPath, showDebugInfo, savingGameToChangeScene);
}
public override void loadGame (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
loadGameContent (saveNumberToLoad, playerID, currentSaveDataPath, showDebugInfo);
}
public override void initializeValuesOnComponent ()
{
initializeValues ();
}
public void saveGameContent (int currentSaveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
getMainManager ();
if (mainPlayerStatsSystem == null) {
return;
}
if (!mainPlayerStatsSystem.playerStatsActive) {
return;
}
if (!mainPlayerStatsSystem.saveCurrentPlayerStatsToSaveFile) {
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Saving stats");
}
bool saveLocated = false;
bool playerLocated = false;
int saveSlotIndex = -1;
int listIndex = -1;
BinaryFormatter bf = new BinaryFormatter ();
FileStream file;
persistancePlayerStatInfo statsToSave = getPersistanceList (playerID, showDebugInfo);
persistancePlayerStatsListBySaveSlotInfo newPersistancePlayerStatsListBySaveSlotInfo = new persistancePlayerStatsListBySaveSlotInfo ();
List<persistancePlayerStatsListBySaveSlotInfo> infoListToSave = new List<persistancePlayerStatsListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToSave = currentData as List<persistancePlayerStatsListBySaveSlotInfo>;
file.Close ();
}
int infoListToSaveCount = infoListToSave.Count;
for (int j = 0; j < infoListToSaveCount; j++) {
if (infoListToSave [j].saveNumber == currentSaveNumber) {
newPersistancePlayerStatsListBySaveSlotInfo = infoListToSave [j];
saveLocated = true;
saveSlotIndex = j;
}
}
if (saveLocated) {
int playerStatsListCount = newPersistancePlayerStatsListBySaveSlotInfo.playerStatsList.Count;
for (int j = 0; j < playerStatsListCount; j++) {
if (newPersistancePlayerStatsListBySaveSlotInfo.playerStatsList [j].playerID == statsToSave.playerID) {
playerLocated = true;
listIndex = j;
}
}
}
if (showDebugInfo) {
print ("\n\n");
print ("EXTRA INFO\n");
print ("Number of stats: " + statsToSave.statsList.Count);
print ("Current Save Number " + currentSaveNumber);
print ("Save Located " + saveLocated);
print ("Player Located " + playerLocated);
print ("Player ID " + statsToSave.playerID);
}
//if the save is located, check if the player id exists
if (saveLocated) {
//if player id exists, overwrite it
if (playerLocated) {
infoListToSave [saveSlotIndex].playerStatsList [listIndex].statsList = statsToSave.statsList;
} else {
infoListToSave [saveSlotIndex].playerStatsList.Add (statsToSave);
}
} else {
newPersistancePlayerStatsListBySaveSlotInfo.saveNumber = currentSaveNumber;
newPersistancePlayerStatsListBySaveSlotInfo.playerStatsList.Add (statsToSave);
infoListToSave.Add (newPersistancePlayerStatsListBySaveSlotInfo);
}
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.OpenOrCreate);
bf.Serialize (file, infoListToSave);
file.Close ();
}
public void loadGameContent (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
getMainManager ();
if (mainPlayerStatsSystem == null) {
return;
}
if (!mainPlayerStatsSystem.playerStatsActive) {
return;
}
if (!mainPlayerStatsSystem.saveCurrentPlayerStatsToSaveFile) {
initializeValues ();
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Loading stats");
}
//need to store and check the current slot saved and the player which is saving, to get that concrete info
persistanceInfoList = new List<persistanceStatInfo> ();
List<persistancePlayerStatsListBySaveSlotInfo> infoListToLoad = new List<persistancePlayerStatsListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToLoad = currentData as List<persistancePlayerStatsListBySaveSlotInfo>;
file.Close ();
}
if (saveNumberToLoad > -1) {
persistancePlayerStatsListBySaveSlotInfo newPersistancePlayerStatsListBySaveSlotInfo = new persistancePlayerStatsListBySaveSlotInfo ();
int infoListToLoadCount = infoListToLoad.Count;
for (int j = 0; j < infoListToLoadCount; j++) {
if (infoListToLoad [j].saveNumber == saveNumberToLoad) {
newPersistancePlayerStatsListBySaveSlotInfo = infoListToLoad [j];
}
}
int listIndex = -1;
int playerStatsListCount = newPersistancePlayerStatsListBySaveSlotInfo.playerStatsList.Count;
for (int j = 0; j < playerStatsListCount; j++) {
if (newPersistancePlayerStatsListBySaveSlotInfo.playerStatsList [j].playerID == playerID) {
listIndex = j;
}
}
if (listIndex > -1) {
persistanceInfoList.AddRange (newPersistancePlayerStatsListBySaveSlotInfo.playerStatsList [listIndex].statsList);
}
}
if (showDebugInfo) {
print ("\n\n");
print ("Stats Loaded in Save Number " + saveNumberToLoad);
print ("Number of stats: " + persistanceInfoList.Count);
}
loadInfoOnMainComponent (showDebugInfo);
}
public persistancePlayerStatInfo getPersistanceList (int playerID, bool showDebugInfo)
{
persistancePlayerStatInfo newStatsList = new persistancePlayerStatInfo ();
newStatsList.playerID = playerID;
List<persistanceStatInfo> newPersistanceStatInfoList = new List<persistanceStatInfo> ();
playerStatsSystem.statInfo currentStatInfo = null;
List<playerStatsSystem.statInfo> statInfoList = mainPlayerStatsSystem.statInfoList;
int statInfoListCount = statInfoList.Count;
for (int k = 0; k < statInfoListCount; k++) {
currentStatInfo = statInfoList [k];
persistanceStatInfo newpersistanceStatInfo = new persistanceStatInfo ();
newpersistanceStatInfo.currentValue = currentStatInfo.currentValue;
newpersistanceStatInfo.extraCurrentValue = currentStatInfo.extraCurrentValue;
if (newpersistanceStatInfo.extraCurrentValue > 0) {
newpersistanceStatInfo.currentValue -= newpersistanceStatInfo.extraCurrentValue;
newpersistanceStatInfo.currentValue = Mathf.Clamp (newpersistanceStatInfo.currentValue, 0, newpersistanceStatInfo.currentValue);
}
newpersistanceStatInfo.currentBoolState = currentStatInfo.currentBoolState;
newPersistanceStatInfoList.Add (newpersistanceStatInfo);
}
newStatsList.statsList = newPersistanceStatInfoList;
return newStatsList;
}
void loadInfoOnMainComponent (bool showDebugInfo)
{
valuesInitializedOnLoad = true;
initializeValues ();
if (persistanceInfoList != null && persistanceInfoList.Count > 0) {
List<playerStatsSystem.statInfo> statInfoList = mainPlayerStatsSystem.statInfoList;
int statInfoListCount = statInfoList.Count;
for (int k = 0; k < statInfoListCount; k++) {
playerStatsSystem.statInfo currentStatInfo = statInfoList [k];
persistanceStatInfo currentPersistanceStatInfo = persistanceInfoList [k];
if (!currentStatInfo.ignoreStatInitializationOnLoadGame) {
currentStatInfo.currentValue = currentPersistanceStatInfo.currentValue;
currentStatInfo.currentBoolState = currentPersistanceStatInfo.currentBoolState;
if (showDebugInfo) {
print (statInfoList [k].Name + " " + statInfoList [k].currentValue + " " + statInfoList [k].currentBoolState);
}
}
}
mainPlayerStatsSystem.setIsLoadingGameState (true);
}
mainPlayerStatsSystem.initializeStatsValues ();
}
void getMainManager ()
{
if (mainPlayerStatsSystem == null) {
mainPlayerStatsSystem = FindObjectOfType<playerStatsSystem> ();
}
}
void initializeValues ()
{
mainPlayerStatsSystem.setIsLoadingGameState (false);
if (!valuesInitializedOnLoad) {
mainPlayerStatsSystem.initializeStatsValues ();
}
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 524a8737699a14b48ac2ef81f6505503
timeCreated: 1602222626
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Save System/Custom Class To Save/saveStatsInfo.cs
uploadId: 814740

View File

@@ -0,0 +1,250 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System;
public class saveTravelStationInfo : saveGameInfo
{
public travelStationUISystem mainTravelStationUISystem;
List<persistanceTravelStationInfo> persistanceInfoList;
public override void saveGame (int saveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
saveGameContent (saveNumber, playerID, currentSaveDataPath, showDebugInfo, savingGameToChangeScene);
}
public override void loadGame (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
loadGameContent (saveNumberToLoad, playerID, currentSaveDataPath, showDebugInfo);
}
public override void initializeValuesOnComponent ()
{
initializeValues ();
}
public void saveGameContent (int currentSaveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
if (mainTravelStationUISystem == null) {
return;
}
if (!mainTravelStationUISystem.travelStationUIActive) {
return;
}
if (!mainTravelStationUISystem.saveCurrentTravelStationToSaveFile) {
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Saving travel stations");
}
bool saveLocated = false;
bool playerLocated = false;
int saveSlotIndex = -1;
int listIndex = -1;
BinaryFormatter bf = new BinaryFormatter ();
FileStream file;
persistancePlayerTravelStationInfo traveStationListToSave = getPersistanceList (playerID, showDebugInfo);
persistanceTravelStationListBySaveSlotInfo newPersistanceTravelStationListBySaveSlotInfo = new persistanceTravelStationListBySaveSlotInfo ();
List<persistanceTravelStationListBySaveSlotInfo> infoListToSave = new List<persistanceTravelStationListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToSave = currentData as List<persistanceTravelStationListBySaveSlotInfo>;
file.Close ();
}
int infoListToSaveCount = infoListToSave.Count;
for (int j = 0; j < infoListToSaveCount; j++) {
if (infoListToSave [j].saveNumber == currentSaveNumber) {
newPersistanceTravelStationListBySaveSlotInfo = infoListToSave [j];
saveLocated = true;
saveSlotIndex = j;
}
}
if (saveLocated) {
int playerTravelStationListCount = newPersistanceTravelStationListBySaveSlotInfo.playerTravelStationList.Count;
for (int j = 0; j < playerTravelStationListCount; j++) {
if (newPersistanceTravelStationListBySaveSlotInfo.playerTravelStationList [j].playerID == traveStationListToSave.playerID) {
playerLocated = true;
listIndex = j;
}
}
}
//if the save is located, check if the player id exists
if (saveLocated) {
//if player id exists, overwrite it
if (playerLocated) {
infoListToSave [saveSlotIndex].playerTravelStationList [listIndex].travelStationList = traveStationListToSave.travelStationList;
} else {
infoListToSave [saveSlotIndex].playerTravelStationList.Add (traveStationListToSave);
}
} else {
newPersistanceTravelStationListBySaveSlotInfo.saveNumber = currentSaveNumber;
newPersistanceTravelStationListBySaveSlotInfo.playerTravelStationList.Add (traveStationListToSave);
infoListToSave.Add (newPersistanceTravelStationListBySaveSlotInfo);
}
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.OpenOrCreate);
bf.Serialize (file, infoListToSave);
file.Close ();
}
public void loadGameContent (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
if (mainTravelStationUISystem == null) {
return;
}
if (!mainTravelStationUISystem.travelStationUIActive) {
return;
}
if (!mainTravelStationUISystem.saveCurrentTravelStationToSaveFile) {
initializeValues ();
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Loading travel stations");
}
persistanceInfoList = new List<persistanceTravelStationInfo> ();
//need to store and check the current slot saved and the player which is saving, to get that concrete info
List<persistanceTravelStationListBySaveSlotInfo> infoListToLoad = new List<persistanceTravelStationListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToLoad = currentData as List<persistanceTravelStationListBySaveSlotInfo>;
file.Close ();
}
if (saveNumberToLoad > -1) {
persistanceTravelStationListBySaveSlotInfo newPersistanceTravelStationListBySaveSlotInfo = new persistanceTravelStationListBySaveSlotInfo ();
int infoListToLoadCount = infoListToLoad.Count;
for (int j = 0; j < infoListToLoadCount; j++) {
if (infoListToLoad [j].saveNumber == saveNumberToLoad) {
newPersistanceTravelStationListBySaveSlotInfo = infoListToLoad [j];
}
}
int listIndex = -1;
int playerTravelStationListCount = newPersistanceTravelStationListBySaveSlotInfo.playerTravelStationList.Count;
for (int j = 0; j < playerTravelStationListCount; j++) {
if (newPersistanceTravelStationListBySaveSlotInfo.playerTravelStationList [j].playerID == playerID) {
listIndex = j;
}
}
if (listIndex > -1) {
persistanceInfoList.AddRange (newPersistanceTravelStationListBySaveSlotInfo.playerTravelStationList [listIndex].travelStationList);
}
}
if (showDebugInfo) {
print ("\n\n");
print ("Travel Stations Loaded in Save Number " + saveNumberToLoad);
print ("Number of travel station: " + persistanceInfoList.Count);
}
loadInfoOnMainComponent ();
}
persistancePlayerTravelStationInfo getPersistanceList (int playerID, bool showDebugInfo)
{
persistancePlayerTravelStationInfo newPersistancePlayerTravelStationInfo = new persistancePlayerTravelStationInfo ();
newPersistancePlayerTravelStationInfo.playerID = playerID;
List<persistanceTravelStationInfo> newPersistanceTravelStationInfoList = new List<persistanceTravelStationInfo> ();
List<travelStationUISystem.foundTravelStationInfo> foundTravelStationInfoList = mainTravelStationUISystem.foundTravelStationInfoList;
int foundTravelStationInfoListCount = foundTravelStationInfoList.Count;
for (int k = 0; k < foundTravelStationInfoListCount; k++) {
persistanceTravelStationInfo newPersistanceTravelStationInfo = new persistanceTravelStationInfo ();
travelStationUISystem.foundTravelStationInfo currentStationInfo = foundTravelStationInfoList [k];
newPersistanceTravelStationInfo.sceneNumberToLoad = currentStationInfo.sceneNumberToLoad;
newPersistanceTravelStationInfo.levelManagerIDToLoad = currentStationInfo.levelManagerIDToLoad;
newPersistanceTravelStationInfoList.Add (newPersistanceTravelStationInfo);
}
newPersistancePlayerTravelStationInfo.travelStationList = newPersistanceTravelStationInfoList;
return newPersistancePlayerTravelStationInfo;
}
void loadInfoOnMainComponent ()
{
initializeValues ();
if (persistanceInfoList != null && persistanceInfoList.Count > 0) {
int persistanceInfoListCount = persistanceInfoList.Count;
// print (persistanceInfoListCount);
List<travelStationUISystem.foundTravelStationInfo> foundTravelStationInfoList = mainTravelStationUISystem.foundTravelStationInfoList;
for (int i = 0; i < persistanceInfoListCount; i++) {
persistanceTravelStationInfo currentPersistanceTravelStationInfo = persistanceInfoList [i];
travelStationUISystem.foundTravelStationInfo newFoundTravelStationInfo = new travelStationUISystem.foundTravelStationInfo ();
newFoundTravelStationInfo.sceneNumberToLoad = currentPersistanceTravelStationInfo.sceneNumberToLoad;
newFoundTravelStationInfo.levelManagerIDToLoad = currentPersistanceTravelStationInfo.levelManagerIDToLoad;
foundTravelStationInfoList.Add (newFoundTravelStationInfo);
}
}
}
void initializeValues ()
{
mainTravelStationUISystem.initializeTravelStationValues ();
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 57fc4e01f8773cc4593616d9fe40923d
timeCreated: 1602177608
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Save System/Custom Class To Save/saveTravelStationInfo.cs
uploadId: 814740

View File

@@ -0,0 +1,432 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System;
public class saveVendorInfo : saveGameInfo
{
public vendorSystem mainVendorSystem;
List<inventoryListElement> persistanceInfoList;
public override void saveGame (int saveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
saveGameContent (saveNumber, playerID, currentSaveDataPath, showDebugInfo, savingGameToChangeScene);
}
public override void loadGame (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
loadGameContent (saveNumberToLoad, playerID, currentSaveDataPath, showDebugInfo);
}
public override void saveGameFromEditor (int saveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
saveGameContentFromEditor (saveNumber, playerID, currentSaveDataPath, showDebugInfo);
}
public void saveGameContent (int currentSaveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo, bool savingGameToChangeScene)
{
getMainManager ();
if (mainVendorSystem == null) {
return;
}
if (!mainVendorSystem.saveCurrentVendorInventoryToSaveFile) {
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Saving vendor");
}
bool saveLocated = false;
bool vendorLocated = false;
int saveSlotIndex = -1;
int listIndex = -1;
BinaryFormatter bf = new BinaryFormatter ();
FileStream file;
persistanceInventoryListByPlayerInfo vendorToSave = getPersistanceList (playerID, showDebugInfo);
persistanceInventoryListBySaveSlotInfo newPersistanceInventoryListBySaveSlotInfo = new persistanceInventoryListBySaveSlotInfo ();
List<persistanceInventoryListBySaveSlotInfo> infoListToSave = new List<persistanceInventoryListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToSave = currentData as List<persistanceInventoryListBySaveSlotInfo>;
file.Close ();
}
int infoListToSaveCount = infoListToSave.Count;
for (int j = 0; j < infoListToSaveCount; j++) {
if (saveSlotIndex == -1) {
persistanceInventoryListBySaveSlotInfo currentSlot = infoListToSave [j];
if (currentSlot.saveNumber == currentSaveNumber) {
newPersistanceInventoryListBySaveSlotInfo = currentSlot;
saveLocated = true;
saveSlotIndex = j;
}
}
}
if (showDebugInfo) {
print ("\n\n");
print ("VENDOR SYSTEM");
print ("Number of objects: " + vendorToSave.inventoryObjectList.Count);
print ("Current Save Number " + currentSaveNumber);
print ("Save Located " + saveLocated);
}
if (saveLocated) {
if (newPersistanceInventoryListBySaveSlotInfo.playerInventoryList.Count > 0) {
vendorLocated = true;
listIndex = 0;
}
}
//if the save is located, check if the vendor exists
if (saveLocated) {
//if player id exists, overwrite it
if (vendorLocated) {
infoListToSave [saveSlotIndex].playerInventoryList [listIndex].inventoryObjectList = vendorToSave.inventoryObjectList;
} else {
infoListToSave [saveSlotIndex].playerInventoryList.Add (vendorToSave);
}
} else {
newPersistanceInventoryListBySaveSlotInfo.saveNumber = currentSaveNumber;
newPersistanceInventoryListBySaveSlotInfo.playerInventoryList.Add (vendorToSave);
infoListToSave.Add (newPersistanceInventoryListBySaveSlotInfo);
}
if (showDebugInfo) {
print ("\n\n");
for (int j = 0; j < vendorToSave.inventoryObjectList.Count; j++) {
persistanceInventoryObjectInfo currentInfo = vendorToSave.inventoryObjectList [j];
print ("Object Name: " + currentInfo.Name + " Amount: " + currentInfo.amount);
}
}
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.OpenOrCreate);
bf.Serialize (file, infoListToSave);
file.Close ();
}
public void loadGameContent (int saveNumberToLoad, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
getMainManager ();
if (mainVendorSystem == null) {
return;
}
if (showDebugInfo) {
print ("\n\n");
print ("Loading vendor");
}
//need to store and check the current slot saved and the player which is saving, to get that concrete info
persistanceInfoList = new List<inventoryListElement> ();
List<persistanceInventoryListBySaveSlotInfo> infoListToLoad = new List<persistanceInventoryListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToLoad = currentData as List<persistanceInventoryListBySaveSlotInfo>;
file.Close ();
}
if (saveNumberToLoad > -1) {
persistanceInventoryListBySaveSlotInfo newPersistanceInventoryListBySaveSlotInfo = new persistanceInventoryListBySaveSlotInfo ();
int infoListToLoadCount = infoListToLoad.Count;
bool slotLocated = false;
for (int j = 0; j < infoListToLoadCount; j++) {
if (!slotLocated) {
persistanceInventoryListBySaveSlotInfo currentSlot = infoListToLoad [j];
if (currentSlot.saveNumber == saveNumberToLoad) {
newPersistanceInventoryListBySaveSlotInfo = currentSlot;
slotLocated = true;
}
}
}
int vendorIndex = 0;
if (newPersistanceInventoryListBySaveSlotInfo.playerInventoryList.Count > 0) {
persistanceInventoryListByPlayerInfo vendorListToLoad = newPersistanceInventoryListBySaveSlotInfo.playerInventoryList [vendorIndex];
int inventoryObjectListCount = vendorListToLoad.inventoryObjectList.Count;
for (int j = 0; j < inventoryObjectListCount; j++) {
inventoryListElement newInventoryListElement = new inventoryListElement ();
persistanceInventoryObjectInfo currentInventoryInfo = vendorListToLoad.inventoryObjectList [j];
newInventoryListElement.Name = currentInventoryInfo.Name;
newInventoryListElement.amount = currentInventoryInfo.amount;
newInventoryListElement.infiniteAmount = currentInventoryInfo.infiniteAmount;
newInventoryListElement.inventoryObjectName = currentInventoryInfo.inventoryObjectName;
newInventoryListElement.categoryIndex = currentInventoryInfo.categoryIndex;
newInventoryListElement.elementIndex = currentInventoryInfo.elementIndex;
newInventoryListElement.vendorPrice = currentInventoryInfo.vendorPrice;
newInventoryListElement.infiniteVendorAmountAvailable = currentInventoryInfo.infiniteVendorAmountAvailable;
newInventoryListElement.sellPrice = currentInventoryInfo.sellPrice;
newInventoryListElement.useMinLevelToBuy = currentInventoryInfo.useMinLevelToBuy;
newInventoryListElement.minLevelToBuy = currentInventoryInfo.minLevelToBuy;
newInventoryListElement.spawnObject = currentInventoryInfo.spawnObject;
persistanceInfoList.Add (newInventoryListElement);
}
}
}
if (showDebugInfo) {
print ("\n\n");
print ("VENDOR SYSTEM");
print ("Vendor Loaded in Save Number " + saveNumberToLoad);
print ("Number of objects: " + persistanceInfoList.Count);
for (int j = 0; j < persistanceInfoList.Count; j++) {
inventoryListElement currentElement = persistanceInfoList [j];
print ("Object Name: " + currentElement.Name + " Amount: " + currentElement.amount);
}
}
loadInfoOnMainComponent ();
}
public persistanceInventoryListByPlayerInfo getPersistanceList (int playerID, bool showDebugInfo)
{
persistanceInventoryListByPlayerInfo newPersistanceInventoryListByPlayerInfo = new persistanceInventoryListByPlayerInfo ();
newPersistanceInventoryListByPlayerInfo.playerID = playerID;
List<persistanceInventoryObjectInfo> newPersistanceInventoryObjectInfoList = new List<persistanceInventoryObjectInfo> ();
List<inventoryInfo> vendorInventoryList = mainVendorSystem.vendorInventoryList;
if (showDebugInfo) {
print ("\n\n");
}
int vendorInventoryListCount = vendorInventoryList.Count;
for (int k = 0; k < vendorInventoryListCount; k++) {
persistanceInventoryObjectInfo newPersistanceInventoryObjectInfo = new persistanceInventoryObjectInfo ();
inventoryInfo currentInventoryInfo = vendorInventoryList [k];
newPersistanceInventoryObjectInfo.Name = currentInventoryInfo.Name;
newPersistanceInventoryObjectInfo.amount = currentInventoryInfo.amount;
newPersistanceInventoryObjectInfo.infiniteAmount = currentInventoryInfo.infiniteAmount;
newPersistanceInventoryObjectInfo.inventoryObjectName = currentInventoryInfo.Name;
newPersistanceInventoryObjectInfo.elementIndex = currentInventoryInfo.elementIndex;
newPersistanceInventoryObjectInfo.categoryIndex = currentInventoryInfo.categoryIndex;
newPersistanceInventoryObjectInfo.vendorPrice = currentInventoryInfo.vendorPrice;
newPersistanceInventoryObjectInfo.infiniteVendorAmountAvailable = currentInventoryInfo.infiniteVendorAmountAvailable;
newPersistanceInventoryObjectInfo.sellPrice = currentInventoryInfo.sellPrice;
newPersistanceInventoryObjectInfo.useMinLevelToBuy = currentInventoryInfo.useMinLevelToBuy;
newPersistanceInventoryObjectInfo.minLevelToBuy = currentInventoryInfo.minLevelToBuy;
newPersistanceInventoryObjectInfo.spawnObject = currentInventoryInfo.spawnObject;
if (showDebugInfo) {
print (newPersistanceInventoryObjectInfo.Name + " " + newPersistanceInventoryObjectInfo.amount);
}
newPersistanceInventoryObjectInfoList.Add (newPersistanceInventoryObjectInfo);
}
newPersistanceInventoryListByPlayerInfo.inventoryObjectList = newPersistanceInventoryObjectInfoList;
return newPersistanceInventoryListByPlayerInfo;
}
void loadInfoOnMainComponent ()
{
if (persistanceInfoList != null && persistanceInfoList.Count > 0) {
mainVendorSystem.setNewInventoryListManagerList (persistanceInfoList);
}
}
void getMainManager ()
{
if (mainVendorSystem == null) {
mainVendorSystem = FindObjectOfType<vendorSystem> ();
}
}
public void saveGameContentFromEditor (int currentSaveNumber, int playerID, string currentSaveDataPath, bool showDebugInfo)
{
getMainManager ();
if (mainVendorSystem == null) {
return;
}
bool saveLocated = false;
bool vendorLocated = false;
int saveSlotIndex = -1;
int listIndex = -1;
BinaryFormatter bf = new BinaryFormatter ();
FileStream file;
persistanceInventoryListByPlayerInfo vendorToSave = getPersistanceVendorListElement (playerID, showDebugInfo);
persistanceInventoryListBySaveSlotInfo newPersistanceInventoryListBySaveSlotInfo = new persistanceInventoryListBySaveSlotInfo ();
List<persistanceInventoryListBySaveSlotInfo> infoListToSave = new List<persistanceInventoryListBySaveSlotInfo> ();
if (File.Exists (currentSaveDataPath)) {
bf = new BinaryFormatter ();
file = File.Open (currentSaveDataPath, FileMode.Open);
object currentData = bf.Deserialize (file);
infoListToSave = currentData as List<persistanceInventoryListBySaveSlotInfo>;
file.Close ();
}
int infoListToSaveCount = infoListToSave.Count;
for (int j = 0; j < infoListToSaveCount; j++) {
if (saveSlotIndex == -1) {
persistanceInventoryListBySaveSlotInfo currentSlot = infoListToSave [j];
if (currentSlot.saveNumber == currentSaveNumber) {
newPersistanceInventoryListBySaveSlotInfo = currentSlot;
saveLocated = true;
saveSlotIndex = j;
}
}
}
if (showDebugInfo) {
print ("VENDOR SYSTEM");
print ("Number of objects: " + vendorToSave.inventoryObjectList.Count);
print ("Current Save Number " + currentSaveNumber);
print ("Save Located " + saveLocated);
}
if (saveLocated) {
if (newPersistanceInventoryListBySaveSlotInfo.playerInventoryList.Count > 0) {
vendorLocated = true;
listIndex = 0;
}
}
//if the save is located, check if the vendor exists
if (saveLocated) {
//if player id exists, overwrite it
if (vendorLocated) {
infoListToSave [saveSlotIndex].playerInventoryList [listIndex].inventoryObjectList = vendorToSave.inventoryObjectList;
} else {
infoListToSave [saveSlotIndex].playerInventoryList.Add (vendorToSave);
}
} else {
newPersistanceInventoryListBySaveSlotInfo.saveNumber = currentSaveNumber;
newPersistanceInventoryListBySaveSlotInfo.playerInventoryList.Add (vendorToSave);
infoListToSave.Add (newPersistanceInventoryListBySaveSlotInfo);
}
bf = new BinaryFormatter ();
file = File.Create (currentSaveDataPath);
bf.Serialize (file, infoListToSave);
file.Close ();
}
public persistanceInventoryListByPlayerInfo getPersistanceVendorListElement (int playerID, bool showDebugInfo)
{
persistanceInventoryListByPlayerInfo newPersistanceInventoryListByPlayerInfo = new persistanceInventoryListByPlayerInfo ();
newPersistanceInventoryListByPlayerInfo.playerID = playerID;
List<persistanceInventoryObjectInfo> newPersistanceInventoryObjectInfoList = new List<persistanceInventoryObjectInfo> ();
List<inventoryListElement> inventoryListManagerList = mainVendorSystem.inventoryListManagerList;
int inventoryListManagerListCount = inventoryListManagerList.Count;
for (int k = 0; k < inventoryListManagerListCount; k++) {
persistanceInventoryObjectInfo newPersistanceInventoryObjectInfo = new persistanceInventoryObjectInfo ();
inventoryListElement currentElement = inventoryListManagerList [k];
newPersistanceInventoryObjectInfo.Name = currentElement.Name;
newPersistanceInventoryObjectInfo.amount = currentElement.amount;
newPersistanceInventoryObjectInfo.infiniteAmount = currentElement.infiniteAmount;
newPersistanceInventoryObjectInfo.inventoryObjectName = currentElement.inventoryObjectName;
newPersistanceInventoryObjectInfo.elementIndex = currentElement.elementIndex;
newPersistanceInventoryObjectInfo.categoryIndex = currentElement.categoryIndex;
newPersistanceInventoryObjectInfo.vendorPrice = currentElement.vendorPrice;
newPersistanceInventoryObjectInfo.infiniteVendorAmountAvailable = currentElement.infiniteVendorAmountAvailable;
newPersistanceInventoryObjectInfo.sellPrice = currentElement.sellPrice;
newPersistanceInventoryObjectInfo.useMinLevelToBuy = currentElement.useMinLevelToBuy;
newPersistanceInventoryObjectInfo.minLevelToBuy = currentElement.minLevelToBuy;
newPersistanceInventoryObjectInfo.spawnObject = currentElement.spawnObject;
if (showDebugInfo) {
print (newPersistanceInventoryObjectInfo.Name + " " + newPersistanceInventoryObjectInfo.amount);
}
newPersistanceInventoryObjectInfoList.Add (newPersistanceInventoryObjectInfo);
}
newPersistanceInventoryListByPlayerInfo.inventoryObjectList = newPersistanceInventoryObjectInfoList;
return newPersistanceInventoryListByPlayerInfo;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: eb6b14312d71d0a438ad41479cd98773
timeCreated: 1602215815
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 40995
packageName: Game Kit Controller - Shooter Melee Adventure Creator 3D + 2.5D
packageVersion: 3.77g
assetPath: Assets/Game Kit Controller/Scripts/Save System/Custom Class To Save/saveVendorInfo.cs
uploadId: 814740