plantilla base para movimiento básico
This commit is contained in:
Robii Aragon
2026-02-05 05:07:55 -08:00
parent 195b696771
commit 779f2c8b20
14443 changed files with 23840465 additions and 452 deletions

View File

@@ -0,0 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class experienceObtainedInfoPanel : MonoBehaviour
{
public playerExperienceSystem.experienceObtainedInfo experienceObtainedInfo;
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 4b463e11035b41147a22e2c197652b41
timeCreated: 1564274838
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/Experience System/experienceObtainedInfoPanel.cs
uploadId: 814740

View File

@@ -0,0 +1,516 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class objectExperienceSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool giveRewardOnlyOnceEnabled;
[Space]
[Header ("Experience Settings")]
[Space]
public bool useExperienceRandomRange;
public Vector2 experienceRandomRange;
public int experienceAmount;
public bool useTransformAsExpTextPosition = true;
public Transform objectTransform;
public string extraExperienceText;
[Space]
[Header ("Money Settings")]
[Space]
public bool useMoneyRandomRange;
public Vector2 moneyRandomRange;
public int moneyAmount;
[Space]
[Header ("Inventory Object Settings")]
[Space]
public bool giveInventoryObject;
public string inventoryObjectName;
public int inventoryObjectAmount;
public bool onlyRefillCertainAmountOfInventoryObjectAmount;
[Space]
public Transform positionToInstantiateInventoryObjectPickup;
public float maxRadiusToInstantiate;
public float forceAmount;
public float forceRadius;
public ForceMode inventoryObjectForceMode;
public bool spawnAllInventoryObjects;
public bool spawnObjectIfNotEnoughSpaceOnInventory = true;
[Space]
public bool giveRandomSingleObjectFromList;
public bool giveInventoryObjectList;
[Space]
public List<inventoryElementInfo> inventoryElementInfoList = new List<inventoryElementInfo> ();
[Space]
public bool getInventoryObjectsFromInventoryBank;
public inventoryBankSystem mainInventoryBankSystem;
[Space]
[Header ("Stamina Settings")]
[Space]
public bool refillStamina;
public bool refillFullStamina;
public float staminaAmountToRefill;
[Space]
[Header ("Inventory Extra Slots Settings")]
[Space]
public bool increaseInventorySlotsAmount;
public int extraInventorySlotsAmount;
[Space]
[Header ("Inventory Extra Weight Settings")]
[Space]
public bool increaseInventoryWeightLimit;
public float extraWeightLimit;
[Space]
[Header ("Stats To Increase Settings")]
[Space]
public bool increaseStatsValues;
[Space]
public List<statInfo> statInfoList = new List<statInfo> ();
[Space]
[Header ("Skill Points Settings")]
[Space]
public bool getSkillPoints;
public bool useSkillPointsRandomRange;
public Vector2 skillPointsRandomRange;
public int skillPointsAmount;
[Space]
[Header ("Skill Settings")]
[Space]
public bool getSkill;
public string skillToGetName;
[Space]
public bool getSkillList;
public List<string> skillToGetNameList = new List<string> ();
[Space]
public bool showMessageOnGetSkill;
[Tooltip ("Write -SKILLNAME- in the string to replace that part of the message with the name of the skill.")]
public string messageOnGetSkill;
[Space]
[Header ("Abilities Settings")]
[Space]
public bool getAbility;
public string abilityToGetName;
[Space]
public bool getAbilityList;
public List<string> abilityToGetNameList = new List<string> ();
[Space]
public bool showMessageOnGetAbility;
[Tooltip ("Write -ABILITYNAME- in the string to replace that part of the message with the name of the skill.")]
public string messageOnGetAbility;
[Space]
[Header ("Crafting Settings")]
[Space]
public bool getCraftingRecipes;
[Space]
public List<string> craftingRecipesList = new List<string> ();
[Space]
[Header ("Player Manual Settings")]
[Space]
public bool setPlayerManually;
public bool sendAlwaysToMainPlayer;
public bool searchPlayerByTagIfNotAssigned = true;
public GameObject playerToConfigure;
[Space]
[Header ("Remote Events Settings")]
[Space]
public bool useRemoteEvents;
public List<string> removeEventNameList = new List<string> ();
[Space]
[Header ("Event Settings")]
[Space]
public bool useEventOnReward;
public UnityEvent eventtOnReward;
[Space]
[Header ("Debug")]
[Space]
public bool showDebugPrint;
public bool rewardObtained;
public void sendExperienceToPlayerManually ()
{
if (setPlayerManually) {
sendExperienceToAttacker (playerToConfigure);
}
}
public void sendExperienceToPlayer (GameObject playerToUse)
{
if (setPlayerManually) {
playerToUse = playerToConfigure;
}
sendExperienceToAttacker (playerToUse);
}
public void sendExperienceToAttacker (GameObject attackerGameObject)
{
if (giveRewardOnlyOnceEnabled) {
if (rewardObtained) {
return;
}
}
if (sendAlwaysToMainPlayer) {
attackerGameObject = GKC_Utils.findMainPlayerOnScene ();
}
if (attackerGameObject == null) {
if (setPlayerManually && searchPlayerByTagIfNotAssigned) {
attackerGameObject = GKC_Utils.findMainPlayerOnScene ();
if (attackerGameObject == null) {
return;
}
} else {
return;
}
}
if (objectTransform == null) {
objectTransform = transform;
}
if (applyDamage.isVehicle (attackerGameObject)) {
GameObject vehicleDriver = applyDamage.getVehicleDriver (attackerGameObject);
if (vehicleDriver != null) {
attackerGameObject = vehicleDriver;
}
}
playerComponentsManager currentPlayerComponentsManager = attackerGameObject.GetComponent<playerComponentsManager> ();
if (currentPlayerComponentsManager != null) {
if (experienceAmount != 0 || (useExperienceRandomRange && (experienceRandomRange.x != 0 || experienceRandomRange.y != 0))) {
playerExperienceSystem currentPlayerExperienceSystem = currentPlayerComponentsManager.getPlayerExperienceSystem ();
if (currentPlayerExperienceSystem != null) {
float newAmount = experienceAmount;
if (useExperienceRandomRange) {
newAmount = Random.Range (experienceRandomRange.x, experienceRandomRange.y);
newAmount = Mathf.RoundToInt (newAmount);
}
currentPlayerExperienceSystem.getExperienceAmount ((int)newAmount, objectTransform, useTransformAsExpTextPosition, extraExperienceText);
}
}
if (moneyAmount != 0) {
currencySystem currentCurrencySystem = currentPlayerComponentsManager.getCurrencySystem ();
if (currentCurrencySystem != null) {
float newAmount = moneyAmount;
if (useMoneyRandomRange && moneyRandomRange != Vector2.zero) {
newAmount = Random.Range (moneyRandomRange.x, moneyRandomRange.y);
newAmount = Mathf.RoundToInt (newAmount);
}
currentCurrencySystem.increaseTotalMoneyAmount (newAmount);
}
}
if (giveInventoryObject) {
if (positionToInstantiateInventoryObjectPickup == null) {
positionToInstantiateInventoryObjectPickup = transform;
}
if (giveInventoryObjectList) {
if (giveRandomSingleObjectFromList) {
if (getInventoryObjectsFromInventoryBank) {
List<inventoryInfo> inventoryBankElementInfoList = mainInventoryBankSystem.getBankInventoryListFromFullBank ();
if (inventoryBankElementInfoList != null && inventoryBankElementInfoList.Count > 0) {
int randomObjectIndex = Random.Range (0, inventoryBankElementInfoList.Count - 1);
applyDamage.giveInventoryObjectToCharacter (attackerGameObject,
inventoryBankElementInfoList [randomObjectIndex].Name,
inventoryBankElementInfoList [randomObjectIndex].amount,
positionToInstantiateInventoryObjectPickup, forceAmount,
maxRadiusToInstantiate, inventoryObjectForceMode, forceRadius, spawnAllInventoryObjects,
false, spawnObjectIfNotEnoughSpaceOnInventory);
}
} else {
int randomObjectIndex = Random.Range (0, inventoryElementInfoList.Count - 1);
if (inventoryElementInfoList [randomObjectIndex].inventoryObjectAmount == 0) {
inventoryElementInfoList [randomObjectIndex].inventoryObjectAmount = 1;
}
applyDamage.giveInventoryObjectToCharacter (attackerGameObject,
inventoryElementInfoList [randomObjectIndex].Name,
inventoryElementInfoList [randomObjectIndex].inventoryObjectAmount,
positionToInstantiateInventoryObjectPickup, forceAmount,
maxRadiusToInstantiate, inventoryObjectForceMode, forceRadius, spawnAllInventoryObjects,
inventoryElementInfoList [randomObjectIndex].onlyRefillCertainAmountOfInventoryObjectAmount,
spawnObjectIfNotEnoughSpaceOnInventory);
}
} else {
if (getInventoryObjectsFromInventoryBank) {
List<inventoryInfo> inventoryBankElementInfoList = mainInventoryBankSystem.getBankInventoryListFromFullBank ();
if (inventoryBankElementInfoList != null && inventoryBankElementInfoList.Count > 0) {
for (int i = 0; i < inventoryBankElementInfoList.Count; i++) {
applyDamage.giveInventoryObjectToCharacter (attackerGameObject,
inventoryBankElementInfoList [i].Name,
inventoryBankElementInfoList [i].amount,
positionToInstantiateInventoryObjectPickup, forceAmount,
maxRadiusToInstantiate, inventoryObjectForceMode, forceRadius, spawnAllInventoryObjects,
false, spawnObjectIfNotEnoughSpaceOnInventory);
}
}
} else {
for (int i = 0; i < inventoryElementInfoList.Count; i++) {
if (inventoryElementInfoList [i].inventoryObjectAmount == 0) {
inventoryElementInfoList [i].inventoryObjectAmount = 1;
}
applyDamage.giveInventoryObjectToCharacter (attackerGameObject,
inventoryElementInfoList [i].Name,
inventoryElementInfoList [i].inventoryObjectAmount,
positionToInstantiateInventoryObjectPickup, forceAmount,
maxRadiusToInstantiate, inventoryObjectForceMode, forceRadius, spawnAllInventoryObjects,
inventoryElementInfoList [i].onlyRefillCertainAmountOfInventoryObjectAmount,
spawnObjectIfNotEnoughSpaceOnInventory);
}
}
}
} else {
if (inventoryObjectAmount == 0) {
inventoryObjectAmount = 1;
}
applyDamage.giveInventoryObjectToCharacter (attackerGameObject, inventoryObjectName,
inventoryObjectAmount, positionToInstantiateInventoryObjectPickup,
forceAmount, maxRadiusToInstantiate,
inventoryObjectForceMode, forceRadius, spawnAllInventoryObjects,
onlyRefillCertainAmountOfInventoryObjectAmount, spawnObjectIfNotEnoughSpaceOnInventory);
}
}
if (refillStamina) {
applyDamage.setStamina (staminaAmountToRefill, attackerGameObject, refillFullStamina);
}
if (increaseInventorySlotsAmount) {
applyDamage.addInventoryExtraSpace (attackerGameObject, extraInventorySlotsAmount);
}
if (increaseInventoryWeightLimit) {
applyDamage.increaseInventoryBagWeight (extraWeightLimit, attackerGameObject);
}
if (increaseStatsValues) {
playerStatsSystem currentPlayerStatsSystem = currentPlayerComponentsManager.getPlayerStatsSystem ();
if (currentPlayerStatsSystem != null) {
for (int k = 0; k < statInfoList.Count; k++) {
if (statInfoList [k].statIsAmount) {
float extraValue = statInfoList [k].statExtraValue;
if (statInfoList [k].useRandomRange) {
extraValue = Random.Range (statInfoList [k].randomRange.x, statInfoList [k].randomRange.y);
extraValue = Mathf.RoundToInt (extraValue);
}
currentPlayerStatsSystem.increasePlayerStat (statInfoList [k].Name, extraValue);
} else {
currentPlayerStatsSystem.enableOrDisableBoolPlayerStat (statInfoList [k].Name, statInfoList [k].newBoolState);
}
}
}
}
if (getSkillPoints) {
playerExperienceSystem currentPlayerExperienceSystem = currentPlayerComponentsManager.getPlayerExperienceSystem ();
if (currentPlayerExperienceSystem != null) {
float newAmount = skillPointsAmount;
if (useSkillPointsRandomRange) {
newAmount = Random.Range (skillPointsRandomRange.x, skillPointsRandomRange.y);
newAmount = Mathf.RoundToInt (newAmount);
}
currentPlayerExperienceSystem.getSkillPoints ((int)newAmount);
}
}
if (getSkill) {
playerSkillsSystem currentPlayerSkillsSystem = currentPlayerComponentsManager.getPlayerSkillsSystem ();
if (currentPlayerSkillsSystem != null) {
if (getSkillList) {
GKC_Utils.setUnlockStateOnSkillList (attackerGameObject.transform, skillToGetNameList, true);
} else {
currentPlayerSkillsSystem.getSkillByName (skillToGetName);
}
if (showMessageOnGetSkill) {
pickUpsScreenInfo currentPickUpsScreenInfo = currentPlayerComponentsManager.getPickUpsScreenInfo ();
if (currentPickUpsScreenInfo != null) {
messageOnGetSkill = messageOnGetSkill.Replace ("-SKILLNAME-", skillToGetName);
currentPickUpsScreenInfo.recieveInfo (messageOnGetSkill);
}
}
}
}
if (getAbility) {
playerAbilitiesSystem currentPlayerAbilitiesSystem = currentPlayerComponentsManager.getPlayerAbilitiesSystem ();
if (currentPlayerAbilitiesSystem != null) {
if (getAbilityList) {
currentPlayerAbilitiesSystem.enableAbilityGroupByName (abilityToGetNameList);
GKC_Utils.setUnlockStateOnSkillList (attackerGameObject.transform, abilityToGetNameList, true);
} else {
currentPlayerAbilitiesSystem.enableAbilityByName (abilityToGetName);
GKC_Utils.setUnlockStateOnSkill (attackerGameObject.transform, abilityToGetName, true);
}
if (showMessageOnGetAbility) {
pickUpsScreenInfo currentPickUpsScreenInfo = currentPlayerComponentsManager.getPickUpsScreenInfo ();
if (currentPickUpsScreenInfo != null) {
messageOnGetSkill = messageOnGetSkill.Replace ("-ABILITYNAME-", abilityToGetName);
currentPickUpsScreenInfo.recieveInfo (messageOnGetAbility);
}
}
}
}
if (getCraftingRecipes) {
GKC_Utils.addNewBlueprintsUnlockedList (attackerGameObject, craftingRecipesList);
}
if (useRemoteEvents) {
remoteEventSystem currentRemoteEventSystem = attackerGameObject.GetComponent<remoteEventSystem> ();
if (currentRemoteEventSystem == null && currentPlayerComponentsManager != null) {
currentRemoteEventSystem = currentPlayerComponentsManager.getRemoteEventSystem ();
}
if (currentRemoteEventSystem != null) {
for (int i = 0; i < removeEventNameList.Count; i++) {
currentRemoteEventSystem.callRemoteEvent (removeEventNameList [i]);
}
}
}
if (useEventOnReward) {
eventtOnReward.Invoke ();
}
}
if (showDebugPrint) {
print ("giving reward to character");
}
rewardObtained = true;
}
[System.Serializable]
public class inventoryElementInfo
{
public string Name;
public int inventoryObjectAmount;
public bool onlyRefillCertainAmountOfInventoryObjectAmount;
}
[System.Serializable]
public class statInfo
{
public string Name;
public bool statIsAmount = true;
public float statExtraValue;
public bool useRandomRange;
public Vector2 randomRange;
public bool newBoolState;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: eb0f4c1137141684088c37bd25ef8e27
timeCreated: 1564272275
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/Experience System/objectExperienceSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,923 @@
using System.Collections;
using System.Collections.Generic;
using GameKitController.Audio;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
public class playerExperienceSystem : MonoBehaviour
{
public bool experienceSystemEnabled = true;
public string XPExtraString = " XP";
public List<levelInfo> levelInfoList = new List<levelInfo> ();
public List<statUIInfo> statUIInfoList = new List<statUIInfo> ();
public int currentLevelExperienceAmount;
public int currentLevelExperienceToNextLevel;
public int totalExperienceAmount;
public int totalExperiencePoints;
public int currentLevel = 1;
public int totalExperienceAmountLimit = 9999999;
public float experienceTextMovementSpeed;
public float experienceTextMovementDelay;
public float timeToShowLevelUpPanel;
[Range (0, 1)] public float experienceAmountTextOffset;
public bool useMaxLevel;
public int maxLevel;
public bool hideExperienceSliderAfterTime;
public float timeToHideExperienceSlider;
public bool experienceMenuActive = true;
public bool experienceMenuOpened;
public float currentExperienceMultiplier = 1;
public bool experienceMultiplerEnabled;
public GameObject experienceMultiplierTextPanel;
public Text experienceMultiplerText;
public UnityEvent eventOnExperienceMultiplerEnabled;
public UnityEvent eventOnExperienceMultiplerDisabled;
public string extraTextOnLevelNumber = "LV ";
public string extraTextOnNewLevelNumber = "LV ";
public string totalExperiencePointsName = "Skill Points";
public string totalExperienceAmountName = "Experience";
public string currentLevelExperienceAmountName = "Current Level Experience Amount";
public string currentLevelExperienceToNextLevelName = "Current Level Experience To Next Level Amount";
public string currentLevelName = "Level";
public bool setLevelManually;
public eventParameters.eventToCallWithString eventOnExperienceWithoutTextPosition;
public Transform experienceSliderPanelPositionInsideMenu;
public Transform experienceSliderPanelPositionOutsideMenu;
public GameObject statsMenuPanel;
public UnityEvent eventOnExperienceMenuOpened;
public UnityEvent eventOnExperienceMenuClosed;
public playerController playerControllerManager;
public playerCamera mainPlayerCamera;
public GameObject experienceMenuGameObject;
public GameObject experienceObtaniedTextPrefab;
public Transform experienceObtainedTextParent;
public Text currentLevelText;
public GameObject levelUpPanel;
public Text levelUpText;
public RectTransform experienceTextTargetPosition;
public RectTransform experienceSliderTransform;
public Slider experienceSlider;
public GameObject experienceSliderPanel;
public bool playSoundOnLevelUpEnabled = true;
public AudioSource levelUpAudioSource;
public AudioClip levelUpAudioClip;
public AudioElement levelUpAudioElement;
public playerSkillsSystem playerSkillManager;
public playerStatsSystem playerStatsManager;
public Camera mainCamera;
public menuPause pauseManager;
public bool useEventIfSystemDisabled;
public UnityEvent eventIfSystemDisabled;
public bool callEventOnLevelReachedOnLoadEnabled = true;
public string menuPanelName = "Experience System";
Vector2 mainCanvasSizeDelta;
Vector2 halfMainCanvasSizeDelta;
Vector2 iconPosition2d;
bool usingScreenSpaceCamera;
Vector3 screenPoint;
bool targetOnScreen;
Coroutine showLevelUpCoroutine;
Coroutine showSliderCoroutine;
float angle;
float cos;
float sin;
float m;
Vector3 screenBounds;
Vector3 screenCenter;
levelInfo currentLevelInfo;
bool startInitialized;
float screenWidth;
float screenHeight;
bool isLoadingGame;
private void InitializeAudioElements ()
{
if (levelUpAudioSource != null) {
levelUpAudioElement.audioSource = levelUpAudioSource;
}
if (levelUpAudioClip != null) {
levelUpAudioElement.clip = levelUpAudioClip;
}
}
void Start ()
{
InitializeAudioElements ();
if (!experienceSystemEnabled) {
checkEventOnSystemDisabled ();
if (experienceSliderPanel.activeSelf) {
experienceSliderPanel.SetActive (false);
}
return;
}
mainCanvasSizeDelta = mainPlayerCamera.getMainCanvasSizeDelta ();
halfMainCanvasSizeDelta = mainCanvasSizeDelta * 0.5f;
usingScreenSpaceCamera = mainPlayerCamera.isUsingScreenSpaceCamera ();
if (setLevelManually && currentLevel > 1) {
for (int i = 0; i < currentLevel; i++) {
currentLevelInfo = levelInfoList [i];
totalExperienceAmount += currentLevelInfo.experienceRequiredToNextLevel;
if (i + 1 <= levelInfoList.Count) {
currentLevelInfo = levelInfoList [i + 1];
currentLevelInfo.eventsOnLevelReached.Invoke ();
currentLevelInfo.levelUnlocked = true;
totalExperiencePoints += currentLevelInfo.experiencePointsAmount;
currentLevelExperienceToNextLevel = currentLevelInfo.experienceRequiredToNextLevel;
}
}
}
if (callEventOnLevelReachedOnLoadEnabled) {
isLoadingGame = playerSkillManager.isLoadingGameActive ();
if (isLoadingGame) {
if (currentLevel > 1) {
for (int i = 0; i < currentLevel; i++) {
currentLevelInfo = levelInfoList [i];
if (currentLevelInfo.levelNumber <= currentLevel) {
if (currentLevelInfo.callEventOnLevelReachedOnLoad) {
currentLevelInfo.eventsOnLevelReached.Invoke ();
}
}
}
}
}
}
playerStatsManager.updateStatValue (totalExperiencePointsName, totalExperiencePoints);
playerStatsManager.updateStatValue (currentLevelExperienceToNextLevelName, currentLevelExperienceToNextLevel);
playerStatsManager.updateStatValue (currentLevelExperienceAmountName, currentLevelExperienceAmount);
playerStatsManager.updateStatValue (totalExperienceAmountName, totalExperienceAmount);
updateExperienceInfo ();
if (hideExperienceSliderAfterTime) {
if (experienceSliderPanel.activeSelf) {
experienceSliderPanel.SetActive (false);
}
}
StartCoroutine (initializeComponent ());
}
public void checkEventOnSystemDisabled ()
{
if (useEventIfSystemDisabled) {
eventIfSystemDisabled.Invoke ();
}
}
public bool checkIncreasePlayerLevel ()
{
if (useMaxLevel) {
if (currentLevel >= maxLevel) {
return false;
}
}
if (currentLevel <= levelInfoList.Count) {
currentLevelInfo = levelInfoList [currentLevel - 1];
if (currentLevelExperienceAmount >= currentLevelInfo.experienceRequiredToNextLevel) {
if (currentLevel + 1 <= levelInfoList.Count) {
currentLevel++;
currentLevelInfo = levelInfoList [currentLevel - 1];
currentLevelInfo.eventsOnLevelReached.Invoke ();
currentLevelInfo.levelUnlocked = true;
currentLevelExperienceAmount = currentLevelExperienceAmount - levelInfoList [currentLevel - 2].experienceRequiredToNextLevel;
totalExperiencePoints += currentLevelInfo.experiencePointsAmount;
updateExperienceInfo ();
if (startInitialized) {
showLevelUpPanel ();
}
currentLevelExperienceToNextLevel = currentLevelInfo.experienceRequiredToNextLevel;
for (int k = 0; k < currentLevelInfo.statInfoList.Count; k++) {
if (currentLevelInfo.statInfoList [k].statIsAmount) {
float extraValue = currentLevelInfo.statInfoList [k].statExtraValue;
if (currentLevelInfo.statInfoList [k].useRandomRange) {
extraValue = Random.Range (currentLevelInfo.statInfoList [k].randomRange.x, currentLevelInfo.statInfoList [k].randomRange.y);
extraValue = Mathf.RoundToInt (extraValue);
}
playerStatsManager.increasePlayerStat (currentLevelInfo.statInfoList [k].Name, extraValue);
} else {
playerStatsManager.enableOrDisableBoolPlayerStat (currentLevelInfo.statInfoList [k].Name, currentLevelInfo.statInfoList [k].newBoolState);
}
if (currentLevelInfo.statInfoList [k].unlockSkill) {
playerSkillManager.unlockSkillSlotByName (currentLevelInfo.statInfoList [k].skillNameToUnlock);
}
}
playerStatsManager.updateStatValue (totalExperiencePointsName, totalExperiencePoints);
playerStatsManager.updateStatValue (currentLevelExperienceToNextLevelName, currentLevelExperienceToNextLevel);
playerStatsManager.updateStatValue (currentLevelExperienceAmountName, currentLevelExperienceAmount);
playerStatsManager.updateStatValue (currentLevelName, currentLevel);
return true;
} else {
if (currentLevelExperienceAmount > levelInfoList [currentLevel - 1].experienceRequiredToNextLevel) {
currentLevelExperienceAmount = levelInfoList [currentLevel - 1].experienceRequiredToNextLevel;
}
if (totalExperienceAmount > totalExperienceAmountLimit) {
totalExperienceAmount = totalExperienceAmountLimit;
}
playerStatsManager.updateStatValue (totalExperienceAmountName, totalExperienceAmount);
playerStatsManager.updateStatValue (currentLevelExperienceAmountName, currentLevelExperienceAmount);
}
}
}
return false;
}
public void getExperienceAmount (int newExperienceAmount)
{
if (!experienceSystemEnabled) {
return;
}
getExperienceAmount (newExperienceAmount, null, false, "");
}
public void getExperienceAmount (int newExperienceAmount, Transform objectTransform, bool useTransformAsExpTextPosition, string extraExperienceText)
{
if (!experienceSystemEnabled) {
return;
}
newExperienceAmount *= (int)currentExperienceMultiplier;
totalExperienceAmount += newExperienceAmount;
currentLevelExperienceAmount += newExperienceAmount;
experienceSlider.value = currentLevelExperienceAmount;
playerStatsManager.updateStatValue (totalExperienceAmountName, totalExperienceAmount);
playerStatsManager.updateStatValue (currentLevelExperienceAmountName, currentLevelExperienceAmount);
float experienceAcumulated = currentLevelExperienceAmount;
if (checkIncreasePlayerLevel ()) {
for (int k = 0; k < levelInfoList.Count; k++) {
if (!levelInfoList [k].levelUnlocked) {
experienceAcumulated -= levelInfoList [currentLevel - 1].experienceRequiredToNextLevel;
if (experienceAcumulated > 0) {
checkIncreasePlayerLevel ();
}
}
}
}
if (!startInitialized) {
return;
}
if (hideExperienceSliderAfterTime) {
if (!experienceSliderPanel.activeSelf) {
experienceSliderPanel.SetActive (true);
}
showExperienceSlider ();
}
if (mainCamera == null) {
mainCamera = mainPlayerCamera.getMainCamera ();
}
if (useTransformAsExpTextPosition) {
if (!usingScreenSpaceCamera) {
screenWidth = Screen.width;
screenHeight = Screen.height;
}
Vector3 objectPosition = objectTransform.position;
if (usingScreenSpaceCamera) {
screenPoint = mainCamera.WorldToViewportPoint (objectPosition);
targetOnScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
} else {
screenPoint = mainCamera.WorldToScreenPoint (objectPosition);
targetOnScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < screenWidth && screenPoint.y > 0 && screenPoint.y < screenHeight;
}
GameObject newExperienceText = (GameObject)Instantiate (experienceObtaniedTextPrefab, Vector3.zero, Quaternion.identity, experienceObtainedTextParent);
newExperienceText.transform.localScale = Vector3.one;
if (!newExperienceText.activeSelf) {
newExperienceText.SetActive (true);
}
experienceObtainedInfo currentexperienceObtainedInfo = newExperienceText.GetComponent<experienceObtainedInfoPanel> ().experienceObtainedInfo;
if (usingScreenSpaceCamera) {
if (targetOnScreen) {
iconPosition2d = new Vector2 ((screenPoint.x * mainCanvasSizeDelta.x) - halfMainCanvasSizeDelta.x,
(screenPoint.y * mainCanvasSizeDelta.y) - halfMainCanvasSizeDelta.y);
currentexperienceObtainedInfo.experienceObtainedRectTransform.anchoredPosition = iconPosition2d;
} else {
iconPosition2d = new Vector2 ((screenPoint.x * mainCanvasSizeDelta.x) - halfMainCanvasSizeDelta.x,
(screenPoint.y * mainCanvasSizeDelta.y) - halfMainCanvasSizeDelta.y);
if (screenPoint.z < 0) {
iconPosition2d *= -1;
}
angle = Mathf.Atan2 (iconPosition2d.y, iconPosition2d.x);
angle -= 90 * Mathf.Deg2Rad;
cos = Mathf.Cos (angle);
sin = -Mathf.Sin (angle);
m = cos / sin;
screenBounds = halfMainCanvasSizeDelta * experienceAmountTextOffset;
if (cos > 0) {
iconPosition2d = new Vector2 (screenBounds.y / m, screenBounds.y);
} else {
iconPosition2d = new Vector2 (-screenBounds.y / m, -screenBounds.y);
}
if (iconPosition2d.x > screenBounds.x) {
iconPosition2d = new Vector2 (screenBounds.x, screenBounds.x * m);
} else if (iconPosition2d.x < -screenBounds.x) {
iconPosition2d = new Vector2 (-screenBounds.x, -screenBounds.x * m);
}
currentexperienceObtainedInfo.experienceObtainedRectTransform.anchoredPosition = iconPosition2d;
}
} else {
if (targetOnScreen) {
currentexperienceObtainedInfo.experienceObtainedRectTransform.position = new Vector3 (screenPoint.x, screenPoint.y, 0);
} else {
if (screenPoint.z < 0) {
screenPoint *= -1;
}
screenCenter = new Vector3 (screenWidth, screenHeight, 0) / 2;
screenPoint -= screenCenter;
angle = Mathf.Atan2 (screenPoint.y, screenPoint.x);
angle -= 90 * Mathf.Deg2Rad;
cos = Mathf.Cos (angle);
sin = -Mathf.Sin (angle);
m = cos / sin;
screenBounds = screenCenter * experienceAmountTextOffset;
if (cos > 0) {
screenPoint = new Vector3 (screenBounds.y / m, screenBounds.y, 0);
} else {
screenPoint = new Vector3 (-screenBounds.y / m, -screenBounds.y, 0);
}
if (screenPoint.x > screenBounds.x) {
screenPoint = new Vector3 (screenBounds.x, screenBounds.x * m, 0);
} else if (screenPoint.x < -screenBounds.x) {
screenPoint = new Vector3 (-screenBounds.x, -screenBounds.x * m, 0);
}
//set the position and rotation of the arrow
screenPoint += screenCenter;
currentexperienceObtainedInfo.experienceObtainedRectTransform.position = screenPoint;
}
}
currentexperienceObtainedInfo.experienceAmountText.text = newExperienceAmount + XPExtraString;
currentexperienceObtainedInfo.experienceAmount = newExperienceAmount;
currentexperienceObtainedInfo.moveExperienceTextPanel = StartCoroutine (moveExperienceTextPanelCoroutine (currentexperienceObtainedInfo));
} else {
eventOnExperienceWithoutTextPosition.Invoke (extraExperienceText + newExperienceAmount + XPExtraString);
}
}
IEnumerator moveExperienceTextPanelCoroutine (experienceObtainedInfo currentExperienceObtainedInfo)
{
yield return new WaitForSeconds (experienceTextMovementDelay);
float dist = GKC_Utils.distance (currentExperienceObtainedInfo.experienceObtainedRectTransform.position, experienceSliderTransform.position);
float duration = dist / experienceTextMovementSpeed;
float t = 0;
Vector2 targetPosition = experienceTextTargetPosition.position;
Vector2 currentPosition = currentExperienceObtainedInfo.experienceObtainedRectTransform.position;
float movementTimer = 0;
bool targetReached = false;
Vector2 experienceAmountPosition = Vector2.zero;
Vector2 experienceSliderTransformPosition = Vector2.zero;
float distance = 0;
while (!targetReached) {
t += Time.deltaTime / duration;
currentExperienceObtainedInfo.experienceObtainedRectTransform.position =
Vector2.Lerp (currentExperienceObtainedInfo.experienceObtainedRectTransform.position, targetPosition, t);
experienceAmountPosition = new Vector2 (currentExperienceObtainedInfo.experienceObtainedRectTransform.position.y, 0);
experienceSliderTransformPosition = new Vector2 (targetPosition.y, 0);
distance = GKC_Utils.distance (experienceAmountPosition, experienceSliderTransformPosition);
movementTimer += Time.deltaTime;
if (distance < 0.01f || movementTimer > (duration + 1)) {
targetReached = true;
}
yield return null;
}
Destroy (currentExperienceObtainedInfo.experienceObtainedRectTransform.gameObject);
StopCoroutine (currentExperienceObtainedInfo.moveExperienceTextPanel);
}
public void updateExperienceInfo ()
{
experienceSlider.maxValue = levelInfoList [currentLevel - 1].experienceRequiredToNextLevel;
experienceSlider.value = currentLevelExperienceAmount;
if (extraTextOnLevelNumber != "") {
currentLevelText.text = extraTextOnLevelNumber;
}
currentLevelText.text += currentLevel;
}
public void showLevelUpPanel ()
{
stopShowLevelUpPanelCoroutine ();
showLevelUpCoroutine = StartCoroutine (showLevelUpPanelCoroutine ());
}
public void stopShowLevelUpPanelCoroutine ()
{
if (showLevelUpCoroutine != null) {
StopCoroutine (showLevelUpCoroutine);
}
}
IEnumerator showLevelUpPanelCoroutine ()
{
if (playSoundOnLevelUpEnabled) {
if (levelUpAudioElement != null) {
AudioPlayer.PlayOneShot (levelUpAudioElement, gameObject);
}
}
if (!levelUpPanel.activeSelf) {
levelUpPanel.SetActive (true);
}
if (extraTextOnNewLevelNumber != "") {
levelUpText.text = extraTextOnNewLevelNumber;
}
levelUpText.text += currentLevel;
yield return new WaitForSeconds (timeToShowLevelUpPanel);
levelUpPanel.SetActive (false);
}
public void showExperienceSlider ()
{
stopShowExperienceSliderCoroutine ();
showSliderCoroutine = StartCoroutine (showExperienceSliderCoroutine ());
}
public void stopShowExperienceSliderCoroutine ()
{
if (showSliderCoroutine != null) {
StopCoroutine (showSliderCoroutine);
}
}
IEnumerator showExperienceSliderCoroutine ()
{
yield return new WaitForSeconds (timeToHideExperienceSlider);
if (experienceSliderPanel.activeSelf) {
experienceSliderPanel.SetActive (false);
}
}
public void openOrCloseExperienceMenu (bool state)
{
if (state) {
if (!pauseManager.checkIfMenuCanBeUsedByName (menuPanelName)) {
return;
}
}
bool checkResult =
(!playerControllerManager.isPlayerMenuActive () || experienceMenuOpened) &&
(!playerControllerManager.isUsingDevice () || playerControllerManager.isPlayerDriving ()) &&
!pauseManager.isGamePaused ();
if (checkResult) {
experienceMenuOpened = state;
pauseManager.openOrClosePlayerMenu (experienceMenuOpened, experienceMenuGameObject.transform, true);
experienceMenuGameObject.SetActive (experienceMenuOpened);
pauseManager.setIngameMenuOpenedState (menuPanelName, experienceMenuOpened, true);
pauseManager.enableOrDisablePlayerMenu (experienceMenuOpened, true, false);
if (experienceMenuOpened) {
updateStatsInfo ();
experienceSliderPanel.transform.SetParent (experienceSliderPanelPositionInsideMenu);
if (hideExperienceSliderAfterTime) {
if (!experienceSliderPanel.activeSelf) {
experienceSliderPanel.SetActive (true);
}
}
eventOnExperienceMenuOpened.Invoke ();
} else {
experienceSliderPanel.transform.SetParent (experienceSliderPanelPositionOutsideMenu);
if (hideExperienceSliderAfterTime) {
if (experienceSliderPanel.activeSelf) {
experienceSliderPanel.SetActive (false);
}
}
eventOnExperienceMenuClosed.Invoke ();
}
experienceSliderPanel.transform.localPosition = Vector3.zero;
}
}
public void enableOrDisableHUD (bool state)
{
if (!hideExperienceSliderAfterTime) {
if (experienceSliderPanel.activeSelf != state) {
experienceSliderPanel.SetActive (state);
}
}
}
public void openOrCLoseObjectiveMenuFromTouch ()
{
openOrCloseExperienceMenu (!experienceMenuOpened);
}
public void inputOpenOrCloseObjectiveMenu ()
{
if (experienceMenuActive) {
if (pauseManager.isOpenOrClosePlayerOpenMenuByNamePaused ()) {
return;
}
openOrCloseExperienceMenu (!experienceMenuOpened);
}
}
public void updateStatsInfo ()
{
for (int i = 0; i < statUIInfoList.Count; i++) {
if (statUIInfoList [i].statIsAmount) {
statUIInfoList [i].statAmountText.text =
statUIInfoList [i].extraTextAtStart + playerStatsManager.getStatValue (statUIInfoList [i].Name) + statUIInfoList [i].extraTextAtEnd;
} else {
statUIInfoList [i].statAmountText.text =
statUIInfoList [i].extraTextAtStart + playerStatsManager.getBoolStatValue (statUIInfoList [i].Name) + statUIInfoList [i].extraTextAtEnd;
}
}
}
public void initializeCurrentLevelExperienceAmount (float newValue)
{
currentLevelExperienceAmount = (int)newValue;
updateComponent ();
}
public void initializeTotalExperienceAmount (float newValue)
{
totalExperienceAmount = (int)newValue;
updateComponent ();
}
public void initializeTotalExperiencePointsAmount (float newValue)
{
totalExperiencePoints = (int)newValue;
updateComponent ();
}
public void initializeCurrentLevelAmount (float newValue)
{
currentLevel = (int)newValue;
updateComponent ();
}
public void increaseTotalExperiencePointsAmount (float extraValue)
{
totalExperiencePoints += (int)extraValue;
}
public void increaseTotalExperienceAmount (float extraValue)
{
totalExperienceAmount += ((int)extraValue * (int)currentExperienceMultiplier);
}
public void initializeCurrentLevelExperienceToNextLevelAmount (float newValue)
{
currentLevelExperienceToNextLevel = (int)newValue;
updateComponent ();
}
public void updateCurrentLevelAmountWithoutUpdatingStatManager (int statId, float amount)
{
currentLevel = (int)amount;
}
public void updateTotalExperiencePointsAmountWithoutUpdatingStatManager (int statId, float amount)
{
totalExperiencePoints = (int)amount;
}
public void updateTotalExperienceAmountWithoutUpdatingStatManager (int statId, float amount)
{
totalExperienceAmount = (int)amount;
}
public void updateCurrentLevelExperienceToNextLevelAmountWithoutUpdatingStatManager (int statId, float amount)
{
currentLevelExperienceToNextLevel = (int)amount;
}
public void updateCurrentLevelExperienceAmountWithoutUpdatingStatManager (int statId, float amount)
{
currentLevelExperienceAmount = (int)amount;
}
public int getCurrentLevel ()
{
return currentLevel;
}
public int getSkillPointsAmount ()
{
return totalExperiencePoints;
}
public void useSkillPoints (int amountToUse)
{
totalExperiencePoints -= amountToUse;
if (totalExperiencePoints < 0) {
totalExperiencePoints = 0;
}
playerStatsManager.updateStatValue (totalExperiencePointsName, totalExperiencePoints);
updateStatsInfo ();
}
public void getSkillPoints (int amountToUse)
{
totalExperiencePoints += amountToUse;
playerStatsManager.updateStatValue (totalExperiencePointsName, totalExperiencePoints);
}
Coroutine experienceMultiplierCoroutine;
public void setExperienceMultiplier (float experienceMultiplierAmount, float experienceMultiplierDuration)
{
stopSetExperienceMultiplier ();
experienceMultiplierCoroutine = StartCoroutine (setExperienceMultiplierCoroutine (experienceMultiplierAmount, experienceMultiplierDuration));
}
public void stopSetExperienceMultiplier ()
{
if (experienceMultiplierCoroutine != null) {
StopCoroutine (experienceMultiplierCoroutine);
}
}
IEnumerator setExperienceMultiplierCoroutine (float experienceMultiplierAmount, float experienceMultiplierDuration)
{
currentExperienceMultiplier = experienceMultiplierAmount;
experienceMultiplerEnabled = true;
eventOnExperienceMultiplerEnabled.Invoke ();
if (!experienceMultiplierTextPanel.activeSelf) {
experienceMultiplierTextPanel.SetActive (true);
}
experienceMultiplerText.text = currentExperienceMultiplier.ToString ();
yield return new WaitForSeconds (experienceMultiplierDuration);
currentExperienceMultiplier = 1;
experienceMultiplerEnabled = true;
eventOnExperienceMultiplerDisabled.Invoke ();
experienceMultiplierTextPanel.SetActive (false);
}
IEnumerator initializeComponent ()
{
yield return new WaitForSeconds (0.3f);
startInitialized = true;
}
public void enableOrDisableStatsMenuPanel (bool state)
{
if (statsMenuPanel.activeSelf != state) {
statsMenuPanel.SetActive (state);
}
}
public void setExperienceSystemEnabledState (bool state)
{
experienceSystemEnabled = state;
}
public void setHideExperienceSliderAfterTimeState (bool state)
{
hideExperienceSliderAfterTime = state;
}
void updateComponent ()
{
GKC_Utils.updateComponent (this);
GKC_Utils.updateDirtyScene ("Update Experience System ", gameObject);
}
[System.Serializable]
public class levelInfo
{
public string Name;
public int levelNumber;
public int experienceRequiredToNextLevel;
public int experiencePointsAmount;
public bool levelUnlocked;
public List<statInfo> statInfoList = new List<statInfo> ();
public UnityEvent eventsOnLevelReached;
public bool callEventOnLevelReachedOnLoad;
}
[System.Serializable]
public class statInfo
{
public string Name;
public bool statIsAmount = true;
public float statExtraValue;
public bool useRandomRange;
public Vector2 randomRange;
public bool newBoolState;
public bool unlockSkill;
public string skillNameToUnlock;
}
[System.Serializable]
public class experienceObtainedInfo
{
public RectTransform experienceObtainedRectTransform;
public Text experienceAmountText;
public int experienceAmount;
public Coroutine moveExperienceTextPanel;
}
[System.Serializable]
public class statUIInfo
{
public string Name;
public Text statAmountText;
public string extraTextAtStart;
public string extraTextAtEnd;
public bool statIsAmount = true;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 73710db372bca214e85e6b14d7cf71c1
timeCreated: 1564271361
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/Experience System/playerExperienceSystem.cs
uploadId: 814740