Example #1
0
    /// <summary>
    /// Create sector, return it
    /// </summary>
    /// <returns></returns>
    public GameObject InitSector(int player)
    {
        GameObject obj = null;

        if (NamesHolder.mapMode == MapMode.normal || NamesHolder.mapMode == MapMode.shared)
        {
            Vector3 tmp;
            // utworzenie sektorów dla graczy
            if (NamesHolder.mapMode == MapMode.normal)
            {
                do
                {
                    int xRand = Random.Range(-3, 3);
                    int yRand = Random.Range(-3, 3);
                    tmp = new Vector3(xRand * XSectorDistance, yRand * YSectorDistance, 0);
                }
                while (SpaceSectorAlreadyHere(tmp));
            }
            else
            {
                tmp = new Vector3(0, (Dist * player * YSectorDistance), 0);
            }


            obj = CreateSpaceSystem(tmp);
            obj.GetComponent<SpaceSystem>().CreateSystem();


            if (UseDatabase)
            {
                // utwórz punkt w bazie danych
                db.CreateSpaceSector(obj);
            }
        }
        else if (NamesHolder.mapMode == MapMode.separate)
        {
            GameObject last = null;
            for (int i = 0; i <= 4; i++)
            {
                Vector3 tmp;
                switch (i)
                {
                    case 0:
                    case 4:
                        tmp = new Vector3(0, (Dist * player * YSectorDistance), 0);
                        break;
                    case 1:
                        tmp = new Vector3(0, (Dist * player * YSectorDistance) + YSectorDistance, 0);
                        break;
                    case 2:
                        tmp = new Vector3(0 - XSectorDistance, (Dist * player * YSectorDistance) + YSectorDistance, 0);
                        break;
                    case 3:
                        tmp = new Vector3(0 - XSectorDistance, (Dist * player * YSectorDistance), 0);
                        break;
                    //case 5:
                    //    tmp = new Vector3(0 + XSectorDistance, (Dist * player * YSectorDistance), 0);
                    //    break;
                    //case 6:
                    //    tmp = new Vector3(0 + XSectorDistance, (Dist * player * YSectorDistance) + YSectorDistance, 0);
                    //    break;
                    //case 7:
                    //    tmp = new Vector3(0 , (Dist * player * YSectorDistance) + YSectorDistance, 0);
                    //    break;
                    default:
                        tmp = new Vector3(0, 0, 0);
                        break;
                }


                if (SpaceSectorAlreadyHere(tmp))
                {
                    obj = ReturnSectorAtPos(tmp);
                }
                else
                {
                    obj = CreateSpaceSystem(tmp);
                    obj.GetComponent<SpaceSystem>().CreateSystem();
                }

                if (i == 0) StartSectors.Add(obj);

                if (UseDatabase)
                {
                    // utwórz punkt w bazie danych
                    db.CreateSpaceSector(obj);
                }

                if (last != null)
                {
                    CreateSectorsConnection(last, obj);
                }
                last = obj;
            }
        }

        return obj;
    }