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,19 @@
fileFormatVersion: 2
guid: a0ff6b1613960d548ab8bf97f2ad4483
timeCreated: 1536797273
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/Objectives Mission System/objectiveEventSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,785 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using GKC.Localization;
public class objectiveLogSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool openMenuEnabled = true;
public bool objectiveMenuActive = true;
public bool checkMinLevelOnMissions;
public Color buttonUsable;
public Color buttonNotUsable;
public bool saveCurrentPlayerMissionsToSaveFile;
public string menuPanelName = "Objective Log System";
public string mainMissionManagerName = "Mission Manager";
[Space]
[Header ("Debug")]
[Space]
public bool showDebugPrint;
public bool objectiveMenuOpened;
public bool objectiveInProcess;
public List<objectiveSlotInfo> objectiveSlotInfoList = new List<objectiveSlotInfo> ();
[Space]
[Header ("Events Settings")]
[Space]
public bool useEventIfSystemDisabled;
public UnityEvent eventIfSystemDisabled;
[Space]
[Header ("UI Components")]
[Space]
public GameObject objectiveMenuGameObject;
public GameObject objectiveSlotPrefab;
public Text objectiveNameText;
public Text objectiveDescriptionText;
public Text objectiveFullDescriptionText;
public Text objectiveRewardsText;
public Image activeObjectiveButtonImage;
public Image cancelObjectiveButtonImage;
public Transform objectiveListContent;
public Scrollbar missionListScrollbar;
public Scrollbar missionInfoScrollbar;
public Scrollbar missionRewardScrollbar;
Coroutine missionListScrollbarCoroutine;
Coroutine missionInfoScrollbarCoroutine;
Coroutine missionRewardScrollbarCoroutine;
[Space]
[Header ("Components")]
[Space]
public GameObject playerControllerGameObject;
public menuPause pauseManager;
public playerController playerControllerManager;
public objectiveManager mainObjectiveManager;
objectiveSlotInfo currentObjectiveSlot;
objectiveEventSystem currentObjectiveEventManager;
bool mainObjectiveManagerLocated;
public void initializeMissionValues ()
{
//Load the missions saved previously with those missions found by the player or activated in some way, setting their state or complete or not complete
if (!objectiveMenuActive) {
checkEventOnSystemDisabled ();
return;
}
//Search for an objectives manager in the level, if no one is present, add one
mainObjectiveManagerLocated = mainObjectiveManager != null;
if (!mainObjectiveManagerLocated) {
mainObjectiveManager = objectiveManager.Instance;
mainObjectiveManagerLocated = mainObjectiveManager != null;
}
if (!mainObjectiveManagerLocated) {
GKC_Utils.instantiateMainManagerOnSceneWithTypeOnApplicationPlaying (objectiveManager.getMainManagerName (), typeof (objectiveManager), true);
mainObjectiveManager = objectiveManager.Instance;
mainObjectiveManagerLocated = mainObjectiveManager != null;
}
if (!mainObjectiveManagerLocated) {
mainObjectiveManager = FindObjectOfType<objectiveManager> ();
mainObjectiveManagerLocated = mainObjectiveManager != null;
}
updateObjectiveTextContent ("", "", "", "");
}
public objectiveEventSystem getObjectiveEventSystem (int missionID, int missionSceneToSearch)
{
if (mainObjectiveManagerLocated) {
return mainObjectiveManager.getObjectiveEventSystem (missionID, missionSceneToSearch);
}
return null;
}
public void checkEventOnSystemDisabled ()
{
if (useEventIfSystemDisabled) {
eventIfSystemDisabled.Invoke ();
}
}
public void setButtonsColor (bool activeObjectiveColor, bool cancelObjectiveColor)
{
if (activeObjectiveColor) {
activeObjectiveButtonImage.color = buttonUsable;
} else {
activeObjectiveButtonImage.color = buttonNotUsable;
}
if (cancelObjectiveColor) {
cancelObjectiveButtonImage.color = buttonUsable;
} else {
cancelObjectiveButtonImage.color = buttonNotUsable;
}
}
public void activeObjective ()
{
if (currentObjectiveSlot != null && currentObjectiveSlot.objectiveEventManager != null) {
if (!currentObjectiveSlot.objectiveEventManager.isObjectiveComplete () && !currentObjectiveSlot.objectiveEventManager.isObjectiveInProcess ()) {
currentObjectiveSlot.objectiveEventManager.startObjective ();
if (!currentObjectiveSlot.currentObjectiveIcon.activeSelf) {
currentObjectiveSlot.currentObjectiveIcon.SetActive (true);
}
bool isMissionCanBeCancelledEnabled = currentObjectiveSlot.objectiveEventManager.isMissionCanBeCancelledEnabled ();
setButtonsColor (false, isMissionCanBeCancelledEnabled);
currentObjectiveEventManager = currentObjectiveSlot.objectiveEventManager;
}
}
}
public void cancelObjective ()
{
if (currentObjectiveSlot != null && currentObjectiveSlot.objectiveEventManager != null) {
bool isMissionCanBeCancelledEnabled = currentObjectiveSlot.objectiveEventManager.isMissionCanBeCancelledEnabled ();
if (!isMissionCanBeCancelledEnabled) {
return;
}
if (!currentObjectiveSlot.objectiveEventManager.isObjectiveComplete ()) {
currentObjectiveSlot.objectiveEventManager.stopObjective ();
if (currentObjectiveSlot != null) {
if (currentObjectiveSlot.currentObjectiveIcon.activeSelf) {
currentObjectiveSlot.currentObjectiveIcon.SetActive (false);
}
setButtonsColor (true, false);
} else {
setButtonsColor (false, false);
}
// if (currentObjectiveSlot.objectiveEventManager.removeMissionSlotFromObjectiveLogOnCancelMission) {
// removeObjectiveSlotFromMenu (currentObjectiveSlot.objectiveEventManager.missionID, currentObjectiveSlot.objectiveEventManager.missionScene);
// }
}
}
}
public void objectiveComplete (objectiveEventSystem currentObjectiveEventSystem)
{
int objectiveSlotInfoListCount = objectiveSlotInfoList.Count;
for (int i = 0; i < objectiveSlotInfoListCount; i++) {
objectiveSlotInfo currentObjectiveSlotInfo = objectiveSlotInfoList [i];
if (currentObjectiveSlotInfo.objectiveEventManager == currentObjectiveEventSystem) {
updateObjectiveCompleteSlotInfo (i);
objectiveInProcess = false;
}
}
}
public void updateObjectiveCompleteSlotInfo (int objectiveSlotIndex)
{
objectiveSlotInfo currentObjectiveSlotInfo = objectiveSlotInfoList [objectiveSlotIndex];
bool enableObjectiveSlotResult = false;
if (currentObjectiveSlotInfo.addObjectiveToPlayerLogSystem) {
if (currentObjectiveSlotInfo.disableObjectivePanelOnMissionComplete) {
enableObjectiveSlotResult = false;
} else {
if (currentObjectiveSlotInfo.currentObjectiveIcon.activeSelf) {
currentObjectiveSlotInfo.currentObjectiveIcon.SetActive (false);
}
if (!currentObjectiveSlotInfo.objectiveCompletePanel.activeSelf) {
currentObjectiveSlotInfo.objectiveCompletePanel.SetActive (true);
}
if (!currentObjectiveSlotInfo.objectiveCompleteText.activeSelf) {
currentObjectiveSlotInfo.objectiveCompleteText.SetActive (true);
}
enableObjectiveSlotResult = true;
}
} else {
enableObjectiveSlotResult = false;
}
if (currentObjectiveSlotInfo.objectiveSlotGameObject.activeSelf != enableObjectiveSlotResult) {
currentObjectiveSlotInfo.objectiveSlotGameObject.SetActive (enableObjectiveSlotResult);
}
currentObjectiveSlotInfo.missionInProcess = false;
currentObjectiveSlotInfo.missionComplete = true;
}
public void updateSubObjectiveCompleteListSlotInfo (int objectiveSlotIndex, List<bool> subObjectiveCompleteList)
{
objectiveSlotInfo currentObjectiveSlotInfo = objectiveSlotInfoList [objectiveSlotIndex];
currentObjectiveSlotInfo.subObjectiveCompleteList = subObjectiveCompleteList;
}
public void activeObjective (objectiveEventSystem currentObjectiveEventSystem)
{
int objectiveSlotInfoListCount = objectiveSlotInfoList.Count;
for (int i = 0; i < objectiveSlotInfoListCount; i++) {
objectiveSlotInfo currentObjectiveSlotInfo = objectiveSlotInfoList [i];
if (currentObjectiveSlotInfo.objectiveEventManager == currentObjectiveEventSystem) {
if (!currentObjectiveSlotInfo.currentObjectiveIcon.activeSelf) {
currentObjectiveSlotInfo.currentObjectiveIcon.SetActive (true);
}
currentObjectiveEventManager = currentObjectiveSlotInfo.objectiveEventManager;
currentObjectiveSlotInfo.missionInProcess = true;
objectiveInProcess = true;
}
}
}
public void cancelObjective (objectiveEventSystem currentObjectiveEventSystem)
{
int objectiveSlotInfoListCount = objectiveSlotInfoList.Count;
for (int i = 0; i < objectiveSlotInfoListCount; i++) {
objectiveSlotInfo currentObjectiveSlotInfo = objectiveSlotInfoList [i];
if (currentObjectiveSlotInfo.objectiveEventManager == currentObjectiveEventSystem) {
if (currentObjectiveSlotInfo.currentObjectiveIcon.activeSelf) {
currentObjectiveSlotInfo.currentObjectiveIcon.SetActive (false);
}
objectiveInProcess = false;
currentObjectiveSlotInfo.missionInProcess = false;
if (currentObjectiveEventSystem.isRemoveMissionSlotFromObjectiveLogOnCancelMissionEnabled ()) {
removeObjectiveSlotFromMenu (currentObjectiveEventSystem.missionID, currentObjectiveEventSystem.missionScene);
}
}
}
}
public void cancelCurrentMissionOnPlayerDead ()
{
if (currentObjectiveEventManager != null) {
if (currentObjectiveEventManager.isCancelMissionIfPlayerDiesEnabled ()) {
cancelPreviousObjective ();
}
}
}
public void cancelPreviousObjective ()
{
if (currentObjectiveEventManager != null) {
if (currentObjectiveEventManager.isObjectiveInProcess ()) {
currentObjectiveEventManager.cancelPreviousObjective ();
}
}
}
public objectiveEventSystem getCurrentObjectiveEventSystem ()
{
return currentObjectiveEventManager;
}
public void showObjectiveInformation (GameObject objectiveSlot)
{
if (currentObjectiveSlot != null && currentObjectiveSlot.selectedObjectiveIcon.activeSelf) {
currentObjectiveSlot.selectedObjectiveIcon.SetActive (false);
}
int objectiveSlotInfoListCount = objectiveSlotInfoList.Count;
for (int i = 0; i < objectiveSlotInfoListCount; i++) {
objectiveSlotInfo currentObjectiveSlotInfo = objectiveSlotInfoList [i];
if (currentObjectiveSlotInfo.objectiveSlotGameObject == objectiveSlot) {
currentObjectiveSlot = currentObjectiveSlotInfo;
updateObjectiveTextContent (currentObjectiveSlot.objectiveName, currentObjectiveSlot.objectiveDescription,
currentObjectiveSlot.objectiveFullDescription, currentObjectiveSlot.objectiveRewards);
if (!currentObjectiveSlot.selectedObjectiveIcon.activeSelf) {
currentObjectiveSlot.selectedObjectiveIcon.SetActive (true);
}
if (currentObjectiveSlot.objectiveEventManager != null) {
if (!currentObjectiveSlot.objectiveEventManager.isObjectiveComplete ()) {
if (currentObjectiveSlot.objectiveEventManager.isObjectiveInProcess ()) {
bool isMissionCanBeCancelledEnabled = currentObjectiveSlot.objectiveEventManager.isMissionCanBeCancelledEnabled ();
setButtonsColor (false, isMissionCanBeCancelledEnabled);
} else {
setButtonsColor (true, false);
}
} else {
setButtonsColor (false, false);
}
} else {
setButtonsColor (false, false);
}
return;
}
}
setButtonsColor (false, false);
}
public void updateUIElements ()
{
if (objectiveInProcess) {
currentObjectiveEventManager.updateUIElements ();
}
int objectiveSlotInfoListCount = objectiveSlotInfoList.Count;
for (int i = 0; i < objectiveSlotInfoListCount; i++) {
objectiveSlotInfo currentObjectiveSlotInfo = objectiveSlotInfoList [i];
string objectiveName = currentObjectiveSlotInfo.objectiveName;
string objectiveLocation = currentObjectiveSlotInfo.objectiveLocation;
if (gameLanguageSelector.isCheckLanguageActive ()) {
objectiveName = missionLocalizationManager.GetLocalizedValue (objectiveName);
objectiveLocation = missionLocalizationManager.GetLocalizedValue (objectiveLocation);
}
if (currentObjectiveSlotInfo.objectiveMenuIconElementManager != null) {
currentObjectiveSlotInfo.objectiveMenuIconElementManager.objectiveNameText.text = objectiveName;
currentObjectiveSlotInfo.objectiveMenuIconElementManager.objectiveLocationText.text = objectiveLocation;
}
}
}
public void updateObjectiveTextContent (string objectiveName, string objectiveDescription, string objectiveFullDescription, string objectiveRewards)
{
if (gameLanguageSelector.isCheckLanguageActive ()) {
objectiveName = missionLocalizationManager.GetLocalizedValue (objectiveName);
objectiveDescription = missionLocalizationManager.GetLocalizedValue (objectiveDescription);
objectiveFullDescription = missionLocalizationManager.GetLocalizedValue (objectiveFullDescription);
objectiveRewards = missionLocalizationManager.GetLocalizedValue (objectiveRewards);
}
objectiveNameText.text = objectiveName;
objectiveDescriptionText.text = objectiveDescription;
objectiveFullDescriptionText.text = objectiveFullDescription;
objectiveRewardsText.text = objectiveRewards;
}
public void addObjective (string objectiveName, string objectiveDescription, string objectiveFullDescription, string objectiveLocation,
string objectiveRewards, objectiveEventSystem currentObjectiveEventSystem, bool addObjectiveToPlayerLogSystem)
{
bool addNewObjectivePanel = true;
objectiveSlotInfo newObjectiveSlotInfo = new objectiveSlotInfo ();
if (currentObjectiveEventSystem != null) {
int objectiveSlotInfoListCount = objectiveSlotInfoList.Count;
for (int i = 0; i < objectiveSlotInfoListCount; i++) {
if (objectiveSlotInfoList [i].objectiveEventManager != null) {
if (objectiveSlotInfoList [i].objectiveEventManager == currentObjectiveEventSystem) {
return;
}
} else {
if (objectiveSlotInfoList [i].missionID == currentObjectiveEventSystem.missionID &&
objectiveSlotInfoList [i].missionScene == currentObjectiveEventSystem.missionScene) {
if (objectiveSlotInfoList [i].missionComplete) {
return;
}
newObjectiveSlotInfo = objectiveSlotInfoList [i];
addNewObjectivePanel = false;
}
}
}
}
if (addNewObjectivePanel) {
GameObject newObjectiveSlotPrefab = (GameObject)Instantiate (objectiveSlotPrefab, objectiveSlotPrefab.transform.position, Quaternion.identity, objectiveListContent);
if (!newObjectiveSlotPrefab.activeSelf) {
newObjectiveSlotPrefab.SetActive (true);
}
newObjectiveSlotPrefab.transform.localScale = Vector3.one;
newObjectiveSlotPrefab.transform.localPosition = Vector3.zero;
objectiveMenuIconElement currentobjectiveMenuIconElement = newObjectiveSlotPrefab.GetComponent<objectiveMenuIconElement> ();
if (gameLanguageSelector.isCheckLanguageActive ()) {
objectiveName = missionLocalizationManager.GetLocalizedValue (objectiveName);
objectiveLocation = missionLocalizationManager.GetLocalizedValue (objectiveLocation);
}
currentobjectiveMenuIconElement.objectiveNameText.text = objectiveName;
currentobjectiveMenuIconElement.objectiveLocationText.text = objectiveLocation;
newObjectiveSlotInfo.objectiveMenuIconElementManager = currentobjectiveMenuIconElement;
newObjectiveSlotInfo.objectiveSlotGameObject = newObjectiveSlotPrefab;
newObjectiveSlotInfo.objectiveName = objectiveName;
newObjectiveSlotInfo.objectiveLocation = objectiveLocation;
newObjectiveSlotInfo.objectiveRewards = objectiveRewards;
newObjectiveSlotInfo.objectiveDescription = objectiveDescription;
newObjectiveSlotInfo.objectiveFullDescription = objectiveFullDescription;
newObjectiveSlotInfo.currentObjectiveIcon = currentobjectiveMenuIconElement.currentObjectiveIcon;
newObjectiveSlotInfo.objectiveCompletePanel = currentobjectiveMenuIconElement.objectiveCompletePanel;
newObjectiveSlotInfo.selectedObjectiveIcon = currentobjectiveMenuIconElement.selectedObjectiveIcon;
newObjectiveSlotInfo.objectiveCompleteText = currentobjectiveMenuIconElement.objectiveCompleteText;
newObjectiveSlotInfo.addObjectiveToPlayerLogSystem = addObjectiveToPlayerLogSystem;
}
if (currentObjectiveEventSystem != null) {
newObjectiveSlotInfo.missionID = currentObjectiveEventSystem.missionID;
newObjectiveSlotInfo.disableObjectivePanelOnMissionComplete = currentObjectiveEventSystem.disableObjectivePanelOnMissionComplete;
newObjectiveSlotInfo.missionScene = currentObjectiveEventSystem.missionScene;
newObjectiveSlotInfo.objectiveEventManager = currentObjectiveEventSystem;
newObjectiveSlotInfo.missionAccepted = true;
currentObjectiveEventSystem.setMissionAcceptedState (true);
if (showDebugPrint) {
print (currentObjectiveEventSystem.objectiveInfoList.Count + " " + currentObjectiveEventSystem.generalObjectiveName);
}
for (int i = 0; i < currentObjectiveEventSystem.objectiveInfoList.Count; i++) {
bool subObjectiveComplete = currentObjectiveEventSystem.objectiveInfoList [i].subObjectiveComplete;
newObjectiveSlotInfo.subObjectiveCompleteList.Add (subObjectiveComplete);
}
}
if (!addObjectiveToPlayerLogSystem) {
if (newObjectiveSlotInfo.objectiveSlotGameObject.activeSelf) {
newObjectiveSlotInfo.objectiveSlotGameObject.SetActive (false);
}
}
if (addNewObjectivePanel) {
objectiveSlotInfoList.Add (newObjectiveSlotInfo);
}
if (showDebugPrint) {
print ("Activating mission " + objectiveName);
}
}
public void removeObjectiveSlotFromMenu (int missionID, int missionScene)
{
int objectiveSlotInfoListCount = objectiveSlotInfoList.Count;
for (int k = 0; k < objectiveSlotInfoListCount; k++) {
objectiveSlotInfo currentObjectiveSlotInfo = objectiveSlotInfoList [k];
if (currentObjectiveSlotInfo.missionID == missionID && currentObjectiveSlotInfo.missionScene == missionScene) {
if (currentObjectiveSlotInfo.objectiveSlotGameObject != null) {
Destroy (currentObjectiveSlotInfo.objectiveSlotGameObject);
objectiveSlotInfoList.RemoveAt (k);
currentObjectiveSlot = null;
setButtonsColor (false, false);
updateObjectiveTextContent ("", "", "", "");
}
return;
}
}
}
public void openOrCloseObjectiveMenu (bool state)
{
if (state) {
if (!pauseManager.checkIfMenuCanBeUsedByName (menuPanelName)) {
return;
}
}
bool checkResult =
(!playerControllerManager.isPlayerMenuActive () || objectiveMenuOpened) &&
(!playerControllerManager.isUsingDevice () || playerControllerManager.isPlayerDriving ()) &&
!pauseManager.isGamePaused ();
if (checkResult) {
objectiveMenuOpened = state;
pauseManager.openOrClosePlayerMenu (objectiveMenuOpened, objectiveMenuGameObject.transform, true);
if (objectiveMenuGameObject.activeSelf != objectiveMenuOpened) {
objectiveMenuGameObject.SetActive (objectiveMenuOpened);
}
pauseManager.setIngameMenuOpenedState ("Objective Log System", objectiveMenuOpened, true);
pauseManager.enableOrDisablePlayerMenu (objectiveMenuOpened, true, false);
if (currentObjectiveSlot != null && currentObjectiveSlot.selectedObjectiveIcon.activeSelf) {
currentObjectiveSlot.selectedObjectiveIcon.SetActive (false);
}
currentObjectiveSlot = null;
setButtonsColor (false, false);
updateObjectiveTextContent ("", "", "", "");
if (objectiveMenuOpened) {
resetScrollBarPosition (missionListScrollbar, ref missionListScrollbarCoroutine);
resetScrollBarPosition (missionInfoScrollbar, ref missionInfoScrollbarCoroutine);
resetScrollBarPosition (missionRewardScrollbar, ref missionRewardScrollbarCoroutine);
resetPanelSlotsRectTransform (objectiveListContent, objectiveListContent.GetComponent<ScrollRect> ());
}
}
}
public void checkOpenOrCloseObjectiveMenuFromTouch ()
{
if (pauseManager.isOpenOrClosePlayerOpenMenuByNamePaused ()) {
return;
}
openOrCLoseObjectiveMenuFromTouch ();
}
public void openOrCLoseObjectiveMenuFromTouch ()
{
openOrCloseObjectiveMenu (!objectiveMenuOpened);
}
public void inputOpenOrCloseObjectiveMenu ()
{
if (!openMenuEnabled) {
return;
}
if (objectiveMenuActive) {
if (pauseManager.isOpenOrClosePlayerOpenMenuByNamePaused ()) {
return;
}
openOrCloseObjectiveMenu (!objectiveMenuOpened);
}
}
public void resetScrollBarPosition (Scrollbar scrollBarToReset, ref Coroutine scrollBarCoroutine)
{
if (scrollBarToReset != null) {
if (scrollBarCoroutine != null) {
StopCoroutine (scrollBarCoroutine);
}
scrollBarCoroutine = StartCoroutine (resetScroll (scrollBarToReset));
}
}
private IEnumerator resetScroll (Scrollbar scrollBarToReset)
{
yield return new WaitForEndOfFrame ();
yield return new WaitForEndOfFrame ();
scrollBarToReset.value = 1;
}
public void resetPanelSlotsRectTransform (Transform panelTransform, ScrollRect panelScrollRect)
{
StartCoroutine (resetRectTransformCoroutine (panelTransform, panelScrollRect));
}
IEnumerator resetRectTransformCoroutine (Transform panelTransform, ScrollRect panelScrollRect)
{
LayoutRebuilder.ForceRebuildLayoutImmediate (panelTransform.GetComponent<RectTransform> ());
yield return new WaitForEndOfFrame ();
yield return new WaitForEndOfFrame ();
if (panelScrollRect != null) {
panelScrollRect.verticalNormalizedPosition = 1;
}
}
public bool isObjectiveMenuActive ()
{
return objectiveMenuActive;
}
public bool isObjectiveInProcess ()
{
return objectiveInProcess;
}
public bool isCheckMinLevelOnMissionsEnabled ()
{
return checkMinLevelOnMissions;
}
public void setObtainedRewardState (int missionID, int missionScene, bool state)
{
int objectiveSlotInfoListCount = objectiveSlotInfoList.Count;
for (int k = 0; k < objectiveSlotInfoListCount; k++) {
objectiveSlotInfo currentObjectiveSlotInfo = objectiveSlotInfoList [k];
if (currentObjectiveSlotInfo.missionID == missionID && currentObjectiveSlotInfo.missionScene == missionScene) {
currentObjectiveSlotInfo.rewardObtained = state;
}
}
}
public void setSubObjectiveCompleteState (int missionID, int missionScene, int subObjectiveIndex, bool state)
{
int objectiveSlotInfoListCount = objectiveSlotInfoList.Count;
for (int k = 0; k < objectiveSlotInfoListCount; k++) {
objectiveSlotInfo currentObjectiveSlotInfo = objectiveSlotInfoList [k];
if (currentObjectiveSlotInfo.missionID == missionID && currentObjectiveSlotInfo.missionScene == missionScene) {
if (showDebugPrint) {
print (objectiveSlotInfoList [k].subObjectiveCompleteList.Count + " " + subObjectiveIndex);
}
if (currentObjectiveSlotInfo.subObjectiveCompleteList.Count > subObjectiveIndex) {
currentObjectiveSlotInfo.subObjectiveCompleteList [subObjectiveIndex] = state;
}
}
}
}
public void setObjectiveMenuActiveState (bool state)
{
objectiveMenuActive = state;
}
public void setOpenMenuEnabled (bool state)
{
openMenuEnabled = state;
}
//EDITOR FUNCTIONS
public void setObjectiveMenuActiveStateFromEditor (bool state)
{
setObjectiveMenuActiveState (state);
updateComponent ();
}
public void setOpenMenuEnabledFromEditor (bool state)
{
setOpenMenuEnabled (state);
updateComponent ();
}
void updateComponent ()
{
GKC_Utils.updateComponent (this);
GKC_Utils.updateDirtyScene ("Update objective log system", gameObject);
}
[System.Serializable]
public class objectiveSlotInfo
{
public GameObject objectiveSlotGameObject;
public string objectiveName;
public string objectiveDescription;
public string objectiveFullDescription;
public string objectiveLocation;
public string objectiveRewards;
public GameObject currentObjectiveIcon;
public GameObject objectiveCompletePanel;
public GameObject selectedObjectiveIcon;
public GameObject objectiveCompleteText;
public GameObject objectiveAcceptedText;
public bool disableObjectivePanelOnMissionComplete;
public bool addObjectiveToPlayerLogSystem;
public bool slotSelectedByPlayer;
public bool missionComplete;
public bool missionInProcess;
public bool rewardObtained;
public bool missionAccepted;
public int missionScene;
public int missionID;
public objectiveMenuIconElement objectiveMenuIconElementManager;
public objectiveEventSystem objectiveEventManager;
public List<bool> subObjectiveCompleteList = new List<bool> ();
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 5f6b7201ce702494e972dd79e5f5f13a
timeCreated: 1536944171
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/Objectives Mission System/objectiveLogSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,383 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class objectiveManager : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public int missionScene;
[Space]
[Header ("Objective Station System List Settings")]
[Space]
public List<objectiveStationSystem> objectiveStationSystemList = new List<objectiveStationSystem> ();
[Space]
[Header ("Prefabs List")]
[Space]
public LayerMask layerToPlaceObjects;
public GameObject missionStationPrefab;
public GameObject missionSystemPrefab;
public GameObject emptyMissionStationPrefab;
public GameObject characterMissionSystemPrefab;
[Space]
[Header ("Other Elements")]
[Space]
[TextArea (5, 20)]
public string explanation = "This is the main mission manager, and it contains a list of all the station systems in each level. These station systems " +
"can be used as a physical mission board or just an invisible element to configure different missions which are maybe activate by dialog or trigger." +
"\n\n" + "" + "Each station has a list of missions, which are the one which contains the missions to achieve, task, rewards and events to activate.";
//Main Objective Manager, this component stores all the station systems in each level, managing their states. Each station system can be a physical station to get missions
//Or used as a hidden mission manager to missions which are obtained by conversations with NPCs, with the dialog system or directly by triggers placed anywhere
//So this component manages a list of station systems in the level, each one with different missions assigned and configured on them
objectiveStationSystem currentObjectiveStationSystem;
objectiveStationSystem.objectiveInfo currentObjectiveInfo;
public const string mainManagerName = "Mission Manager";
public static string getMainManagerName ()
{
return mainManagerName;
}
private static objectiveManager _objectiveManagerInstance;
public static objectiveManager Instance { get { return _objectiveManagerInstance; } }
bool instanceInitialized;
public void getComponentInstance ()
{
if (instanceInitialized) {
return;
}
if (_objectiveManagerInstance != null && _objectiveManagerInstance != this) {
Destroy (this.gameObject);
return;
}
_objectiveManagerInstance = this;
instanceInitialized = true;
}
void Awake ()
{
getComponentInstance ();
}
void Start ()
{
//Check the missions which are not complete yet after loading the current info saved previously
int objectiveStationSystemListCount = objectiveStationSystemList.Count;
for (int i = 0; i < objectiveStationSystemListCount; i++) {
if (objectiveStationSystemList [i] != null) {
objectiveStationSystemList [i].checkMissionsState ();
} else {
print ("WARNING: there is a list of missions stations configured in this main mission manager but the element is empty or missing, please make sure " +
"the mission station system is configured properly in the list of this main mission manager");
}
}
}
public objectiveEventSystem getObjectiveEventSystem (int missionID, int missionSceneToSearch)
{
//Get each mission configured in each station system, searching by ID
if (objectiveStationSystemList.Count == 0) {
getAllStationSystemOnLevel ();
}
int objectiveStationSystemListCount = objectiveStationSystemList.Count;
//Return the mission system currently found by ID
for (int i = 0; i < objectiveStationSystemListCount; i++) {
currentObjectiveStationSystem = objectiveStationSystemList [i];
int objectiveInfoListCount = currentObjectiveStationSystem.objectiveInfoList.Count;
for (int j = 0; j < objectiveInfoListCount; j++) {
currentObjectiveInfo = currentObjectiveStationSystem.objectiveInfoList [j];
if (currentObjectiveInfo != null) {
if (currentObjectiveInfo.mainObjectiveEventSystem.missionID == missionID &&
currentObjectiveInfo.mainObjectiveEventSystem.missionScene == missionSceneToSearch) {
return currentObjectiveInfo.mainObjectiveEventSystem;
}
}
}
}
return null;
}
public void getAllStationSystemOnLevel ()
{
//Search all the station systems on the level, so they can be managed here
objectiveStationSystemList.Clear ();
objectiveStationSystem [] newObjectiveStationSystemList = FindObjectsOfType<objectiveStationSystem> ();
foreach (objectiveStationSystem currentObjectiveStationSystem in newObjectiveStationSystemList) {
if (!objectiveStationSystemList.Contains (currentObjectiveStationSystem)) {
objectiveStationSystemList.Add (currentObjectiveStationSystem);
}
}
updateComponent ();
}
public void getAllStationSystemOnLevelAndAssignInfoToAllMissions ()
{
//Seach all station systems on the level and assign an ID to each one
getAllStationSystemOnLevel ();
int currentMissionID = 0;
int objectiveStationSystemListCount = objectiveStationSystemList.Count;
for (int i = 0; i < objectiveStationSystemListCount; i++) {
for (int j = 0; j < objectiveStationSystemList [i].objectiveInfoList.Count; j++) {
if (objectiveStationSystemList [i].objectiveInfoList [j].mainObjectiveEventSystem != null) {
objectiveStationSystemList [i].objectiveInfoList [j].mainObjectiveEventSystem.assignIDToMission (currentMissionID);
objectiveStationSystemList [i].objectiveInfoList [j].mainObjectiveEventSystem.assignMissionScene (missionScene);
currentMissionID++;
}
}
}
updateComponent ();
}
public void getAllStationSystemOnLevelByEditor ()
{
//Search all station systems on the level and assign them here by the editor
getAllStationSystemOnLevel ();
updateComponent ();
}
public void clearStationSystemList ()
{
objectiveStationSystemList.Clear ();
updateComponent ();
}
public void instantiateMissionStation ()
{
instantateObjectOnLevel (missionStationPrefab);
}
public void instantiateMissionSystem ()
{
instantateObjectOnLevel (missionSystemPrefab);
}
public void instantiateEmptyMissionSystem ()
{
instantateObjectOnLevel (emptyMissionStationPrefab);
}
public void instantiateCharacterMissionSystem ()
{
instantateObjectOnLevel (characterMissionSystemPrefab);
}
public void instantateObjectOnLevel (GameObject objectToInstantiate)
{
Vector3 positionToInstantiate = Vector3.zero;
Camera currentCameraEditor = GKC_Utils.getCameraEditor ();
if (currentCameraEditor != null) {
Vector3 editorCameraPosition = currentCameraEditor.transform.position;
Vector3 editorCameraForward = currentCameraEditor.transform.forward;
RaycastHit hit;
if (Physics.Raycast (editorCameraPosition, editorCameraForward, out hit, Mathf.Infinity, layerToPlaceObjects)) {
positionToInstantiate = hit.point + Vector3.up * 0.05f;
}
}
if (objectToInstantiate != null) {
GameObject newCameraTransformElement = (GameObject)Instantiate (objectToInstantiate, positionToInstantiate, Quaternion.identity);
newCameraTransformElement.name = objectToInstantiate.name;
} else {
print ("WARNING: prefab gameObject is empty, make sure it is assigned correctly");
}
}
public void addSubObjectiveCompleteRemotely (string subObjectiveName, int missionScene, int missionID)
{
int objectiveStationSystemListCount = objectiveStationSystemList.Count;
for (int i = 0; i < objectiveStationSystemListCount; i++) {
currentObjectiveStationSystem = objectiveStationSystemList [i];
int objectiveInfoListCount = currentObjectiveStationSystem.objectiveInfoList.Count;
for (int j = 0; j < objectiveInfoListCount; j++) {
currentObjectiveInfo = currentObjectiveStationSystem.objectiveInfoList [j];
if (currentObjectiveInfo != null) {
if (currentObjectiveInfo.mainObjectiveEventSystem.missionID == missionID) {
if (missionScene == -1 || currentObjectiveInfo.mainObjectiveEventSystem.missionScene == missionScene) {
currentObjectiveInfo.mainObjectiveEventSystem.addSubObjectiveComplete (subObjectiveName);
return;
}
}
}
}
}
}
public void increaseObjectiveCounterRemotely (int missionScene, int missionID)
{
int objectiveStationSystemListCount = objectiveStationSystemList.Count;
for (int i = 0; i < objectiveStationSystemListCount; i++) {
currentObjectiveStationSystem = objectiveStationSystemList [i];
int objectiveInfoListCount = currentObjectiveStationSystem.objectiveInfoList.Count;
for (int j = 0; j < objectiveInfoListCount; j++) {
currentObjectiveInfo = currentObjectiveStationSystem.objectiveInfoList [j];
if (currentObjectiveInfo != null) {
if (currentObjectiveInfo.mainObjectiveEventSystem.missionID == missionID) {
if (missionScene == -1 || currentObjectiveInfo.mainObjectiveEventSystem.missionScene == missionScene) {
currentObjectiveInfo.mainObjectiveEventSystem.increaseObjectiveCounter ();
return;
}
}
}
}
}
}
public void increaseObjectiveCounterRemotelyToCurrentMissionActive (int missionScene)
{
int objectiveStationSystemListCount = objectiveStationSystemList.Count;
for (int i = 0; i < objectiveStationSystemListCount; i++) {
currentObjectiveStationSystem = objectiveStationSystemList [i];
int objectiveInfoListCount = currentObjectiveStationSystem.objectiveInfoList.Count;
for (int j = 0; j < objectiveInfoListCount; j++) {
currentObjectiveInfo = currentObjectiveStationSystem.objectiveInfoList [j];
if (currentObjectiveInfo != null) {
if (currentObjectiveInfo.mainObjectiveEventSystem.isObjectiveInProcess ()) {
if (missionScene == -1 || currentObjectiveInfo.mainObjectiveEventSystem.missionScene == missionScene) {
currentObjectiveInfo.mainObjectiveEventSystem.increaseObjectiveCounter ();
return;
}
}
}
}
}
}
public void checkRemoteEventsOnSubObjectiveCompleteRemotely (List<string> removeEventNameList, int missionScene, int missionID)
{
int objectiveStationSystemListCount = objectiveStationSystemList.Count;
for (int i = 0; i < objectiveStationSystemListCount; i++) {
currentObjectiveStationSystem = objectiveStationSystemList [i];
int objectiveInfoListCount = currentObjectiveStationSystem.objectiveInfoList.Count;
for (int j = 0; j < objectiveInfoListCount; j++) {
currentObjectiveInfo = currentObjectiveStationSystem.objectiveInfoList [j];
if (currentObjectiveInfo != null) {
if (currentObjectiveInfo.mainObjectiveEventSystem.missionID == missionID) {
if (missionScene == -1 || currentObjectiveInfo.mainObjectiveEventSystem.missionScene == missionScene) {
currentObjectiveInfo.mainObjectiveEventSystem.checkRemoteEventsOnSubObjectiveComplete (removeEventNameList);
return;
}
}
}
}
}
}
public void checkRemoteEventsOnSubObjectiveCompleteRemotelyToCurrentMissionActive (List<string> removeEventNameList, int missionScene)
{
int objectiveStationSystemListCount = objectiveStationSystemList.Count;
for (int i = 0; i < objectiveStationSystemListCount; i++) {
currentObjectiveStationSystem = objectiveStationSystemList [i];
int objectiveInfoListCount = currentObjectiveStationSystem.objectiveInfoList.Count;
for (int j = 0; j < objectiveInfoListCount; j++) {
currentObjectiveInfo = currentObjectiveStationSystem.objectiveInfoList [j];
if (currentObjectiveInfo != null) {
if (currentObjectiveInfo.mainObjectiveEventSystem.isObjectiveInProcess ()) {
if (missionScene == -1 || currentObjectiveInfo.mainObjectiveEventSystem.missionScene == missionScene) {
currentObjectiveInfo.mainObjectiveEventSystem.checkRemoteEventsOnSubObjectiveComplete (removeEventNameList);
return;
}
}
}
}
}
}
public void cancelCurrentMissionRemotely (int missionScene, int missionID)
{
objectiveEventSystem currentObjectiveEventSystem = getObjectiveEventSystem (missionID, missionScene);
if (currentObjectiveEventSystem != null) {
currentObjectiveEventSystem.cancelCurrentMissionRemotely ();
}
}
public void updateComponent ()
{
GKC_Utils.updateComponent (this);
GKC_Utils.updateDirtyScene ("Update Main Mission Manager info", gameObject);
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 617816b325177954dadb24d053f57433
timeCreated: 1567730933
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/Objectives Mission System/objectiveManager.cs
uploadId: 814740

View File

@@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class objectiveMenuIconElement : MonoBehaviour
{
public GameObject objectiveSlotGameObject;
public Text objectiveNameText;
public Text objectiveLocationText;
public Text objectiveMinLevelText;
public GameObject currentObjectiveIcon;
public GameObject objectiveCompletePanel;
public GameObject selectedObjectiveIcon;
public GameObject objectiveCompleteText;
public GameObject objectiveAcceptedText;
public GameObject getRewardsText;
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 3a055a8eb6b9bdd4aabe7f34f5c58025
timeCreated: 1536943938
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/Objectives Mission System/objectiveMenuIconElement.cs
uploadId: 814740

View File

@@ -0,0 +1,198 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class objectiveStationSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool useCharacterObjectivePanel;
public int currentCharacterObjectiveIndex;
public bool startMissionAfterPressingClosingStation;
public bool useDelayToStartMission;
public float delayToStartMission;
[Space]
[Header ("Objective Info List Settings")]
[Space]
public List<objectiveInfo> objectiveInfoList = new List<objectiveInfo> ();
[Space]
[Header ("Debug")]
[Space]
public bool usingObjectiveStation;
public bool firstTimeMissionsStateChecked;
[Space]
[Header ("Events Settings")]
[Space]
public UnityEvent eventOnMissionAvailables;
public UnityEvent eventOnAllMissionsComplete;
[Space]
[Header ("Explanation")]
[Space]
[TextArea (5, 20)]public string explanation = "This is a station system which " +
"can be used as a physical mission board or just or just an invisible element to configure different missions which are maybe activate by dialog or trigger." +
"\n\n" + "" + "Each station has a list of missions, which are the one which contains the missions to achieve, tasks, and rewards and events to activate.";
GameObject currentPlayer;
playerComponentsManager mainPlayerComponentsManager;
objectiveStationUISystem currentObjectiveStationUISystem;
//Check the mission state, to see if they are already complete and with the reward obtained (in case there is a reward to obtain)
public void checkMissionsState ()
{
for (int i = 0; i < objectiveInfoList.Count; i++) {
if (objectiveInfoList [i].mainObjectiveEventSystem != null) {
if (!objectiveInfoList [i].mainObjectiveEventSystem.isObjectiveComplete () || !objectiveInfoList [i].mainObjectiveEventSystem.isRewardsObtained ()) {
eventOnMissionAvailables.Invoke ();
firstTimeMissionsStateChecked = true;
return;
} else {
if (!firstTimeMissionsStateChecked) {
currentCharacterObjectiveIndex = i;
}
}
} else {
print ("WARNING: There is a list of missions configured in this mission station but the element is empty or missing! " +
"Please make sure the mission system is configured properly.");
}
}
firstTimeMissionsStateChecked = true;
eventOnAllMissionsComplete.Invoke ();
}
public void setCurrentPlayer (GameObject player)
{
currentPlayer = player;
if (currentPlayer != null) {
mainPlayerComponentsManager = currentPlayer.GetComponent<playerComponentsManager> ();
currentObjectiveStationUISystem = mainPlayerComponentsManager.getObjectiveStationUISystem ();
}
}
//Enable or disable the mission station, sending the missions configured on it to the player UI system
public void activateObjectiveStation ()
{
usingObjectiveStation = !usingObjectiveStation;
if (usingObjectiveStation) {
currentObjectiveStationUISystem.setCurrentObjectiveStationSystem (this);
} else {
checkMissionsState ();
}
currentObjectiveStationUISystem.openOrCloseObjectiveStationMenu (usingObjectiveStation);
}
//Set if the current station system is being used or not
public void setUsingObjectiveStationState (bool state)
{
usingObjectiveStation = state;
}
//Get the mission list configured in this station
public List<objectiveInfo> getObjectiveInfoList ()
{
return objectiveInfoList;
}
//Increase the current mission index, used usually on character mission, when the player completes a mission, so the next mission available can be obtained
public void increaseCurrentCharacterObjectiveIndex ()
{
currentCharacterObjectiveIndex++;
if (currentCharacterObjectiveIndex >= objectiveInfoList.Count) {
currentCharacterObjectiveIndex = objectiveInfoList.Count - 1;
}
}
public void setCurrentCharacterObjectiveIndex (int newIndex)
{
currentCharacterObjectiveIndex = newIndex;
if (currentCharacterObjectiveIndex >= objectiveInfoList.Count) {
currentCharacterObjectiveIndex = objectiveInfoList.Count - 1;
}
}
//Get the current mission system index
public int getCurrentCharacterObjectiveIndex ()
{
return currentCharacterObjectiveIndex;
}
//Check if there are more missions available on this station
public bool isThereMissionsAvailableOnStation (int indexMissionToCheck)
{
if (currentCharacterObjectiveIndex <= indexMissionToCheck) {
for (int i = 0; i < objectiveInfoList.Count; i++) {
if (objectiveInfoList [i].mainObjectiveEventSystem != null) {
if (!objectiveInfoList [i].mainObjectiveEventSystem.isObjectiveComplete ()) {
// print ("more missions");
return true;
}
}
}
}
// print ("no missions");
return false;
}
public void getAllMissionsSystemOnLevel ()
{
//Search all the station systems on the level, so they can be managed here
objectiveInfoList.Clear ();
objectiveEventSystem[] newObjectiveEventSystemList = FindObjectsOfType<objectiveEventSystem> ();
foreach (objectiveEventSystem currentObjectiveEventSystem in newObjectiveEventSystemList) {
objectiveInfo newObjectiveInfo = new objectiveInfo ();
newObjectiveInfo.Name = currentObjectiveEventSystem.generalObjectiveName;
newObjectiveInfo.mainObjectiveEventSystem = currentObjectiveEventSystem;
objectiveInfoList.Add (newObjectiveInfo);
}
updateComponent ();
}
public void updateComponent ()
{
GKC_Utils.updateComponent (this);
GKC_Utils.updateDirtyScene ("Update Main Station Manager info", gameObject);
}
[System.Serializable]
public class objectiveInfo
{
public string Name;
public objectiveEventSystem mainObjectiveEventSystem;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 1ed7e10a9f6392f4b80e8bab12d6fc57
timeCreated: 1567730508
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/Objectives Mission System/objectiveStationSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,821 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using GKC.Localization;
public class objectiveStationUISystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool objectiveStationUIEnabled = true;
public bool menuOpened;
public Color buttonUsable;
public Color buttonNotUsable;
public bool onlyActiveNewMissionIfNoPreviousInProcess;
public bool onlyAddNewMissionsToPlayerLogMenuWithoutActivateThem;
public bool useBlurUIPanel;
[Space]
[Header ("Mission Panel Settings")]
[Space]
public float dissableObjectiveAcceptedPanelDelay;
public float delayToDissableCharacterPanelAfterAcceptMission;
public string noMissionsAvailableText = "NO MISSIONS AVAILABLE";
[Space]
public bool disableMissionCompletePanelAfterTime;
public float delayToDisableMissionPanel;
[Space]
[Header ("Events Settings")]
[Space]
public bool showMissionsWithHigherLevel = true;
public UnityEvent eventOnMissionWithHigherLevel;
public UnityEvent eventOnMissionAccepted;
[Space]
[Header ("Debug")]
[Space]
public List<objectiveStationSystem.objectiveInfo> currentObjectiveInfoList = new List<objectiveStationSystem.objectiveInfo> ();
public List<objectiveLogSystem.objectiveSlotInfo> objectiveSlotInfoList = new List<objectiveLogSystem.objectiveSlotInfo> ();
public objectiveStationSystem currentObjectiveStationSystem;
[Space]
[Header ("Objective UI Elements")]
[Space]
public GameObject objectiveSlotPrefab;
public Transform objectiveListContent;
public Text objectiveNameText;
public Text objectiveDescriptionText;
public Text objectiveFullDescriptionText;
public Text objectiveRewardsText;
public Image acceptObjectiveButtonImage;
public GameObject missionCompletePanel;
public Text missionCompleteNameText;
public Text missionCompleteRewardsText;
public GameObject objectiveStationMenu;
public GameObject missionAcceptedPanel;
public Text missionAcceptedNameText;
[Space]
[Header ("Character Objective UI Elements")]
[Space]
public GameObject characterObjectivePanelGameObject;
public Text characterObjectiveNameText;
public Text characterObjectiveDescriptionText;
public Text characterObjectiveFullDescriptionText;
public Text characterObjectiveRewardsText;
public GameObject characterAcceptMissionButton;
public GameObject chracterGetMissionRewardButton;
[Space]
[Header ("Other Elements")]
[Space]
public GameObject playerControllerGameObject;
public menuPause pauseManager;
public usingDevicesSystem usingDevicesManager;
public playerExperienceSystem mainPlayerExperienceSystem;
public playerController playerControllerManager;
public objectiveLogSystem mainObjectiveLogSystem;
public objectiveManager mainObjectiveManager;
objectiveLogSystem.objectiveSlotInfo currentObjectiveSlot;
objectiveStationSystem.objectiveInfo currentObjectiveInfo;
Coroutine missionCompleteCoroutine;
bool useCharacterObjectivePanel;
int currentCharacterObjectiveIndex;
Coroutine acceptMissionFromCharacterCoroutine;
Coroutine missionAcceptedCoroutine;
bool componentInitialized;
objectiveEventSystem currentObjectiveEventSystem;
void Start ()
{
if (!objectiveStationUIEnabled) {
return;
}
bool mainObjectiveManagerLocated = mainObjectiveManager != null;
if (!mainObjectiveManagerLocated) {
mainObjectiveManager = objectiveManager.Instance;
mainObjectiveManagerLocated = mainObjectiveManager != null;
}
if (!mainObjectiveManagerLocated) {
GKC_Utils.instantiateMainManagerOnSceneWithTypeOnApplicationPlaying (objectiveManager.getMainManagerName (), typeof (objectiveManager), true);
mainObjectiveManager = objectiveManager.Instance;
mainObjectiveManagerLocated = mainObjectiveManager != null;
}
if (!mainObjectiveManagerLocated) {
mainObjectiveManager = FindObjectOfType<objectiveManager> ();
}
updateObjectiveTextContent ("", "", "", "");
componentInitialized = true;
}
public void setButtonsColor (bool activeObjectiveColor)
{
if (activeObjectiveColor) {
acceptObjectiveButtonImage.color = buttonUsable;
} else {
acceptObjectiveButtonImage.color = buttonNotUsable;
}
}
//Assign a new station system, to get access to the missions configured on it
public void setCurrentObjectiveStationSystem (objectiveStationSystem newObjectiveStationSystem)
{
currentObjectiveStationSystem = newObjectiveStationSystem;
useCharacterObjectivePanel = currentObjectiveStationSystem.useCharacterObjectivePanel;
}
//Open or close the objective station UI
public void openOrCloseObjectiveStationMenu (bool state)
{
menuOpened = state;
if (useCharacterObjectivePanel) {
pauseManager.openOrClosePlayerMenu (menuOpened, null, false);
} else {
pauseManager.openOrClosePlayerMenu (menuOpened, objectiveStationMenu.transform, useBlurUIPanel);
}
if (useCharacterObjectivePanel) {
characterObjectivePanelGameObject.SetActive (menuOpened);
} else {
objectiveStationMenu.SetActive (menuOpened);
}
if (useCharacterObjectivePanel) {
pauseManager.setIngameMenuOpenedState ("Character Objective Panel System", menuOpened, true);
} else {
pauseManager.setIngameMenuOpenedState ("Objective Station System", menuOpened, true);
}
//set to visible the cursor
pauseManager.showOrHideCursor (menuOpened);
//disable the touch controls
pauseManager.checkTouchControls (!menuOpened);
//disable the camera rotation
pauseManager.changeCameraState (!menuOpened);
playerControllerManager.changeScriptState (!menuOpened);
pauseManager.usingSubMenuState (menuOpened);
pauseManager.enableOrDisableDynamicElementsOnScreen (!menuOpened);
currentObjectiveSlot = null;
if (currentObjectiveSlot != null) {
currentObjectiveSlot.selectedObjectiveIcon.SetActive (false);
}
setButtonsColor (false);
updateObjectiveTextContent ("", "", "", "");
disableMissionCompletePanel ();
disableMissionAcceptedPanel ();
stopAcceptMissionFromCharacterObjectivePanelCoroutine ();
if (menuOpened) {
currentObjectiveInfoList = currentObjectiveStationSystem.getObjectiveInfoList ();
setObjectiveInfoList ();
if (objectiveSlotInfoList.Count > 0) {
objectiveSlotInfoList [0].slotSelectedByPlayer = false;
checkPressedMission (objectiveSlotInfoList [0].objectiveSlotGameObject);
}
} else {
if (startMissionAfterPressingClosingStationActive) {
checkStartCurrentMission ();
startMissionAfterPressingClosingStationActive = false;
}
}
}
//Update the info of the current mission selected on the menu
public void setObjectiveInfoList ()
{
if (useCharacterObjectivePanel) {
currentCharacterObjectiveIndex = currentObjectiveStationSystem.getCurrentCharacterObjectiveIndex ();
if (currentCharacterObjectiveIndex < currentObjectiveInfoList.Count) {
currentObjectiveInfo = currentObjectiveInfoList [currentCharacterObjectiveIndex];
if (currentObjectiveInfo.mainObjectiveEventSystem.isObjectiveComplete () || currentObjectiveInfo.mainObjectiveEventSystem.isMissionAccepted ()) {
characterAcceptMissionButton.SetActive (false);
} else {
characterAcceptMissionButton.SetActive (true);
}
bool showMissionInfo = false;
if (currentObjectiveInfo.mainObjectiveEventSystem.isObjectiveComplete ()) {
if (!currentObjectiveInfo.mainObjectiveEventSystem.giveRewardOnObjectiveComplete && !currentObjectiveInfo.mainObjectiveEventSystem.isRewardsObtained ()) {
chracterGetMissionRewardButton.SetActive (true);
showMissionInfo = true;
} else {
chracterGetMissionRewardButton.SetActive (false);
}
} else {
chracterGetMissionRewardButton.SetActive (false);
showMissionInfo = true;
}
if (showMissionInfo) {
updateChracterObjectiveTextContent (currentObjectiveInfo.mainObjectiveEventSystem.generalObjectiveName, currentObjectiveInfo.mainObjectiveEventSystem.generalObjectiveDescription,
currentObjectiveInfo.mainObjectiveEventSystem.objectiveFullDescription, currentObjectiveInfo.mainObjectiveEventSystem.objectiveRewards);
} else {
updateChracterObjectiveTextContent (noMissionsAvailableText, "", "", "");
}
} else {
print ("WARNING: index of the mission station is not correct, make sure the index of the current mission index on the station system is managed properly");
}
} else {
for (int i = 0; i < objectiveSlotInfoList.Count; i++) {
Destroy (objectiveSlotInfoList [i].objectiveSlotGameObject);
}
objectiveSlotInfoList.Clear ();
for (int i = 0; i < currentObjectiveInfoList.Count; i++) {
currentObjectiveInfo = currentObjectiveInfoList [i];
bool objectiveCanBeAdded = false;
if (mainObjectiveLogSystem.checkMinLevelOnMissions) {
if (!currentObjectiveInfo.mainObjectiveEventSystem.useMinPlayerLevel || showMissionsWithHigherLevel) {
objectiveCanBeAdded = true;
} else {
if (mainPlayerExperienceSystem.getCurrentLevel () >= currentObjectiveInfo.mainObjectiveEventSystem.minPlayerLevel) {
objectiveCanBeAdded = true;
}
}
} else {
objectiveCanBeAdded = true;
}
if (objectiveCanBeAdded) {
GameObject newObjectiveSlotPrefab = (GameObject)Instantiate (objectiveSlotPrefab, objectiveSlotPrefab.transform.position, Quaternion.identity, objectiveListContent);
newObjectiveSlotPrefab.SetActive (true);
newObjectiveSlotPrefab.transform.localScale = Vector3.one;
newObjectiveSlotPrefab.transform.localPosition = Vector3.zero;
objectiveMenuIconElement currentobjectiveMenuIconElement = newObjectiveSlotPrefab.GetComponent<objectiveMenuIconElement> ();
string generalObjectiveName = currentObjectiveInfo.mainObjectiveEventSystem.generalObjectiveName;
string objectiveLocation = currentObjectiveInfo.mainObjectiveEventSystem.objectiveLocation;
if (gameLanguageSelector.isCheckLanguageActive ()) {
generalObjectiveName = missionLocalizationManager.GetLocalizedValue (generalObjectiveName);
objectiveLocation = missionLocalizationManager.GetLocalizedValue (objectiveLocation);
}
currentobjectiveMenuIconElement.objectiveNameText.text = generalObjectiveName;
currentobjectiveMenuIconElement.objectiveLocationText.text = objectiveLocation;
if (mainObjectiveLogSystem.checkMinLevelOnMissions) {
if (currentObjectiveInfo.mainObjectiveEventSystem.useMinPlayerLevel && showMissionsWithHigherLevel) {
currentobjectiveMenuIconElement.objectiveMinLevelText.gameObject.SetActive (true);
string levelText = "Level";
if (gameLanguageSelector.isCheckLanguageActive ()) {
levelText = missionLocalizationManager.GetLocalizedValue (levelText);
}
currentobjectiveMenuIconElement.objectiveMinLevelText.text = levelText + ": " + currentObjectiveInfo.mainObjectiveEventSystem.minPlayerLevel;
}
}
objectiveLogSystem.objectiveSlotInfo newObjectiveSlotInfo = new objectiveLogSystem.objectiveSlotInfo ();
newObjectiveSlotInfo.objectiveMenuIconElementManager = currentobjectiveMenuIconElement;
newObjectiveSlotInfo.objectiveSlotGameObject = newObjectiveSlotPrefab;
newObjectiveSlotInfo.objectiveName = currentObjectiveInfo.mainObjectiveEventSystem.generalObjectiveName;
newObjectiveSlotInfo.objectiveLocation = currentObjectiveInfo.mainObjectiveEventSystem.objectiveLocation;
newObjectiveSlotInfo.objectiveRewards = currentObjectiveInfo.mainObjectiveEventSystem.objectiveRewards;
newObjectiveSlotInfo.objectiveDescription = currentObjectiveInfo.mainObjectiveEventSystem.generalObjectiveDescription;
newObjectiveSlotInfo.objectiveFullDescription = currentObjectiveInfo.mainObjectiveEventSystem.objectiveFullDescription;
newObjectiveSlotInfo.currentObjectiveIcon = currentobjectiveMenuIconElement.currentObjectiveIcon;
newObjectiveSlotInfo.objectiveCompletePanel = currentobjectiveMenuIconElement.objectiveCompletePanel;
newObjectiveSlotInfo.selectedObjectiveIcon = currentobjectiveMenuIconElement.selectedObjectiveIcon;
newObjectiveSlotInfo.objectiveCompleteText = currentobjectiveMenuIconElement.objectiveCompleteText;
newObjectiveSlotInfo.objectiveAcceptedText = currentobjectiveMenuIconElement.objectiveAcceptedText;
newObjectiveSlotInfo.objectiveEventManager = currentObjectiveInfo.mainObjectiveEventSystem;
if (newObjectiveSlotInfo.objectiveEventManager.isObjectiveComplete ()) {
newObjectiveSlotInfo.objectiveCompletePanel.SetActive (true);
newObjectiveSlotInfo.objectiveCompleteText.SetActive (true);
newObjectiveSlotInfo.objectiveAcceptedText.gameObject.SetActive (false);
if (!newObjectiveSlotInfo.objectiveEventManager.isRewardsObtained ()) {
currentobjectiveMenuIconElement.getRewardsText.SetActive (true);
} else {
currentobjectiveMenuIconElement.getRewardsText.SetActive (false);
}
} else {
if (newObjectiveSlotInfo.objectiveEventManager.isMissionAccepted ()) {
newObjectiveSlotInfo.objectiveAcceptedText.gameObject.SetActive (true);
newObjectiveSlotInfo.currentObjectiveIcon.SetActive (true);
} else {
newObjectiveSlotInfo.objectiveAcceptedText.gameObject.SetActive (false);
newObjectiveSlotInfo.currentObjectiveIcon.SetActive (false);
}
}
newObjectiveSlotInfo.slotSelectedByPlayer = true;
objectiveSlotInfoList.Add (newObjectiveSlotInfo);
}
}
}
}
//Check the mission button pressed from the list of available missions on the station
public void checkPressedMission (GameObject objectiveSlot)
{
if (currentObjectiveSlot != null) {
currentObjectiveSlot.selectedObjectiveIcon.SetActive (false);
}
for (int i = 0; i < objectiveSlotInfoList.Count; i++) {
if (objectiveSlotInfoList [i].objectiveSlotGameObject == objectiveSlot) {
currentObjectiveSlot = objectiveSlotInfoList [i];
updateObjectiveTextContent (currentObjectiveSlot.objectiveName, currentObjectiveSlot.objectiveDescription,
currentObjectiveSlot.objectiveFullDescription, currentObjectiveSlot.objectiveRewards);
currentObjectiveSlot.selectedObjectiveIcon.SetActive (true);
for (int j = 0; j < currentObjectiveInfoList.Count; j++) {
if (currentObjectiveInfoList [j].mainObjectiveEventSystem == currentObjectiveSlot.objectiveEventManager) {
currentObjectiveInfo = currentObjectiveInfoList [j];
}
}
if (!currentObjectiveSlot.objectiveEventManager.isObjectiveComplete ()) {
if (currentObjectiveSlot.objectiveEventManager.isObjectiveInProcess ()) {
setButtonsColor (false);
} else {
if (currentObjectiveSlot.objectiveEventManager.isMissionAccepted ()) {
setButtonsColor (false);
return;
}
setButtonsColor (true);
}
} else {
if (currentObjectiveSlot.slotSelectedByPlayer) {
if (!currentObjectiveSlot.objectiveEventManager.giveRewardOnObjectiveComplete) {
if (!currentObjectiveSlot.objectiveEventManager.isRewardsObtained ()) {
showMissionCompleteMessage ();
}
if (!currentObjectiveSlot.objectiveEventManager.isRewardsObtained ()) {
currentObjectiveSlot.objectiveEventManager.giveRewardToPlayer ();
currentObjectiveSlot.objectiveEventManager.setRewardsObtanedState (true);
currentObjectiveSlot.objectiveMenuIconElementManager.getRewardsText.gameObject.SetActive (false);
}
}
}
currentObjectiveSlot.slotSelectedByPlayer = true;
setButtonsColor (false);
}
return;
}
}
setButtonsColor (false);
}
public void updateChracterObjectiveTextContent (string objectiveName, string objectiveDescription, string objectiveFullDescription, string objectiveRewards)
{
if (gameLanguageSelector.isCheckLanguageActive ()) {
objectiveName = missionLocalizationManager.GetLocalizedValue (objectiveName);
objectiveRewards = missionLocalizationManager.GetLocalizedValue (objectiveRewards);
objectiveDescription = missionLocalizationManager.GetLocalizedValue (objectiveDescription);
objectiveFullDescription = missionLocalizationManager.GetLocalizedValue (objectiveFullDescription);
}
characterObjectiveNameText.text = objectiveName;
characterObjectiveRewardsText.text = objectiveRewards;
characterObjectiveDescriptionText.text = objectiveDescription;
characterObjectiveFullDescriptionText.text = objectiveFullDescription;
}
public void updateObjectiveTextContent (string objectiveName, string objectiveDescription, string objectiveFullDescription, string objectiveRewards)
{
if (gameLanguageSelector.isCheckLanguageActive ()) {
objectiveName = missionLocalizationManager.GetLocalizedValue (objectiveName);
objectiveRewards = missionLocalizationManager.GetLocalizedValue (objectiveRewards);
objectiveDescription = missionLocalizationManager.GetLocalizedValue (objectiveDescription);
objectiveFullDescription = missionLocalizationManager.GetLocalizedValue (objectiveFullDescription);
}
objectiveNameText.text = objectiveName;
objectiveRewardsText.text = objectiveRewards;
objectiveDescriptionText.text = objectiveDescription;
objectiveFullDescriptionText.text = objectiveFullDescription;
}
//Accept a mission from the mission station board
public void acceptMissionFromObjectiveStationPanel ()
{
if (currentObjectiveSlot != null) {
if (!currentObjectiveSlot.objectiveEventManager.isObjectiveComplete ()) {
for (int j = 0; j < currentObjectiveInfoList.Count; j++) {
if (currentObjectiveInfoList [j].mainObjectiveEventSystem == currentObjectiveSlot.objectiveEventManager) {
currentObjectiveInfo = currentObjectiveInfoList [j];
}
}
if (mainObjectiveLogSystem.checkMinLevelOnMissions) {
bool objectiveCanBeAdded = false;
if (!currentObjectiveInfo.mainObjectiveEventSystem.useMinPlayerLevel) {
objectiveCanBeAdded = true;
} else {
if (mainPlayerExperienceSystem.getCurrentLevel () >= currentObjectiveInfo.mainObjectiveEventSystem.minPlayerLevel) {
objectiveCanBeAdded = true;
}
}
if (!objectiveCanBeAdded) {
eventOnMissionWithHigherLevel.Invoke ();
return;
}
}
currentObjectiveSlot.objectiveEventManager.setCurrentPlayer (playerControllerGameObject);
if ((!mainObjectiveLogSystem.isObjectiveInProcess () || !onlyActiveNewMissionIfNoPreviousInProcess) && !onlyAddNewMissionsToPlayerLogMenuWithoutActivateThem) {
currentObjectiveSlot.objectiveEventManager.startObjective ();
} else {
currentObjectiveSlot.objectiveEventManager.addObjectiveToPlayerLogMenu ();
}
currentObjectiveSlot.currentObjectiveIcon.SetActive (true);
currentObjectiveSlot.objectiveAcceptedText.SetActive (true);
setButtonsColor (false);
showMissionAcceptedMessage (currentObjectiveInfo.mainObjectiveEventSystem.generalObjectiveName);
}
}
}
//Accept a mission from a character
public void acceptMissionFromCharacterObjectivePanel ()
{
if (currentObjectiveInfo != null) {
if (!currentObjectiveInfo.mainObjectiveEventSystem.isObjectiveComplete () && !currentObjectiveInfo.mainObjectiveEventSystem.isObjectiveInProcess ()) {
if (mainObjectiveLogSystem.checkMinLevelOnMissions) {
bool objectiveCanBeAdded = false;
if (!currentObjectiveInfo.mainObjectiveEventSystem.useMinPlayerLevel) {
objectiveCanBeAdded = true;
} else {
if (mainPlayerExperienceSystem.getCurrentLevel () >= currentObjectiveInfo.mainObjectiveEventSystem.minPlayerLevel) {
objectiveCanBeAdded = true;
}
}
if (!objectiveCanBeAdded) {
eventOnMissionWithHigherLevel.Invoke ();
return;
}
}
currentObjectiveInfo.mainObjectiveEventSystem.setCurrentPlayer (playerControllerGameObject);
startMissionAfterPressingClosingStationActive = currentObjectiveStationSystem.startMissionAfterPressingClosingStation;
if (!startMissionAfterPressingClosingStationActive) {
checkStartCurrentMission ();
}
showMissionAcceptedMessage (currentObjectiveInfo.mainObjectiveEventSystem.generalObjectiveName);
stopAcceptMissionFromCharacterObjectivePanelCoroutine ();
acceptMissionFromCharacterCoroutine = StartCoroutine (acceptMissionFromCharacterObjectivePanelCoroutine ());
characterAcceptMissionButton.SetActive (false);
}
}
}
Coroutine startMissionCoroutine;
public void checkStartCurrentMission ()
{
if (currentObjectiveStationSystem != null && currentObjectiveStationSystem.useDelayToStartMission) {
if (startMissionCoroutine != null) {
StopCoroutine (startMissionCoroutine);
}
startMissionCoroutine = StartCoroutine (startCurrentMissionCoroutine (currentObjectiveStationSystem.delayToStartMission));
} else {
startCurrentMission ();
}
}
bool startMissionAfterPressingClosingStationActive;
public void startCurrentMission ()
{
if ((!mainObjectiveLogSystem.isObjectiveInProcess () || !onlyActiveNewMissionIfNoPreviousInProcess) && !onlyAddNewMissionsToPlayerLogMenuWithoutActivateThem) {
currentObjectiveInfo.mainObjectiveEventSystem.startObjective ();
} else {
currentObjectiveInfo.mainObjectiveEventSystem.addObjectiveToPlayerLogMenu ();
}
}
IEnumerator startCurrentMissionCoroutine (float delayToStartMission)
{
yield return new WaitForSeconds (delayToStartMission);
startCurrentMission ();
}
public void stopAcceptMissionFromCharacterObjectivePanelCoroutine ()
{
if (acceptMissionFromCharacterCoroutine != null) {
StopCoroutine (acceptMissionFromCharacterCoroutine);
}
}
//Close the mission panel after getting a new mission from a character
IEnumerator acceptMissionFromCharacterObjectivePanelCoroutine ()
{
yield return new WaitForSeconds (delayToDissableCharacterPanelAfterAcceptMission);
if (menuOpened) {
usingDevicesManager.useDevice ();
}
}
//Get the reward from a character mission
public void getMissionRewardFromCharacterObjectivePanel ()
{
if (!currentObjectiveInfo.mainObjectiveEventSystem.isRewardsObtained ()) {
showMissionCompleteMessage ();
}
if (!currentObjectiveInfo.mainObjectiveEventSystem.isRewardsObtained ()) {
currentObjectiveInfo.mainObjectiveEventSystem.giveRewardToPlayer ();
currentObjectiveInfo.mainObjectiveEventSystem.setRewardsObtanedState (true);
}
chracterGetMissionRewardButton.SetActive (false);
}
//Different functions to open and close this menu
public void openOrCloseObjectiveMenuFromTouch ()
{
openOrCloseObjectiveStationMenu (!menuOpened);
}
public void openOrCloseObjectiveStationMenuByButton ()
{
usingDevicesManager.useDevice ();
if (currentObjectiveStationSystem) {
currentObjectiveStationSystem.setUsingObjectiveStationState (menuOpened);
}
}
//Show a panel from a mission accepted
public void showMissionCompleteMessage ()
{
if (disableMissionCompletePanelAfterTime) {
showMissionCompleteMessageTemporarily (delayToDisableMissionPanel);
} else {
enableAndSetMissionCompletePanelInfo ();
}
}
public void showMissionCompleteMessageTemporarily ()
{
showMissionCompleteMessageTemporarily (delayToDisableMissionPanel);
}
public void showMissionCompleteMessageTemporarily (float delayToDisablePanel)
{
if (missionCompleteCoroutine != null) {
StopCoroutine (missionCompleteCoroutine);
}
missionCompleteCoroutine = StartCoroutine (showMissionCompleteMessageCoroutine (delayToDisablePanel));
}
IEnumerator showMissionCompleteMessageCoroutine (float delayToDisablePanel)
{
usingDevicesManager.setUseDeviceButtonEnabledState (false);
enableAndSetMissionCompletePanelInfo ();
yield return new WaitForSeconds (delayToDisablePanel);
disableMissionCompletePanel ();
usingDevicesManager.setUseDeviceButtonEnabledState (true);
}
//Check if after complete a mission of a character, that character has more missions available
public void checkIfMissionsAvailableInCharacter ()
{
if (useCharacterObjectivePanel) {
// print (currentObjectiveInfo.mainObjectiveEventSystem.isObjectiveComplete () + " " + currentObjectiveInfo.mainObjectiveEventSystem.isRewardsObtained ());
if (currentObjectiveInfo != null && currentObjectiveInfo.mainObjectiveEventSystem.isObjectiveComplete () && currentObjectiveInfo.mainObjectiveEventSystem.isRewardsObtained ()) {
currentCharacterObjectiveIndex += 1;
if (currentObjectiveStationSystem.isThereMissionsAvailableOnStation (currentCharacterObjectiveIndex)) {
setObjectiveInfoList ();
} else {
updateChracterObjectiveTextContent (noMissionsAvailableText, "", "", "");
}
}
}
}
//Show a mission complete panel
public void enableAndSetMissionCompletePanelInfo ()
{
missionCompletePanel.SetActive (true);
currentObjectiveEventSystem = null;
if (useCharacterObjectivePanel) {
if (currentObjectiveInfo != null) {
currentObjectiveEventSystem = currentObjectiveInfo.mainObjectiveEventSystem;
} else {
currentObjectiveEventSystem = mainObjectiveLogSystem.getCurrentObjectiveEventSystem ();
}
} else {
if (currentObjectiveSlot != null) {
currentObjectiveEventSystem = currentObjectiveSlot.objectiveEventManager;
} else {
currentObjectiveEventSystem = mainObjectiveLogSystem.getCurrentObjectiveEventSystem ();
}
}
if (currentObjectiveEventSystem != null) {
string generalObjectiveName = currentObjectiveEventSystem.generalObjectiveName;
string objectiveRewards = currentObjectiveEventSystem.objectiveRewards;
if (gameLanguageSelector.isCheckLanguageActive ()) {
generalObjectiveName = missionLocalizationManager.GetLocalizedValue (generalObjectiveName);
objectiveRewards = missionLocalizationManager.GetLocalizedValue (objectiveRewards);
}
missionCompleteNameText.text = generalObjectiveName;
missionCompleteRewardsText.text = objectiveRewards;
}
}
//Enable and disable different panels from the mission UI system
public void disableMissionCompletePanel ()
{
missionCompletePanel.SetActive (false);
}
public void showMissionAcceptedMessage (string missionAcceptedMessage, float delayToDisableMissionAcceptedPanelValue)
{
if (!componentInitialized) {
return;
}
if (missionAcceptedCoroutine != null) {
StopCoroutine (missionAcceptedCoroutine);
}
missionAcceptedCoroutine = StartCoroutine (showMissionAcceptedMessageCoroutine (missionAcceptedMessage, delayToDisableMissionAcceptedPanelValue));
}
public void showMissionAcceptedMessage (string missionAcceptedMessage)
{
showMissionAcceptedMessage (missionAcceptedMessage, dissableObjectiveAcceptedPanelDelay);
}
IEnumerator showMissionAcceptedMessageCoroutine (string missionAcceptedMessage, float delayToDisableMissionAcceptedPanelValue)
{
enableAndSetMissionAcceptedPanelInfo (missionAcceptedMessage);
eventOnMissionAccepted.Invoke ();
yield return new WaitForSeconds (delayToDisableMissionAcceptedPanelValue);
disableMissionAcceptedPanel ();
}
public void disableMissionAcceptedPanel ()
{
missionAcceptedPanel.SetActive (false);
}
public void enableAndSetMissionAcceptedPanelInfo (string missionAcceptedMessage)
{
missionAcceptedPanel.SetActive (true);
if (gameLanguageSelector.isCheckLanguageActive ()) {
missionAcceptedMessage = missionLocalizationManager.GetLocalizedValue (missionAcceptedMessage);
}
missionAcceptedNameText.text = missionAcceptedMessage;
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 6915500f00fe00b4f8b94e2bc4dedb66
timeCreated: 1567731328
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/Objectives Mission System/objectiveStationUISystem.cs
uploadId: 814740

View File

@@ -0,0 +1,703 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
public class playerScreenObjectivesSystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool showObjectivesActive = true;
public bool showObjectivesPaused;
[Range (0, 1)] public float iconOffset;
public float minDifferenceToUpdateDistanceToObject = 0.4f;
public bool hideObjectivesIfMaxDistanceReached;
public float maxDistanceToHideObjectives = 2000;
[Space]
[Header ("Other Settings")]
[Space]
public string mainManagerName = "Screen Objectives Manager";
public string mainPanelName = "Screen Objectives Info";
public string mainMapCreatorManagerName = "Map Creator";
// public bool useCanvasGroupOnIcons;
[Space]
[Header ("Debug")]
[Space]
public List<screenObjectivesSystem.objectiveInfo> objectiveList = new List<screenObjectivesSystem.objectiveInfo> ();
[Space]
[Header ("Components")]
[Space]
public Transform objectiveIconParent;
public Transform player;
public Camera mainCamera;
public screenObjectivesSystem screenObjectivesManager;
public playerCamera mainPlayerCamera;
public mapCreator mapCreatorManager;
bool mapCreatorManagerAssigned;
Vector3 currentMapObjectPosition;
float currentDistace;
Vector3 screenPoint;
bool targetOnScreen;
Vector3 screenCenter;
float angle;
float cos;
float sin;
float m;
Vector3 screenBounds;
screenObjectivesSystem.objectiveInfo currentObjective;
Vector2 mainCanvasSizeDelta;
Vector2 halfMainCanvasSizeDelta;
Vector2 iconPosition2d;
bool usingScreenSpaceCamera;
float screenWidth;
float screenHeight;
string stringField;
int objectiveListCount;
Vector3 currenPlayerPosition;
Vector3 vector3Forward = Vector3.forward;
bool ignoreCurrentIconState;
bool mainPanelParentLocated;
bool mainPanelParentChecked;
void Awake ()
{
if (showObjectivesActive) {
initializeElements ();
}
}
void initializeElements ()
{
bool screenObjectivesManagerLocated = screenObjectivesManager != null;
if (!screenObjectivesManagerLocated) {
screenObjectivesManager = screenObjectivesSystem.Instance;
screenObjectivesManagerLocated = screenObjectivesManager != null;
}
if (!screenObjectivesManagerLocated) {
GKC_Utils.instantiateMainManagerOnSceneWithTypeOnApplicationPlaying (screenObjectivesSystem.getMainManagerName (), typeof(screenObjectivesSystem), true);
screenObjectivesManager = screenObjectivesSystem.Instance;
screenObjectivesManagerLocated = screenObjectivesManager != null;
}
if (!screenObjectivesManagerLocated) {
screenObjectivesManager = FindObjectOfType<screenObjectivesSystem> ();
screenObjectivesManagerLocated = screenObjectivesManager != null;
}
if (screenObjectivesManagerLocated) {
screenObjectivesManager.addNewPlayer (this);
} else {
showObjectivesActive = false;
}
}
void Start ()
{
mainCanvasSizeDelta = mainPlayerCamera.getMainCanvasSizeDelta ();
halfMainCanvasSizeDelta = mainCanvasSizeDelta * 0.5f;
usingScreenSpaceCamera = mainPlayerCamera.isUsingScreenSpaceCamera ();
if (mainCamera == null) {
mainCamera = mainPlayerCamera.getMainCamera ();
}
}
void FixedUpdate ()
{
if (!showObjectivesActive || showObjectivesPaused) {
return;
}
objectiveListCount = objectiveList.Count;
if (objectiveListCount == 0) {
return;
}
if (!usingScreenSpaceCamera) {
screenWidth = Screen.width;
screenHeight = Screen.height;
}
currenPlayerPosition = player.position;
for (int i = 0; i < objectiveListCount; i++) {
currentObjective = objectiveList [i];
if (currentObjective.mapObject != null && currentObjective.iconTransform != null) {
currentMapObjectPosition = currentObjective.mapObject.transform.position;
if (currentObjective.iconOffset > 0) {
currentMapObjectPosition += currentObjective.iconOffset * currentObjective.mapObject.transform.up;
}
currentDistace = GKC_Utils.distance (currenPlayerPosition, currentMapObjectPosition);
if (currentObjective.useCloseDistance && currentDistace < currentObjective.closeDistance) {
removeElementFromListByPlayer (currentObjective);
return;
}
if (currentObjective.showIconPaused) {
if (currentObjective.offScreenIcon.activeSelf || currentObjective.onScreenIcon.activeSelf) {
currentObjective.onScreenIcon.SetActive (false);
currentObjective.offScreenIcon.SetActive (false);
currentObjective.iconText.gameObject.SetActive (false);
}
} else {
//get the target position from global to local in the screen
targetOnScreen = false;
if (usingScreenSpaceCamera) {
screenPoint = mainCamera.WorldToViewportPoint (currentMapObjectPosition);
targetOnScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
} else {
screenPoint = mainCamera.WorldToScreenPoint (currentMapObjectPosition);
targetOnScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < screenWidth && screenPoint.y > 0 && screenPoint.y < screenHeight;
}
ignoreCurrentIconState = false;
if (hideObjectivesIfMaxDistanceReached) {
if (currentDistace > maxDistanceToHideObjectives) {
ignoreCurrentIconState = true;
}
}
if (ignoreCurrentIconState) {
if (currentObjective.offScreenIcon.activeSelf || currentObjective.onScreenIcon.activeSelf) {
currentObjective.onScreenIcon.SetActive (false);
currentObjective.offScreenIcon.SetActive (false);
currentObjective.iconText.gameObject.SetActive (false);
}
} else {
//if the target is visible in the screnn, set the icon position and the distance in the text component
if (targetOnScreen) {
//change the icon from offscreen to onscreen
if (!currentObjective.onScreenIcon.activeSelf) {
currentObjective.onScreenIcon.SetActive (true);
currentObjective.offScreenIcon.SetActive (false);
if (currentObjective.showDistance) {
currentObjective.iconText.gameObject.SetActive (true);
} else {
currentObjective.iconText.gameObject.SetActive (false);
}
currentObjective.iconTransform.rotation = Quaternion.identity;
}
if (usingScreenSpaceCamera) {
iconPosition2d = new Vector2 ((screenPoint.x * mainCanvasSizeDelta.x) - halfMainCanvasSizeDelta.x, (screenPoint.y * mainCanvasSizeDelta.y) - halfMainCanvasSizeDelta.y);
currentObjective.iconTransform.anchoredPosition = iconPosition2d;
} else {
currentObjective.iconTransform.position = new Vector3 (screenPoint.x, screenPoint.y, 0);
}
if (currentObjective.showDistance) {
if (currentObjective.lastDistance == 0 || Mathf.Abs (currentObjective.lastDistance - currentDistace) > minDifferenceToUpdateDistanceToObject) {
currentObjective.lastDistance = currentDistace;
stringField = Mathf.Round (currentDistace).ToString ();
currentObjective.iconText.text = stringField;
}
}
} else {
//if the target is off screen, change the icon to an arrow to follow the target position and also rotate the arrow to the target direction
if (currentObjective.showOffScreenIcon) {
//change the icon from onscreen to offscreen
if (!currentObjective.offScreenIcon.activeSelf) {
currentObjective.onScreenIcon.SetActive (false);
currentObjective.offScreenIcon.SetActive (true);
currentObjective.iconText.gameObject.SetActive (false);
if (currentObjective.showDistanceOffScreen) {
currentObjective.iconText.gameObject.SetActive (true);
} else {
currentObjective.iconText.gameObject.SetActive (false);
}
}
if (usingScreenSpaceCamera) {
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 = iconOffset * halfMainCanvasSizeDelta;
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);
}
currentObjective.iconTransform.anchoredPosition = iconPosition2d;
} 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 = iconOffset * screenCenter;
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;
currentObjective.iconTransform.position = screenPoint;
}
currentObjective.iconTransform.eulerAngles = (angle * Mathf.Rad2Deg) * vector3Forward;
if (currentObjective.showDistanceOffScreen) {
if (currentObjective.lastDistance == 0 || Mathf.Abs (currentObjective.lastDistance - currentDistace) > minDifferenceToUpdateDistanceToObject) {
currentObjective.lastDistance = currentDistace;
stringField = Mathf.Round (currentDistace).ToString ();
currentObjective.iconText.text = stringField;
}
currentObjective.iconText.transform.rotation = Quaternion.identity;
}
} else {
if (currentObjective.onScreenIcon.activeSelf || currentObjective.iconText.gameObject.activeSelf) {
currentObjective.onScreenIcon.SetActive (false);
currentObjective.iconText.gameObject.SetActive (false);
}
}
}
}
}
} else {
removeElementFromListByPlayer (currentObjective);
}
}
}
//get the renderer parts of the target to set its colors with the objective color, to see easily the target to reach
public void addElementToList (screenObjectivesSystem.objectiveInfo newObjectiveToAdd, GameObject screenIconPrefab, int objectID)
{
if (!showObjectivesActive) {
return;
}
if (mainPanelParentChecked) {
if (!mainPanelParentLocated) {
return;
}
} else {
mainPanelParentChecked = true;
if (!mainPanelParentLocated) {
mainPanelParentLocated = objectiveIconParent != null;
if (!mainPanelParentLocated) {
GameObject newPanelParentGameObject = GKC_Utils.getHudElementParent (player.gameObject, mainPanelName);
if (newPanelParentGameObject != null) {
objectiveIconParent = newPanelParentGameObject.transform;
mainPanelParentLocated = objectiveIconParent != null;
GKC_Utils.updateCanvasValuesByPlayer (player.gameObject, null, newPanelParentGameObject);
}
}
if (!mainPanelParentLocated) {
return;
}
}
}
objectiveListCount = objectiveList.Count;
for (int i = 0; i < objectiveListCount; i++) {
if (objectiveList [i].ID == objectID) {
return;
}
}
GameObject newScreenIcon = (GameObject)Instantiate (screenIconPrefab, Vector3.zero, Quaternion.identity);
screenObjectivesSystem.objectiveInfo newObjective = new screenObjectivesSystem.objectiveInfo ();
newObjective.Name = newObjectiveToAdd.Name;
newObjective.mapObject = newObjectiveToAdd.mapObject;
newObjective.ID = objectID;
newObjective.useCloseDistance = newObjectiveToAdd.useCloseDistance;
newObjective.closeDistance = newObjectiveToAdd.closeDistance;
newObjective.showOffScreenIcon = newObjectiveToAdd.showOffScreenIcon;
newObjective.showDistance = newObjectiveToAdd.showDistance;
newObjective.showDistanceOffScreen = newObjectiveToAdd.showDistanceOffScreen;
newObjective.iconOffset = newObjectiveToAdd.iconOffset;
newObjective.showIconPaused = newObjectiveToAdd.showIconPaused;
newObjective.iconTransform = newScreenIcon.GetComponent<RectTransform> ();
newObjective.iconTransform.SetParent (objectiveIconParent);
newObjective.iconTransform.localScale = Vector3.one;
newObjective.iconTransform.localPosition = Vector3.zero;
objectiveIconInfo newObjectiveIcon = newScreenIcon.GetComponent<objectiveIconInfo> ();
newObjective.onScreenIcon = newObjectiveIcon.onScreenIcon;
newObjective.offScreenIcon = newObjectiveIcon.offScreenIcon;
newObjective.iconText = newObjectiveIcon.iconText;
objectiveList.Add (newObjective);
if (showObjectivesPaused) {
if (objectiveIconParent != null) {
if (objectiveIconParent.gameObject.activeSelf == showObjectivesPaused) {
objectiveIconParent.gameObject.SetActive (!showObjectivesPaused);
}
}
}
}
//if the target is reached, disable all the parameters and clear the list, so a new objective can be added in any moment
public void removeElementFromList (int objectID)
{
if (!showObjectivesActive) {
return;
}
for (int i = 0; i < objectiveList.Count; i++) {
if (objectiveList [i].ID == objectID) {
if (objectiveList [i].iconTransform != null) {
Destroy (objectiveList [i].iconTransform.gameObject);
}
objectiveList.RemoveAt (i);
return;
}
}
}
public void removeElementFromListByPlayer (screenObjectivesSystem.objectiveInfo objectiveListElement)
{
if (!showObjectivesActive) {
return;
}
if (objectiveListElement.iconTransform != null) {
Destroy (objectiveListElement.iconTransform.gameObject);
}
screenObjectivesManager.removeElementFromObjectiveListCalledByPlayer (objectiveListElement.ID, player.gameObject);
objectiveList.Remove (objectiveListElement);
}
public void pauseOrResumeShowObjectives (bool state)
{
showObjectivesPaused = state;
if (objectiveIconParent != null) {
if (objectiveIconParent.gameObject.activeSelf == showObjectivesPaused) {
objectiveIconParent.gameObject.SetActive (!showObjectivesPaused);
}
}
}
public void pauseOrResumeShowObjectivesFromEditor (bool state)
{
pauseOrResumeShowObjectives (state);
updateComponent ();
}
public void addElementToPlayerList (GameObject obj, bool addMapIcon, bool useCloseDistance, float radiusDistance, bool showOffScreen, bool showMapWindowIcon,
bool showDistanceInfo, bool showDistanceOffScreenInfo, string objectiveIconName, bool useCustomObjectiveColor, Color objectiveColor,
bool removeCustomObjectiveColor, int buildingIndex, float iconOffset, bool addIconOnRestOfPlayers)
{
if (!showObjectivesActive) {
return;
}
if (objectAlreadyOnList (obj)) {
return;
}
screenObjectivesSystem.objectiveInfo newObjective = new screenObjectivesSystem.objectiveInfo ();
newObjective.Name = obj.name;
newObjective.mapObject = obj;
newObjective.iconOffset = iconOffset;
newObjective.ID = screenObjectivesManager.getCurrentID ();
screenObjectivesManager.increaseCurrentID ();
int currentObjectiveIconIndex = -1;
for (int i = 0; i < screenObjectivesManager.objectiveIconList.Count; i++) {
if (currentObjectiveIconIndex == -1 && screenObjectivesManager.objectiveIconList [i].name.Equals (objectiveIconName)) {
currentObjectiveIconIndex = i;
}
}
if (currentObjectiveIconIndex != -1) {
screenObjectivesSystem.objectiveIconElement currentObjectiveIconElement = screenObjectivesManager.objectiveIconList [currentObjectiveIconIndex];
if (radiusDistance < 0) {
radiusDistance = currentObjectiveIconElement.minDefaultDistance;
}
newObjective.useCloseDistance = useCloseDistance;
newObjective.closeDistance = radiusDistance;
newObjective.showOffScreenIcon = showOffScreen;
newObjective.showDistance = showDistanceInfo;
newObjective.showDistanceOffScreen = showDistanceOffScreenInfo;
if (currentObjectiveIconElement.changeObjectiveColors && !removeCustomObjectiveColor) {
int propertyNameID = Shader.PropertyToID ("_Color");
Component[] components = obj.GetComponentsInChildren (typeof(Renderer));
foreach (Renderer child in components) {
if (child.material.HasProperty (propertyNameID)) {
int materialsLength = child.materials.Length;
for (int j = 0; j < materialsLength; j++) {
Material currentMaterial = child.materials [j];
newObjective.materials.Add (currentMaterial);
newObjective.originalColor.Add (currentMaterial.color);
if (useCustomObjectiveColor) {
currentMaterial.color = objectiveColor;
} else {
currentMaterial.color = currentObjectiveIconElement.objectiveColor;
}
}
}
}
}
// print ("1 " + obj.name);
//add the target to the radar, to make it also visible there
if (!mapCreatorManagerAssigned) {
checkGetMapCreatorManager ();
}
// print ("2 " + obj.name);
if (mapCreatorManagerAssigned && addMapIcon && showMapWindowIcon) {
mapCreatorManager.addMapObject (true, true, false, obj, "Objective", Vector3.zero, -1, -1, buildingIndex, 0, false, false, false, false, null, 0);
}
// print ("3 " + obj.name);
addElementToList (newObjective, currentObjectiveIconElement.iconInfoElement.gameObject, newObjective.ID);
// print ("4 " + obj.name);
screenObjectivesManager.addElementFromPlayerList (newObjective, currentObjectiveIconElement, player, addIconOnRestOfPlayers);
// print ("5 " + obj.name);
} else {
print ("Element not found in objective icon list");
}
}
public void checkGetMapCreatorManager ()
{
mapCreatorManagerAssigned = (mapCreatorManager != null);
if (!mapCreatorManagerAssigned) {
mapCreatorManager = mapCreator.Instance;
mapCreatorManagerAssigned = mapCreatorManager != null;
}
if (!mapCreatorManagerAssigned) {
GKC_Utils.instantiateMainManagerOnSceneWithTypeOnApplicationPlaying (mapCreator.getMainManagerName (), typeof(mapCreator), true);
mapCreatorManager = mapCreator.Instance;
mapCreatorManagerAssigned = (mapCreatorManager != null);
}
if (!mapCreatorManagerAssigned) {
mapCreatorManager = FindObjectOfType<mapCreator> ();
mapCreatorManagerAssigned = mapCreatorManager != null;
}
}
public bool objectAlreadyOnList (GameObject objectToCheck)
{
if (!showObjectivesActive) {
return true;
}
if (objectToCheck == null) {
return true;
}
for (int i = 0; i < objectiveList.Count; i++) {
if (objectiveList [i].mapObject == objectToCheck) {
return true;
}
}
return false;
}
public void removeElementFromListByPlayer (GameObject objectToCheck)
{
if (!showObjectivesActive) {
return;
}
if (objectToCheck == null) {
return;
}
for (int i = 0; i < objectiveList.Count; i++) {
if (objectiveList [i].mapObject == objectToCheck) {
if (objectiveList [i].iconTransform != null) {
Destroy (objectiveList [i].iconTransform.gameObject);
}
int currentID = objectiveList [i].ID;
objectiveList.Remove (objectiveList [i]);
screenObjectivesManager.removeElementFromObjectiveListCalledByPlayer (currentID, player.gameObject);
return;
}
}
}
public void removeElementListFromListByPlayer (List<Transform> objectToCheckList)
{
if (!showObjectivesActive) {
return;
}
if (objectToCheckList == null || objectToCheckList.Count == 0) {
return;
}
for (int i = 0; i < objectToCheckList.Count; i++) {
if (objectToCheckList [i] != null) {
removeElementFromListByPlayer (objectToCheckList [i].gameObject);
}
}
}
public void setShowObjectivesActiveState (bool state)
{
showObjectivesActive = state;
}
public void setShowObjectivesActiveStateFromEditor (bool state)
{
setShowObjectivesActiveState (state);
updateComponent ();
}
void updateComponent ()
{
GKC_Utils.updateComponent (this);
GKC_Utils.updateDirtyScene ("Update Player Screen Objectives Manager", gameObject);
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 0b6f733f7bb48804a96eefdb764def58
timeCreated: 1527945373
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/Objectives Mission System/playerScreenObjectivesSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,435 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
public class screenObjectivesSystem : MonoBehaviour
{
public bool showObjectivesActive = true;
public List<objectiveIconElement> objectiveIconList = new List<objectiveIconElement> ();
public List<objectiveInfo> objectiveList = new List<objectiveInfo> ();
public List<playerScreenObjectivesSystem> playerScreenObjectivesList = new List<playerScreenObjectivesSystem> ();
public string mainMapCreatorManagerName = "Map Creator";
mapCreator mapCreatorManager;
int currentID = 0;
public const string mainManagerName = "Screen Objectives Manager";
public static string getMainManagerName ()
{
return mainManagerName;
}
private static screenObjectivesSystem _screenObjectivesSystemInstance;
public static screenObjectivesSystem Instance { get { return _screenObjectivesSystemInstance; } }
bool instanceInitialized;
public void getComponentInstance ()
{
if (instanceInitialized) {
// print ("already initialized manager");
return;
}
if (_screenObjectivesSystemInstance != null && _screenObjectivesSystemInstance != this) {
Destroy (this.gameObject);
return;
}
_screenObjectivesSystemInstance = this;
instanceInitialized = true;
}
void Awake ()
{
getComponentInstance ();
if (!showObjectivesActive) {
return;
}
checkGetMapCreatorManager ();
}
public void addNewPlayer (playerScreenObjectivesSystem newPlayer)
{
if (!showObjectivesActive) {
return;
}
playerScreenObjectivesList.Add (newPlayer);
int objectiveListCount = objectiveList.Count;
if (objectiveListCount > 0) {
for (int i = 0; i < objectiveListCount; i++) {
newPlayer.addElementToList (objectiveList [i], objectiveList [i].iconPrefab, objectiveList [i].ID);
}
}
}
//get the renderer parts of the target to set its colors with the objective color, to see easily the target to reach
public void addElementToScreenObjectiveList (GameObject obj, bool useCloseDistance, float radiusDistance, bool showOffScreen, bool showDistanceInfo,
bool showDistanceOffScreen, string objectiveIconName, bool useCustomObjectiveColor, Color objectiveColor,
bool removeCustomObjectiveColor, float iconOffset)
{
if (!showObjectivesActive) {
return;
}
objectiveInfo newObjective = new objectiveInfo ();
newObjective.Name = obj.name;
newObjective.mapObject = obj;
newObjective.iconOffset = iconOffset;
newObjective.ID = currentID;
int currentObjectiveIconIndex = -1;
int objectiveIconListCount = objectiveIconList.Count;
for (int i = 0; i < objectiveIconListCount; i++) {
if (currentObjectiveIconIndex == -1 && objectiveIconList [i].name.Equals (objectiveIconName)) {
currentObjectiveIconIndex = i;
}
}
if (currentObjectiveIconIndex != -1) {
objectiveIconElement currentObjectiveIconElement = objectiveIconList [currentObjectiveIconIndex];
if (radiusDistance < 0) {
radiusDistance = currentObjectiveIconElement.minDefaultDistance;
}
newObjective.useCloseDistance = useCloseDistance;
newObjective.closeDistance = radiusDistance;
newObjective.showOffScreenIcon = showOffScreen;
newObjective.showDistance = showDistanceInfo;
newObjective.showDistanceOffScreen = showDistanceOffScreen;
int propertyNameID = Shader.PropertyToID ("_Color");
if (currentObjectiveIconElement.changeObjectiveColors && !removeCustomObjectiveColor) {
Component[] components = obj.GetComponentsInChildren (typeof(Renderer));
foreach (Renderer child in components) {
if (child.material.HasProperty (propertyNameID)) {
int materialsLength = child.materials.Length;
for (int j = 0; j < materialsLength; j++) {
Material currentMaterial = child.materials [j];
newObjective.materials.Add (currentMaterial);
newObjective.originalColor.Add (currentMaterial.color);
if (useCustomObjectiveColor) {
currentMaterial.color = objectiveColor;
} else {
currentMaterial.color = currentObjectiveIconElement.objectiveColor;
}
}
}
}
}
newObjective.iconPrefab = currentObjectiveIconElement.iconInfoElement.gameObject;
objectiveList.Add (newObjective);
int playerScreenObjectivesListCount = playerScreenObjectivesList.Count;
for (int i = 0; i < playerScreenObjectivesListCount; i++) {
playerScreenObjectivesList [i].addElementToList (newObjective, currentObjectiveIconElement.iconInfoElement.gameObject, currentID);
}
} else {
print ("Element not found in objective icon list");
}
currentID++;
}
public int getCurrentID ()
{
return currentID;
}
public void increaseCurrentID ()
{
currentID++;
}
public void addElementFromPlayerList (objectiveInfo newObjectiveInfo, objectiveIconElement currentObjectiveIconElement, Transform currentPlayer, bool addIconOnRestOfPlayers)
{
if (!showObjectivesActive) {
return;
}
objectiveList.Add (newObjectiveInfo);
if (addIconOnRestOfPlayers) {
int playerScreenObjectivesListCount = playerScreenObjectivesList.Count;
for (int i = 0; i < playerScreenObjectivesListCount; i++) {
if (playerScreenObjectivesList [i].player != currentPlayer) {
playerScreenObjectivesList [i].addElementToList (newObjectiveInfo, currentObjectiveIconElement.iconInfoElement.gameObject, newObjectiveInfo.ID);
}
}
}
}
//if the target is reached, disable all the parameters and clear the list, so a new objective can be added in any moment
public void removeElementFromList (objectiveInfo objectiveListElement)
{
if (!showObjectivesActive) {
return;
}
if (objectiveListElement.iconRemoved) {
return;
}
checkObjectiveInfoOnMapSystem (objectiveListElement);
if (objectiveListElement.materials.Count > 0) {
StartCoroutine (changeObjectColors (objectiveListElement, true));
} else {
removeElementFromObjectiveList (objectiveListElement);
}
}
public void removeGameObjectFromList (GameObject objectToSearch)
{
if (!showObjectivesActive) {
return;
}
int objectiveListCount = objectiveList.Count;
for (int j = objectiveListCount - 1; j >= 0; j--) {
if (objectiveList [j].mapObject == objectToSearch) {
removeElementFromList (objectiveList [j]);
}
}
}
public void removeGameObjectListFromList (List<GameObject> list)
{
if (!showObjectivesActive) {
return;
}
bool mapCreatorLocated = mapCreatorManager != null;
for (int i = 0; i < list.Count; i++) {
for (int j = 0; j < objectiveList.Count; j++) {
if (objectiveList [j].mapObject == list [i]) {
if (mapCreatorLocated) {
mapCreatorManager.removeMapObject (objectiveList [j].mapObject, true);
}
removeElementFromObjectiveList (objectiveList [j]);
}
}
}
}
IEnumerator changeObjectColors (objectiveInfo objectiveListElement, bool removeElement)
{
if (objectiveListElement.materials.Count != 0) {
for (float t = 0; t < 1;) {
t += Time.deltaTime;
int materialsCount = objectiveListElement.materials.Count;
for (int k = 0; k < materialsCount; k++) {
Material currentMaterial = objectiveListElement.materials [k];
currentMaterial.color = Color.Lerp (currentMaterial.color, objectiveListElement.originalColor [k], t / 3);
}
yield return null;
}
}
if (removeElement) {
removeElementFromObjectiveList (objectiveListElement);
}
}
public void removeElementFromObjectiveList (objectiveInfo objectiveListElement)
{
if (!showObjectivesActive) {
return;
}
int playerScreenObjectivesListCount = playerScreenObjectivesList.Count;
for (int i = 0; i < playerScreenObjectivesListCount; i++) {
playerScreenObjectivesList [i].removeElementFromList (objectiveListElement.ID);
}
int objectiveListIndex = objectiveList.FindIndex (s => s.ID == objectiveListElement.ID);
if (objectiveListIndex > -1) {
objectiveList.RemoveAt (objectiveListIndex);
}
}
public void removeElementFromObjectiveListCalledByPlayer (int objectId, GameObject currentPlayer)
{
if (!showObjectivesActive) {
return;
}
for (int i = 0; i < objectiveList.Count; i++) {
if (objectiveList [i].ID == objectId) {
checkObjectiveInfoOnMapSystem (objectiveList [i]);
if (i < objectiveList.Count && objectiveList [i].ID == objectId) {
if (objectiveList [i].materials.Count > 0) {
StartCoroutine (changeObjectColors (objectiveList [i], true));
} else {
objectiveList.Remove (objectiveList [i]);
}
// print ("Screen Icon removed without the map system");
} else {
// print ("Screen Icon removed with the map system");
}
int playerScreenObjectivesListCount = playerScreenObjectivesList.Count;
for (int j = 0; j < playerScreenObjectivesListCount; j++) {
if (playerScreenObjectivesList [j].player != currentPlayer) {
playerScreenObjectivesList [j].removeElementFromList (objectId);
}
}
return;
}
}
}
public void checkObjectiveInfoOnMapSystem (objectiveInfo objectiveListElement)
{
if (!showObjectivesActive) {
return;
}
if (objectiveListElement.mapObject != null) {
objectiveListElement.iconRemoved = true;
bool isPathElement = false;
mapObjectInformation currentMapObjectInformation = objectiveListElement.mapObject.GetComponent<mapObjectInformation> ();
if (currentMapObjectInformation != null) {
if (currentMapObjectInformation.typeName.Equals ("Path Element")) {
isPathElement = true;
}
currentMapObjectInformation.checkPointReachedEvent ();
}
if (mapCreatorManager != null) {
mapCreatorManager.removeMapObject (objectiveListElement.mapObject, isPathElement);
}
}
}
public void setScreenObjectiveVisibleState (bool state, GameObject mapObject)
{
if (!showObjectivesActive) {
return;
}
int objectiveListCount = objectiveList.Count;
for (int j = 0; j < objectiveListCount; j++) {
if (objectiveList [j].mapObject == mapObject) {
objectiveList [j].showIconPaused = state;
}
}
}
public void checkGetMapCreatorManager ()
{
bool mapCreatorManagerAssigned = (mapCreatorManager != null);
if (!mapCreatorManagerAssigned) {
mapCreatorManager = mapCreator.Instance;
mapCreatorManagerAssigned = mapCreatorManager != null;
}
if (!mapCreatorManagerAssigned) {
GKC_Utils.instantiateMainManagerOnSceneWithTypeOnApplicationPlaying (mapCreator.getMainManagerName (), typeof(mapCreator), true);
mapCreatorManager = mapCreator.Instance;
mapCreatorManagerAssigned = (mapCreatorManager != null);
}
if (!mapCreatorManagerAssigned) {
mapCreatorManager = FindObjectOfType<mapCreator> ();
}
}
[System.Serializable]
public class objectiveInfo
{
public string Name;
public GameObject mapObject;
public RectTransform iconTransform;
public GameObject onScreenIcon;
public GameObject offScreenIcon;
public Text iconText;
public int ID;
public bool useCloseDistance;
public float closeDistance;
public bool showOffScreenIcon;
public bool showDistance;
public bool showDistanceOffScreen;
public float iconOffset;
public bool showIconPaused;
public float lastDistance;
public bool iconRemoved;
[HideInInspector] public List<Material> materials = new List<Material> ();
[HideInInspector] public List<Color> originalColor = new List<Color> ();
public GameObject iconPrefab;
}
[System.Serializable]
public class objectiveIconElement
{
public string name;
public objectiveIconInfo iconInfoElement;
public bool changeObjectiveColors = true;
public Color objectiveColor;
public float minDefaultDistance = 10;
}
}

View File

@@ -0,0 +1,17 @@
fileFormatVersion: 2
guid: 20f59603f25f89b4ea2469751ddc7f06
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/Objectives Mission System/screenObjectivesSystem.cs
uploadId: 814740

View File

@@ -0,0 +1,179 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class setMissionSubObjectiveStateRemotelySystem : MonoBehaviour
{
[Header ("Main Settings")]
[Space]
public bool setMissionInfoEnabled = true;
public int missionID;
public int missionScene = -1;
public string subObjectiveName;
[Space]
[Header ("Other Settings")]
[Space]
public bool useObjectiveCounterInsteadOfList;
public bool increasetCounterToCurrentMissionActive;
[Space]
[Header ("Remote Events Settings")]
[Space]
public bool useRemoteEvents;
public List<string> removeEventNameList = new List<string> ();
[Space]
[Header ("Events Settings")]
[Space]
public bool useEventOnSubObjectiveComplete;
public UnityEvent eventOnSubObjectiveComplete;
[Space]
public bool useEventOnSubObjectiveCancelled;
public UnityEvent eventOnSubObjectiveCompleteCancelled;
bool mainObjectiveManagerLocated;
objectiveManager mainObjectiveManager;
public void addSubObjectiveCompleteRemotely (string customSubObjectiveName)
{
sendMissionInfo (customSubObjectiveName);
}
public void addSubObjectiveCompleteRemotely ()
{
sendMissionInfo (subObjectiveName);
}
public void sendMissionInfo (string newSubObjectiveName)
{
if (!setMissionInfoEnabled) {
return;
}
getMainObjectiveManager ();
if (mainObjectiveManagerLocated) {
if (useObjectiveCounterInsteadOfList) {
if (increasetCounterToCurrentMissionActive) {
mainObjectiveManager.increaseObjectiveCounterRemotelyToCurrentMissionActive (missionScene);
} else {
mainObjectiveManager.increaseObjectiveCounterRemotely (missionScene, missionID);
}
} else {
mainObjectiveManager.addSubObjectiveCompleteRemotely (newSubObjectiveName, missionScene, missionID);
}
if (useRemoteEvents) {
if (increasetCounterToCurrentMissionActive) {
mainObjectiveManager.checkRemoteEventsOnSubObjectiveCompleteRemotelyToCurrentMissionActive (removeEventNameList, missionScene);
} else {
mainObjectiveManager.checkRemoteEventsOnSubObjectiveCompleteRemotely (removeEventNameList, missionScene, missionID);
}
}
if (useEventOnSubObjectiveComplete) {
eventOnSubObjectiveComplete.Invoke ();
}
}
}
public void cancelCurrentMissionRemotely ()
{
if (!setMissionInfoEnabled) {
return;
}
getMainObjectiveManager ();
if (mainObjectiveManagerLocated) {
mainObjectiveManager.cancelCurrentMissionRemotely (missionScene, missionID);
if (useEventOnSubObjectiveCancelled) {
eventOnSubObjectiveCompleteCancelled.Invoke ();
}
}
}
void getMainObjectiveManager ()
{
if (mainObjectiveManagerLocated) {
return;
}
mainObjectiveManager = objectiveManager.Instance;
mainObjectiveManagerLocated = mainObjectiveManager != null;
if (!mainObjectiveManagerLocated) {
GKC_Utils.instantiateMainManagerOnSceneWithTypeOnApplicationPlaying (objectiveManager.getMainManagerName (), typeof (objectiveManager), true);
mainObjectiveManager = objectiveManager.Instance;
mainObjectiveManagerLocated = mainObjectiveManager != null;
}
if (!mainObjectiveManagerLocated) {
mainObjectiveManager = FindObjectOfType<objectiveManager> ();
mainObjectiveManagerLocated = mainObjectiveManager != null;
}
}
public void setMissionID (int newValue)
{
missionID = newValue;
}
public void increaseMissionID ()
{
missionID++;
}
public void decreaseMissionID ()
{
missionID--;
if (missionID < 0) {
missionID = 0;
}
}
public void setSubObjectiveName (string newValue)
{
subObjectiveName = newValue;
}
public void setMissionInfoEnabledState (bool state)
{
setMissionInfoEnabled = state;
}
public void setMissionInfoEnabledStateFromEditor (bool state)
{
setMissionInfoEnabledState (state);
updateComponent ();
}
void updateComponent ()
{
GKC_Utils.updateComponent (this);
GKC_Utils.updateDirtyScene ("update mission state remotely state " + gameObject.name, gameObject);
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 803c8148424f0464a8d99ab0dd9bd512
timeCreated: 1611424878
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/Objectives Mission System/setMissionSubObjectiveStateRemotelySystem.cs
uploadId: 814740