간선의 프리펩

간선의 프리펩

간선의 부모자식 구조

간선의 부모자식 구조

    public GameObject NodeA;    //노드정보A
    public GameObject NodeB;    //노드정보B
    public GameObject SideA;    //게이지바A
    public GameObject SideB;    //게이지바B
    public GameObject LinkedNodeInteraction;    //연결된 노드 상호작용 오브젝트

    public bool fight;      //전투여부
    public bool moveToA;    //게이지바를 A로 이동할지
    public bool moveToB;    //게이지바를 B로 이동할지
    public bool isContact;  //두 게이지바가 서로 닿았는지
    public bool isMoving;   //게이지바가 움직일지
    public bool touchA;     //게이지바가 노드A에 닿았는지
    public bool touchB;     //게이지바가 노드B에 닿았는지
    public bool DelWay;     //삭제 트리거(임시)

    public float movePower; //게이지바가 움직일 수치
    public float wayLength; //간선 길이
    MeshRenderer mesh;
    Material mat;
    void Start()
    {
        SideA.SetActive(false);
        SideB.SetActive(false);
        mesh = GetComponent<MeshRenderer>();
        mat = mesh.sharedMaterial;
        mat.SetFloat("_Amt", 0.5f);
        wayLength = gameObject.transform.localScale.x;  //way의 길이
        SideA.transform.localPosition = new Vector3(-0.5f, SideA.transform.localPosition.y, SideA.transform.localPosition.z);
        SideB.transform.localPosition = new Vector3(0.5f, SideA.transform.localPosition.y, SideA.transform.localPosition.z);
    }

    // Update is called once per frame
    void Update()
    {
        DetectContact();
        DetectOver();
    }

노드의 상호작용을 시각적으로 표현하는 간선은 NodeInteraction에서 처리되고 결과에 따라 조작된다.

따라서 적대적 관계사이의 상황과 그렇지 않은 경우를 나누어 실행될 함수를 생성하였다.

//두 노드가 같을 때 게이지바의 움직임은 필요하지 않으므로 개체의 색과 동일한 게이지바를 최대 크기로 생성한다.
    public void SetSameNode(int _type){ //매개변수의 값이 1이면 플레이어 2일경우 적
        if(_type == 1){
            MeshRenderer aMeshRenderer = SideA.GetComponent<MeshRenderer>();    //플레이어 노드 사이일 경우 sideA를 활성화
            Material aMaterial = aMeshRenderer.material;    
            SideA.SetActive(true);
            aMaterial.color = new Color(0,0,1);                                 //플레이어의 노드색과 동일하게
            SideA.transform.localPosition = SideA.transform.localPosition + Vector3.right * 0.5f;   //간선의 위치와 동일하게
            SideA.transform.localScale = SideA.transform.localScale + Vector3.right;                //간선과 크기가 동일하게
        }else if(_type == 2){
            MeshRenderer bMeshRenderer = SideB.GetComponent<MeshRenderer>();    //적의 노드 사이일 경우 sideB를 활성화
            Material bMaterial = bMeshRenderer.material;
            SideB.SetActive(true);
            bMaterial.color = new Color(1,0,0);
            SideB.transform.localPosition = SideB.transform.localPosition + Vector3.left * 0.5f;   //간선의 위치와 동일하게
            SideB.transform.localScale = SideB.transform.localScale + Vector3.left;                //간선과 크기가 동일하게
        }
    }

매개변수(1 또는 2)에 의해 인접한 노드가 플레이어인지 적인지 전달받는다.

두 경우의 처리과정은 동일하다.

플레이어의 경우 SideA오브젝트가, 적의 경우 SideB오브젝트가 활성화 되고 크기 및 색상이 변경, 위치가 조정 된다.

 public void FightStart(){       //fightEvent가 실행될 때 양쪽 공격게이지 바를 활성화 및 색 조정을 한다
        fight = true;
        MeshRenderer aMeshRenderer = SideA.GetComponent<MeshRenderer>();
        Material aMaterial = aMeshRenderer.material;
        MeshRenderer bMeshRenderer = SideB.GetComponent<MeshRenderer>();
        Material bMaterial = bMeshRenderer.material;
        if(NodeA.GetComponent<Node>().nodeType == Node.NodeType.Player){
            SideA.SetActive(true);
            aMaterial.color = new Color(0,0,1);
        }else if(NodeA.GetComponent<Node>().nodeType == Node.NodeType.Enemy){
            SideA.SetActive(true);
            aMaterial.color = new Color(1,0,0);
        }
        
        if(NodeB.GetComponent<Node>().nodeType == Node.NodeType.Player){
            SideB.SetActive(true);
            bMaterial.color = new Color(0,0,1);
        }else if(NodeB.GetComponent<Node>().nodeType == Node.NodeType.Enemy){
            SideB.SetActive(true);
            bMaterial.color = new Color(1,0,0);
        }
    }

    public void MovingLine(float _moving){      //fightEve에서 호출되는 함수, 음수 양수를 판단하여 왼쪽, 오른쪽으로 움직일지 결정한다.
        Debug.Log("MovingLine실행, 움직일 수치  : "+ _moving);
        if(_moving < 0 ){           //way 상에서 B가 A쪽으로 공격
            if(touchA == true){     //A노드에 직접 닿아있을 경우
                //a노드 체력 감소 (예정)
            }else{
                moveToB = false;
                moveToA = true;
                ReSizeSideObj(_moving);
            }
        }else if(_moving > 0){      //way 상에서 A가 B쪽으로 공격
            if(touchB == true){     //b노드에 직접 닿아있을 경우
                //b노드 체력 감소 (예정)
            }else{
                moveToA = false;
                moveToB = true;
                ReSizeSideObj(_moving);
            }
        }else{
            StopLine();
        }
    }

   

두 노드가 적대적 관계일 경우 전투가 발생하게 된다.

전투가 실행되기 전 FightStart()함수를 먼저 호출하여 SideA, SideB 오브젝트를 호출 한뒤 위치를 양 끝으로 이동한다.

그 다음 A, B쪽에 존재하는 노드의 타입을 확인하고 플레이어, 적 타입마다 색을 다르게 적용한다.

    public void MovingLine(float _moving){      //fightEve에서 호출되는 함수, 음수 양수를 판단하여 왼쪽, 오른쪽으로 움직일지 결정한다.
        Debug.Log("MovingLine실행, 움직일 수치  : "+ _moving);
        if(_moving < 0 ){           //way 상에서 B가 A쪽으로 공격
            if(touchA == true){     //A노드에 직접 닿아있을 경우
                //a노드 체력 감소 (예정)
            }else{
                moveToB = false;
                moveToA = true;
                ReSizeSideObj(_moving);
            }
        }else if(_moving > 0){      //way 상에서 A가 B쪽으로 공격
            if(touchB == true){     //b노드에 직접 닿아있을 경우
                //b노드 체력 감소 (예정)
            }else{
                moveToA = false;
                moveToB = true;
                ReSizeSideObj(_moving);
            }
        }else{
            StopLine();
        }
    }

NodeInteraction에서 호출되는 함수로 양수일때 음수일때를 판별하여 게이지바가 맞닿은 부분을 이동시키는 함수를 호출(ResizeSideObj)하는 역할을 한다.