NodeInteraction은 노드와 노드사이에 이어진 간선과 함께 상호작용 연산을 수행하는 스크립트가 담긴 오브젝트가 생성되고 간선상의 전투 시각적 효과를 직접적으로 컨트롤한다.

Untitled

이 오브젝트는 프리펩화 되어 있고 시각적으로 표시되지 않는다.

	  public GameObject nodeA;
    public GameObject nodeB;
    public GameObject wayBetween;

    public enum InterType{Fight, RecoverNode}
    public InterType interType;

    public float fNodeUnitTime;    //첫번째 노드의 유닛 생산주기
    public float sNodeUnitTime;    //두번째 노드의 유닛 생산주기

    bool fNodeNotFight;     //첫번째 노드의 전투상태, 간선에서 전투 라인이 인접하면 true로 변경됨
    bool sNodeNotFight;     //두번째 노드의 전투상태

기본적으로 상호작용을 할 노드 두개와 간선하나를 저장한다.

이 상호작용이 수행할 타입을 저장한다.(전투, 지)

각 노드의 공격주기(유닛 생산주기)를 저장한다.

    public void SetFightStat(GameObject _nodeA, GameObject _nodeB, GameObject _way){
        nodeA = _nodeA;
        nodeB = _nodeB;
        wayBetween = _way;
    }

이 오브젝트는 GroundMaker에 의해 생성되고 초기화된다.

매개변수를 전달받아 위의 함수를 통해 선언한 변수에 대입한다.

    void Start()
    {
        Debug.Log("Fight Event 생성됨");
        Debug.Log("첫번째 : " + nodeA + " 두번째 : " + nodeB);
        wayBetween.GetComponent<Way>().FightStart();
        InitUnitOutTime();
        StartCoroutine(fNodeUnitOut());
        StartCoroutine(sNodeUnitOut());
        Debug.Log("첫번째 노드 유닛 생산 속도 : " + fNodeUnitTime);
        Debug.Log("두번째 노드 유닛 생산 속도 : " + sNodeUnitTime);
        InitWay();  //way 오브젝트 전투라인 초기화
    }

    // Update is called once per frame
    void Update()
    {

    }

이 오브젝트는 시작과 동시에 코루틴을 시작한다.

    //첫번째 노드의 설정된 유닛 생산주기에 맞춰 way의 게이지바 증가 함수를 호출
    IEnumerator fNodeUnitOut(){
        while(interType == InterType.Fight){    //두 노드가 싸우는 상태일때만
            InitUnitOutTime();                  //생산속도가 변경될 경우를 대비해 지속적으로 갱신
            Node nodeAcomp = nodeA.GetComponent<Node>();
            nodeAcomp.Attack(nodeAcomp.attackScore);                //아래 호출빈도 조절
            if(wayBetween.GetComponent<Way>().isMoving == true){    //게이지 바가 한쪽 끝으로 도달하지 않았을 때
                wayBetween.GetComponent<Way>().MovingLine(1);       //1을 전달해서 x축 + 방향으로
            }else{
                //게이지바가 끝까지 도달했을 경우 A노드의 공격력만큼 B노드에게 데미지를 준다.
                nodeB.GetComponent<Node>().Damaged(nodeAcomp.attackScore, nodeAcomp.nodeType);
            }
            yield return new WaitForSecondsRealtime(fNodeUnitTime); //코루틴 호출 주기는 노드별로 상이
        }
    }

    //두번째 노드의 설정된 유닛 생산주기에 맞춰 way의 게이지바 증가 함수를 호출
    IEnumerator sNodeUnitOut(){
        while(interType == InterType.Fight){    //두 노드가 싸우는 상태일때만
            InitUnitOutTime();
            Node nodeBcomp = nodeB.GetComponent<Node>();
            if(wayBetween.GetComponent<Way>().isMoving == true){      //게이지 바가 한쪽 끝으로 도달하지 않았을 때
                wayBetween.GetComponent<Way>().MovingLine(-1);      //-1을 전달해서 x축 - 방향으로
            }else{
                //게이지바가 끝까지 도달했을 경우 B노드의 공격력만큼 A노드에게 데미지를 준다.
                nodeA.GetComponent<Node>().Damaged(nodeBcomp.attackScore, nodeBcomp.nodeType);
            }
            yield return new WaitForSecondsRealtime(sNodeUnitTime);
        }
    }

각 노드는 하나의 코루틴을 반복적으로 수행하며 상호작용의 타입이 전투일때만 작업을 시행한다.

위의 코루틴은 외부상황(인접노드의 전투지원 등)에 의해 공격주기 및 관여 수치가 변경될 수 있기 때문에 코루틴이 반복될 때마다 수치를 새로고친다.(아래 코드)

먼저 간선의 게이지바가 서로 맞닿을 때까지 반복적으로 게이지바의 크기를 늘려간다. 게이지바가 맞닿게 된다면 게이지바의 경계를 이동시키는 함수를 실행한다.

   void InitUnitOutTime(){ //유닛 생성주기 재설정
        fNodeUnitTime = nodeA.GetComponent<Node>().unitOutSpeed;
        sNodeUnitTime = nodeB.GetComponent<Node>().unitOutSpeed;
    }