2024/01/30

안석환·2024년 1월 30일

🧐기본 공부 내용


  1. 공부내용 핵심 키워드
  • 설명


💾 코드

코드내용

📖 참고

참고할 코드 내용




⛔️ 에러


  1. 문제: 설치물을 클릭하여 현제 상태를 반환하여 기능을 처리하는데 이전에 켰던 기능들이 꺼지지않는 현상
    • 시도: 설치물 이벤트 구독 시점에 이전과 데이터가 다르다면 이벤트 구독목록 초기화
    • 해결: 기능별로 달라질때마다 이벤트의 구독자가 달라져서 해결됨
    • 알게된것: 게임오브젝트의 setactive값이 false가 된다고 해서 이벤트 구독이 자동 취소 되지 않는다.

💾 코드

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Resources;
using Unity.VisualScripting.InputSystem;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

public class InstallationController : MonoBehaviour, IInteractable
{
    public MachineSO _installationData;
    public GameObject spawnFunction;
    public GameObject inventoryFunction;
    public GameObject moveFunction;
    public GameObject destinationFunction;

    public Queue<GameObject> doughContainer;

    private int index = -1;

    public event Action installationFuctionSet;
    public event Action installationFuctionOut;
    
    private void Start()
    {
        gameObject.GetComponentInChildren<SpriteRenderer>().sprite = _installationData.sprite;
        
        if (_installationData.haveDoughInventory)
            doughContainer = new Queue<GameObject>();

        if(_installationData.canSpawn)
            spawnFunction.SetActive(true);
        
        if(_installationData.haveDoughInventory)
            inventoryFunction.SetActive(true);
    }
    

    public bool Continuous()
    {
        return false;
    }

    public void OnClickInteract()
    {
        if (index != GameManager.instance.interactionManager.installationFunctionIndex)
        {
            installationFuctionSet = null;
            
            switch (GameManager.instance.interactionManager.installationFunctionIndex)
            {
                case 0:
                    inventoryFunction.SetActive(true);
                    moveFunction.SetActive(false);
                    destinationFunction.SetActive(false);
                    break;
                case 1:
                    inventoryFunction.SetActive(false);
                    moveFunction.SetActive(true);
                    destinationFunction.SetActive(false);
                    break;
                case 2:
                    inventoryFunction.SetActive(false);
                    moveFunction.SetActive(false);
                    destinationFunction.SetActive(true);
                    break;
            }
        }
        installationFuctionSet?.Invoke();
    }

    public void OffClickInteract()
    {
        installationFuctionOut?.Invoke();
    }

    public void OnColliderInteract()
    {
        return;
    }
}




💭 느낀점


  1. 느낀점
  • 느낀 것에 대한 내용 or 피드백
profile
안석환!

0개의 댓글