Exemplo n.º 1
0
        //======================================================================

        /// <summary>
        /// Create SnakePlayer with the specified data and pos.
        /// </summary>
        /// <returns>void</returns>
        /// <param name="data">Data.</param>
        /// <param name="pos">Position.</param>
        public void Create(PlayerData data, Vector3 pos)
        {
            LOG_TAG = LOG_TAG + "[" + data.id + "]";

            m_data    = data;
            m_context = GameManager.Instance.Context;

            //create gameobject for player
            m_container = new GameObject("SnakePlayer" + data.id);

            //create snake head
            m_head = EntityFactory.InstanceEntity <SnakeHead>();
            m_head.Create(0, m_data, m_container.transform);

            //create snake tail
            m_tail = EntityFactory.InstanceEntity <SnakeTail>();
            m_tail.Create(0, m_data, m_container.transform);

            //connect head and tail
            m_head.SetNext(m_tail);
            m_tail.SetPrev(m_head);

            //add default number of nodes to snake
            int initCount = m_data.snakeData.length;

            m_data.snakeData.length = 0;
            AddNodes(initCount);

            //create aiSnake
            if (m_data.ai > 0)
            {
                var ai = new AISnake(this);
                m_listCompoent.Add(ai);
            }

            //move to position where the snake is born
            MoveTo(pos);
        }
Exemplo n.º 2
0
        //======================================================================

        /// <summary>
        /// Create SnakePlayer with the specified data and pos.
        /// </summary>
        /// <returns>void</returns>
        /// <param name="data">Data.</param>
        /// <param name="pos">Position.</param>
        public void Create(PlayerData data, Vector3 pos)
        {
            LOG_TAG = LOG_TAG + "[" + data.id + "]";

            m_data    = data;
            m_context = GameManager.Instance.Context;

            //创建用来显示视图的容器
            m_container = new GameObject("SnakePlayer" + data.id);

            //创建Head
            m_head = EntityFactory.InstanceEntity <SnakeHead>();
            m_head.Create(0, m_data, m_container.transform);

            //创建Tail
            m_tail = EntityFactory.InstanceEntity <SnakeTail>();
            m_tail.Create(0, m_data, m_container.transform);

            //组合成一条蛇
            m_head.SetNext(m_tail);
            m_tail.SetPrev(m_head);

            //增加默认数量的Node
            int initCount = m_data.snakeData.length;

            m_data.snakeData.length = 0;
            AddNodes(initCount);

            //创建AI
            if (m_data.ai > 0)
            {
                var ai = new PCSnakeAI(this);
                m_listCompoent.Add(ai);
            }

            //放置在出生坐标
            MoveTo(pos);
        }