//初始化逻辑 private void InitLogicData(UserEntityData data) { HotLogicInstance = GameEntry.Hotfix.CreateInstance(data.HotLogicTypeFullName, null); //创建实例 HotLogicScript = data.HotLogicTypeFullName; #if ILRuntime //获取方法 OnInitMethod = ReferencePool.Acquire <ILInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnInit", 1); OnShowMethod = ReferencePool.Acquire <ILInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnShow", 1); OnHideMethod = ReferencePool.Acquire <ILInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnHide", 1); OnUpdateMethod = ReferencePool.Acquire <ILInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnUpdate", 0); OnAttachedMethod = ReferencePool.Acquire <ILInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnAttached", 3); OnDetachedMethod = ReferencePool.Acquire <ILInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnDetached", 2); OnAttachToMethod = ReferencePool.Acquire <ILInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnAttachTo", 3); OnDetachFromMethod = ReferencePool.Acquire <ILInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnDetachFrom", 2); InternalSetVisibleMethod = ReferencePool.Acquire <ILInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "InternalSetVisible", 1); OnTriggerEnterMethod = ReferencePool.Acquire <ILInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnTriggerEnter", 1); OnTriggerExitMethod = ReferencePool.Acquire <ILInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnTriggerExit", 1); #else //获取方法 OnInitMethod = ReferencePool.Acquire <ReflectInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnInit"); OnShowMethod = ReferencePool.Acquire <ReflectInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnShow"); OnHideMethod = ReferencePool.Acquire <ReflectInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnHide"); OnUpdateMethod = ReferencePool.Acquire <ReflectInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnUpdate"); OnAttachedMethod = ReferencePool.Acquire <ReflectInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnAttached"); OnDetachedMethod = ReferencePool.Acquire <ReflectInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnDetached"); OnAttachToMethod = ReferencePool.Acquire <ReflectInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnAttachTo"); OnDetachFromMethod = ReferencePool.Acquire <ReflectInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnDetachFrom"); InternalSetVisibleMethod = ReferencePool.Acquire <ReflectInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "InternalSetVisible"); OnTriggerEnterMethod = ReferencePool.Acquire <ReflectInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnTriggerEnter"); OnTriggerExitMethod = ReferencePool.Acquire <ReflectInstanceMethod>().Fill(HotLogicInstance, data.HotLogicTypeFullName, "OnTriggerExit"); #endif if (OnInitMethod.IsAvalible) { OnInitMethod.Run(this); } }
//显示实体 public static void ShowHotEntity(this EntityComponent entityComponent, string hotLogicTypeName, string entityGroup, int priority, int entityId, int dataId, object userData) { if (entityId == 0 || dataId == 0) { Log.Warning("[EntityExtension.ShowRuntimeEntity] entityId or dataId is invalid."); return; } IDataTable <DREntity> dtEntity = GameEntry.DataTable.GetDataTable <DREntity>(); DREntity drEntity = dtEntity.GetDataRow(dataId); if (drEntity == null) { Log.Warning("Can not load entity id '{0}' from data table.", dataId.ToString()); return; } //实体传递的数据 //UserEntityData uiData = ReferencePool.Acquire<UserEntityData>(); //uiData.Fill(hotLogicTypeName, userData); UserEntityData entityData = new UserEntityData(hotLogicTypeName, userData); entityComponent.ShowEntity(entityId, typeof(HotEntity), RuntimeAssetUtility.GetEntityAsset(drEntity.AssetName), entityGroup, priority, entityData); }
/// <summary> /// 实体显示 /// </summary> /// <param name="userData">用户自定义数据</param> protected override void OnShow(object userData) { base.OnShow(userData); UserEntityData data = userData as UserEntityData; //临时缓存,避免下面ReleaseLogicData时Release //Log.Info($"显示实体OnShow -> {data.HotLogicTypeFullName} ={HotLogicScript}"); if (UserEntityData != data) { data.RuntimeEntity = this; if (data.HotLogicTypeFullName != HotLogicScript) //检查逻辑类名是否一样 { ReleaseLogicData(); //释放保存的Hot逻辑 InitLogicData(data); //重新初始化Hot逻辑,并调用Init方法 } UserEntityData = data; } if (OnShowMethod.IsAvalible) { OnShowMethod.Run(UserEntityData.UserData); } }