예제 #1
0
        void HandleOn_AnimatorEvent(UnityEngine.Object value)
        {
            float      screenX = _playerController.playerInputState.X;
            float      screenY = _playerController.playerInputState.Y;
            RaycastHit hit;

            if (Terrain.RayToWorld(screenX, screenY, _playerController.transform.position,
                                   distance, out hit, oppoMaskLayer))
            {
                WorldPos pos = Terrain.GetWorldPos(hit, false);
                if (hit.collider.GetComponentInParent <ChunkObj>() == null)
                {
                    return;
                }
                Block hitBlock = World.world.GetBlock(pos.x, pos.y, pos.z);
                if (hitBlock.BlockType == BlockType.Air)
                {
                    return;
                }
                int handMaterialId = _playerController.playerAttribute.handMaterialId;
                if (MineController.Instance.Mine(handMaterialId, pos, hitBlock))
                {
                    BlockExplodeController.Instance.Explode(pos, hitBlock, hit.normal);
                    Terrain.SetBlock(pos, air);
                    DropController.Instance.Drop(handMaterialId, pos, hitBlock);
                }
            }
        }
예제 #2
0
        public bool startAutoMove(Vector3 targetPosition, float speed = 1F)
        {
            _movespeed = speed;
            WorldPos startWorldPos = Terrain.GetWorldPos(gameObject.transform.position);
            Vector3  startPos      = new Vector3(startWorldPos.x, startWorldPos.y, startWorldPos.z);

            _movePath  = MTBPathFinder.Instance.GetPath(startPos, targetPosition, true);
            isAutoMove = true;
            _moveStep  = 0;
            return(_movePath.pathData != null);
        }
예제 #3
0
        protected override void ResetPos()
        {
            WorldPos pos    = Terrain.GetWorldPos(transform.position);
            int      height = WorldConfig.Instance.heightCap;

            for (int y = height - 1; y >= 0; y--)
            {
                if (World.world.GetBlock(pos.x, y + World.MinHeight, pos.z).BlockType != BlockType.Air)
                {
                    height = y + World.MinHeight;
                    break;
                }
            }
            this.gameObject.transform.position = new Vector3(transform.position.x, (float)height + 1, transform.position.z);
        }
예제 #4
0
        public GameObjectState(GameObjectController controller)
        {
            _controller = controller;
            _curPos     = Terrain.GetWorldPos(_controller.transform.position);
            CheckAndResetPos();
            Chunk chunk = World.world.GetChunk(_curPos.x, 0, _curPos.z);

            AttachChunk(chunk);
            WorldPos chunkPos = chunk.worldPos;

            _inBlock         = _attachChunk.GetBlock(_curPos.x - chunkPos.x, _curPos.y - chunkPos.y, _curPos.z - chunkPos.z, true);
            _standBlock      = _attachChunk.GetBlock(_curPos.x - chunkPos.x, _curPos.y - chunkPos.y - 1, _curPos.z - chunkPos.z, true);
            _blockLightLevel = _attachChunk.GetBlockLight(_curPos.x - chunkPos.x, _curPos.y - chunkPos.y, _curPos.z - chunkPos.z, true);
            _sunLightLevel   = _attachChunk.GetSunLight(_curPos.x - chunkPos.x, _curPos.y - chunkPos.y, _curPos.z - chunkPos.z, true);
            InitRenderLight(_blockLightLevel, _sunLightLevel);
        }
