コード例 #1
0
    void OnHitObject(Collider2D _col, Vector3 _hitPoint)
    {
        //Debug.Log (this + "OnHitObject" + hit.collider.gameObject.name);
        //IDamageable _scp = _col.GetComponent<IDamageable>();
        //if (_scp != null) {
        //	_scp.TakeDamage(damage);
        //}

        //Sound, Particle
        PoolMaster _p = PoolManager.ins.Instantiate("EffectCollected", _hitPoint, Quaternion.identity).GetComponent <PoolMaster>();

        _p.Play();

        SoundManager.ins.Play("ItemEat", false);

        Destroy();
    }
コード例 #2
0
 void Start()
 {
     if (obj != null)
     {
         int          i      = 0;
         var          rtypes = ResourceType.materialsForCovering;
         MeshFilter   mf;
         MeshRenderer mr;
         while (i < obj.Length & i < rtypes.Length)
         {
             mf = obj[i].GetComponent <MeshFilter>();
             mr = obj[i].GetComponent <MeshRenderer>();
             PoolMaster.SetMaterialByID(ref mf, ref mr, rtypes[i].ID, 255);
             i++;
         }
     }
 }
コード例 #3
0
 override public void Annihilate()
 {
     // #block annihilate
     if (destroyed)
     {
         return;
     }
     else
     {
         destroyed = true;
     }
     if (worksite != null)
     {
         worksite.StopWork();
     }
     if (mainStructure != null)
     {
         mainStructure.Annihilate(true);
     }
     // end
     if (excavatingStatus == 0 & faces[4] != null)
     {
         PoolMaster.ReturnQuadToPool(faces[4].gameObject);
     }
     if (faces[0] != null)
     {
         PoolMaster.ReturnQuadToPool(faces[0].gameObject);
     }
     if (faces[1] != null)
     {
         PoolMaster.ReturnQuadToPool(faces[1].gameObject);
     }
     if (faces[2] != null)
     {
         PoolMaster.ReturnQuadToPool(faces[2].gameObject);
     }
     if (faces[3] != null)
     {
         PoolMaster.ReturnQuadToPool(faces[3].gameObject);
     }
     if (faces[5] != null)
     {
         PoolMaster.ReturnQuadToPool(faces[5].gameObject);
     }
     Destroy(gameObject);
 }
コード例 #4
0
ファイル: Plane.cs プロジェクト: Hengle/VoxelGame
 virtual public BlockpartVisualizeInfo GetVisualInfo(Chunk chunk, ChunkPos cpos)
 {
     if (materialID == PoolMaster.NO_MATERIAL_ID | meshType == MeshType.NoMesh)
     {
         return(null);
     }
     else
     {
         return(new BlockpartVisualizeInfo(cpos,
                                           new MeshVisualizeInfo(faceIndex, PoolMaster.GetMaterialType(materialID),
                                                                 GetLightValue(chunk, cpos, faceIndex)),
                                           meshType,
                                           materialID,
                                           meshRotation
                                           ));
     }
 }
コード例 #5
0
    override protected void SetModel()
    {
        if (type == Settlement.SettlementStructureType.Empty)
        {
            return;
        }
        GameObject model;
        Quaternion prevRot = Quaternion.identity;

        if (transform.childCount != 0)
        {
            var p = transform.GetChild(0);
            prevRot = p.localRotation;
            Destroy(p.gameObject);
        }
        bool replacementCheck = true;

        switch (type)
        {
        case Settlement.SettlementStructureType.House:
            model            = GetHouseModel(level);
            replacementCheck = false;
            break;

        case Settlement.SettlementStructureType.Shop:
            model = Instantiate(Resources.Load <GameObject>("Structures/Settlement/shopPart"));
            break;

        case Settlement.SettlementStructureType.Garden:
            model = Instantiate(Resources.Load <GameObject>("Structures/Settlement/parkPart"));
            // also using by Gardens.cs
            break;

        default:
            model = GameObject.CreatePrimitive(PrimitiveType.Cube);
            break;
        }
        model.transform.parent        = transform;
        model.transform.localRotation = prevRot;
        model.transform.localPosition = Vector3.zero;
        if (!PoolMaster.useDefaultMaterials & replacementCheck)
        {
            PoolMaster.ReplaceMaterials(model);
        }
    }
コード例 #6
0
 public void SetActivationStatus(bool x)
 {
     if (x != isActive)
     {
         isActive = x;
         if (model != null)
         {
             if (x)
             {
                 PoolMaster.SwitchMaterialToOnline(model.GetComponentInChildren <Renderer>());
             }
             else
             {
                 PoolMaster.SwitchMaterialToOffline(model.GetComponentInChildren <Renderer>());
             }
         }
     }
 }
コード例 #7
0
 public void PrepareList(IListable i_datahoster)
 {
     datahoster          = i_datahoster;
     selectedButtonIndex = -1;
     if (!spriteLoaded)
     {
         if (PoolMaster.gui_overridingSprite == null)
         {
             overridingSprite = PoolMaster.LoadOverridingSprite();
         }
         else
         {
             overridingSprite = PoolMaster.gui_overridingSprite;
         }
         spriteLoaded = true;
     }
     RefreshList();
 }
コード例 #8
0
    public void InitializeSurfaceBlock(Chunk f_chunk, ChunkPos f_chunkPos, int f_material_id)
    {
        cellsStatus = 0; map = new bool[INNER_RESOLUTION, INNER_RESOLUTION];
        for (int i = 0; i < map.GetLength(0); i++)
        {
            for (int j = 0; j < map.GetLength(1); j++)
            {
                map[i, j] = false;
            }
        }
        material_id          = 0;
        illumination         = 255;
        surfaceObjects       = new List <Structure>();
        artificialStructures = 0;
        isTransparent        = false;
        type             = BlockType.Surface;
        myChunk          = f_chunk;
        transform.parent = f_chunk.transform;
        pos = f_chunkPos;
        transform.localPosition = new Vector3(pos.x, pos.y, pos.z);
        transform.localRotation = Quaternion.Euler(Vector3.zero);

        if (surfaceRenderer == null)
        {
            GameObject g = PoolMaster.GetQuad();
            surfaceRenderer = g.GetComponent <MeshRenderer>();
            surfaceRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            Transform meshTransform = g.transform;
            meshTransform.parent        = transform;
            meshTransform.localPosition = new Vector3(0, -QUAD_SIZE / 2f, 0);
            meshTransform.localRotation = Quaternion.Euler(90, 0, 0);
            g.name = "upper_plane";
            g.tag  = "BlockCollider";
        }
        material_id = f_material_id;
        surfaceRenderer.sharedMaterial = ResourceType.GetMaterialById(material_id, surfaceRenderer.GetComponent <MeshFilter>(), illumination);

        if (visibilityMask != 0)
        {
            surfaceRenderer.enabled = true;
        }

        name = "block " + pos.x.ToString() + ';' + pos.y.ToString() + ';' + pos.z.ToString();
    }
コード例 #9
0
    public static Material GetMaterialById(int f_id, MeshFilter mf, byte illumination)
    {
        switch (f_id)
        {
        default: return(PoolMaster.default_material);

        case STONE_ID: return(PoolMaster.GetBasicMaterial(BasicMaterial.Stone, mf, illumination));

        case DIRT_ID: return(PoolMaster.GetBasicMaterial(BasicMaterial.Dirt, mf, illumination));

        case LUMBER_ID: return(PoolMaster.GetBasicMaterial(BasicMaterial.Lumber, mf, illumination));

        case METAL_K_ID:
        case METAL_K_ORE_ID:
            return(PoolMaster.GetMetalMaterial(MetalMaterial.MetalK, mf, illumination));

        case METAL_M_ORE_ID:
        case METAL_M_ID: return(PoolMaster.GetMetalMaterial(MetalMaterial.MetalM, mf, illumination));

        case METAL_E_ORE_ID:
        case METAL_E_ID: return(PoolMaster.GetMetalMaterial(MetalMaterial.MetalE, mf, illumination));

        case METAL_N_ORE_ID:
        case METAL_N_ID: return(PoolMaster.GetMetalMaterial(MetalMaterial.MetalN, mf, illumination));

        case METAL_P_ORE_ID:
        case METAL_P_ID: return(PoolMaster.GetMetalMaterial(MetalMaterial.MetalP, mf, illumination));

        case METAL_S_ORE_ID:
        case METAL_S_ID: return(PoolMaster.GetMetalMaterial(MetalMaterial.MetalS, mf, illumination));

        case MINERAL_F_ID: return(PoolMaster.GetBasicMaterial(BasicMaterial.MineralF, mf, illumination));

        case MINERAL_L_ID: return(PoolMaster.GetBasicMaterial(BasicMaterial.MineralL, mf, illumination));

        case PLASTICS_ID: return(PoolMaster.GetBasicMaterial(BasicMaterial.Plastic, mf, illumination));

        case CONCRETE_ID: return(PoolMaster.GetBasicMaterial(BasicMaterial.Concrete, mf, illumination));

        case FERTILE_SOIL_ID: return(PoolMaster.GetBasicMaterial(BasicMaterial.Farmland, mf, illumination));

        case GRAPHONIUM_ID: return(PoolMaster.energy_material);
        }
    }
