コード例 #1
0
    void Start()
    {
        if (gameStarted)
        {
            return;
        }

        if (gameMode != GameMode.Editor)
        {
            difficulty = gameStartSettings.difficulty;
            SetDefaultValues();
            //byte chunksize = gss.chunkSize;
            byte chunksize;
            chunksize = gameStartSettings.chunkSize;
            if (testMode && savenameToLoad != string.Empty)
            {
                gameStartSettings = new GameStartSettings(ChunkGenerationMode.GameLoading);
                savename          = savenameToLoad;
            }
            if (gameStartSettings.generationMode != ChunkGenerationMode.GameLoading)
            {
                if (gameStartSettings.generationMode != ChunkGenerationMode.DontGenerate)
                {
                    if (gameStartSettings.generationMode != ChunkGenerationMode.TerrainLoading)
                    {
                        Constructor.ConstructChunk(chunksize, gameStartSettings.generationMode);
                        // Constructor.ConstructBlock(chunksize);
                        if (gameStartSettings.generationMode == ChunkGenerationMode.Peak)
                        {
                            environmentMaster.PrepareIslandBasis(ChunkGenerationMode.Peak);
                        }
                    }
                    else
                    {
                        LoadTerrain(SaveSystemUI.GetTerrainsPath() + '/' + savename + '.' + SaveSystemUI.TERRAIN_FNAME_EXTENSION);
                    }
                }
                FollowingCamera.main.ResetTouchRightBorder();
                FollowingCamera.main.CameraRotationBlock(false);
                warProximity   = 0.01f;
                layerCutHeight = Chunk.chunkSize; prevCutHeight = layerCutHeight;
                switch (startGameWith)
                {
                case GameStart.Zeppelin:
                    Instantiate(Resources.Load <GameObject>("Prefs/Zeppelin"));
                    if (needTutorial)
                    {
                        GameLogUI.EnableDecisionWindow(null, Localization.GetTutorialHint(LocalizedTutorialHint.Landing));
                    }
                    else
                    {
                        GameLogUI.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.SetLandingPoint));
                    }
                    break;

                case GameStart.Headquarters:
                    var   sblocks = mainChunk.surfaces;
                    Plane sb      = sblocks[Random.Range(0, sblocks.Length)];
                    int   xpos    = sb.pos.x;
                    int   zpos    = sb.pos.z;

                    Structure s;
                    if (testMode)
                    {
                        s = HeadQuarters.GetHQ(6);
                        weNeedNoResources = true;
                    }
                    else
                    {
                        weNeedNoResources = false;
                        s = HeadQuarters.GetHQ(1);
                    }

                    Plane b = mainChunk.GetHighestSurfacePlane(xpos, zpos);
                    s.SetBasement(b, PixelPosByte.zero);


                    sb = mainChunk.GetHighestSurfacePlane(xpos - 1, zpos + 1);
                    if (sb == null)
                    {
                        sb = mainChunk.GetHighestSurfacePlane(xpos, zpos + 1);
                        if (sb == null)
                        {
                            sb = mainChunk.GetHighestSurfacePlane(xpos + 1, zpos + 1);
                            if (sb == null)
                            {
                                sb = mainChunk.GetHighestSurfacePlane(xpos - 1, zpos);
                                if (sb == null)
                                {
                                    sb = mainChunk.GetHighestSurfacePlane(xpos + 1, zpos);
                                    if (sb == null)
                                    {
                                        sb = mainChunk.GetHighestSurfacePlane(xpos - 1, zpos - 1);
                                        if (sb == null)
                                        {
                                            sb = mainChunk.GetHighestSurfacePlane(xpos, zpos - 1);
                                            if (sb == null)
                                            {
                                                sb = mainChunk.GetHighestSurfacePlane(xpos + 1, zpos - 1);
                                                if (sb == null)
                                                {
                                                    print("bad generation, do something!");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    StorageHouse firstStorage = Structure.GetStructureByID(Structure.STORAGE_0_ID) as StorageHouse;
                    firstStorage.SetBasement(sb, PixelPosByte.zero);
                    SetStartResources();
                    break;
                }
                FollowingCamera.main.WeNeedUpdate();
            }
            else
            {
                LoadGame(SaveSystemUI.GetSavesPath() + '/' + savename + ".sav");
            }
        }
        else
        {
            gameObject.AddComponent <PoolMaster>().Load();
            mainChunk = new GameObject("chunk").AddComponent <Chunk>();
            int size = Chunk.chunkSize;
            int[,,] blocksArray = new int[size, size, size];
            size /= 2;
            blocksArray[size, size, size] = ResourceType.STONE_ID;
            mainChunk.CreateNewChunk(blocksArray);
        }

        { // set look point
            FollowingCamera.camBasisTransform.position = sceneCenter;
        }
        gameStarted = true;
    }
コード例 #2
0
ファイル: KnowledgeTabUI.cs プロジェクト: Hengle/VoxelGame
    public void Redraw()
    {
        var        carray = knowledge.colorCodesArray;
        var        colors = Knowledge.colors;
        GameObject b;
        Transform  bt;
        byte       code;
        int        i = 0;

        for (; i < 64; i++)
        {
            code = carray[i];
            b    = buttons[i];
            if (code != Knowledge.NOCOLOR_CODE)
            {
                bt = buttons[i].transform;
                bt.GetChild(0).GetComponent <RawImage>().color = colors[code];
                if (!b.activeSelf)
                {
                    b.SetActive(true);
                }
            }
            else
            {
                if (b.activeSelf)
                {
                    b.SetActive(false);
                }
            }
        }

        var parts = knowledge.puzzlePartsCount;

        ascensionPanel.GetChild(1).GetComponent <Text>().text  = ((int)(knowledge.completeness * 100f)).ToString() + '%';
        redpartsPanel.GetChild(1).GetComponent <Text>().text   = parts[Knowledge.REDCOLOR_CODE].ToString();
        greenpartsPanel.GetChild(1).GetComponent <Text>().text = parts[Knowledge.GREENCOLOR_CODE].ToString();
        bluepartsPanel.GetChild(1).GetComponent <Text>().text  = parts[Knowledge.BLUECOLOR_CODE].ToString();
        cyanpartsPanel.GetChild(1).GetComponent <Text>().text  = parts[Knowledge.CYANCOLOR_CODE].ToString();
        var t  = blackpartsPanel;
        var pc = parts[Knowledge.BLACKCOLOR_CODE];

        if (pc > 0)
        {
            t.GetChild(1).GetComponent <Text>().text = pc.ToString();
            if (!t.gameObject.activeSelf)
            {
                t.gameObject.SetActive(true);
            }
        }
        else
        {
            if (t.gameObject.activeSelf)
            {
                t.gameObject.SetActive(false);
            }
        }
        t  = whitepartsPanel;
        pc = parts[Knowledge.WHITECOLOR_CODE];
        if (pc > 0)
        {
            t.GetChild(1).GetComponent <Text>().text = pc.ToString();
            if (!t.gameObject.activeSelf)
            {
                t.gameObject.SetActive(true);
            }
        }
        else
        {
            if (t.gameObject.activeSelf)
            {
                t.gameObject.SetActive(false);
            }
        }

        var  cca = knowledge.colorCodesArray;
        var  ia  = Knowledge.routeButtonsIndexes;
        bool unblocked;
        var  nocode = Knowledge.NOCOLOR_CODE;

        for (i = 0; i < Knowledge.ROUTES_COUNT; i++)
        {
            unblocked = true;
            for (int j = 0; j < Knowledge.STEPS_COUNT; j++)
            {
                if (cca[ia[i, j]] != nocode)
                {
                    unblocked = false;
                    break;
                }
            }
            if (unblocked)
            {
                var           g        = new GameObject();
                RectTransform eqButton = g.AddComponent <RectTransform>();
                eqButton.transform.parent = routeBackgrounds[i].transform;
                eqButton.anchorMax        = Vector2.zero;
                eqButton.anchorMin        = Vector2.zero;
                eqButton.localPosition    = Vector3.zero;
                float s = Screen.height / 10f;
                eqButton.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, s);
                eqButton.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, s);
                var ri = g.AddComponent <RawImage>();
                ri.texture = UIController.current.iconsTexture;
                ri.uvRect  = UIController.GetIconUVRect(Icons.GuidingStar);
                var  btn   = g.AddComponent <Button>();
                byte index = (byte)i;
                btn.onClick.AddListener(() => GameLogUI.EnableDecisionWindow(
                                            Localization.GetPhrase(LocalizedPhrase.Ask_StartFinalQuest),
                                            () => QuestUI.current.StartEndQuest(index), Localization.GetWord(LocalizedWord.Yes),
                                            GameLogUI.DisableDecisionPanel, Localization.GetWord(LocalizedWord.No)
                                            ));
            }
        }

        lastChMarkerValue = knowledge.changesMarker;
    }