浏览代码

Code Cleaning/refractoring

/main
uChema 3 年前
当前提交
6938ba52
共有 13 个文件被更改,包括 167 次插入206 次删除
  1. 15
      UOP1_Project/Assets/Scripts/Cutscenes/CutsceneManager.cs
  2. 25
      UOP1_Project/Assets/Scripts/Dialogues/DialogueManager.cs
  3. 50
      UOP1_Project/Assets/Scripts/Inventory/InventoryManager.cs
  4. 138
      UOP1_Project/Assets/Scripts/Inventory/UIInventoryManager.cs
  5. 2
      UOP1_Project/Assets/Scripts/Quests/Editor/QuestEditorWindow.cs
  6. 21
      UOP1_Project/Assets/Scripts/Quests/QuestManagerSO.cs
  7. 16
      UOP1_Project/Assets/Scripts/Quests/ScriptableObjects/StepSO.cs
  8. 11
      UOP1_Project/Assets/Scripts/Quests/StepController.cs
  9. 10
      UOP1_Project/Assets/Scripts/SpawnSystem.cs
  10. 5
      UOP1_Project/Assets/Scripts/UI/UIDialogueManager.cs
  11. 23
      UOP1_Project/Assets/Scripts/UI/UIHealthBarManager.cs
  12. 50
      UOP1_Project/Assets/Scripts/UI/UIManager.cs
  13. 7
      UOP1_Project/Assets/Addons/DOTween/Editor/DOTweenEditor.sln.meta