コード例 #10
0
    private void Awake()
    {
        //testzone
        //gameStartSettings.generationMode = ChunkGenerationMode.GameLoading;
        //savename = "test";
        //

        if (realMaster != null & realMaster != this)
        {
            Destroy(this);
            return;
        }
        gameMode      = _gameMode;
        realMaster    = this;
        sceneClearing = false;
        if (PoolMaster.current == null)
        {
            PoolMaster pm = gameObject.AddComponent <PoolMaster>();
            pm.Load();
        }
        if (gameMode == GameMode.Play)
        {
            if (globalMap == null)
            {
                globalMap = gameObject.AddComponent <GlobalMap>();
            }
            globalMap.Prepare();
            eventTracker = new EventChecker();
        }
        if (environmentMaster == null)
        {
            environmentMaster = new GameObject("Environment master").AddComponent <EnvironmentMaster>();
        }
        environmentMaster.Prepare();
        if (audiomaster == null)
        {
            audiomaster = gameObject.AddComponent <Audiomaster>();
            audiomaster.Prepare();
        }
        if (geologyModule == null)
        {
            geologyModule = gameObject.AddComponent <GeologyModule>();
        }
    }
コード例 #11
0
 // в финальном виде копипастить в потомков
 protected void SetStructureData(SurfaceBlock b, PixelPosByte pos)
 {
     //#setStructureData
     basement      = b;
     innerPosition = new SurfaceRect(pos.x, pos.y, innerPosition.size);
     if (transform.childCount == 0)
     {
         SetModel();
     }
     b.AddStructure(this);
     if (isBasement)
     {
         if (!subscribedToChunkUpdate)
         {
             basement.myChunk.ChunkUpdateEvent += ChunkUpdated;
             subscribedToChunkUpdate            = true;
         }
         if (basement is CaveBlock)
         {
             basement.myChunk.ReplaceBlock(basement.pos, BlockType.Surface, basement.material_id, false);
         }
         if (basement.pos.y + 1 < Chunk.CHUNK_SIZE)
         {
             ChunkPos npos       = new ChunkPos(basement.pos.x, basement.pos.y + 1, basement.pos.z);
             Block    upperBlock = basement.myChunk.GetBlock(npos.x, npos.y, npos.z);
             if (upperBlock == null)
             {
                 basement.myChunk.AddBlock(npos, BlockType.Surface, ResourceType.CONCRETE_ID, false);
             }
         }
         else
         {
             GameObject g = PoolMaster.GetRooftop(this);
             g.transform.parent        = basement.transform;
             g.transform.localPosition = Vector3.up * Block.QUAD_SIZE / 2f;
             g.name = "block ceiling";
         }
     }
 }
コード例 #12
0
 virtual protected void ChangeRenderersView(bool setOnline)
 {
     if (transform.childCount == 0)
     {
         return;
     }
     Renderer[] myRenderers = transform.GetChild(0).GetComponentsInChildren <Renderer>();
     if (myRenderers == null | myRenderers.Length == 0)
     {
         return;
     }
     if (setOnline)
     {
         PoolMaster.SwitchMaterialsToOnline(myRenderers);
     }
     else
     {
         PoolMaster.SwitchMaterialsToOffline(myRenderers);
     }
     //copy to SettlementStructure.SetActivationStatus
     //copy to StorageBlock and other IPlanables
 }
コード例 #13
0
    void Start()
    {
        float   x    = Random.value * 360;
        float   cs   = Chunk.chunkSize / 2;
        Vector3 rpos = Quaternion.AngleAxis(x, Vector3.up) * Vector3.forward * cs * 1.5f * Block.QUAD_SIZE;

        rpos.y             = cs;
        rpos.x            += cs;
        rpos.z            += cs;
        transform.position = rpos;
        Vector3 v = GameMaster.sceneCenter - transform.position;

        v.y = 0;
        transform.forward = Quaternion.AngleAxis(-90, Vector3.up) * v;
        leftScrew.Rotate(0, Random.value * 360, 0);
        rightScrew.Rotate(0, Random.value * 360, 0);

        landingMarkObject = Instantiate(Resources.Load <GameObject>("Prefs/LandingX")) as GameObject;
        landingMarkObject.SetActive(false);
        lineDrawer = GetComponent <LineRenderer>();

        if (current != null)
        {
            Destroy(current);
        }
        current = this;
        if (!PoolMaster.useDefaultMaterials)
        {
            PoolMaster.ReplaceMaterials(gameObject);
        }

        landingCanvas = Instantiate(Resources.Load <GameObject>("UIPrefs/landingCanvas")).transform;
        landingCanvas.GetComponentInChildren <UnityEngine.UI.Text>().text = Localization.GetWord(LocalizedWord.Land_verb);
        UIController.GetCurrent().AddSpecialCanvasToHolder(landingCanvas);
        landingCanvas.GetChild(0).GetComponent <UnityEngine.UI.Button>().onClick.AddListener(this.Raycasting);
        landButton = landingCanvas.GetChild(1).gameObject;
        landButton.SetActive(false);
        landButton.GetComponent <UnityEngine.UI.Button>().onClick.AddListener(this.LandActionAccepted);
    }
コード例 #14
0
    protected override void SetModel()
    {
        Transform model         = Instantiate(Resources.Load <GameObject>("Prefs/defaultContainer")).transform;
        Transform meshTransform = model.transform.GetChild(0);
        var       mf            = meshTransform.GetComponent <MeshFilter>();
        var       mr            = meshTransform.GetComponent <MeshRenderer>();

        PoolMaster.SetMaterialByID(
            ref mf,
            ref mr,
            mainResource.ID,
            255
            );
        model_id            = ContainerModelType.Default;
        model.parent        = transform;
        model.localPosition = Vector3.zero;
        model.localRotation = Quaternion.Euler(Vector3.zero);
        if (PoolMaster.useAdvancedMaterials)
        {
            PoolMaster.ReplaceMaterials(model.gameObject, true);
        }
    }
コード例 #15
0
    //------------------------------------
    //Damage -> TakeHit, TakeDamage -> Die
    //------------------------------------
    protected override void Die()
    {
        bDead = true;

        //Expire Effect
        PoolMaster _p = PoolManager.ins.Instantiate("EffectEnemyDeath", hitPoint, Quaternion.identity).GetComponent <PoolMaster>();

        _p.Play();

        //Sound
        //SoundManager.ins.Play ("Enemy attack", false);

        //Message Show
        //Ui_MsgRoot.ins.InvokeShowMessage("UiHitMessage", "[00ff00]Hit[-]", hitPoint, 5f);

        //등록된 콜백사용...
        if (callbackDeath != null)
        {
            callbackDeath(this);
            callbackDeath = null;
        }
        Destroy();
    }
