예제 #1
0
    protected override void OnUpdate()
    {
        var requestArray = Group.GetComponentDataArray <NameboardSpawnRequest>();
        var entityArray  = Group.GetEntityArray();

        var spawnRequests = new NameboardSpawnRequest[requestArray.Length];

        for (var i = 0; i < requestArray.Length; i++)
        {
            spawnRequests[i] = requestArray[i];
            PostUpdateCommands.DestroyEntity(entityArray[i]);
        }

        for (var i = 0; i < spawnRequests.Length; i++)
        {
            var request = spawnRequests[i];
            GameObjectEntity nameboardGOE = m_world.Spawn <GameObjectEntity>(ResMgr.GetInstance().GetPrefab("Nameboard"));
            nameboardGOE.transform.SetParent(nameboardCanvas);
            var    nameboardBehav = nameboardGOE.GetComponent <Nameboard>();
            var    uid            = EntityManager.GetComponentData <UID>(request.Owner);
            string name           = SceneMgr.Instance.GetNameByUID(uid.Value);
            nameboardBehav.Name = name;
            var isMainRole = RoleMgr.GetInstance().IsMainRoleEntity(request.Owner);
            nameboardBehav.CurColorStyle = isMainRole ? Nameboard.ColorStyle.Green : Nameboard.ColorStyle.Red;
            if (EntityManager.HasComponent <NameboardData>(request.Owner))
            {
                var nameboardData = EntityManager.GetComponentData <NameboardData>(request.Owner);
                nameboardData.UIEntity   = nameboardGOE.Entity;
                nameboardData.UIResState = NameboardData.ResState.Loaded;
                EntityManager.SetComponentData(request.Owner, nameboardData);
            }
        }
    }
예제 #2
0
    public static void Create(EntityCommandBuffer commandBuffer, Entity Owner)
    {
        var data = new NameboardSpawnRequest()
        {
            Owner = Owner,
        };
        var entity = commandBuffer.CreateEntity();

        commandBuffer.AddComponent(entity, data);
    }
예제 #3
0
    protected override void OnUpdate()
    {
        var requestArray  = Group.ToComponentDataArray <NameboardSpawnRequest>(Allocator.TempJob);
        var entityArray   = Group.ToEntityArray(Allocator.TempJob);
        var spawnRequests = new NameboardSpawnRequest[requestArray.Length];

        for (var i = 0; i < requestArray.Length; i++)
        {
            spawnRequests[i] = requestArray[i];
            PostUpdateCommands.DestroyEntity(entityArray[i]);
        }

        for (var i = 0; i < spawnRequests.Length; i++)
        {
            var request = spawnRequests[i];
            if (!EntityManager.Exists(request.Owner))
            {
                continue;
            }
            GameObjectEntity nameboardGOE = m_world.SpawnByGameObject <GameObjectEntity>(ResMgr.GetInstance().GetGameObject("Nameboard"));
            nameboardGOE.transform.SetParent(nameboardCanvas);
            nameboardGOE.transform.localScale = new Vector3(-1, 1, 1);
            var    nameboardBehav = nameboardGOE.GetComponent <Nameboard>();
            var    uid            = EntityManager.GetComponentData <UID>(request.Owner);
            string name           = SceneMgr.Instance.GetNameByUID(uid.Value);
            nameboardBehav.Name = name;
            var isMainRole = RoleMgr.GetInstance().IsMainRoleEntity(request.Owner);
            // Debug.Log("name : "+name+" isMainRole:"+isMainRole);
            nameboardBehav.CurColorStyle = isMainRole ? Nameboard.ColorStyle.Green : Nameboard.ColorStyle.Red;
            if (EntityManager.HasComponent <NameboardData>(request.Owner))
            {
                var nameboardData = EntityManager.GetComponentData <NameboardData>(request.Owner);
                nameboardData.UIEntity   = nameboardGOE.Entity;
                nameboardData.UIResState = NameboardData.ResState.Loaded;
                EntityManager.SetComponentData(request.Owner, nameboardData);
            }
            bool hasHPData = EntityManager.HasComponent <HealthStateData>(request.Owner);
            // Debug.Log("has Hp data "+hasHPData);
            if (hasHPData)
            {
                var hpData = EntityManager.GetComponentData <HealthStateData>(request.Owner);
                nameboardBehav.MaxHp = hpData.MaxHp;
                nameboardBehav.CurHp = hpData.CurHp;
                // nameboardBehav.UpdateBloodBar(hpData.CurHp, hpData.MaxHp);
            }

            var sceneObjType = EntityManager.GetComponentData <SceneObjectTypeData>(request.Owner);
            nameboardBehav.SetBloodVisible(sceneObjType.Value == SceneObjectType.Role || sceneObjType.Value == SceneObjectType.Monster);
        }
        requestArray.Dispose();
        entityArray.Dispose();
    }