15
UOP1_Project/Assets/Scripts/Cutscenes/CutsceneManager.cs


}
private void Start()
{
if (_playCutsceneEvent != null)
{
}
if (_playDialogueEvent != null)
{
}
if (_pauseTimelineEvent != null)
{
}
}
void PlayCutscene(PlayableDirector activePlayableDirector)
{

25
UOP1_Project/Assets/Scripts/Dialogues/DialogueManager.cs


private void Start()
{
if (_startDialogue != null)
{
}
}

/// <param name="dialogueLine"></param>
public void DisplayDialogueLine(LocalizedString dialogueLine, ActorSO actor)
{
if (_openUIDialogueEvent != null)
{
}
}
private void OnAdvance()

private void DisplayChoices(List<Choice> choices)
{
_inputReader.advanceDialogueEvent -= OnAdvance;
if (_makeDialogueChoiceEvent != null)
{
}
if (_showChoicesUIEvent != null)
{
}
if (_makeDialogueChoiceEvent != null)
{
}
if (choice.ActionType == ChoiceActionType.continueWithStep)
{
if (_continueWithStep != null)

50
UOP1_Project/Assets/Scripts/Inventory/InventoryManager.cs


private void OnEnable()
{
//Check if the event exists to avoid errors
if (_cookRecipeEvent != null)
{
}
if (_useItemEvent != null)
{
}
if (_equipItemEvent != null)
{
}
if (_addItemEvent != null)
{
}
if (_removeItemEvent != null)
{
}
if (_rewardItemEvent != null)
{
}
if (_giveItemEvent != null)
{
}
if (_cookRecipeEvent != null)
{
}
if (_useItemEvent != null)
{
}
if (_equipItemEvent != null)
{
}
if (_addItemEvent != null)
{
}
if (_removeItemEvent != null)
{
}
}

138
UOP1_Project/Assets/Scripts/Inventory/UIInventoryManager.cs


{
[SerializeField]
private Inventory currentInventory = default;
private Inventory _currentInventory = default;
private InventoryItemFiller itemPrefab = default;
private InventoryItemFiller _itemPrefab = default;
private GameObject contentParent = default;
private GameObject _contentParent = default;
private InspectorFiller inspectorFiller = default;
private InspectorFiller _inspectorFiller = default;
private InventoryTypeTabsFiller tabFiller = default;
private InventoryTypeTabsFiller _tabFiller = default;
private InventoryButtonFiller buttonFiller = default;
private InventoryButtonFiller _buttonFiller = default;
InventoryTabType _selectedTab = default;
InventoryTabType selectedTab = default;
List<InventoryTabType> tabTypesList = new List<InventoryTabType>();
List<InventoryTabType> _tabTypesList = new List<InventoryTabType>();
private ItemEventChannelSO CookRecipeEvent = default;
private ItemEventChannelSO _cookRecipeEvent = default;
private ItemEventChannelSO UseItemEvent = default;
private ItemEventChannelSO _useItemEvent = default;
private ItemEventChannelSO EquipItemEvent = default;
private ItemEventChannelSO _equipItemEvent = default;
private TabEventChannelSO ChangeTabEvent = default;
private TabEventChannelSO _changeTabEvent = default;
private ItemEventChannelSO SelectItemEvent = default;
private ItemEventChannelSO _selectItemEvent = default;
private VoidEventChannelSO ActionButtonClicked = default;
private VoidEventChannelSO _actionButtonClicked = default;
private VoidEventChannelSO OnInteractionEndedEvent = default;
private VoidEventChannelSO _onInteractionEndedEvent = default;
[SerializeField]
private InputReader _inputReader = default;

//Check if the event exists to avoid errors
if (ActionButtonClicked != null)
{
ActionButtonClicked.OnEventRaised += ActionButtonEventRaised;
}
if (ChangeTabEvent != null)
{
ChangeTabEvent.OnEventRaised += ChangeTabEventRaised;
}
if (SelectItemEvent != null)
{
SelectItemEvent.OnEventRaised += InspectItem;
}
if (OnInteractionEndedEvent != null)
{
OnInteractionEndedEvent.OnEventRaised += InteractionEnded;
}
if(_inputReader)
_actionButtonClicked.OnEventRaised += ActionButtonEventRaised;
_changeTabEvent.OnEventRaised += ChangeTabEventRaised;
_selectItemEvent.OnEventRaised += InspectItem;
_onInteractionEndedEvent.OnEventRaised += InteractionEnded;
_inputReader.menuSwitchTab += SwitchTab;
}

if (ActionButtonClicked != null)
{
ActionButtonClicked.OnEventRaised -= ActionButtonEventRaised;
}
if (ChangeTabEvent != null)
{
ChangeTabEvent.OnEventRaised -= ChangeTabEventRaised;
}
if (SelectItemEvent != null)
{
SelectItemEvent.OnEventRaised -= InspectItem;
}
_actionButtonClicked.OnEventRaised -= ActionButtonEventRaised;
_changeTabEvent.OnEventRaised -= ChangeTabEventRaised;
_selectItemEvent.OnEventRaised -= InspectItem;
}
public void SwitchTab(float orientation)

{
bool isLeft = orientation < 0;
int initialIndex = tabTypesList.FindIndex(o => o == selectedTab);
int initialIndex = _tabTypesList.FindIndex(o => o == _selectedTab);
if (initialIndex != -1)
{
if (isLeft)

initialIndex++;
}
initialIndex= Mathf.Clamp(initialIndex, 0, tabTypesList.Count-1);
initialIndex= Mathf.Clamp(initialIndex, 0, _tabTypesList.Count-1);
ChangeTabEventRaised(tabTypesList[initialIndex]);
ChangeTabEventRaised(_tabTypesList[initialIndex]);
}

{
isNearPot = _isNearPot;
if ((_selectedTabType != TabType.none) && (tabTypesList.Exists(o => o.TabType == _selectedTabType)))
if ((_selectedTabType != TabType.none) && (_tabTypesList.Exists(o => o.TabType == _selectedTabType)))
selectedTab = tabTypesList.Find(o => o.TabType == _selectedTabType);
_selectedTab = _tabTypesList.Find(o => o.TabType == _selectedTabType);
if (tabTypesList != null)
if (_tabTypesList != null)
if (tabTypesList.Count > 0)
if (_tabTypesList.Count > 0)
selectedTab = tabTypesList[0];
_selectedTab = _tabTypesList[0];
}
}

if (selectedTab != null)
if (_selectedTab != null)
FillTypeTabs(tabTypesList, selectedTab);
FillTypeTabs(_tabTypesList, _selectedTab);
listItemsToShow = currentInventory.Items.FindAll(o => o.Item.ItemType.TabType == selectedTab);
listItemsToShow = _currentInventory.Items.FindAll(o => o.Item.ItemType.TabType == _selectedTab);
FillItems(listItemsToShow);
}

void FillTypeTabs(List<InventoryTabType> typesList, InventoryTabType selectedType)
{
tabFiller.FillTabs(typesList, selectedType, ChangeTabEvent);
_tabFiller.FillTabs(typesList, selectedType, _changeTabEvent);
}

if (i >= _instanciatedItems.Count)
{
//instantiate
InventoryItemFiller instantiatedPrefab = Instantiate(itemPrefab, contentParent.transform) as InventoryItemFiller;
InventoryItemFiller instantiatedPrefab = Instantiate(_itemPrefab, _contentParent.transform) as InventoryItemFiller;
_instanciatedItems.Add(instantiatedPrefab);
}

_instanciatedItems[i].SetItem(listItemsToShow[i], isSelected, SelectItemEvent);
_instanciatedItems[i].SetItem(listItemsToShow[i], isSelected, _selectItemEvent);
}