コード例 #16
0
ファイル: EnvironmentMaster.cs プロジェクト: Hengle/VoxelGame
    private void AddVisibleStar(SunPoint sp)
    {
        var g = new GameObject("star");

        g.layer = GameConstants.CELESTIAL_LAYER;
        var sr = g.AddComponent <SpriteRenderer>();

        sr.sprite         = PoolMaster.GetStarSprite(false);
        sr.sharedMaterial = PoolMaster.celestialBillboardMaterial;
        sr.color          = sp.color;
        celestialBodies.Add(sp, g.transform);
        if (!showCelestialBodies)
        {
            g.SetActive(false);
        }
        Vector3 cpoint = Quaternion.AngleAxis(gmap.cityPoint.angle, Vector3.back) * (Vector3.up * gmap.cityPoint.height),
                mpoint = Quaternion.AngleAxis(sp.angle, Vector3.back) * (Vector3.up * sp.height);

        mpoint              -= cpoint;
        mpoint.z             = mpoint.y;
        mpoint.y             = 0.2f;
        g.transform.position = mpoint * SKY_SPHERE_RADIUS;
    }
コード例 #17
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            Vector3 _pos = new Vector3(Random.Range(-x, y), Random.Range(-x, y), 0);

            Instantiate(prefab, _pos, Quaternion.identity);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            Vector3 _pos = new Vector3(Random.Range(-x, y), Random.Range(-x, y), 0);

            Instantiate(list[0].prefab, _pos, Quaternion.identity);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            Vector3 _pos = new Vector3(Random.Range(-x, y), Random.Range(-x, y), 0);

            PoolMaster _scp = PoolManager.ins.Instantiate("HitEffectParticle", _pos, Quaternion.identity).GetComponent <PoolMaster>();
            _scp.Play();
        }
        else if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            Vector3 _pos = Vector3.zero;

            PoolMaster _scp = PoolManager.ins.Instantiate("HitEffectParticle", _pos, Quaternion.identity).GetComponent <PoolMaster>();
            _scp.Play();
        }
        else if (Input.GetKey(KeyCode.Alpha5))
        {
            Vector3 _pos = new Vector3(Random.Range(-x, y), Random.Range(-x, y), 0);

            PoolMaster _scp = PoolManager.ins.Instantiate("HitEffectParticle", _pos, Quaternion.identity).GetComponent <PoolMaster>();
            _scp.Play();
        }
    }
コード例 #18
0
    void Awake()
    {
        //singleton pattern
        if (mainPool != null)
        {
            Component.Destroy(mainPool);
        }
        mainPool = this;
        //---
        Localization.ChangeLanguage(Language.Russian);
        watersplash2 = Instantiate(watersplash2_pref);
        dustsplash2  = Instantiate(dustsplash2_pref);
        GameMaster.SetGUIPiece(Screen.height / 36);

        wave_tx = new Texture2D(WAVE_TX_RES, WAVE_TX_RES);
        Color[] pixels = new Color[WAVE_TX_RES * WAVE_TX_RES];
        for (int i = 0; i < WAVE_TX_RES; i++)
        {
            float xsin = i; xsin /= WAVE_TX_RES;
            float ysin = Mathf.Sin(xsin * 2 * Mathf.PI) * WAVE_TX_RES;
            for (int j = 0; j < WAVE_TX_RES; j++)
            {
                float k = (float)(j - ysin); k /= WAVE_TX_RES / 2; if (k < 0)
                {
                    k *= -1;
                }
                pixels[i * WAVE_TX_RES + j] = Color.Lerp(Color.white, Color.green, Mathf.Abs(Mathf.Sin(k * Mathf.PI)));
            }
        }

        wave_tx.SetPixels(pixels);
        wave_tx.Apply();
        waterMaterial.SetTexture("_NoiseTex", wave_tx);

        choosingFrame_tx = Resources.Load <Texture>("Textures/GUI/choosingFrame_tx");
    }
コード例 #19
0
ファイル: Grassland.cs プロジェクト: Alan-Baylis/VoxelGame-1
    public void Annihilation(bool forced)
    {
        if (destroyed)
        {
            return;
        }
        else
        {
            destroyed = true;
        }
        if (!forced)
        {
            myBlock.myChunk.AddLifePower((int)lifepower);
        }
        if (myBlock.cellsStatus != 0)
        {
            int   k = 0;
            Plant p = null;
            while (k < myBlock.surfaceObjects.Count)
            {
                p = myBlock.surfaceObjects[k] as Plant;
                if (p != null)
                {
                    p.Dry();
                }
                k++;
            }
        }
        myBlock.surfaceRenderer.sharedMaterial = PoolMaster.GetBasicMaterial(BasicMaterial.Dirt, myBlock.surfaceRenderer.GetComponent <MeshFilter>(), myBlock.illumination);
        int i = grasslandList.IndexOf(this);

        if (i > 0)
        {
            grasslandList.RemoveAt(i);
        }
    }
コード例 #20
0
    protected override void SetModel()
    {
        GameObject model;

        if (transform.childCount != 0)
        {
            Destroy(transform.GetChild(0).gameObject);
        }
        if (level < 2)
        {
            model = Instantiate(Resources.Load <GameObject>("Structures/ZeppelinBasement"));
        }
        else
        {
            model = Instantiate(Resources.Load <GameObject>("Structures/Buildings/HQ_level_" + level.ToString()));
        }
        model.transform.parent        = transform;
        model.transform.localRotation = Quaternion.Euler(0, 0, 0);
        model.transform.localPosition = Vector3.zero;
        if (PoolMaster.useAdvancedMaterials)
        {
            PoolMaster.ReplaceMaterials(model, true);
        }
    }
コード例 #21
0
 override public void Annihilate()
 {
     if (destroyed)
     {
         return;
     }
     else
     {
         destroyed = true;
     }
     if (cellsStatus != 0)
     {
         ClearSurface(false);
     }
     if (grassland != null)
     {
         grassland.Annihilation(true);
     }
     if (surfaceRenderer != null)
     {
         PoolMaster.ReturnQuadToPool(surfaceRenderer.gameObject);
     }
     Destroy(gameObject);
 }
コード例 #22
0
    //

    private void Awake()
    {
        gameRules = GameRules.defaultRules;
        if (testMode && test_gameStartSettings != null)
        {
            _applyingGameStartSettings = test_gameStartSettings;
            test_gameStartSettings     = null;
        }
        if (_applyingGameStartSettings == null && startSettings == null)
        {
            _applyingGameStartSettings = GameStartSettings.GetDefaultStartSettings();
        }
        if (startSettings == null)
        {
            startSettings = _applyingGameStartSettings;
            _applyingGameStartSettings = null;
        }
        gameMode = startSettings.DefineGameMode();
        if (gameMode == GameMode.MainMenu)
        {
            Destroy(gameObject);
            return;
        }
        if (realMaster != null & realMaster != this)
        {
            Destroy(realMaster);
            realMaster = this;
            return;
        }
        realMaster    = this;
        sceneClearing = false;
        //
        uicontroller = UIController.GetCurrent();
        //
        if (PoolMaster.current == null)
        {
            PoolMaster pm = gameObject.AddComponent(typeof(PoolMaster)) as PoolMaster;
            pm.Load();
        }
        if (gameMode == GameMode.Survival)
        {
            globalMap = InitializeGlobalMap();
        }
        if (environmentMaster == null)
        {
            environmentMaster = new GameObject("Environment master").AddComponent <EnvironmentMaster>();
        }
        environmentMaster.Prepare();

        if (audiomaster == null)
        {
            audiomaster = gameObject.AddComponent <Audiomaster>();
            audiomaster.Prepare();
        }
        if (geologyModule == null)
        {
            geologyModule = gameObject.AddComponent <GeologyModule>();
        }

        Screen.sleepTimeout = SleepTimeout.NeverSleep;
    }