예제 #4
0
    void UpdateNameboard(Transform target, NameboardData nameboardData, Entity entity)
    {
        Vector2 board2DPosition   = Camera.main.WorldToScreenPoint(target.position);
        Vector3 BloodSlotWorldPos = target.position + new Vector3(0f, 1.5f, 0f);
        Vector3 BloodSlotToCamera = Camera.main.transform.position - BloodSlotWorldPos;
        float   BloodSlotDIs      = BloodSlotToCamera.magnitude;
        float   maxVisualDis      = 20;
        float   scaleFactor       = Mathf.Clamp(1 - (BloodSlotDIs - maxVisualDis) / maxVisualDis, 0, 1);
        Vector3 dir            = (target.position - Camera.main.transform.position).normalized;
        float   dot            = Vector3.Dot(Camera.main.transform.forward, dir); //判断物体是否在相机前面
        bool    isBoardVisible = dot > 0 && (board2DPosition.x <= Screen.width && board2DPosition.x >= 0 && board2DPosition.y <= Screen.height && board2DPosition.y >= 0);

        if (isBoardVisible)
        {
            if (nameboardData.UIResState == NameboardData.ResState.WaitLoad)
            {
                NameboardSpawnRequest.Create(PostUpdateCommands, entity);
                nameboardData.UIResState = NameboardData.ResState.Loading;
                EntityManager.SetComponentData(entity, nameboardData);
            }
            else if (nameboardData.UIResState == NameboardData.ResState.Loaded)
            {
                var transform = EntityManager.GetComponentObject <RectTransform>(nameboardData.UIEntity);
                // transform.position = Camera.main.WorldToScreenPoint(BloodSlotWorldPos);
                transform.position = BloodSlotWorldPos;
                // transform.localScale = new Vector3(scaleFactor, scaleFactor, scaleFactor);
            }
        }
        else if (nameboardData.UIResState == NameboardData.ResState.Loaded)
        {
            var transform = EntityManager.GetComponentObject <RectTransform>(nameboardData.UIEntity);
            // m_world.RequestDespawn(transform.gameObject, PostUpdateCommands);
            transform.gameObject.SetActive(false);
            ResMgr.GetInstance().UnuseGameObject("Nameboard", transform.gameObject);
            nameboardData.UIResState = NameboardData.ResState.Deleting;
            nameboardData.UIEntity   = Entity.Null;
            EntityManager.SetComponentData(entity, nameboardData);
        }
        if (nameboardData.UIResState == NameboardData.ResState.Deleting)
        {
            //m_world.RequestDespawn删掉要下帧才会生效
            nameboardData.UIResState = NameboardData.ResState.WaitLoad;
            EntityManager.SetComponentData(entity, nameboardData);
        }
    }
