Example #1
0
    public static void Init()
    {
        EntityViewCommandHandler.Start();

        GameObject go = new GameObject("EntityFactory");

        DontDestroyOnLoad(go);
        go.AddComponent <EntityFactory>();


        EffectGroup     = new GameObject("EffectGroup");
        GloabaleManager = EffectGroup.AddComponent <LightingEffectManager>(); //这里放全局光效
        GloabaleManager.Init();
        GloabaleManager.isGlobal = true;

        DontDestroyOnLoad(EffectGroup);


        SkinCacheGroup = new GameObject("SkinCacheGroup");
        DontDestroyOnLoad(SkinCacheGroup);


        Trace.Log("==================initialize EntityView Factory===================");
    }
Example #2
0
 /// <summary>
 /// 发送命令给实体
 /// </summary>
 /// <param name="entityID">实体ID</param>
 /// <param name="cmdID">命令ID,具体定义见(EntityViewDef.h)</param>
 /// <param name="nParam">整形参数</param>
 /// <param name="strParam">字符串参数</param>
 /// <param name="ptrParam">指针参数</param>
 /// <returns></returns>
 public static bool entry_sendCommand(ENTITY_ID entityID, int cmdID, int nParam, string strParam, IntPtr ptrParam, int nPtrLen, int nTickCount)
 {
     //Trace.LogWarning("entry_sendCommand cmdID=" + cmdID);
     return(EntityViewCommandHandler.onCommand(entityID, cmdID, nParam, strParam, ptrParam, nPtrLen, nTickCount));
 }
Example #3
0
    private static GameObject entry_loadEntry(EntityView objev)
    {
        ENTITY_ID id = objev.ID;

        //已经被卸载了.
        if (EntityFactory.Instance.m_entityContainer.Get(id) == null)
        {
            return(null);
        }
        EntityViewItem evItem = objev.createinfo;

        ENTITY_TYPE entityType = (ENTITY_TYPE)evItem.EntityType;

        UnityEngine.Object objPrefab = PrefabManager.GetPrefab(entityType);
        if (null == objPrefab)
        {
            Trace.LogError("找不到对应的类型的prefab,请检查PrefabManager中的Init函数,是否忘记加载? " + entityType.ToString());
            return(null);
        }
        GameObject entity = null;

        entity = objPrefab as GameObject;

        if (entity == null)
        {
            Trace.LogError("实例预设体对象失败! " + entityType.ToString());
            return(null);
        }

        entity.name += "-" + id.ToString();
        if (entity.transform.childCount > 0)
        {
            Trace.LogWarning("EntityView GameObject 有子节点!" + entity.transform.GetChild(0).name);
        }

        // 设置游戏对象
        objev.SetGameObject(entity);

        // 设置创建数据
        if (!objev.InitBuildeData(evItem))
        {
            Trace.LogError("初始化实体对象数据失败! id=" + id.ToString());
            return(null);
        }


        //如果是队友,则加入队友列表,
        if (objev.Type == ENTITY_TYPE.TYPE_PLAYER_ROLE && objev.CampFlag == CampFlag.CampFlag_Friend)
        {
            if (!m_friendPlayerList.Contains((uint)objev.ID))
            {
                m_friendPlayerList.Add((uint)objev.ID);
            }
        }

        //string entityname = "UnKnow";
        //Skin sk = SkinManager.GetSkin(objev.Property.GetNumProp(ENTITY_PROPERTY.PROPERTY_SKIN));
        //if (sk != null)
        //{
        //    entityname = sk.ResSkinObj.AssetName;
        //}
        //entity.name = entityname;
        //entity.name += "(entity" + evItem.EntityID.ToString() + ")";

        if (id == MainHeroID)
        {
            entity.transform.parent = null;
            MainHeroView            = objev;

            if (CreateMainHeroEntityEvent != null)
            {
                CreateMainHeroEntityEventArgs e = new CreateMainHeroEntityEventArgs();
                e.MainHeroID   = evItem.nHeroID;
                e.MainHeroUID  = MainHeroID;
                e.nMatchTypeID = GameLogicAPI.getCurRoomMatchType();
                CreateMainHeroEntityEvent(e);
                LogicDataCenter.playerSystemDataManager.Reset();
            }

            ViewEventHelper.Instance.SendCommand(GameLogicDef.GVIEWCMD_MASTER_VIEW_LOADED);
            Trace.Log("Load Hero Entry:" + entity.name);
        }
        else
        {
            entity.transform.parent = Instance.transform;
        }

        objPrefab = null;
        if (ENTITY_TYPE.TYPE_PLAYER_ROLE == entityType)
        {
            // 发送人物加载完指令到逻辑层
            EntityEventHelper.Instance.SendCommand(id, EntityLogicDef.ENTITY_CMD_LOAD_COMPLETED);
        }

        BaseStateMachine bs = entity.GetComponent <BaseStateMachine>();

        //已经有位置信息,创建模型时立即同步瞬移过去,之后的同步消息是走过去
        if (objev.data.nActorID == evItem.EntityID)
        {
            Vector3 pos;
            pos.x = objev.data.fPosition_x;
            pos.y = objev.data.fPosition_y;
            pos.z = objev.data.fPosition_z;

            Vector3 rot;
            rot.x = objev.data.fRotation_x;
            rot.y = objev.data.fRotation_y;
            rot.z = objev.data.fRotation_z;

            //怪物要走传送,不能直接设置位置
            if (entityType == ENTITY_TYPE.TYPE_MONSTER)
            {
                if (bs)
                {
                    cmd_creature_transport data = new cmd_creature_transport();
                    data.fPosition_x = pos.x;
                    data.fPosition_y = pos.y;
                    data.fPosition_z = pos.z;

                    data.fRotation_x = rot.x;
                    data.fRotation_y = rot.y;
                    data.fRotation_z = rot.z;

                    data.bUseAngle = 1;
                    bs.Transport(data);
                }
            }
            else
            {
                entity.transform.SetPosition(pos);
                entity.transform.eulerAngles = rot;
            }
        }

        CheckEntityMaskToRangeSearch(objev);
        //执行延迟处理的消息
        EntityViewCommandHandler.onCommandsDelay(objev);
        return(entity);
    }