//====================================================================== /// <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); }
//====================================================================== /// <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); }
internal void AddNodes(int cnt) { for (int i = 0; i < cnt; i++) { //apart from head and tail, the number for nodes starts from 1 m_data.snakeData.length++; SnakeNode newNode = EntityFactory.InstanceEntity <SnakeNode>(); newNode.Create(m_data.snakeData.length, m_data, m_container.transform); m_tail.Prev.SetNext(newNode); newNode.SetNext(m_tail); m_tail.SetPrev(newNode); } //calculate the view scale of snake float vs = m_data.snakeData.length / 500f; vs = Mathf.Min(vs, 1); vs = Mathf.Max(vs, 0.5f); m_data.snakeData.viewScale = vs; m_data.score++; this.Log(LOG_TAG, "AddNodes() NewCount:{0}, SnakeLength:{1}, ViewSize:{2}", cnt, m_data.snakeData.length, vs); }
internal void AddNodes(int cnt) { for (int i = 0; i < cnt; i++) { //除了头尾外,其它Node从1开始编号 m_data.snakeData.length++; SnakeNode newNode = EntityFactory.InstanceEntity <SnakeNode>(); newNode.Create(m_data.snakeData.length, m_data, m_container.transform); m_tail.Prev.SetNext(newNode); newNode.SetNext(m_tail); m_tail.SetPrev(newNode); } //计算View的大小 float vs = m_data.snakeData.length / 500f; vs = Mathf.Min(vs, 1); vs = Mathf.Max(vs, 0.5f); m_data.snakeData.viewScale = vs; //m_viewScale = 1; Debuger.Log(LOG_TAG, "AddNodes() NewCount:{0}, SnakeLength:{1}, ViewSize:{2}", cnt, m_data.snakeData.length, vs); }