else
{
//if the new item needs to be instantiated
if (currentInventory.Items.Count > _instanciatedItems.Count)
if (_currentInventory.Items.Count > _instanciatedItems.Count)
InventoryItemFiller instantiatedPrefab = Instantiate(itemPrefab, contentParent.transform) as InventoryItemFiller;
InventoryItemFiller instantiatedPrefab = Instantiate(_itemPrefab, _contentParent.transform) as InventoryItemFiller;
index = currentInventory.Items.Count;
index = _currentInventory.Items.Count;
}

_instanciatedItems[index].SetItem(itemToUpdate, isSelected, SelectItemEvent);
_instanciatedItems[index].SetItem(itemToUpdate, isSelected, _selectItemEvent);

//check if interactable
bool isInteractable = true;
buttonFiller.gameObject.SetActive(true);
_buttonFiller.gameObject.SetActive(true);
isInteractable = currentInventory.hasIngredients(itemToInspect.IngredientsList) && isNearPot;
isInteractable = _currentInventory.hasIngredients(itemToInspect.IngredientsList) && isNearPot;
buttonFiller.gameObject.SetActive(false);
_buttonFiller.gameObject.SetActive(false);
buttonFiller.FillInventoryButtons(itemToInspect.ItemType, isInteractable);
_buttonFiller.FillInventoryButtons(itemToInspect.ItemType, isInteractable);
}

void ShowItemInformation(Item item)
{
bool[] availabilityArray = currentInventory.IngredientsAvailability(item.IngredientsList);
bool[] availabilityArray = _currentInventory.IngredientsAvailability(item.IngredientsList);
inspectorFiller.FillItemInspector(item, availabilityArray);
_inspectorFiller.FillItemInspector(item, availabilityArray);
buttonFiller.gameObject.SetActive(false);
inspectorFiller.HideItemInspector();
_buttonFiller.gameObject.SetActive(false);
_inspectorFiller.HideItemInspector();
}