예제 #5
0
 protected virtual void CheckAndResetPos()
 {
     if (_curPos.y <= 0 || _curPos.y > 256)
     {
         WorldPos pos    = Terrain.GetWorldPos(_controller.transform.position);
         int      height = WorldConfig.Instance.heightCap;
         for (int y = height - 1; y >= 0; y--)
         {
             if (World.world.GetBlock(pos.x, y + World.MinHeight, pos.z).BlockType != BlockType.Air)
             {
                 height = y + World.MinHeight;
                 break;
             }
         }
         _controller.transform.position = new Vector3(_controller.transform.position.x, (float)height + 1, _controller.transform.position.z);
         _curPos = Terrain.GetWorldPos(_controller.transform.position);
     }
 }
        public void Do(float screenX, float screenY, Vector3 position, float distance)
        {
            RaycastHit hit;
            int        mask = LayerMask.GetMask(new string[] { "TerrainMesh", "SupportColliderMesh" });

            if (Terrain.RayToWorld(screenX, screenY, position, distance, out hit, mask))
            {
                WorldPos pos = Terrain.GetWorldPos(hit, false);
                if (hit.collider.GetComponentInParent <ChunkObj>() == null)
                {
                    return;
                }
                ShowMaskObj(pos);
            }
            else
            {
                HideMaskObj();
            }
        }
예제 #7
0
        public void LoadFirst(Vector3 pos, int size)
        {
            EventManager.SendEvent(EventMacro.START_GENERATE_FIRST_WORLD, null);
            EventManager.RegisterEvent(EventMacro.CHUNK_GENERATE_FINISH, OnFirstWorldChunkGenerate);
            WorldPos worldPos    = Terrain.GetWorldPos(pos);
            WorldPos curChunkPos = Terrain.GetChunkPos(worldPos.x, 0, worldPos.z);

            for (int x = -size; x <= size; x++)
            {
                for (int z = -size; z <= size; z++)
                {
                    WorldPos chunkPos = new WorldPos(curChunkPos.x + x * Chunk.chunkWidth, curChunkPos.y, curChunkPos.z + z * Chunk.chunkDepth);
                    if ((x >= -size + 2 && x <= size - 2) && (z >= -size + 2 && z <= size - 2))
                    {
                        firstChunks.Add(chunkPos);
                    }
                    world.WorldGenerator.GenerateChunk(chunkPos.x, chunkPos.y, chunkPos.z, curChunkPos);
                }
            }
        }
예제 #8
0
 public void Update()
 {
     if (player == null)
     {
         player = HasActionObjectManager.Instance.playerManager.getMyPlayer();
     }
     else
     {
         WorldPos playerPos   = Terrain.GetWorldPos(player.transform.position);
         WorldPos curChunkPos = Terrain.GetChunkPos(playerPos.x, 0, playerPos.z);
         if (!curChunkPos.EqualOther(_curChunkPos))
         {
             _curChunkPos = curChunkPos;
             world.WorldGenerator.DataProcessorManager.UpdateChunkPriority(_curChunkPos);
             ChangeAllEntityVisible();
             LoadChunks();
             RemoveChunks();
             UpdatePersistanceOperate();
         }
     }
 }
예제 #9
0
 void Update()
 {
     if (!_isFly)
     {
         _curTime += Time.deltaTime;
         if (_curTime > disappearTime)
         {
             On_SelfDisappear(this);
         }
         WorldPos pos   = Terrain.GetWorldPos(this.transform.position);
         Block    block = World.world.GetBlock(pos.x, pos.y, pos.z);
         BlockAttributeCalculator calculator = BlockAttributeCalculatorFactory.GetCalculator(block.BlockType);
         int   sunLight       = World.world.GetSunLight(pos.x, pos.y, pos.z);
         int   blockLight     = World.world.GetBlockLight(pos.x, pos.y, pos.z);
         float lightIntensity = MTBSkyBox.Instance.GetLightIntensity(sunLight, blockLight);
         render.material.SetFloat("_lightIntensity", lightIntensity);
         if (calculator.GetMeshColliderType(block.ExtendId) == MeshColliderType.terrainCollider)
         {
             On_SelfDisappear(this);
         }
     }
     else
     {
         if (_player != null)
         {
             Vector3 dis = _player.transform.position + new Vector3(0, 1.5f, 0) - this.transform.position;
             if (dis.magnitude < 0.3f)
             {
                 On_SelfDisappear(this);
                 return;
             }
             Vector3 v = dis.normalized * flySpeed;
             this.transform.position += v * Time.deltaTime;
         }
         else
         {
             On_SelfDisappear(this);
         }
     }
 }
