Ejemplo n.º 1
0
        public void CloseDoor(IChunk chunk)
        {
            UnityChunk unityChunk = chunk as UnityChunk;

            UnityChunkDoor[] doors = unityChunk.Doors;
            foreach (var door in doors)
            {
                door.gameObject.SetActive(true);
            }
        }
Ejemplo n.º 2
0
        public void SummonNpc(IChunk chunk)
        {
            UnityChunk unityChunk = chunk as UnityChunk;

            GameEntity sceneEntity = _contexts.game.sceneEntity;

            foreach (var npcSpawn in unityChunk.m_Npcs)
            {
                uint    entityId = IdSystem.Instance.GenId(IdEnum.Entity);
                Vector3 position = unityChunk.gameObject.transform.TransformPoint(npcSpawn.Position);
                float   rotation = 0;

                Services.Instance.CreateCharacterService.CreateNpc(entityId, sceneEntity.id.value, npcSpawn.NpcId, (int)CampId.Blue, position, rotation);
            }
        }
Ejemplo n.º 3
0
        private void GenerateGameMap(Transform root, ChunkEntity[] entities)
        {
            Bounds bounds = new Bounds();

            foreach (var chunkEntity in entities)
            {
                UnityChunk unityChunk = chunkEntity.chunk.Value as UnityChunk;
                bounds.Encapsulate(unityChunk.transform.position);
            }
            Vector3 min  = bounds.min;
            Vector3 max  = bounds.max;
            Vector3 size = max - min;

            float mapXSize = 1000;
            float mapYSize = size.z / size.x * mapXSize;

            float scale = (mapXSize / size.x) / 2;

            foreach (var chunkEntity in entities)
            {
                UnityChunk unityChunk = chunkEntity.chunk.Value as UnityChunk;
                string     chunkName  = unityChunk.m_ChunkName;
                Vector3    position   = unityChunk.transform.position;
                float      yAngle     = unityChunk.transform.rotation.eulerAngles.y;

                GameObject chunkMap = Resources.Load("BlocksUI/" + chunkName) as GameObject;
                if (null == chunkMap)
                {
                    Util.LogUtil.Error("can not load chunk map {0}.", chunkName);
                    continue;
                }
                GameObject chunkMapObj = GameObject.Instantiate(chunkMap);

                chunkMapObj.transform.SetParent(root, false);

                Image chunkImage = chunkMapObj.GetComponent <Image>();

                float xPercent = (position.x - min.x) / size.x;
                float yPercent = (position.z - min.z) / size.z;

                chunkImage.rectTransform.rotation         = Quaternion.Euler(0, 0, yAngle);
                chunkImage.rectTransform.anchoredPosition = new Vector2(xPercent * mapXSize - mapXSize / 2, yPercent * mapYSize - mapYSize / 2);
                chunkImage.rectTransform.localScale      *= scale;
            }
        }
Ejemplo n.º 4
0
        public void LoadChunk(ChunkEntity entity, IChunk chunk)
        {
            UnityChunk unityChunk = chunk as UnityChunk;

            UnityChunkDoor[] chunkDoors = unityChunk.GetComponentsInChildren <UnityChunkDoor>();
            foreach (var chunkDoor in chunkDoors)
            {
                LoadChunkDoor(unityChunk, chunkDoor);
            }

            UnityChunkTrigger[] chunkTriggers = unityChunk.GetComponentsInChildren <UnityChunkTrigger>();
            foreach (var chunkTrigger in chunkTriggers)
            {
                LoadChunkTrigger(unityChunk, chunkTrigger);
            }

            unityChunk.Init(entity, chunkDoors, chunkTriggers);
            OpenDoor(chunk);
        }
Ejemplo n.º 5
0
        private void OnChunkTriggerEnter(IChunk chunk, IView view)
        {
            UnityChunk unityChunk = chunk as UnityChunk;

            if (unityChunk.Triggered)
            {
                return;
            }

            UnityView unityView = view as UnityView;

            if (unityView.Entity is GameEntity gameEntity)
            {
                if (gameEntity.isMainPlayer)
                {
                    unityChunk.Entity.isActiveChunk = true;
                    CloseDoor(chunk);
                    SummonNpc(chunk);
                    unityChunk.Triggered = true;
                }
            }
        }
 public void Init(UnityChunk chunk)
 {
     m_Chunk = chunk;
 }
Ejemplo n.º 7
0
        private void LoadChunkTrigger(UnityChunk chunk, UnityChunkTrigger chunkTrigger)
        {
            chunkTrigger.Init(chunk);

            chunkTrigger.OnChunkTriggerEnter += OnChunkTriggerEnter;
        }
Ejemplo n.º 8
0
 private void LoadChunkDoor(UnityChunk chunk, UnityChunkDoor chunkDoor)
 {
     chunkDoor.Init(chunk);
 }