add ckg
plantilla base para movimiento básico
This commit is contained in:
@@ -0,0 +1,503 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class elementOnScene : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool saveElementEnabled = true;
|
||||
|
||||
public int elementScene;
|
||||
public int elementID;
|
||||
|
||||
public bool elementActiveState = true;
|
||||
|
||||
[Space]
|
||||
[Header ("Transform Settings")]
|
||||
[Space]
|
||||
|
||||
public bool savePositionValues;
|
||||
|
||||
public bool saveRotationValues;
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
public bool useCustomTransform;
|
||||
|
||||
public Transform customTransform;
|
||||
|
||||
[Space]
|
||||
[Header ("Element Prefab Settings")]
|
||||
[Space]
|
||||
|
||||
public int elementPrefabID = -1;
|
||||
|
||||
[Space]
|
||||
[Header ("Element Stats Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useStats;
|
||||
|
||||
public float loadStatsDelay;
|
||||
|
||||
public List<statInfo> statInfoList = new List<statInfo> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Events Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useEventOnObjectActive;
|
||||
public UnityEvent eventOnObjectActive;
|
||||
|
||||
public bool useEventOnObjectInactive = true;
|
||||
public UnityEvent eventOnObjectInactive;
|
||||
|
||||
public bool useDelayForEvent;
|
||||
public float delayForEvent;
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
public bool useEventObjectObjectActiveWithoutDelay;
|
||||
public UnityEvent eventObjectObjectActiveWithoutDelay;
|
||||
|
||||
public bool useEventObjectObjectInactiveWithoutDelay;
|
||||
public UnityEvent eventObjectObjectInactiveWithoutDelay;
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public bool showDebugPrint;
|
||||
public bool useElementPrefabID;
|
||||
public bool objectOriginallyOnScene;
|
||||
|
||||
Vector3 newPosition;
|
||||
Vector3 newRotation;
|
||||
|
||||
string currentStatNameToCheck;
|
||||
|
||||
elementOnSceneManager mainElementOnSceneManager;
|
||||
|
||||
bool mainElementOnSceneManagerLocated;
|
||||
|
||||
|
||||
public void setElementScene (int newValue)
|
||||
{
|
||||
elementScene = newValue;
|
||||
}
|
||||
|
||||
public void setElementID (int newValue)
|
||||
{
|
||||
elementID = newValue;
|
||||
}
|
||||
|
||||
public void setNewPositionValues (Vector3 newValue)
|
||||
{
|
||||
newPosition = newValue;
|
||||
}
|
||||
|
||||
public void setNewRotationValues (Vector3 newValue)
|
||||
{
|
||||
newRotation = newValue;
|
||||
}
|
||||
|
||||
public void setUseEventOnObjectActiveState (bool state)
|
||||
{
|
||||
useEventOnObjectActive = state;
|
||||
}
|
||||
|
||||
public void setUseEventOnObjectInactive (bool state)
|
||||
{
|
||||
useEventOnObjectInactive = state;
|
||||
}
|
||||
|
||||
public void setElementActiveState (bool state)
|
||||
{
|
||||
elementActiveState = state;
|
||||
|
||||
if (showDebugPrint) {
|
||||
print ("\n");
|
||||
print ("SETTING ELEMENT STATE ON " + gameObject.name + " as " + state);
|
||||
|
||||
print ("\n");
|
||||
}
|
||||
}
|
||||
|
||||
public void setElementPrefabIDValue (int newValue)
|
||||
{
|
||||
elementPrefabID = newValue;
|
||||
}
|
||||
|
||||
public void setNewInstantiatedElementOnSceneManagerIngame ()
|
||||
{
|
||||
if (!saveElementEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
setElementActiveState (true);
|
||||
|
||||
if (!mainElementOnSceneManagerLocated) {
|
||||
getMainElementOnSceneManager ();
|
||||
}
|
||||
|
||||
if (mainElementOnSceneManagerLocated) {
|
||||
mainElementOnSceneManager.setNewInstantiatedElementOnSceneManagerIngame (this);
|
||||
}
|
||||
}
|
||||
|
||||
public void setElementActiveStateToMainElementOnSceneManager (bool state)
|
||||
{
|
||||
if (!saveElementEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
setElementActiveState (state);
|
||||
|
||||
if (!mainElementOnSceneManagerLocated) {
|
||||
getMainElementOnSceneManager ();
|
||||
}
|
||||
|
||||
if (mainElementOnSceneManagerLocated) {
|
||||
if (objectOriginallyOnScene) {
|
||||
mainElementOnSceneManager.setTemporalElementActiveState (elementID, elementScene, elementActiveState);
|
||||
} else {
|
||||
mainElementOnSceneManager.removeElementFromSceneList (this);
|
||||
|
||||
Destroy (this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setNewInstantiatedElementOnSceneManagerIngameWithInfo ()
|
||||
{
|
||||
if (!mainElementOnSceneManagerLocated) {
|
||||
getMainElementOnSceneManager ();
|
||||
}
|
||||
|
||||
if (mainElementOnSceneManagerLocated) {
|
||||
mainElementOnSceneManager.setNewInstantiatedElementOnSceneManagerIngameWithInfo (this);
|
||||
}
|
||||
}
|
||||
|
||||
public void addNewElementOnSceneManager ()
|
||||
{
|
||||
if (!saveElementEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mainElementOnSceneManagerLocated) {
|
||||
getMainElementOnSceneManager ();
|
||||
}
|
||||
|
||||
if (mainElementOnSceneManagerLocated) {
|
||||
mainElementOnSceneManager.addNewElementOnScene (this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void checkStateOnLoad ()
|
||||
{
|
||||
if (!saveElementEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (useDelayForEvent) {
|
||||
activateStateOnLoadWithDelay ();
|
||||
} else {
|
||||
activateStateOnLoad ();
|
||||
}
|
||||
|
||||
checkActivateStateOnLoadWithoutDelay ();
|
||||
}
|
||||
|
||||
void checkActivateStateOnLoadWithoutDelay ()
|
||||
{
|
||||
if (saveElementEnabled) {
|
||||
if (elementActiveState) {
|
||||
if (useEventObjectObjectActiveWithoutDelay) {
|
||||
eventObjectObjectActiveWithoutDelay.Invoke ();
|
||||
}
|
||||
} else {
|
||||
if (useEventObjectObjectInactiveWithoutDelay) {
|
||||
eventObjectObjectInactiveWithoutDelay.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void activateStateOnLoadWithDelay ()
|
||||
{
|
||||
StartCoroutine (activateStateOnLoadCoroutine ());
|
||||
}
|
||||
|
||||
IEnumerator activateStateOnLoadCoroutine ()
|
||||
{
|
||||
WaitForSeconds delay = new WaitForSeconds (delayForEvent);
|
||||
|
||||
yield return delay;
|
||||
|
||||
activateStateOnLoad ();
|
||||
}
|
||||
|
||||
public void activateStateOnLoad ()
|
||||
{
|
||||
if (saveElementEnabled) {
|
||||
if (elementActiveState) {
|
||||
if (useEventOnObjectActive) {
|
||||
eventOnObjectActive.Invoke ();
|
||||
}
|
||||
|
||||
if (savePositionValues) {
|
||||
if (useCustomTransform) {
|
||||
customTransform.position = newPosition;
|
||||
} else {
|
||||
transform.position = newPosition;
|
||||
}
|
||||
}
|
||||
|
||||
if (saveRotationValues) {
|
||||
if (useCustomTransform) {
|
||||
customTransform.eulerAngles = newRotation;
|
||||
} else {
|
||||
transform.eulerAngles = newRotation;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (useEventOnObjectInactive) {
|
||||
eventOnObjectInactive.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 getElementPosition ()
|
||||
{
|
||||
if (useCustomTransform) {
|
||||
return customTransform.position;
|
||||
} else {
|
||||
return transform.position;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 getElementRotation ()
|
||||
{
|
||||
if (useCustomTransform) {
|
||||
return customTransform.eulerAngles;
|
||||
} else {
|
||||
return transform.eulerAngles;
|
||||
}
|
||||
}
|
||||
|
||||
public bool isSaveElementEnabled ()
|
||||
{
|
||||
return saveElementEnabled;
|
||||
}
|
||||
|
||||
public void setSaveElementEnabledState (bool state)
|
||||
{
|
||||
saveElementEnabled = state;
|
||||
}
|
||||
|
||||
public void setObjectOriginallyOnSceneState (bool state)
|
||||
{
|
||||
objectOriginallyOnScene = state;
|
||||
}
|
||||
|
||||
|
||||
//STATS FUNCTIONS
|
||||
public void setStatsSearchingByInfo (int currentElementScene, int currentElementID)
|
||||
{
|
||||
if (!mainElementOnSceneManagerLocated) {
|
||||
getMainElementOnSceneManager ();
|
||||
}
|
||||
|
||||
if (mainElementOnSceneManagerLocated) {
|
||||
mainElementOnSceneManager.setStatsSearchingByInfo (currentElementScene, currentElementID, this);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkStatsStateOnLoad ()
|
||||
{
|
||||
if (!saveElementEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (useStats) {
|
||||
if (loadStatsDelay > 0) {
|
||||
setStatsOnLoadWithDelay ();
|
||||
} else {
|
||||
setStatsOnLoad ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setStatsOnLoadWithDelay ()
|
||||
{
|
||||
StartCoroutine (setStatsOnLoadCoroutine ());
|
||||
}
|
||||
|
||||
IEnumerator setStatsOnLoadCoroutine ()
|
||||
{
|
||||
WaitForSeconds delay = new WaitForSeconds (loadStatsDelay);
|
||||
|
||||
yield return delay;
|
||||
|
||||
setStatsOnLoad ();
|
||||
}
|
||||
|
||||
public void setStatsOnLoad ()
|
||||
{
|
||||
if (saveElementEnabled) {
|
||||
if (elementActiveState) {
|
||||
if (useStats) {
|
||||
if (showDebugPrint) {
|
||||
print ("\n");
|
||||
print ("SETTING STATS INFO ON " + gameObject.name);
|
||||
|
||||
print ("\n");
|
||||
}
|
||||
|
||||
for (int i = 0; i < statInfoList.Count; i++) {
|
||||
statInfo currentStatInfo = statInfoList [i];
|
||||
|
||||
if (currentStatInfo.statIsAmount) {
|
||||
currentStatInfo.eventToInitializeFloatStat.Invoke (currentStatInfo.currentFloatValue);
|
||||
} else {
|
||||
currentStatInfo.eventToInitializeBoolStat.Invoke (currentStatInfo.currentBoolState);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentStatNameToSave (string newValue)
|
||||
{
|
||||
currentStatNameToCheck = newValue;
|
||||
}
|
||||
|
||||
public void setCurrentFloatValueToSave (float newValue)
|
||||
{
|
||||
if (saveElementEnabled) {
|
||||
if (useStats) {
|
||||
for (int i = 0; i < statInfoList.Count; i++) {
|
||||
statInfo currentStatInfo = statInfoList [i];
|
||||
|
||||
if (currentStatInfo.Name.Equals (currentStatNameToCheck)) {
|
||||
currentStatInfo.currentFloatValue = newValue;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentBoolValueToSave (bool newValue)
|
||||
{
|
||||
if (saveElementEnabled) {
|
||||
if (useStats) {
|
||||
for (int i = 0; i < statInfoList.Count; i++) {
|
||||
statInfo currentStatInfo = statInfoList [i];
|
||||
|
||||
if (currentStatInfo.Name.Equals (currentStatNameToCheck)) {
|
||||
currentStatInfo.currentBoolState = newValue;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void checkEventOnStatsSave ()
|
||||
{
|
||||
if (saveElementEnabled) {
|
||||
if (useStats) {
|
||||
for (int i = 0; i < statInfoList.Count; i++) {
|
||||
statInfo currentStatInfo = statInfoList [i];
|
||||
|
||||
currentStatNameToCheck = currentStatInfo.Name;
|
||||
|
||||
if (currentStatInfo.statIsAmount) {
|
||||
currentStatInfo.eventToGetFloatStat.Invoke ();
|
||||
} else {
|
||||
currentStatInfo.eventToGetBoolStat.Invoke ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setUseElementPrefabIDState (bool state)
|
||||
{
|
||||
useElementPrefabID = state;
|
||||
}
|
||||
|
||||
public void addSingleElementOnSceneToManager ()
|
||||
{
|
||||
if (!mainElementOnSceneManagerLocated) {
|
||||
getMainElementOnSceneManager ();
|
||||
}
|
||||
|
||||
if (mainElementOnSceneManagerLocated) {
|
||||
mainElementOnSceneManager.addSingleElementOnSceneToManager (this);
|
||||
}
|
||||
}
|
||||
|
||||
void getMainElementOnSceneManager ()
|
||||
{
|
||||
mainElementOnSceneManagerLocated = mainElementOnSceneManager != null;
|
||||
|
||||
if (!mainElementOnSceneManagerLocated) {
|
||||
mainElementOnSceneManager = elementOnSceneManager.Instance;
|
||||
|
||||
mainElementOnSceneManagerLocated = mainElementOnSceneManager != null;
|
||||
}
|
||||
|
||||
if (!mainElementOnSceneManagerLocated) {
|
||||
GKC_Utils.instantiateMainManagerOnSceneWithTypeOnApplicationPlaying (elementOnSceneManager.getMainManagerName (), typeof(elementOnSceneManager), true);
|
||||
|
||||
mainElementOnSceneManager = elementOnSceneManager.Instance;
|
||||
|
||||
mainElementOnSceneManagerLocated = mainElementOnSceneManager != null;
|
||||
}
|
||||
|
||||
if (!mainElementOnSceneManagerLocated) {
|
||||
|
||||
mainElementOnSceneManager = FindObjectOfType<elementOnSceneManager> ();
|
||||
|
||||
mainElementOnSceneManagerLocated = mainElementOnSceneManager != null;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class statInfo
|
||||
{
|
||||
public string Name;
|
||||
|
||||
public bool statIsAmount = true;
|
||||
|
||||
[Space]
|
||||
|
||||
public float currentFloatValue;
|
||||
|
||||
public eventParameters.eventToCallWithAmount eventToInitializeFloatStat;
|
||||
|
||||
public UnityEvent eventToGetFloatStat;
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
public bool currentBoolState;
|
||||
|
||||
public eventParameters.eventToCallWithBool eventToInitializeBoolStat;
|
||||
|
||||
public UnityEvent eventToGetBoolStat;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 703bee9dfca61354fa8809e52e0ce318
|
||||
timeCreated: 1650495024
|
||||
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/Elements On Scene/elementOnScene.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,74 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class elementOnSceneHelper : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool checkElementOnSceneEnabled = true;
|
||||
|
||||
public elementOnScene mainElementOnScene;
|
||||
|
||||
|
||||
public void setElementActiveStateToMainElementOnSceneManager (bool state)
|
||||
{
|
||||
if (!checkElementOnSceneEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainElementOnScene != null) {
|
||||
mainElementOnScene.setElementActiveStateToMainElementOnSceneManager (state);
|
||||
}
|
||||
}
|
||||
|
||||
public void setNewInstantiatedElementOnSceneManagerIngameWithInfo ()
|
||||
{
|
||||
if (!checkElementOnSceneEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainElementOnScene != null) {
|
||||
mainElementOnScene.setNewInstantiatedElementOnSceneManagerIngameWithInfo ();
|
||||
}
|
||||
}
|
||||
|
||||
public void setElementActiveState (bool state)
|
||||
{
|
||||
if (!checkElementOnSceneEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mainElementOnScene != null) {
|
||||
mainElementOnScene.setElementActiveState (state);
|
||||
}
|
||||
}
|
||||
|
||||
public int getElementScene ()
|
||||
{
|
||||
if (!checkElementOnSceneEnabled) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return mainElementOnScene.elementScene;
|
||||
}
|
||||
|
||||
public int getElementID ()
|
||||
{
|
||||
if (!checkElementOnSceneEnabled) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return mainElementOnScene.elementID;
|
||||
}
|
||||
|
||||
public void setStatsSearchingByInfo (int currentElementScene, int currentElementID)
|
||||
{
|
||||
if (!checkElementOnSceneEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mainElementOnScene.setStatsSearchingByInfo (currentElementScene, currentElementID);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a4dea7e35424d648a1831b24c81ffdc
|
||||
timeCreated: 1651306761
|
||||
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/Elements On Scene/elementOnSceneHelper.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class elementsOnSceneInfo
|
||||
{
|
||||
public string elementOnSceneCategoryName;
|
||||
public List<elementOnSceneInfo> elementOnSceneInfoList = new List<elementOnSceneInfo> ();
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class elementOnSceneInfo
|
||||
{
|
||||
public int elementPrefabID;
|
||||
|
||||
public GameObject elementPrefab;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b0cfeca9fba56940ad1466fb5759474
|
||||
timeCreated: 1650818321
|
||||
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/Elements On Scene/elementOnSceneInfo.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,445 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class elementOnSceneManager : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool saveCurrentPlayerElementsOnSceneToSaveFile = true;
|
||||
|
||||
public int elementsScene;
|
||||
|
||||
public bool findDisabledElementsOnSceneGameObjects;
|
||||
|
||||
[Space]
|
||||
[Header ("Elements On Scene Prefabs Settings")]
|
||||
[Space]
|
||||
|
||||
public bool useElementsOnSceneData;
|
||||
|
||||
public elementsOnSceneData mainElementsOnSceneData;
|
||||
|
||||
[Space]
|
||||
[Header ("Elements On Scene Prefabs Settings")]
|
||||
[Space]
|
||||
|
||||
public bool ignoreLoadStatsOnObjectIDList;
|
||||
public List<int> ignoreLoadStatsOnObjectIDListInfo = new List<int> ();
|
||||
|
||||
[Space]
|
||||
|
||||
public bool ignoreLoadStatsOnObjectPrefabIDList;
|
||||
public List<int> ignoreLoadStatsOnObjectPrefabIDListInfo = new List<int> ();
|
||||
|
||||
[Space]
|
||||
[Header ("Debug")]
|
||||
[Space]
|
||||
|
||||
public int currentElementID = 0;
|
||||
|
||||
public List<elementOnScene> elementOnSceneList = new List<elementOnScene> ();
|
||||
|
||||
[Space]
|
||||
[Space]
|
||||
|
||||
public List<temporalElementOnSceneInfo> temporalElementOnSceneInfoList = new List<temporalElementOnSceneInfo> ();
|
||||
|
||||
|
||||
//Possible cases of objects on scene to save its info:
|
||||
//-Pickups:
|
||||
//When placed on scene, the regular scene manager will get its info on the editor
|
||||
//When picked, they send a signal to be removed, by setting its info on a temporal list, as the original object is destroyed
|
||||
//the system should check if the object picked was an original element on the scene or it was instantiated as a new object from a previous save
|
||||
//so in that case, that element info is removed from the list, as it is not needed to be loaded or taken into account in next load/save
|
||||
//When spawned, they are stored as regular object info when the game is saved, increasing the ID value and adding them as new info elements on the
|
||||
//main list, so when the game loads, it searches their prefab ID to instantiate a copy of each one, adding them as new objects info on the list
|
||||
|
||||
//-Vehicles:
|
||||
//When placed on scene, the regular scene manager will get its info on the editor
|
||||
//When moving to new scenes, they are disabled from the main list, so the original vehicle is disabled from scene in that case
|
||||
//in that case, the vehicle is checked on the new scene, instantiated and added on the main info list
|
||||
//When destroyed, they are disabled from the main list, so the original vehicle is disabled from scene in that case
|
||||
//When spawned, they are stored as regular object info when the game is saved, increasing the ID value and adding them as new info elements on the
|
||||
//main list, so when the game loads, it searches their prefab ID to instantiate a copy of each one, adding them as new objects info on the list
|
||||
|
||||
//-AI:
|
||||
//When placed on scene, the regular scene manager will get its info on the editor
|
||||
//When destroyed, they are disabled from the main list, so the original AI is disabled from scene in that case
|
||||
//When spawned, they are stored as regular object info when the game is saved, increasing the ID value and adding them as new info elements on the
|
||||
//main list, so when the game loads, it searches their prefab ID to instantiate a copy of each one, adding them as new objects info on the list
|
||||
|
||||
public const string mainManagerName = "Elements On Scene Manager";
|
||||
|
||||
public static string getMainManagerName ()
|
||||
{
|
||||
return mainManagerName;
|
||||
}
|
||||
|
||||
private static elementOnSceneManager _elementOnSceneManagerInstance;
|
||||
|
||||
public static elementOnSceneManager Instance { get { return _elementOnSceneManagerInstance; } }
|
||||
|
||||
bool instanceInitialized;
|
||||
|
||||
|
||||
public void getComponentInstance ()
|
||||
{
|
||||
if (instanceInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_elementOnSceneManagerInstance != null && _elementOnSceneManagerInstance != this) {
|
||||
Destroy (this.gameObject);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_elementOnSceneManagerInstance = this;
|
||||
|
||||
instanceInitialized = true;
|
||||
}
|
||||
|
||||
void Awake ()
|
||||
{
|
||||
getComponentInstance ();
|
||||
}
|
||||
|
||||
public void initializeValues ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void checkForInstantiatedElementsOnSceneOnSave ()
|
||||
{
|
||||
if (findDisabledElementsOnSceneGameObjects) {
|
||||
List<elementOnScene> newElementOnSceneList = GKC_Utils.FindObjectsOfTypeAll<elementOnScene> ();
|
||||
|
||||
if (newElementOnSceneList != null) {
|
||||
for (var i = 0; i < newElementOnSceneList.Count; i++) {
|
||||
if (!elementOnSceneList.Contains (newElementOnSceneList [i])) {
|
||||
setNewInstantiatedElementOnSceneManagerIngameWithInfo (newElementOnSceneList [i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
elementOnScene[] newElementOnSceneList = FindObjectsOfType<elementOnScene> ();
|
||||
|
||||
foreach (elementOnScene currentElementOnScene in newElementOnSceneList) {
|
||||
if (!elementOnSceneList.Contains (currentElementOnScene)) {
|
||||
setNewInstantiatedElementOnSceneManagerIngameWithInfo (currentElementOnScene);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setNewInstantiatedElementOnSceneManagerIngame (elementOnScene newElementOnScene)
|
||||
{
|
||||
currentElementID++;
|
||||
|
||||
newElementOnScene.setSaveElementEnabledState (true);
|
||||
|
||||
newElementOnScene.setElementID (currentElementID);
|
||||
|
||||
newElementOnScene.setElementScene (elementsScene);
|
||||
|
||||
newElementOnScene.setUseElementPrefabIDState (true);
|
||||
|
||||
elementOnSceneList.Add (newElementOnScene);
|
||||
}
|
||||
|
||||
public void setNewInstantiatedElementOnSceneManagerIngameWithInfo (elementOnScene newElementOnScene)
|
||||
{
|
||||
currentElementID++;
|
||||
|
||||
newElementOnScene.setSaveElementEnabledState (true);
|
||||
|
||||
newElementOnScene.setElementActiveState (true);
|
||||
|
||||
newElementOnScene.setElementID (currentElementID);
|
||||
|
||||
newElementOnScene.setElementScene (elementsScene);
|
||||
|
||||
if (useElementsOnSceneData) {
|
||||
int elementPrefabID = mainElementsOnSceneData.getElementScenePrefabIDByName (newElementOnScene.gameObject.name);
|
||||
|
||||
if (elementPrefabID > -1) {
|
||||
newElementOnScene.setElementPrefabIDValue (elementPrefabID);
|
||||
|
||||
newElementOnScene.setUseElementPrefabIDState (true);
|
||||
}
|
||||
}
|
||||
|
||||
elementOnSceneList.Add (newElementOnScene);
|
||||
}
|
||||
|
||||
public void setTemporalElementActiveState (int elementID, int elementScene, bool elementActiveState)
|
||||
{
|
||||
temporalElementOnSceneInfo newTemporalElementOnSceneInfo = new temporalElementOnSceneInfo ();
|
||||
|
||||
newTemporalElementOnSceneInfo.elementID = elementID;
|
||||
|
||||
newTemporalElementOnSceneInfo.elementScene = elementScene;
|
||||
|
||||
newTemporalElementOnSceneInfo.elementActiveState = elementActiveState;
|
||||
|
||||
temporalElementOnSceneInfoList.Add (newTemporalElementOnSceneInfo);
|
||||
}
|
||||
|
||||
public void removeElementFromSceneList (elementOnScene newElementOnScene)
|
||||
{
|
||||
if (elementOnSceneList.Contains (newElementOnScene)) {
|
||||
elementOnSceneList.Remove (newElementOnScene);
|
||||
}
|
||||
}
|
||||
|
||||
public elementOnScene getElementOnSceneInfo (int elementID, int elementScene)
|
||||
{
|
||||
//Get each elemento on scene configured,searching by ID
|
||||
if (elementOnSceneList.Count == 0) {
|
||||
getAllElementsOnSceneOnLevel ();
|
||||
}
|
||||
|
||||
int elementOnSceneListCount = elementOnSceneList.Count;
|
||||
|
||||
//Return the element on scene currently found by ID
|
||||
for (int i = 0; i < elementOnSceneListCount; i++) {
|
||||
elementOnScene currentElementOnScene = elementOnSceneList [i];
|
||||
|
||||
if (currentElementOnScene != null && currentElementOnScene.isSaveElementEnabled ()) {
|
||||
if (currentElementOnScene.elementScene == elementScene && currentElementOnScene.elementID == elementID) {
|
||||
|
||||
return currentElementOnScene;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addNewElementOnScene (elementOnScene newElementOnScene)
|
||||
{
|
||||
currentElementID++;
|
||||
|
||||
newElementOnScene.setElementID (currentElementID);
|
||||
|
||||
newElementOnScene.setElementScene (elementsScene);
|
||||
|
||||
elementOnSceneList.Add (newElementOnScene);
|
||||
}
|
||||
|
||||
public void getAllElementsOnSceneOnLevel ()
|
||||
{
|
||||
//Search all the station systems on the level, so they can be managed here
|
||||
elementOnSceneList.Clear ();
|
||||
|
||||
if (findDisabledElementsOnSceneGameObjects) {
|
||||
List<elementOnScene> newElementOnSceneList = GKC_Utils.FindObjectsOfTypeAll<elementOnScene> ();
|
||||
|
||||
if (newElementOnSceneList != null) {
|
||||
for (var i = 0; i < newElementOnSceneList.Count; i++) {
|
||||
if (!elementOnSceneList.Contains (newElementOnSceneList [i])) {
|
||||
elementOnSceneList.Add (newElementOnSceneList [i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
elementOnScene[] newElementOnSceneList = FindObjectsOfType<elementOnScene> ();
|
||||
|
||||
foreach (elementOnScene currentElementOnScene in newElementOnSceneList) {
|
||||
if (!elementOnSceneList.Contains (currentElementOnScene)) {
|
||||
elementOnSceneList.Add (currentElementOnScene);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setStatsSearchingByInfo (int currentElementScene, int currentElementID, elementOnScene currentElementOnScene)
|
||||
{
|
||||
saveElementsOnSceneInfo mainSaveElementsOnSceneInfo = FindObjectOfType<saveElementsOnSceneInfo> ();
|
||||
|
||||
if (mainSaveElementsOnSceneInfo != null) {
|
||||
|
||||
mainSaveElementsOnSceneInfo.setStatsSearchingByInfo (currentElementScene, currentElementID, currentElementOnScene);
|
||||
}
|
||||
}
|
||||
|
||||
public bool isSaveCurrentPlayerElementsOnSceneToSaveFile ()
|
||||
{
|
||||
return saveCurrentPlayerElementsOnSceneToSaveFile;
|
||||
}
|
||||
|
||||
public void setSaveCurrentPlayerElementsOnSceneToSaveFileState (bool state)
|
||||
{
|
||||
saveCurrentPlayerElementsOnSceneToSaveFile = state;
|
||||
}
|
||||
|
||||
//EDITOR FUNCTIONS
|
||||
public void getAllElementsOnSceneOnLevelAndAssignInfoToAllElements ()
|
||||
{
|
||||
//Seach all station systems on the level and assign an ID to each one
|
||||
getAllElementsOnSceneOnLevel ();
|
||||
|
||||
currentElementID = 0;
|
||||
|
||||
int elementOnSceneListCount = elementOnSceneList.Count;
|
||||
|
||||
for (int i = 0; i < elementOnSceneListCount; i++) {
|
||||
|
||||
if (elementOnSceneList [i] != null) {
|
||||
elementOnSceneList [i].setElementActiveState (elementOnSceneList [i].gameObject.activeSelf);
|
||||
|
||||
elementOnSceneList [i].setElementID (currentElementID);
|
||||
|
||||
elementOnSceneList [i].setElementScene (elementsScene);
|
||||
|
||||
elementOnSceneList [i].setObjectOriginallyOnSceneState (true);
|
||||
|
||||
GKC_Utils.updateComponent (elementOnSceneList [i]);
|
||||
|
||||
currentElementID++;
|
||||
}
|
||||
}
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void setEnableStateOnAllElementsOnScene (bool state)
|
||||
{
|
||||
//Seach all station systems on the level and assign an ID to each one
|
||||
getAllElementsOnSceneOnLevel ();
|
||||
|
||||
int elementOnSceneListCount = elementOnSceneList.Count;
|
||||
|
||||
for (int i = 0; i < elementOnSceneListCount; i++) {
|
||||
|
||||
if (elementOnSceneList [i] != null) {
|
||||
elementOnSceneList [i].setSaveElementEnabledState (state);
|
||||
|
||||
GKC_Utils.updateComponent (elementOnSceneList [i]);
|
||||
}
|
||||
}
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void setIDOnElementsOnScenePrefabs ()
|
||||
{
|
||||
if (useElementsOnSceneData) {
|
||||
int elementPrefabIDCount = 0;
|
||||
|
||||
for (int i = 0; i < mainElementsOnSceneData.elementsOnSceneInfoList.Count; i++) {
|
||||
for (int j = 0; j < mainElementsOnSceneData.elementsOnSceneInfoList [i].elementOnSceneInfoList.Count; j++) {
|
||||
mainElementsOnSceneData.elementsOnSceneInfoList [i].elementOnSceneInfoList [j].elementPrefabID = elementPrefabIDCount;
|
||||
|
||||
GameObject elementPrefab = mainElementsOnSceneData.elementsOnSceneInfoList [i].elementOnSceneInfoList [j].elementPrefab;
|
||||
|
||||
if (elementPrefab != null) {
|
||||
elementOnScene currentElementOnScene = elementPrefab.GetComponentInChildren<elementOnScene> ();
|
||||
|
||||
if (currentElementOnScene != null) {
|
||||
currentElementOnScene.setElementPrefabIDValue (elementPrefabIDCount);
|
||||
}
|
||||
}
|
||||
|
||||
elementPrefabIDCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateComponent ();
|
||||
|
||||
GKC_Utils.refreshAssetDatabase ();
|
||||
}
|
||||
|
||||
public void setIDOnElementsOnScenePrefabsLocatedOnScene ()
|
||||
{
|
||||
if (!useElementsOnSceneData) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (findDisabledElementsOnSceneGameObjects) {
|
||||
List<elementOnScene> newElementOnSceneList = GKC_Utils.FindObjectsOfTypeAll<elementOnScene> ();
|
||||
|
||||
if (newElementOnSceneList != null) {
|
||||
for (var i = 0; i < newElementOnSceneList.Count; i++) {
|
||||
int elementPrefabID = mainElementsOnSceneData.getElementScenePrefabIDByName (newElementOnSceneList [i].gameObject.name);
|
||||
|
||||
if (elementPrefabID > -1) {
|
||||
newElementOnSceneList [i].setElementPrefabIDValue (elementPrefabID);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
elementOnScene[] newElementOnSceneList = FindObjectsOfType<elementOnScene> ();
|
||||
|
||||
foreach (elementOnScene currentElementOnScene in newElementOnSceneList) {
|
||||
|
||||
int elementPrefabID = mainElementsOnSceneData.getElementScenePrefabIDByName (currentElementOnScene.gameObject.name);
|
||||
|
||||
if (elementPrefabID > -1) {
|
||||
currentElementOnScene.setElementPrefabIDValue (elementPrefabID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void getAllElementsOnSceneOnLevelByEditor ()
|
||||
{
|
||||
//Search all station systems on the level and assign them here by the editor
|
||||
getAllElementsOnSceneOnLevel ();
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void clearElementsOnSceneList ()
|
||||
{
|
||||
elementOnSceneList.Clear ();
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
|
||||
public void addSingleElementOnSceneToManager (elementOnScene newElementOnScene)
|
||||
{
|
||||
if (!elementOnSceneList.Contains (newElementOnScene)) {
|
||||
newElementOnScene.setElementActiveState (newElementOnScene.gameObject.activeSelf);
|
||||
|
||||
newElementOnScene.setElementID (currentElementID);
|
||||
|
||||
newElementOnScene.setElementScene (elementsScene);
|
||||
|
||||
newElementOnScene.setObjectOriginallyOnSceneState (true);
|
||||
|
||||
GKC_Utils.updateComponent (newElementOnScene);
|
||||
|
||||
currentElementID++;
|
||||
|
||||
elementOnSceneList.Add (newElementOnScene);
|
||||
|
||||
updateComponent ();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateComponent ()
|
||||
{
|
||||
GKC_Utils.updateComponent (this);
|
||||
|
||||
GKC_Utils.updateDirtyScene ("Update Main Elements On Scene Manager info", gameObject);
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class temporalElementOnSceneInfo
|
||||
{
|
||||
public int elementScene;
|
||||
public int elementID;
|
||||
|
||||
public bool elementActiveState;
|
||||
|
||||
public bool useElementPrefabID;
|
||||
|
||||
public int elementPrefabID;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b4701a2ee3024c42b47758b675b4d84
|
||||
timeCreated: 1650494901
|
||||
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/Elements On Scene/elementOnSceneManager.cs
|
||||
uploadId: 814740
|
||||
@@ -0,0 +1,53 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu (fileName = "Element On Scene Data", menuName = "GKC/Create Element On Scene Data", order = 51)]
|
||||
public class elementsOnSceneData : ScriptableObject
|
||||
{
|
||||
public List<elementsOnSceneInfo> elementsOnSceneInfoList = new List<elementsOnSceneInfo> ();
|
||||
|
||||
|
||||
public GameObject getElementScenePrefabById (int prefabID)
|
||||
{
|
||||
if (prefabID <= -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int elementsOnSceneInfoListCount = elementsOnSceneInfoList.Count;
|
||||
|
||||
for (int i = 0; i < elementsOnSceneInfoListCount; i++) {
|
||||
|
||||
int elementOnSceneInfoListCount = elementsOnSceneInfoList [i].elementOnSceneInfoList.Count;
|
||||
|
||||
for (int j = 0; j < elementOnSceneInfoListCount; j++) {
|
||||
if (elementsOnSceneInfoList [i].elementOnSceneInfoList [j].elementPrefabID == prefabID) {
|
||||
return elementsOnSceneInfoList [i].elementOnSceneInfoList [j].elementPrefab;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getElementScenePrefabIDByName (string prefabName)
|
||||
{
|
||||
int elementsOnSceneInfoListCount = elementsOnSceneInfoList.Count;
|
||||
|
||||
for (int i = 0; i < elementsOnSceneInfoListCount; i++) {
|
||||
int elementOnSceneInfoListCount = elementsOnSceneInfoList [i].elementOnSceneInfoList.Count;
|
||||
|
||||
for (int j = 0; j < elementOnSceneInfoListCount; j++) {
|
||||
if (elementsOnSceneInfoList [i].elementOnSceneInfoList [j].elementPrefab != null) {
|
||||
string currentName = elementsOnSceneInfoList [i].elementOnSceneInfoList [j].elementPrefab.name;
|
||||
|
||||
if (currentName.Equals (prefabName) || prefabName.Contains (currentName)) {
|
||||
return elementsOnSceneInfoList [i].elementOnSceneInfoList [j].elementPrefabID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 290f8efc18bc7eb46a5cac8425f88652
|
||||
timeCreated: 1650818425
|
||||
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/Elements On Scene/elementsOnSceneData.cs
|
||||
uploadId: 814740
|
||||
Reference in New Issue
Block a user