Beispiel #1
0
    public virtual void RemoveEdge(Transform edgeTr)
    {
        IInputParam <T> inputParamT = edgeTr.GetComponent <IInputParam <T> >();

        for (int i = 0; i < connectedInputModules.Count; ++i)
        {
            if (connectedInputModules[i].Equals(inputParamT))
            {
                connectedInputModules.RemoveAt(i);
                break;
            }
        }
    }
Beispiel #2
0
    public virtual void CreateEdge(Transform targetTr)
    {
        currentEdge = Instantiate(edgePrefab).GetComponent <NewEdge>();
        if (EdgeManager.instance.registerEdge(currentEdge, targetTr, transform))
        {
            IInputParam <T> targetInputModule = targetTr.GetComponent <IInputParam <T> >();
            edges.Add(currentEdge);
            connectedInputModules.Add(targetInputModule);
            currentEdge.SetStartTarget(this);
            currentEdge.SetEndTarget(targetTr);

            //Ordering
            SpriteRenderer edgePointRenderer = GetComponentInChildren <SpriteRenderer>();
            string         sortingLayerName  = edgePointRenderer.sortingLayerName;
            int            sortingOrder      = edgePointRenderer.sortingOrder;
            currentEdge.SetOrdering(sortingLayerName, sortingOrder);
        }
        else
        {
            Debug.LogWarning("Edge Register Failed : " + name + " -> " + targetTr.gameObject.name);
            Destroy(currentEdge.gameObject);
        }
    }
Beispiel #3
0
    public virtual void MoveEnd(Vector2 pos, bool bGroup = false)
    {
        if (bGroup)
        {
            return;
        }
        bool bFoundInputModule = false;  //colls에서 InputNode를 찾았는지 체크

        Collider2D[] colls;
        colls = Physics2D.OverlapCircleAll(pos, autoAssignRadius);
        if (colls.Length > 0)
        {
            int min_dist_idx = -1;
            for (int i = 0; i < colls.Length; ++i)
            {
                Collider2D coll = colls[i];
                if (coll.CompareTag("InputNode"))
                {
                    //아직 최저가 결정되지 않았거나 최저보다 더 적을 때 갱신
                    if (min_dist_idx == -1 ||
                        Vector3.Distance(coll.transform.position, pos) < Vector3.Distance(colls[min_dist_idx].transform.position, pos))
                    {
                        min_dist_idx = i;
                    }
                }
            }
            if (min_dist_idx != -1)
            {
                IInputParam <T> nearestInputModule = colls[min_dist_idx].GetComponent <IInputParam <T> >();
                if (nearestInputModule != null)
                {
                    bool bExist = false;
                    foreach (IInputParam <T> target in connectedInputModules)
                    {
                        if (target.Equals(nearestInputModule))
                        {
                            bExist = true;
                            break;
                        }
                    }
                    if (!bExist)
                    {
                        if (EdgeManager.instance.registerEdge(currentEdge, colls[min_dist_idx].transform, transform))
                        {
                            connectedInputModules.Add(nearestInputModule);
                            currentEdge.SetEndTarget(colls[min_dist_idx].transform);
                            Debug.Log(colls[min_dist_idx].gameObject.name + " connected");
                            bFoundInputModule = true;
                        }
                        else
                        {
                            Debug.LogWarning("Edge Register Failed : " + name + " -> " + colls[min_dist_idx].gameObject.name);
                        }
                    }
                }
            }
        }
        if (!bFoundInputModule)
        {
            edges.Remove(currentEdge);
            Destroy(currentEdge.gameObject);
            currentEdge = null;
        }

        isMoving = false;
    }