Ejemplo n.º 1
0
        GameObject CreateRobot(string name, float x = 15f, float z = 15f)
        {
            GameObject robot = new GameObject(name);

            robot.transform.position = new Vector3(15f, 10f, 15f);
            robot.tag = "Robot";
            //если нету записи, то выходим
            if (!PlayerPrefs.HasKey(string.Format("robot{0}", Setup.IdActiveRobot)))
            {
                return(null);
            }
            //получаем строку, содержащую все блоки
            string strBlocks = PlayerPrefs.GetString(string.Format("robot{0}", Setup.IdActiveRobot));

            //получаем массив блоков
            string[] masBlocks = strBlocks.Split(new char[] { ';' }, System.StringSplitOptions.RemoveEmptyEntries);
            //перебираем каждый блок
            foreach (string s in masBlocks)
            {
                //Массив параметров блока
                string[] masParam = s.Split(new char[] { '#' }, System.StringSplitOptions.RemoveEmptyEntries);
                //Позиция
                Vector3 pos = new Vector3(float.Parse(masParam[0]), float.Parse(masParam[1]), float.Parse(masParam[2]));
                //цвет
                Color color = Setup.IntToColor(int.Parse(masParam[3]));
                //номер
                int id = int.Parse(masParam[4]);
                //наклон
                Vector3 rot;
                rot.x = float.Parse(masParam[5]);
                rot.y = float.Parse(masParam[6]);
                rot.z = float.Parse(masParam[7]);
                //Добавляем блок на сцену
                GameObject zzz = Setup.AddFigureWithPlanes(id, pos, rot, color, robot.transform, "Figure");
            }
            robot.transform.position = new Vector3(x, 10f, z);
            robot.transform.rotation = Quaternion.Euler(0, -90, 0);            ////
            robot.AddComponent <Rigidbody>();
            robot.GetComponent <Rigidbody>().mass        = 1500f;
            robot.GetComponent <Rigidbody>().angularDrag = 1;
            int     i      = 0;
            Vector3 center = Vector3.zero;

            foreach (Transform child in robot.transform)
            {
                center += child.position;
                i++;
            }
            center /= i;
            PivotTo(robot, center);
            //robot.AddComponent<MeshRenderer>();
            return(robot);
        }