Ejemplo n.º 1
0
    private void EngineEvents_OnSetDirection(Entity entity)
    {
        if (entity.renderObj == null)
        {
            return;
        }
        BaseSynchronizer s = null;

        if (!_entitySynchronizerDict.TryGetValue(entity.id, out s))
        {
            return;
        }
        //服务器上是roll, pitch, yaw,所以是y,z,x对应unity的x,y,z
        s.SetDestDirection(EngineUtils.EngineDirectionToUnity(entity.direction));
        s.SpaceID = KBEngineApp.app.spaceID;
        //GameEntity gameEntity = ((UnityEngine.GameObject)entity.renderObj).GetComponent<GameEntity>();
        //gameEntity.destDirection = new Vector3(entity.direction.y, entity.direction.z, entity.direction.x);
        //gameEntity.spaceID = KBEngineApp.app.spaceID;
    }
Ejemplo n.º 2
0
    void OnEntityResLoaded(string resName, string resPath, UnityEngine.Object resObject, System.Object userData)
    {
        IGameObject go     = userData as IGameObject;
        Entity      entity = userData as Entity;

        if (go == null || entity == null)
        {
            throw new Exception("World::OnResLoaded: userData cannot transfer to IGameObject or Entity");
        }
        if (KBEngineApp.app.findEntity(entity.id) == null)
        {
            Debug.LogWarningFormat("World::OnEntityResLoaded:发现entity已经不存在,则不需要加载资源了");
            return;
        }
        float y = entity.position.y;
        //if (entity.isOnGround)
        //	y = 1.3f;
        Vector3    pos       = new Vector3(entity.position.x, y, entity.position.z);
        Quaternion rotation  = Quaternion.Euler(EngineUtils.EngineDirectionToUnity(entity.direction));
        GameObject renderObj = GameObject.Instantiate(resObject, pos, rotation) as GameObject;

        renderObj.name = entity.className + "_" + entity.id;
        //该方法会由Entity的实现类去完成Unity相关组件的添加和初始化
        go.SetRenderObj(renderObj);
        var synchronizer = renderObj.GetComponent <BaseSynchronizer>();

        if (synchronizer != null)
        {
            synchronizer.SetDestPosition(entity.position);
            synchronizer.SetDestDirection(EngineUtils.EngineDirectionToUnity(entity.direction));
            synchronizer.SpaceID = KBEngineApp.app.spaceID;
            _entitySynchronizerDict.Add(entity.id, synchronizer);
        }



        EntityUnityComponent component = null;

        if (entity.isPlayer())
        {        //如果是玩家自己,需要先disable一下,等待地形完成加载
            _playerEntity = renderObj.GetComponent <EntityUnityComponent>();
        }
        component = renderObj.GetComponent <EntityUnityComponent>();

        if (component == null)
        {
            Debug.LogErrorFormat("Entity资源加载后,竟然没有EntityUnityComponent!,entityId={0}, className={1}", entity.id, entity.className);
            return;
        }
        _entityList.Add(component);
        _entityDict.Add(entity.id, component);

        if (OnEntityEnter != null)
        {
            OnEntityEnter(component);
        }

        if (entity.isPlayer())
        {
            if (_terrain != null)
            {
                FinishMyselfLoadTask();
            }
        }
    }