コード例 #23
0
ファイル: GameMaster.cs プロジェクト: Alan-Baylis/VoxelGame-1
    void Start()
    {
        if (!firstSet)
        {
            return;
        }
        gameSpeed = 1;

        editMode = _editMode;
        if (!editMode)
        {
            lifeGrowCoefficient = 1;
            //Localization.ChangeLanguage(Language.English);

            if (geologyModule == null)
            {
                geologyModule = gameObject.AddComponent <GeologyModule>();
            }
            difficulty = gameStartSettings.difficulty;
            if (colonyController == null)
            {
                colonyController = gameObject.AddComponent <ColonyController>();
                colonyController.CreateStorage();
            }
            if (PoolMaster.current == null)
            {
                PoolMaster pm = gameObject.AddComponent <PoolMaster>();
                pm.Load();
            }
            //byte chunksize = gss.chunkSize;
            byte chunksize;
            chunksize = gameStartSettings.chunkSize;
            if (gameStartSettings.generationMode != ChunkGenerationMode.GameLoading)
            {
                if (gameStartSettings.generationMode != ChunkGenerationMode.DontGenerate)
                {
                    if (gameStartSettings.generationMode != ChunkGenerationMode.TerrainLoading)
                    {
                        Chunk.SetChunkSize(chunksize);
                        constructor.ConstructChunk(chunksize, gameStartSettings.generationMode);
                    }
                    else
                    {
                        LoadTerrain(Application.persistentDataPath + "/Terrains/" + savename + '.' + SaveSystemUI.TERRAIN_FNAME_EXTENSION);
                    }
                }
                FollowingCamera.CenterCamera(Vector3.one * chunksize / 2f);
                switch (difficulty)
                {
                case Difficulty.Utopia:
                    LUCK_COEFFICIENT               = 1;
                    demolitionLossesPercent        = 0;
                    lifepowerLossesPercent         = 0;
                    sellPriceCoefficient           = 1;
                    tradeVesselsTrafficCoefficient = 0.2f;
                    upgradeDiscount         = 0.5f; upgradeCostIncrease = 1.1f;
                    environmentalConditions = 1;
                    break;

                case Difficulty.Easy:
                    LUCK_COEFFICIENT               = 0.7f;
                    demolitionLossesPercent        = 0.2f;
                    lifepowerLossesPercent         = 0.1f;
                    sellPriceCoefficient           = 0.9f;
                    tradeVesselsTrafficCoefficient = 0.4f;
                    upgradeDiscount         = 0.3f; upgradeCostIncrease = 1.3f;
                    environmentalConditions = 1;
                    break;

                case Difficulty.Normal:
                    LUCK_COEFFICIENT               = 0.5f;
                    demolitionLossesPercent        = 0.4f;
                    lifepowerLossesPercent         = 0.3f;
                    sellPriceCoefficient           = 0.75f;
                    tradeVesselsTrafficCoefficient = 0.5f;
                    upgradeDiscount         = 0.25f; upgradeCostIncrease = 1.5f;
                    environmentalConditions = 0.95f;
                    break;

                case Difficulty.Hard:
                    LUCK_COEFFICIENT               = 0.1f;
                    demolitionLossesPercent        = 0.7f;
                    lifepowerLossesPercent         = 0.5f;
                    sellPriceCoefficient           = 0.5f;
                    tradeVesselsTrafficCoefficient = 0.75f;
                    upgradeDiscount         = 0.2f; upgradeCostIncrease = 1.7f;
                    environmentalConditions = 0.9f;
                    break;

                case Difficulty.Torture:
                    LUCK_COEFFICIENT               = 0.01f;
                    demolitionLossesPercent        = 1;
                    lifepowerLossesPercent         = 0.85f;
                    sellPriceCoefficient           = 0.33f;
                    tradeVesselsTrafficCoefficient = 1;
                    upgradeDiscount         = 0.1f; upgradeCostIncrease = 2f;
                    environmentalConditions = 0.8f;
                    break;
                }
                warProximity   = 0.01f;
                layerCutHeight = Chunk.CHUNK_SIZE; prevCutHeight = layerCutHeight;
                switch (startGameWith)
                {
                case GameStart.Zeppelin:
                    LandingUI lui = gameObject.AddComponent <LandingUI>();
                    lui.lineDrawer = systemDrawLR;
                    Instantiate(Resources.Load <GameObject>("Prefs/Zeppelin"));
                    break;

                case GameStart.Headquarters:
                    List <SurfaceBlock> sblocks = mainChunk.surfaceBlocks;
                    SurfaceBlock        sb      = sblocks[(int)(Random.value * (sblocks.Count - 1))];
                    int xpos = sb.pos.x;
                    int zpos = sb.pos.z;

                    if (colonyController == null)
                    {
                        colonyController = gameObject.AddComponent <ColonyController>();
                    }
                    Structure    s = Structure.GetStructureByID(Structure.LANDED_ZEPPELIN_ID);
                    SurfaceBlock b = mainChunk.GetSurfaceBlock(xpos, zpos);
                    s.SetBasement(b, PixelPosByte.zero);
                    b.MakeIndestructible(true);
                    b.myChunk.GetBlock(b.pos.x, b.pos.y - 1, b.pos.z).MakeIndestructible(true);

                    colonyController.AddCitizens(START_WORKERS_COUNT);

                    sb = mainChunk.GetSurfaceBlock(xpos - 1, zpos + 1);
                    if (sb == null)
                    {
                        sb = mainChunk.GetSurfaceBlock(xpos, zpos + 1);
                        if (sb == null)
                        {
                            sb = mainChunk.GetSurfaceBlock(xpos + 1, zpos + 1);
                            if (sb == null)
                            {
                                sb = mainChunk.GetSurfaceBlock(xpos - 1, zpos);
                                if (sb == null)
                                {
                                    sb = mainChunk.GetSurfaceBlock(xpos + 1, zpos);
                                    if (sb == null)
                                    {
                                        sb = mainChunk.GetSurfaceBlock(xpos - 1, zpos - 1);
                                        if (sb == null)
                                        {
                                            sb = mainChunk.GetSurfaceBlock(xpos, zpos - 1);
                                            if (sb == null)
                                            {
                                                sb = mainChunk.GetSurfaceBlock(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);
                    //start resources
                    colonyController.storage.AddResource(ResourceType.metal_K, 100);
                    colonyController.storage.AddResource(ResourceType.metal_M, 50);
                    colonyController.storage.AddResource(ResourceType.metal_E, 20);
                    colonyController.storage.AddResource(ResourceType.Plastics, 100);
                    colonyController.storage.AddResource(ResourceType.Food, 200);

                    //UI ui = gameObject.AddComponent<UI>();
                    //ui.lineDrawer = systemDrawLR;
                    break;
                }
                FollowingCamera.main.WeNeedUpdate();
            }
            else
            {
                LoadGame(Application.persistentDataPath + "/Saves/" + savename + ".sav");
            }
        }
        else
        {
            gameObject.AddComponent <PoolMaster>().Load();

            Chunk.SetChunkSize(test_size);
            mainChunk = new GameObject("chunk").AddComponent <Chunk>();
            mainChunk.InitializeBlocksArray();
            mainChunk.ChunkLightmapFullRecalculation();
            mainChunk.AddBlock(new ChunkPos(Chunk.CHUNK_SIZE / 2, Chunk.CHUNK_SIZE / 2, Chunk.CHUNK_SIZE / 2), BlockType.Cube, ResourceType.STONE_ID, true);

            FollowingCamera.CenterCamera(Vector3.one * Chunk.CHUNK_SIZE / 2f);
        }
    }
コード例 #24
0
ファイル: Constructor.cs プロジェクト: Hengle/VoxelGame
    private static GameObject ConstructGeneratedMesh(GeneratedMeshPartInfo[,,] dataArray, int materialID)
    {
        Vector3 scale = Vector3.one;
        var     ci = new CombineInstance[RefineGeneratedMesh(ref dataArray)];
        int     i = 0, xsize = dataArray.GetLength(0), ysize = dataArray.GetLength(1), zsize = dataArray.GetLength(2);
        float   xhalf = xsize / 2f, zhalf = zsize / 2f;

        Quaternion[] rotations = new Quaternion[6]
        {
            Quaternion.identity, Quaternion.Euler(0f, 90f, 0f), Quaternion.Euler(0f, 180f, 0f),
            Quaternion.Euler(0f, 270f, 0f), Quaternion.Euler(90f, 0f, 0f), Quaternion.Euler(-90f, 0f, 0f)
        };
        Vector3[] correctionVectors = new Vector3[6]
        {
            Vector3.forward * 0.5f *scale.z, Vector3.right * 0.5f *scale.x, Vector3.back * 0.5f *scale.z,
                  Vector3.left * 0.5f *scale.x, Vector3.up * 0.5f *scale.y, Vector3.down * 0.5f *scale.y
        };
        for (int x = 0; x < xsize; x++)
        {
            for (int y = 0; y < ysize; y++)
            {
                for (int z = 0; z < zsize; z++)
                {
                    var gmi = dataArray[x, y, z];
                    if (gmi.fwdFaceType != MeshType.NoMesh)
                    {
                        ci[i].mesh      = MeshMaster.GetMesh(gmi.fwdFaceType, materialID);
                        ci[i].transform = Matrix4x4.TRS((new Vector3(x - xhalf, y - ysize, z - zhalf) + correctionVectors[0]), rotations[0], scale);
                        i++;
                    }
                    if (gmi.rightFaceType != MeshType.NoMesh)
                    {
                        ci[i].mesh      = MeshMaster.GetMesh(gmi.rightFaceType, materialID);
                        ci[i].transform = Matrix4x4.TRS((new Vector3(x - xhalf, y - ysize, z - zhalf) + correctionVectors[1]), rotations[1], scale);
                        i++;
                    }
                    if (gmi.backFaceType != MeshType.NoMesh)
                    {
                        ci[i].mesh      = MeshMaster.GetMesh(gmi.backFaceType, materialID);
                        ci[i].transform = Matrix4x4.TRS((new Vector3(x - xhalf, y - ysize, z - zhalf) + correctionVectors[2]), rotations[2], scale);
                        i++;
                    }
                    if (gmi.leftFaceType != MeshType.NoMesh)
                    {
                        ci[i].mesh      = MeshMaster.GetMesh(gmi.leftFaceType, materialID);
                        ci[i].transform = Matrix4x4.TRS((new Vector3(x - xhalf, y - ysize, z - zhalf) + correctionVectors[3]), rotations[3], scale);
                        i++;
                    }
                    if (gmi.upFaceType != MeshType.NoMesh)
                    {
                        ci[i].mesh      = MeshMaster.GetMesh(gmi.upFaceType, materialID);
                        ci[i].transform = Matrix4x4.TRS((new Vector3(x - xhalf, y - ysize, z - zhalf) + correctionVectors[4]), rotations[5], scale);
                        i++;
                    }
                    if (gmi.downFaceType != MeshType.NoMesh)
                    {
                        ci[i].mesh      = MeshMaster.GetMesh(gmi.downFaceType, materialID);
                        ci[i].transform = Matrix4x4.TRS((new Vector3(x - xhalf, y - ysize, z - zhalf) + correctionVectors[5]), rotations[5], scale);
                        i++;
                    }
                    if (gmi.innerFaceType != MeshType.NoMesh)
                    {
                        ci[i].mesh      = MeshMaster.GetMesh(gmi.innerFaceType, materialID);
                        ci[i].transform = Matrix4x4.TRS((new Vector3(x - xhalf, y - ysize, z - zhalf)),
                                                        (gmi.fwdFaceType == MeshType.NoMesh) ? rotations[0] : (gmi.rightFaceType == MeshType.NoMesh ? rotations[1] : (
                                                                                                                   gmi.backFaceType == MeshType.NoMesh ? rotations[2] : rotations[3]
                                                                                                                   )),
                                                        scale);
                        i++;
                    }
                }
            }
        }
        GameObject g  = new GameObject("peak model");
        var        mf = g.AddComponent <MeshFilter>();
        var        m  = new Mesh();

        m.CombineMeshes(ci, true);
        mf.sharedMesh = m;
        var mr = g.AddComponent <MeshRenderer>();

        mr.sharedMaterial = PoolMaster.GetMaterial(materialID);
        if (PoolMaster.shadowCasting)
        {
            mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
            mr.receiveShadows    = true;
        }
        else
        {
            mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            mr.receiveShadows    = false;
        }
        mr.lightProbeUsage      = UnityEngine.Rendering.LightProbeUsage.Off;
        mr.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
        return(g);
    }
コード例 #25
0
    override public void SetVisibilityMask(byte x)
    {
        byte prevMask = visibilityMask;

        // блоки, отключающиеся полностью, возвращают модели обратно в пул
        if (prevMask == 0 & x != 0) // включение
        {
            visibilityMask = x;
            for (int i = 0; i < 6; i++)
            {
                if (faces[i] == null)
                {
                    CreateFace(i);
                }
                else
                {
                    faces[i].gameObject.SetActive(true);
                }
            }
            ChangeFacesStatus(); // т.к в случае полного отключение вырубаем не рендереры, а сами объекты
        }
        else
        {
            if (prevMask != 0 & x == 0) // полное выключение
            {
                visibilityMask = 0;
                if (faces[4] != null)
                {
                    if (excavatingStatus == 0)
                    {
                        PoolMaster.ReturnQuadToPool(faces[4].gameObject); faces[4] = null;
                    }
                    else
                    {
                        faces[4].gameObject.SetActive(false);
                    }
                }
                if (faces[0] != null)
                {
                    PoolMaster.ReturnQuadToPool(faces[0].gameObject); faces[0] = null;
                }
                if (faces[1] != null)
                {
                    PoolMaster.ReturnQuadToPool(faces[1].gameObject); faces[1] = null;
                }
                if (faces[2] != null)
                {
                    PoolMaster.ReturnQuadToPool(faces[2].gameObject); faces[2] = null;
                }
                if (faces[3] != null)
                {
                    PoolMaster.ReturnQuadToPool(faces[3].gameObject); faces[3] = null;
                }
                if (faces[5] != null)
                {
                    PoolMaster.ReturnQuadToPool(faces[5].gameObject); faces[5] = null;
                }
            }
            else
            {
                visibilityMask = x;
                ChangeFacesStatus();
            }
        }
    }
コード例 #26
0
    /// <summary>
    /// Make checks before invoking
    /// </summary>
    public int CreateLODPack(LODPackType i_lpackType, GameObject model, RenderPoint[] renderPoints, int resolution, float shotSize, Color backgroundColor, LODRegisterInfo regInfo)
    {
        backgroundColor.a = 0;
        LODController lcontroller = LODController.GetCurrent();

        backgroundColor.a = 0;
        int savedLayer  = model.layer;
        var layerNumber = 8;

        Renderer[] allObjects = model.transform.GetComponentsInChildren <Renderer>();
        foreach (Renderer r in allObjects)
        {
            r.gameObject.layer = layerNumber;
        }
        if (!PoolMaster.useDefaultMaterials)
        {
            PoolMaster.ReplaceMaterials(allObjects);
        }

        cam.orthographicSize = shotSize;
        cam.backgroundColor  = backgroundColor;

        RenderTexture m_RenderTexture = new RenderTexture(resolution, resolution, 8, RenderTextureFormat.ARGB32);

        cam.transform.parent        = model.transform;
        cam.transform.localRotation = Quaternion.Euler(Vector3.up * 180);

        cam.enabled = true;
        Texture2D atlas;

        switch (i_lpackType)
        {
        case LODPackType.Point:
        {
            cam.transform.localPosition = renderPoints[0].position;
            cam.transform.localRotation = Quaternion.Euler(renderPoints[0].rotation);
            m_RenderTexture.Create();
            cam.targetTexture = m_RenderTexture;
            cam.Render();
            RenderTexture.active = m_RenderTexture;
            atlas = new Texture2D(resolution, resolution);
            atlas.ReadPixels(new Rect(0, 0, resolution, resolution), 0, 0);
            atlas.Apply();
            break;
        }

        case LODPackType.OneSide:
        {
            Texture2D[] spriteRenders = new Texture2D[4];
            // 0 degrees
            cam.transform.localPosition = renderPoints[0].position;
            cam.transform.localRotation = Quaternion.Euler(renderPoints[0].rotation);
            m_RenderTexture.Create();
            cam.targetTexture = m_RenderTexture;
            cam.Render();
            RenderTexture.active = m_RenderTexture;
            spriteRenders[0]     = new Texture2D(resolution, resolution);
            spriteRenders[0].ReadPixels(new Rect(0, 0, resolution, resolution), 0, 0);
            spriteRenders[0].Apply();
            // 22.5 degrees
            cam.transform.localPosition = renderPoints[1].position;
            cam.transform.localRotation = Quaternion.Euler(renderPoints[1].rotation);
            m_RenderTexture.Create();
            cam.targetTexture = m_RenderTexture;
            cam.Render();
            RenderTexture.active = m_RenderTexture;
            spriteRenders[1]     = new Texture2D(resolution, resolution);
            spriteRenders[1].ReadPixels(new Rect(0, 0, resolution, resolution), 0, 0);
            spriteRenders[1].Apply();
            // 45 degrees
            cam.transform.localPosition = renderPoints[2].position;
            cam.transform.localRotation = Quaternion.Euler(renderPoints[2].rotation);
            m_RenderTexture.Create();
            cam.targetTexture = m_RenderTexture;
            cam.Render();
            RenderTexture.active = m_RenderTexture;
            spriteRenders[2]     = new Texture2D(resolution, resolution);
            spriteRenders[2].ReadPixels(new Rect(0, 0, resolution, resolution), 0, 0);
            spriteRenders[2].Apply();
            // 85 degrees
            cam.transform.localPosition = renderPoints[3].position;
            cam.transform.localRotation = Quaternion.Euler(renderPoints[3].rotation);
            m_RenderTexture.Create();
            cam.targetTexture = m_RenderTexture;
            cam.Render();
            RenderTexture.active = m_RenderTexture;
            spriteRenders[3]     = new Texture2D(resolution, resolution);
            spriteRenders[3].ReadPixels(new Rect(0, 0, resolution, resolution), 0, 0);
            spriteRenders[3].Apply();

            atlas = new Texture2D(2 * resolution, 2 * resolution);
            atlas.PackTextures(spriteRenders, 0, 2 * resolution, false);
            break;
        }

        case LODPackType.Full:
        {
            Texture2D[] spriteRenders = new Texture2D[32];
            int         index         = 0;
            for (int i = 0; i < 8; i++)
            {
                // 0 degrees
                cam.transform.localPosition = renderPoints[index].position;
                cam.transform.localRotation = Quaternion.Euler(renderPoints[index].rotation);
                m_RenderTexture.Create();
                cam.targetTexture = m_RenderTexture;
                cam.Render();
                RenderTexture.active = m_RenderTexture;
                spriteRenders[index] = new Texture2D(resolution, resolution);
                spriteRenders[index].ReadPixels(new Rect(0, 0, resolution, resolution), 0, 0);
                spriteRenders[index].Apply();
                index++;
                // 22.5 degrees
                cam.transform.localPosition = renderPoints[index].position;
                cam.transform.localRotation = Quaternion.Euler(renderPoints[index].rotation);
                m_RenderTexture.Create();
                cam.targetTexture = m_RenderTexture;
                cam.Render();
                RenderTexture.active = m_RenderTexture;
                spriteRenders[index] = new Texture2D(resolution, resolution);
                spriteRenders[index].ReadPixels(new Rect(0, 0, resolution, resolution), 0, 0);
                spriteRenders[index].Apply();
                index++;
                // 45 degrees
                cam.transform.localPosition = renderPoints[index].position;
                cam.transform.localRotation = Quaternion.Euler(renderPoints[index].rotation);
                m_RenderTexture.Create();
                cam.targetTexture = m_RenderTexture;
                cam.Render();
                RenderTexture.active = m_RenderTexture;
                spriteRenders[index] = new Texture2D(resolution, resolution);
                spriteRenders[index].ReadPixels(new Rect(0, 0, resolution, resolution), 0, 0);
                spriteRenders[index].Apply();
                index++;
                // 85 degrees
                cam.transform.localPosition = renderPoints[index].position;
                cam.transform.localRotation = Quaternion.Euler(renderPoints[index].rotation);
                m_RenderTexture.Create();
                cam.targetTexture = m_RenderTexture;
                cam.Render();
                RenderTexture.active = m_RenderTexture;
                spriteRenders[index] = new Texture2D(resolution, resolution);
                spriteRenders[index].ReadPixels(new Rect(0, 0, resolution, resolution), 0, 0);
                spriteRenders[index].Apply();
                index++;
            }
            atlas = new Texture2D(4 * resolution, 8 * resolution);
            atlas.PackTextures(spriteRenders, 0, 8 * resolution, false);
            break;
        }

        default: return(-1);
        }


        cam.enabled          = false;
        cam.transform.parent = null;
        RenderTexture.active = null;

        foreach (Renderer r in allObjects)
        {
            r.gameObject.layer = savedLayer;
        }
        if (!PoolMaster.useDefaultMaterials)
        {
            PoolMaster.ReplaceMaterials(allObjects);
        }
        return(lcontroller.RegisterLOD(new LODRegistrationTicket(regInfo, atlas, i_lpackType)));
    }
コード例 #27
0
    void CreateFace(int i)
    {
        GameObject g = PoolMaster.GetQuad();

        g.tag = "BlockCollider";
        Transform t = g.transform;

        t.parent = transform;
        faces[i] = g.GetComponent <MeshRenderer>();

        byte faceIllumination = 255;

        switch (i)
        {
        case 0:         // fwd
            g.name          = "north_plane";
            t.localRotation = Quaternion.Euler(0, 180, 0);
            t.localPosition = new Vector3(0, 0, QUAD_SIZE / 2f);
            if (pos.z != Chunk.CHUNK_SIZE - 1)
            {
                faceIllumination = myChunk.lightMap[pos.x, pos.y, pos.z + 1];
            }
            break;

        case 1:         // right
            g.name          = "east_plane";
            t.localRotation = Quaternion.Euler(0, 270, 0);
            t.localPosition = new Vector3(QUAD_SIZE / 2f, 0, 0);
            if (pos.x != Chunk.CHUNK_SIZE - 1)
            {
                faceIllumination = myChunk.lightMap[pos.x + 1, pos.y, pos.z];
            }
            break;

        case 2:         // back
            g.name          = "south_plane";
            t.localRotation = Quaternion.Euler(0, 0, 0);
            t.localPosition = new Vector3(0, 0, -QUAD_SIZE / 2f);
            if (pos.z != 0)
            {
                faceIllumination = myChunk.lightMap[pos.x, pos.y, pos.z - 1];
            }
            break;

        case 3:         // left
            g.name          = "west_plane";
            t.localRotation = Quaternion.Euler(0, 90, 0);
            t.localPosition = new Vector3(-QUAD_SIZE / 2f, 0, 0);
            if (pos.x != 0)
            {
                faceIllumination = myChunk.lightMap[pos.x - 1, pos.y, pos.z];
            }
            break;

        case 4:         // up
            g.name          = "upper_plane";
            t.localPosition = new Vector3(0, QUAD_SIZE / 2f, 0);
            t.localRotation = Quaternion.Euler(90, 0, 0);
            if (pos.y != Chunk.CHUNK_SIZE - 1)
            {
                faceIllumination = myChunk.lightMap[pos.x, pos.y + 1, pos.z];
            }
            break;

        case 5:         // down
            g.name          = "bottom_plane";
            t.localRotation = Quaternion.Euler(-90, 0, 0);
            t.localPosition = new Vector3(0, -QUAD_SIZE / 2f, 0);
            if (pos.y != 0)
            {
                faceIllumination = myChunk.lightMap[pos.x, pos.y - 1, pos.z];
            }
            //GameObject.Destroy( faces[i].gameObject.GetComponent<MeshCollider>() );
            break;
        }
        faces[i].sharedMaterial       = ResourceType.GetMaterialById(material_id, faces[i].GetComponent <MeshFilter>(), faceIllumination);
        faces[i].shadowCastingMode    = UnityEngine.Rendering.ShadowCastingMode.Off;
        faces[i].lightProbeUsage      = UnityEngine.Rendering.LightProbeUsage.Off;
        faces[i].reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
        //if (Block.QUAD_SIZE != 1) faces[i].transform.localScale = Vector3.one * Block.QUAD_SIZE;
        faces[i].enabled = true;
    }
コード例 #28
0
    void CheckExcavatingStatus()
    {
        if (volume == 0)
        {
            if (career)
            {
                myChunk.DeleteBlock(pos);
            }
            else
            {
                myChunk.ReplaceBlock(pos, BlockType.Cave, material_id, false);
            }
            return;
        }
        float pc = volume / (float)MAX_VOLUME;

        if (pc > 0.5f)
        {
            if (pc > 0.75f)
            {
                if (excavatingStatus != 0)
                {
                    excavatingStatus = 0;
                    if (faces[4] == null)
                    {
                        CreateFace(4);
                    }
                    MeshFilter mf = faces[4].GetComponent <MeshFilter>();
                    mf.sharedMesh = PoolMaster.GetOriginalQuadMesh();
                    ResourceType.GetMaterialById(material_id, mf, illumination);
                }
            }
            else
            {
                if (excavatingStatus != 1)
                {
                    excavatingStatus = 1;
                    if (faces[4] == null)
                    {
                        CreateFace(4);
                    }
                    MeshFilter mf = faces[4].GetComponent <MeshFilter>();
                    mf.sharedMesh = PoolMaster.plane_excavated_025;
                    ResourceType.GetMaterialById(material_id, mf, illumination);
                }
            }
        }
        else           // выкопано больше половины
        {
            if (pc > 0.25f)
            {
                if (excavatingStatus != 2)
                {
                    excavatingStatus = 2;
                    if (faces[4] == null)
                    {
                        CreateFace(4);
                    }
                    MeshFilter mf = faces[4].GetComponent <MeshFilter>();
                    mf.sharedMesh = PoolMaster.plane_excavated_05;
                    ResourceType.GetMaterialById(material_id, mf, illumination);
                }
            }
            else
            {
                if (excavatingStatus != 3)
                {
                    excavatingStatus = 3;
                    if (faces[4] == null)
                    {
                        CreateFace(4);
                    }
                    MeshFilter mf = faces[4].GetComponent <MeshFilter>();
                    mf.sharedMesh = PoolMaster.plane_excavated_075;
                    ResourceType.GetMaterialById(material_id, mf, illumination);
                }
            }
        }
    }
コード例 #29
0
    override protected void SetModel()
    {
        GameObject model = null;

        if (transform.childCount > 0)
        {
            model = transform.GetChild(0).gameObject;
        }
        Mesh m     = null;
        byte level = (byte)(resourceCount / RESOURCES_PER_LEVEL);

        if (meshes.ContainsKey(level))
        {
            meshes.TryGetValue(level, out m);
        }
        else
        {
            if (resourceCount == 0)
            {
                Annihilate(StructureAnnihilationOrder.SystemDestruction);
                return;
            }
            else
            {
                m = new Mesh();
                float p = Block.QUAD_SIZE * RESOURCE_STICK_RECT_SIZE / (float)PlaneExtension.INNER_RESOLUTION, x = p / 2f;
                float h        = level * 1f / (MAX_STICK_VOLUME / RESOURCES_PER_LEVEL);
                var   vertices = new Vector3[12]
                {
                    new Vector3(-x, 0, x), new Vector3(-x, h, x), new Vector3(x, h, x), new Vector3(x, 0, x),
                    new Vector3(x, 0, -x), new Vector3(x, h, -x),
                    new Vector3(-x, h, -x), new Vector3(-x, 0, -x),
                    new Vector3(-x, h, x), new Vector3(x, h, x), new Vector3(x, h, -x), new Vector3(-x, h, -x)
                };
                var triangles = new int[30]
                {
                    3, 2, 1, 3, 1, 0,
                    4, 5, 2, 4, 2, 3,
                    7, 6, 5, 7, 5, 4,
                    0, 1, 6, 0, 6, 7,
                    11, 8, 9, 11, 9, 10
                };
                x = 1f;
                var uvs = new Vector2[12]
                {
                    new Vector2(x - 0.01f, 0.01f), new Vector2(x - 0.01f, x - 0.01f), new Vector2(0.01f, x - 0.01f), Vector2.one * 0.01f,
                    new Vector2(x - 0.01f, 0.01f), new Vector2(x - 0.01f, x - 0.01f),
                    new Vector2(0.01f, x - 0.01f), Vector2.one * 0.01f,
                    new Vector2(0, x - 0.01f), new Vector2(x - 0.01f, x - 0.01f), new Vector2(x - 0.01f, 0), Vector2.one * 0.01f
                };
                m.vertices  = vertices;
                m.triangles = triangles;
                m.uv        = uvs;
                meshes.Add(level, m);
            }
        }

        MeshFilter mf; MeshRenderer mr;

        if (model != null)
        {
            mf = model.GetComponent <MeshFilter>();
            mr = model.GetComponent <MeshRenderer>();
        }
        else
        {
            model = new GameObject("resourceStick");
            model.transform.parent        = transform;
            model.transform.localRotation = Quaternion.Euler(0, 0, 0);
            model.transform.localPosition = Vector3.zero;
            mf = model.AddComponent <MeshFilter>();
            mr = model.AddComponent <MeshRenderer>();
            mr.receiveShadows       = PoolMaster.shadowCasting;
            mr.shadowCastingMode    = !PoolMaster.useDefaultMaterials ? UnityEngine.Rendering.ShadowCastingMode.On : UnityEngine.Rendering.ShadowCastingMode.Off;
            mr.lightProbeUsage      = UnityEngine.Rendering.LightProbeUsage.Off;
            mr.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
        }

        byte light;

        if (basement != null)
        {
            light = basement.myChunk.lightMap[basement.pos.x, basement.pos.y, basement.pos.z];
        }
        else
        {
            light = 255;
        }

        if (prevModelMesh != null)
        {
            if (prevModelLight == light && prevModelLevel == level && prevModelMaterialID == mainResource.ID)
            {
                mf.sharedMesh     = prevModelMesh;
                mr.sharedMaterial = PoolMaster.GetMaterial(mainResource.ID);
                return;
            }
        }

        mf.sharedMesh       = m;
        prevModelMesh       = PoolMaster.SetMaterialByID(ref mf, ref mr, mainResource.ID, light);
        prevModelLevel      = level;
        prevModelLight      = light;
        prevModelMaterialID = mainResource.ID;
    }
コード例 #30
0
ファイル: Gardens.cs プロジェクト: Hengle/VoxelGame
    override protected void SetModel()
    {
        //switch skin index
        GameObject model;
        Quaternion prevRot = Quaternion.identity;

        if (transform.childCount != 0)
        {
            return;
        }
        model = new GameObject("gardenModel");
        model.transform.parent        = transform;
        model.transform.localRotation = prevRot;
        model.transform.localPosition = Vector3.zero;

        //generating model info
        if (modelsInfo == null)
        {
            var   milist = new List <byte>();
            float f = Random.value;
            byte  modelCode = 0, posCodeX = 0, posCodeZ = 0;
            // 0-8, 0-8
            if (f > 0.5f)
            {
                f *= 2f;
                if (f <= 0.4f) // small
                {
                    f /= 0.4f;
                    if (f > 0.6f)
                    {
                        if (f > 0.9f)
                        {
                            modelCode = SMALL_TOWER_ID;
                        }
                        else
                        {
                            modelCode = SMALL_TANK_ID;
                        }
                    }
                    else
                    {
                        if (f < 0.4f)
                        {
                            modelCode = SMALL_HIGHTREE_ID;
                        }
                        else
                        {
                            modelCode = SMALL_PARK_ID;
                        }
                    }
                    f = Random.value;
                    if (f > 0.5f)
                    {
                        if (f > 0.75f)
                        {
                            posCodeX = 0; posCodeZ = 4;
                        }
                        else
                        {
                            posCodeX = 0; posCodeZ = 0;
                        }
                    }
                    else
                    {
                        if (f > 0.25f)
                        {
                            posCodeX = 4; posCodeZ = 0;
                        }
                        else
                        {
                            posCodeX = 4; posCodeZ = 4;
                        }
                    }
                }
                else
                {
                    if (f >= 0.8f) // big
                    {
                        f = (f - 0.8f) / 0.2f;
                        if (f > 0.65f)
                        {
                            modelCode = BIG_HIGHPARK_ID;
                        }
                        else
                        {
                            modelCode = BIG_MIDPARK_ID;
                        }
                        posCodeX = 0;
                        posCodeZ = 0;
                    }
                    else // double
                    {
                        f = (f - 0.4f) / 0.4f;
                        if (f > 0.65f)
                        {
                            modelCode = DOUBLE_HIGHPARK_ID;
                        }
                        else
                        {
                            modelCode = DOUBLE_MIDPARK_ID;
                        }
                        posCodeX = 0;
                        posCodeZ = 0;
                    }
                }
                milist.Add(posCodeX);
                milist.Add(posCodeZ);
                milist.Add(modelCode);
            }
            // 8-16, 0-8
            f = Random.value;
            if (f > 0.5f)
            {
                f *= 2f;
                if (f <= 0.4f) // small
                {
                    f /= 0.4f;
                    if (f > 0.6f)
                    {
                        if (f > 0.9f)
                        {
                            modelCode = SMALL_TOWER_ID;
                        }
                        else
                        {
                            modelCode = SMALL_TANK_ID;
                        }
                    }
                    else
                    {
                        if (f < 0.4f)
                        {
                            modelCode = SMALL_HIGHTREE_ID;
                        }
                        else
                        {
                            modelCode = SMALL_PARK_ID;
                        }
                    }
                    f = Random.value;
                    if (f > 0.5f)
                    {
                        if (f > 0.75f)
                        {
                            posCodeX = 8; posCodeZ = 4;
                        }
                        else
                        {
                            posCodeX = 8; posCodeZ = 0;
                        }
                    }
                    else
                    {
                        if (f > 0.25f)
                        {
                            posCodeX = 12; posCodeZ = 0;
                        }
                        else
                        {
                            posCodeX = 12; posCodeZ = 4;
                        }
                    }
                }
                else
                {
                    if (f >= 0.8f) // big
                    {
                        f = (f - 0.8f) / 0.2f;
                        if (f > 0.65f)
                        {
                            modelCode = BIG_HIGHPARK_ID;
                        }
                        else
                        {
                            modelCode = BIG_MIDPARK_ID;
                        }
                        posCodeX = 8;
                        posCodeZ = 0;
                    }
                    else // double
                    {
                        f = (f - 0.4f) / 0.4f;
                        if (f > 0.65f)
                        {
                            modelCode = DOUBLE_HIGHPARK_ID;
                        }
                        else
                        {
                            modelCode = DOUBLE_MIDPARK_ID;
                        }
                        posCodeX = 8;
                        posCodeZ = 0;
                    }
                }
                milist.Add(posCodeX);
                milist.Add(posCodeZ);
                milist.Add(modelCode);
            }
            // 0-8, 8-16
            f = Random.value;
            if (f > 0.5f)
            {
                f *= 2f;
                if (f <= 0.4f) // small
                {
                    f /= 0.4f;
                    if (f > 0.6f)
                    {
                        if (f > 0.9f)
                        {
                            modelCode = SMALL_TOWER_ID;
                        }
                        else
                        {
                            modelCode = SMALL_TANK_ID;
                        }
                    }
                    else
                    {
                        if (f < 0.4f)
                        {
                            modelCode = SMALL_HIGHTREE_ID;
                        }
                        else
                        {
                            modelCode = SMALL_PARK_ID;
                        }
                    }
                    f = Random.value;
                    if (f > 0.5f)
                    {
                        if (f > 0.75f)
                        {
                            posCodeX = 0; posCodeZ = 12;
                        }
                        else
                        {
                            posCodeX = 0; posCodeZ = 8;
                        }
                    }
                    else
                    {
                        if (f > 0.25f)
                        {
                            posCodeX = 4; posCodeZ = 8;
                        }
                        else
                        {
                            posCodeX = 4; posCodeZ = 12;
                        }
                    }
                }
                else
                {
                    if (f >= 0.8f) // big
                    {
                        f = (f - 0.8f) / 0.2f;
                        if (f > 0.65f)
                        {
                            modelCode = BIG_HIGHPARK_ID;
                        }
                        else
                        {
                            modelCode = BIG_MIDPARK_ID;
                        }
                        posCodeX = 0;
                        posCodeZ = 8;
                    }
                    else // double
                    {
                        f = (f - 0.4f) / 0.4f;
                        if (f > 0.65f)
                        {
                            modelCode = DOUBLE_HIGHPARK_ID;
                        }
                        else
                        {
                            modelCode = DOUBLE_MIDPARK_ID;
                        }
                        posCodeX = 0;
                        posCodeZ = 8;
                    }
                }
                milist.Add(posCodeX);
                milist.Add(posCodeZ);
                milist.Add(modelCode);
            }
            // 8- 16, 8 - 16
            f = Random.value;
            if (f <= 0.4f) // small
            {
                f /= 0.4f;
                if (f > 0.6f)
                {
                    if (f > 0.9f)
                    {
                        modelCode = SMALL_TOWER_ID;
                    }
                    else
                    {
                        modelCode = SMALL_TANK_ID;
                    }
                }
                else
                {
                    if (f < 0.4f)
                    {
                        modelCode = SMALL_HIGHTREE_ID;
                    }
                    else
                    {
                        modelCode = SMALL_PARK_ID;
                    }
                }
                f = Random.value;
                if (f > 0.5f)
                {
                    if (f > 0.75f)
                    {
                        posCodeX = 8; posCodeZ = 12;
                    }
                    else
                    {
                        posCodeX = 8; posCodeZ = 8;
                    }
                }
                else
                {
                    if (f > 0.25f)
                    {
                        posCodeX = 12; posCodeZ = 8;
                    }
                    else
                    {
                        posCodeX = 12; posCodeZ = 12;
                    }
                }
            }
            else
            {
                if (f >= 0.8f) // big
                {
                    f = (f - 0.8f) / 0.2f;
                    if (f > 0.65f)
                    {
                        modelCode = BIG_HIGHPARK_ID;
                    }
                    else
                    {
                        modelCode = BIG_MIDPARK_ID;
                    }
                    posCodeX = 8;
                    posCodeZ = 8;
                }
                else // double
                {
                    f = (f - 0.4f) / 0.4f;
                    if (f > 0.65f)
                    {
                        modelCode = DOUBLE_HIGHPARK_ID;
                    }
                    else
                    {
                        modelCode = DOUBLE_MIDPARK_ID;
                    }
                    posCodeX = 8;
                    posCodeZ = 8;
                }
            }
            milist.Add(posCodeX);
            milist.Add(posCodeZ);
            milist.Add(modelCode);
            //
            modelsInfo = milist.ToArray();
        }
        //constructing model
        int        i      = 0;
        byte       size   = 0;
        var        mlist  = new List <GameObject>();
        GameObject g      = null;
        Transform  parent = model.transform;
        float      ir     = (float)PlaneExtension.INNER_RESOLUTION;

        while (i < modelsInfo.Length)
        {
            switch (modelsInfo[i])
            {
            case SMALL_PARK_ID:
                g = Instantiate(Resources.Load <GameObject>("Structures/Settlement/parkPart"));
                break;

            case SMALL_TOWER_ID:
                g = Instantiate(Resources.Load <GameObject>("Prefs/Gardenparts/small_mast"));
                break;

            case SMALL_TANK_ID:
                g = Instantiate(Resources.Load <GameObject>("Prefs/Gardenparts/small_tank"));
                break;

            case SMALL_HIGHTREE_ID:
                g = Instantiate(Resources.Load <GameObject>("Prefs/Gardenparts/small_hightree"));
                break;

            case DOUBLE_HIGHPARK_ID:
                size = 2;
                g    = Instantiate(Resources.Load <GameObject>("Prefs/Gardenparts/double_highpark"));
                break;

            case DOUBLE_MIDPARK_ID:
                size = 2;
                g    = Instantiate(Resources.Load <GameObject>("Prefs/Gardenparts/double_midhpark"));
                break;

            case BIG_HIGHPARK_ID:
                size = 1;
                g    = Instantiate(Resources.Load <GameObject>("Prefs/Gardenparts/big_highpark"));
                break;

            case BIG_MIDPARK_ID:
                size = 1;
                g    = Instantiate(Resources.Load <GameObject>("Prefs/Gardenparts/big_midpark"));
                break;
            }
            if (g != null)
            {
                g.transform.parent        = parent;
                g.transform.localPosition =
                    (Vector3.right * (modelsInfo[i + 1] / ir - 0.5f)) * Block.QUAD_SIZE +
                    (Vector3.forward * (modelsInfo[i + 2] / ir - 0.5f)) * Block.QUAD_SIZE;
            }
            i += 3;
        }
        //
        if (PoolMaster.useAdvancedMaterials)
        {
            PoolMaster.ReplaceMaterials(model, true);
        }
    }