示例#1
0
    private void AssignNewHead()
    {
        if (_centipedeTailsList.Count <= 0)
        {
            GameClient.Get <ICentipedeManager>().RemoveCentipede(this);
            _centipedeHead = null;
            return;
        }

        HorizontalDirection horizontalDirection = _centipedeHead.HorizontalDirection;
        VerticalDirection   verticalDirection   = _centipedeHead.VerticalDirection;

        // make next tail to new head
        CentipedeTail tail = _centipedeTailsList[0];

        tail.GetTailObject().name = "Head_" + CentipedeManager.CentipedeCount;

        _centipedeHead = new CentipedeHead();
        _centipedeHead.Init();
        _centipedeHead.SetNewHeadGameObject(tail.GetTailObject(), tail.LastPosition, horizontalDirection,
                                            verticalDirection);

        // remove this tail from tail list, because its a head now
        _centipedeTailsList.Remove(tail);

        //change indexing according to new head
        for (int i = 0; i < _centipedeTailsList.Count; i++)
        {
            _centipedeTailsList[i].AssignNewLeader(i == 0 ? (IBodyPart)_centipedeHead : _centipedeTailsList[i - 1], i);
            _centipedeTailsList[i].GetTailObject().name = "Head_" + CentipedeManager.CentipedeCount + "_tail_" + i;
        }
    }
示例#2
0
    public void CreateCentipede(GameObject head, Vector2 lastPosition, List <CentipedeTail> remainingTail,
                                HorizontalDirection horizontalDirection, VerticalDirection verticalDirection)
    {
        head.name      = "Head_" + CentipedeManager.CentipedeCount;
        _centipedeHead = new CentipedeHead();
        _centipedeHead.Init();
        _centipedeHead.SetNewHeadGameObject(head, head.transform.position, horizontalDirection, verticalDirection);

        _centipedeTailsList = new List <CentipedeTail>();
        for (int i = 0; i < remainingTail.Count; i++)
        {
            GameObject tail = remainingTail[i].GetTailObject();
            tail.name = head.name + "_tail_" + (i);
            remainingTail[i].AssignNewLeader(i == 0 ? (IBodyPart)_centipedeHead : remainingTail[i - 1], i);

            _centipedeTailsList.Add(remainingTail[i]);
        }
    }