void ActionButtonEventRaised()
{
if (ActionButtonClicked != null)
if (_actionButtonClicked != null)
{
//find the selected Item
if (_instanciatedItems.Count > selectedItemId && selectedItemId > -1)

{
Debug.Log("USE ITEM " + itemToUse.name);
UseItemEvent.OnEventRaised(itemToUse);
_useItemEvent.OnEventRaised(itemToUse);
//update inventory
FillInventory();
}

{
Debug.Log("Equip ITEM " + itemToUse.name);
EquipItemEvent.OnEventRaised(itemToUse);
_equipItemEvent.OnEventRaised(itemToUse);
}
void CookRecipe(Item recipeToCook)

CookRecipeEvent.OnEventRaised(recipeToCook);
_cookRecipeEvent.OnEventRaised(recipeToCook);
//update inspector
InspectItem(recipeToCook);

2
UOP1_Project/Assets/Scripts/Quests/Editor/QuestEditorWindow.cs


LoadAndInitOptionsDialogueLineUXML(step.CompleteDialogue, step.IncompleteDialogue, dialogueAreaVE);
//Type (Check Item etc)
if (step.Type == stepType.dialogue)
if (step.Type == StepType.Dialogue)
{
VisualElement itemValidateVE = stepVE.Q<VisualElement>("item-validate");
itemValidateVE.style.display = DisplayStyle.None;

21
UOP1_Project/Assets/Scripts/Quests/QuestManagerSO.cs


[SerializeField] private DialogueDataChannelSO _endDialogueEvent = default;
[Header("Broadcasting on channels")]
[FormerlySerializedAs("_winDialogueEvent")]
[FormerlySerializedAs("_loseDialogueEvent")]
[SerializeField] private VoidEventChannelSO _incompleteDialogueEvent = default;
[SerializeField] private ItemEventChannelSO _giveItemEvent = default;

public void StartGame()
{//Add code for saved information
if (_checkStepValidityEvent != null)
{
}
if (_endDialogueEvent != null)
{
}
StartQuestline();
}
void StartQuestline()

}
}
bool hasStep(ActorSO actorToCheckWith)
bool HasStep(ActorSO actorToCheckWith)
{
if (_currentStep != null)
{

}
if (hasStep(actor))
if (HasStep(actor))
{
if (isCheckValidity)
{

{
switch (_currentStep.Type)
{
case stepType.checkItem:
case StepType.CheckItem:
if (_inventory.Contains(_currentStep.Item))
{

_incompleteDialogueEvent.RaiseEvent();
}
break;
case stepType.giveItem:
case StepType.GiveItem:
if (_inventory.Contains(_currentStep.Item))
{
_giveItemEvent.RaiseEvent(_currentStep.Item);

}
break;
case stepType.rewardItem:
case StepType.RewardItem:
_rewardItemEvent.RaiseEvent(_currentStep.Item);
//no dialogue is needed after Reward Item
if (_currentStep.CompleteDialogue != null)

EndStep();
}
break;
case stepType.dialogue:
case StepType.Dialogue:
//dialogue has already been played
if (_currentStep.CompleteDialogue != null)
{

16
UOP1_Project/Assets/Scripts/Quests/ScriptableObjects/StepSO.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
public enum stepType
public enum StepType
dialogue,
giveItem,
checkItem,
rewardItem
Dialogue,
GiveItem,
CheckItem,
RewardItem
}
[CreateAssetMenu(fileName = "step", menuName = "Quests/step", order = 51)]
public class StepSO : ScriptableObject

private DialogueDataSO _dialogueBeforeStep = default;
[Tooltip("The dialogue that will be diplayed when the step is achieved")]
[SerializeField]
[FormerlySerializedAs("_winDialogue")]
[FormerlySerializedAs("_loseDialogue")]
private DialogueDataSO _incompleteDialogue = default;
[Tooltip("The item to check/give/reward")]
[SerializeField]

private stepType _type = default;
private StepType _type = default;
[SerializeField]
bool _isDone = false;
public DialogueDataSO DialogueBeforeStep => _dialogueBeforeStep;

public stepType Type => _type;
public StepType Type => _type;
public bool IsDone => _isDone;
public ActorSO Actor => _actor;

11
UOP1_Project/Assets/Scripts/Quests/StepController.cs


private void Start()
{
if (_winDialogueEvent != null)
{ _winDialogueEvent.OnEventRaised += PlayWinDialogue; }
if (_loseDialogueEvent != null)
{ _loseDialogueEvent.OnEventRaised += PlayLoseDialogue; }
_winDialogueEvent.OnEventRaised += PlayWinDialogue;
_loseDialogueEvent.OnEventRaised += PlayLoseDialogue;
}

void StartDialogue()
{
if (_startDialogueEvent != null)
{
}
}
void PlayLoseDialogue()
{

10
UOP1_Project/Assets/Scripts/SpawnSystem.cs


private void OnEnable()
{
if (_OnSceneReady != null)
{
}
if (_OnSceneReady != null)
{
}
}
private void SpawnPlayer()

5
UOP1_Project/Assets/Scripts/UI/UIDialogueManager.cs


[SerializeField] private DialogueChoicesChannelSO _showChoicesEvent = default;
private void Start()
{
if (_showChoicesEvent != null)
{
}
}
public void SetDialogue(LocalizedString dialogueLine, ActorSO actor)
{

23
UOP1_Project/Assets/Scripts/UI/UIHealthBarManager.cs


}
private void Start()
{
if (_setHealthBar != null)
{
}
if (_inflictDamage != null)
{
}
if (_restoreHealth != null)
{
}
}
private void OnDestroy()
{
_setHealthBar.OnEventRaised -= SetHealthBar;
_inflictDamage.OnEventRaised -= InflictDamage;
_restoreHealth.OnEventRaised -= RestoreHealth;
}
public void SetHealthBar(int _maxHealth)
{

50
UOP1_Project/Assets/Scripts/UI/UIManager.cs


private void OnEnable()
{
//Check if the event exists to avoid errors
if (_openUIDialogueEvent != null)
{
}
if (_closeUIDialogueEvent != null)
{
}
if (_openInventoryScreenForCookingEvent != null)
{
}
if (_openInventoryScreenEvent != null)
{
}
if (_closeInventoryScreenEvent != null)
{
}
if (_setInteractionEvent != null)
{
}
if (_onSceneReady != null)
{
}
private void OnDestroy()
{
//Check if the event exists to avoid errors
_openUIDialogueEvent.OnEventRaised -= OpenUIDialogue;
_closeUIDialogueEvent.OnEventRaised -= CloseUIDialogue;
_openInventoryScreenForCookingEvent.OnEventRaised -= SetInventoryScreenForCooking;
_openInventoryScreenEvent.OnEventRaised -= SetInventoryScreen;
_closeInventoryScreenEvent.OnEventRaised -= CloseInventoryScreen;
_setInteractionEvent.OnEventRaised -= SetInteractionPanel;
_onSceneReady.OnEventRaised -= ResetUI;
}
private void Start()
{

7
UOP1_Project/Assets/Addons/DOTween/Editor/DOTweenEditor.sln.meta


fileFormatVersion: 2
guid: 60d46e2a5f9bc4b1fb039c7d39b2b60b
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存