예제 #10
0
        public void UpdateState()
        {
            WorldPos pos = Terrain.GetWorldPos(_controller.transform.position);

            if (!_curPos.EqualOther(pos))
            {
                _curPos = pos;
                CheckAndResetPos();
                WorldPos chunkPos = Terrain.GetChunkPos(_curPos.x, 0, _curPos.z);
                if (!chunkPos.EqualOther(_attachChunk.worldPos))
                {
                    Chunk chunk = World.world.GetChunk(chunkPos.x, chunkPos.y, chunkPos.z);
                    AttachChunk(chunk);
                }

                _inBlock         = _attachChunk.GetBlock(_curPos.x - chunkPos.x, _curPos.y - chunkPos.y, _curPos.z - chunkPos.z, true);
                _standBlock      = _attachChunk.GetBlock(_curPos.x - chunkPos.x, _curPos.y - chunkPos.y - 1, _curPos.z - chunkPos.z, true);
                _blockLightLevel = _attachChunk.GetBlockLight(_curPos.x - chunkPos.x, _curPos.y - chunkPos.y, _curPos.z - chunkPos.z, true);
                _sunLightLevel   = _attachChunk.GetSunLight(_curPos.x - chunkPos.x, _curPos.y - chunkPos.y, _curPos.z - chunkPos.z, true);
            }
            UpdateRenderLight(_sunLightLevel, _blockLightLevel);
        }
예제 #11
0
        public void UpdatePersistanceOperate()
        {
            WorldPos playerPos = Terrain.GetWorldPos(player.transform.position);

            WorldPersistanceManager.Instance.UpdateRegionFileLinkByChunkPos(_curChunkPos);
        }
예제 #12
0
 protected virtual void Update()
 {
     _pos = Terrain.GetWorldPos(followCamera.transform.position + followCamera.transform.forward * (followCamera.nearClipPlane + 0.001f));
 }
        public override void ActionIn()
        {
            float screenX = _playerController.playerInputState.X;
            float screenY = _playerController.playerInputState.Y;

            BlockMaskController.Instance.Do(screenX, screenY, _playerController.transform.position, distance);
            RaycastHit hit;
            int        handMaterialId = _playerController.playerAttribute.handMaterialId;

            if (handMaterialId <= 0)
            {
                return;
            }
            Item item = ItemManager.Instance.GetItem(handMaterialId);

            if (item.itemType != (int)ItemType.Block)
            {
                return;
            }
            if (Terrain.RayToWorld(screenX, screenY, _playerController.transform.position,
                                   distance, out hit, oppoMaskLayer))
            {
                WorldPos pos = Terrain.GetWorldPos(hit, true);
                if (hit.collider.GetComponentInParent <ChunkObj>() == null)
                {
                    return;
                }
                if (!Terrain.CheckPosCanPlaced(_playerController.transform, pos))
                {
                    return;
                }
                Block handBlock = new Block((BlockType)item.sceneBlockType, item.sceneBlockExtendId);

                BlockAttributeCalculator calculator = BlockAttributeCalculatorFactory.GetCalculator(handBlock.BlockType);
                if (calculator is BAC_ModelBlock)
                {
                    Vector3 forward  = _gameObjectController.transform.forward;
                    float   degree   = Vector2.Angle(Vector2.right, new Vector2(forward.x, forward.z));
                    byte    extendId = 8;
                    if (degree < 45)
                    {
                        extendId |= 3;
                    }
                    else if (degree > 135)
                    {
                        extendId |= 1;
                    }
                    else if (forward.z > 0)
                    {
                        extendId |= 2;
                    }
                    handBlock = new Block(BlockType.Block_100, extendId);
                }

                int decType = HasActionObjectManager.Instance.plantManager.checkIsPlantSeedling(handMaterialId);
                if (decType != -1)
                {
                    HasActionObjectManager.Instance.plantManager.buildPlant(new Vector3(pos.x, pos.y, pos.z), (DecorationType)decType);
                    return;
                }

                Terrain.SetBlock(pos, handBlock);
            }
        }