예제 #5
0
    void UpdateNameboard(Transform target, NameboardData nameboardData, Entity entity)
    {
        Vector2 board2DPosition   = Camera.main.WorldToScreenPoint(target.position);
        Vector3 BloodSlotWorldPos = target.position + new Vector3(0f, 1.8f, 0f);
        Vector3 BloodSlotToCamera = Camera.main.transform.position - BloodSlotWorldPos;
        float   BloodSlotDIs      = BloodSlotToCamera.magnitude;
        float   maxVisualDis      = 20;
        float   scaleFactor       = Mathf.Clamp(1 - (BloodSlotDIs - maxVisualDis) / maxVisualDis, 0, 1);
        bool    isBoardVisible    = !(board2DPosition.x > Screen.width || board2DPosition.x <0 || board2DPosition.y> Screen.height || board2DPosition.y < 0);

        if (isBoardVisible)
        {
            if (nameboardData.UIResState == NameboardData.ResState.WaitLoad)
            {
                NameboardSpawnRequest.Create(PostUpdateCommands, entity);
                nameboardData.UIResState = NameboardData.ResState.Loading;
                EntityManager.SetComponentData(entity, nameboardData);
            }
            else if (nameboardData.UIResState == NameboardData.ResState.Loaded)
            {
                var transform = EntityManager.GetComponentObject <RectTransform>(nameboardData.UIEntity);
                transform.position   = Camera.main.WorldToScreenPoint(BloodSlotWorldPos);
                transform.localScale = new Vector3(scaleFactor, scaleFactor, scaleFactor);
            }
        }
        else if (nameboardData.UIResState == NameboardData.ResState.Loaded)
        {
            //TODO: use object pool
            var transform = EntityManager.GetComponentObject <RectTransform>(nameboardData.UIEntity);
            transform.localScale = Vector3.zero;
            m_world.RequestDespawn(transform.gameObject, PostUpdateCommands);
            nameboardData.UIResState = NameboardData.ResState.Deleting;
            nameboardData.UIEntity   = Entity.Null;
            EntityManager.SetComponentData(entity, nameboardData);
        }
        if (nameboardData.UIResState == NameboardData.ResState.Deleting)
        {
            //m_world.RequestDespawn删掉要下帧才会生效
            nameboardData.UIResState = NameboardData.ResState.WaitLoad;
            EntityManager.SetComponentData(entity, nameboardData);
        }
    }
예제 #6
0
 void UpdateNameboard(Transform target, NameboardData nameboardData, Entity entity)
 {
     if (nameboardData.UIResState == NameboardData.ResState.Loaded)
     {
         if (nameboardData.UIEntity != Entity.Null)
         {
             Vector2 player2DPosition  = Camera.main.WorldToScreenPoint(target.position);
             Vector3 BloodSlotWorldPos = target.position + new Vector3(0f, 1.8f, 0f);
             Vector3 BloodSlotToCamera = Camera.main.transform.position - BloodSlotWorldPos;
             float   BloodSlotDIs      = BloodSlotToCamera.magnitude;
             float   maxVisualDis      = 20;
             float   scaleFactor       = Mathf.Clamp(1 - (BloodSlotDIs - maxVisualDis) / maxVisualDis, 0, 1);
             // Debug.Log("scaleFactor : "+scaleFactor+" dis:"+BloodSlotDIs);
             if (EntityManager.HasComponent <RectTransform>(nameboardData.UIEntity))
             {
                 var transform = EntityManager.GetComponentObject <RectTransform>(nameboardData.UIEntity);
                 transform.position   = Camera.main.WorldToScreenPoint(BloodSlotWorldPos);
                 transform.localScale = new Vector3(scaleFactor, scaleFactor, scaleFactor);
                 //TODO: DeSpawnRequest.Create
                 // if (player2DPosition.x > Screen.width || player2DPosition.x < 0 || player2DPosition.y > Screen.height || player2DPosition.y < 0)
                 // {
                 //     transform.gameObject.SetActive(false);
                 // }
                 // else
                 // {
                 //     transform.gameObject.SetActive(true);
                 // }
             }
         }
     }
     else if (nameboardData.UIResState == NameboardData.ResState.WaitLoad)
     {
         NameboardSpawnRequest.Create(PostUpdateCommands, entity);
         nameboardData.UIResState = NameboardData.ResState.Loading;
         EntityManager.SetComponentData(entity, nameboardData);
     }
 }