public void ShowShip() { ShipProxy shipProxy = GameFacade.Instance.RetrieveProxy(ProxyName.ShipProxy) as ShipProxy; IShip ship = shipProxy.GetAppointWarShip(); if (ship != null) { CfgEternityProxy cfgEternityProxy = GameFacade.Instance.RetrieveProxy(ProxyName.CfgEternityProxy) as CfgEternityProxy; Model model = cfgEternityProxy.GetItemModelByKey(ship.GetTID()); GameObject container = GameObject.Find(model.ExhibitionPoint); if (container) { m_Show = true; TransformUtil.FindUIObject <Transform>(container.transform, "Ship_Light").gameObject.SetActive(true); AssetUtil.InstanceAssetAsync(model.AssetName, (pathOrAddress, returnObject, userData) => { if (returnObject != null) { GameObject gameobj = (GameObject)returnObject; gameobj.transform.SetParent(container.transform, false); m_ShipGameObject = gameobj; if (!m_Show) { HideShip(); } } else { Debug.LogError(string.Format("资源加载成功,但返回null, pathOrAddress = {0}", pathOrAddress)); } }); } } }
private void InstantiateUnit(SceneUnitInfo unitInfo, Transform parent) { if (m_Owner.UseAsset) { AssetUtil.InstanceAssetAsync(m_AreaDetailInfo.AssetInfos[unitInfo.AssetIndex].AddressableKey, (pathOrAddress, uObj, userData) => { if (uObj != null) { GameObject resultObj = uObj as GameObject; if (resultObj != null) { m_WaitInstantiateCount--; Transform t = resultObj.transform; t.SetParent(m_UnitsRoot); t.localPosition = unitInfo.LocalPosition; t.localRotation = unitInfo.LocalRotation; t.localScale = unitInfo.LocalScale; } } }); } else { m_WaitInstantiateCount--; string path = string.Format("{0}/{1}Map_{2}/{3}.prefab" , MapEditorUtility.GetOrCreateMapEditorSetting().AssetExportDirectory , Constants.UNIT_PREFAB_EXPORT_DIRECTORY , m_Owner.MapInfo.Uid , m_AreaDetailInfo.AssetInfos[unitInfo.AssetIndex].AddressableKey); GameObject asset = AssetDatabase.LoadAssetAtPath <GameObject>(path); if (asset == null) { string[] paths = AssetDatabase.FindAssets(m_AreaDetailInfo.AssetInfos[unitInfo.AssetIndex].AddressableKey); if (paths != null && paths.Length > 0) { path = AssetDatabase.GUIDToAssetPath(paths[0]); asset = AssetDatabase.LoadAssetAtPath <GameObject>(path); } } if (asset != null) { Transform t = Instantiate(asset).transform; t.SetParent(parent); t.localPosition = unitInfo.LocalPosition; t.localRotation = unitInfo.LocalRotation; t.localScale = unitInfo.LocalScale; } } }
private BulletTriggerCollisionEnter m_TriggerCollisionEnter; //碰撞检测器 public override void OnInitialize(IBulletAppearanceProperty property) { m_Property = property; m_BulletTf = m_Property.GetTransform(); CfgEternityProxy cfgEternity = GameFacade.Instance.RetrieveProxy(ProxyName.CfgEternityProxy) as CfgEternityProxy; int flyerdataId = m_Property.GetFlyerDataId(); m_FlyerData = cfgEternity.GetFlyerData(flyerdataId); BaseEntity bulletOwerEntity = GameplayManager.Instance.GetEntityManager().GetEntityById <BaseEntity>(m_Property.GetOwnerSpacecaftEntityId()); BaseEntity targetEnity = m_Property.IsHaveTarget() ? GameplayManager.Instance.GetEntityManager().GetEntityById <BaseEntity>(m_Property.GetTargetEntityID()) : null; Vector3 targetPoint = m_Property.GetTargetPoint(); m_TriggerCollisionEnter = m_BulletTf.GetOrAddComponent <BulletTriggerCollisionEnter>(); m_TriggerCollisionEnter.Init(bulletOwerEntity, //子弹拥有者Enity m_Property.GetOwner(), //子弹Enity m_FlyerData.BaseData.Value.IsRigibody, //碰撞后单位是否继续飞 ,刚体爆炸,非刚体继续飞 m_Property.IsHaveTarget(), //是否指定了目标 targetEnity, //指定的飞向的目标 targetPoint, //指定的飞向的点 m_FlyerData.BaseData.Value.FactionType, //碰撞后的阵营判断 TriggerToEnitity); //碰撞后的回调函数 string assetPath = m_FlyerData.BaseData.Value.ApperanceAddress; if (!string.IsNullOrEmpty(assetPath)) { AssetUtil.InstanceAssetAsync(assetPath, (pathOrAddress, returnObject, userData) => { if (returnObject != null) { GameObject pObj = (GameObject)returnObject; OnLoadModel(pObj); } else { Debug.LogError(string.Format("资源加载成功,但返回null, pathOrAddress = {0}", pathOrAddress)); } }); } }
/// <summary> /// 异步加载模型 /// </summary> private void LoadAsync() { Leyoutech.Utility.DebugUtility.Assert(m_AssetState == AssetState.Unload, LOG_TAG, "m_AssetState == AssetState.Unload"); m_AssetState = AssetState.Loading; AssetUtil.InstanceAssetAsync(ModelName, (pathOrAddress, returnObject, userData) => { if (returnObject != null) { GameObject obj = (GameObject)returnObject; obj.transform.SetParent(Parent, false); OnLoaded(obj); } else { Debug.LogError(string.Format("资源加载成功,但返回null, pathOrAddress = {0}", pathOrAddress)); } }); }
public override void OnInitialize(IHumanAvatarProperty property) { m_HumanAvatarProperty = property; if (m_HumanAvatarProperty.GetModelName() != "None") { AssetUtil.InstanceAssetAsync(property.GetModelName(), (pathOrAddress, returnObject, userData) => { if (returnObject != null) { GameObject pObj = (GameObject)returnObject; pObj.transform.SetParent(property.GetModleParent(), false); OnLoadModel(pObj); } else { Debug.LogError(string.Format("资源加载成功,但返回null, pathOrAddress = {0}", pathOrAddress)); } }); } }
private void CreateDropItem(string key, MineDropItemInfo mineDropItemInfo, bool needFly = false) { NpcCombat?nc = m_CfgEternityProxy.GetNpcCombatByKey(mineDropItemInfo.tid); if (!nc.HasValue) { return; } PackageBoxAttr?pb = m_CfgEternityProxy.GetPackageBoxAttrByModelIdAndGrade((uint)nc.Value.BoxModel, mineDropItemInfo.ship_tlv); if (!pb.HasValue) { return; } int modelid = pb.Value.BoxModel; Model?mdata = m_CfgEternityProxy.GetModel(modelid); if (mdata.Value.AssetName.Equals(string.Empty)) { return; } Vector3 curPos = Vector3.zero; SpacecraftEntity spe = m_GameplayProxy.GetEntityById <SpacecraftEntity>((uint)mineDropItemInfo.parentid) as SpacecraftEntity; if (spe) { curPos = spe.GetRootTransform().position; } AssetUtil.InstanceAssetAsync(mdata.Value.AssetName, (address, uObj, userData) => { mineDropItemInfo.obj = uObj as GameObject; MineDropComponent mineDropComponent = mineDropItemInfo.obj.GetComponent <MineDropComponent>(); if (!mineDropComponent) { mineDropComponent = mineDropItemInfo.obj.AddComponent <MineDropComponent>(); } SpacecraftEntity mainPlayer = m_GameplayProxy.GetMainPlayer(); mineDropComponent.Initialize(mainPlayer, mineDropItemInfo.uid, mineDropItemInfo.tid, mineDropItemInfo.item_tid, pb); if (needFly) { mineDropItemInfo.obj.transform.position = curPos; mineDropComponent.AddFlyEffect(mineDropItemInfo.positon_x, mineDropItemInfo.positon_y, mineDropItemInfo.positon_z); } else { Vector3 endPos = new Vector3(mineDropItemInfo.positon_x, mineDropItemInfo.positon_y, mineDropItemInfo.positon_z); Vector3 clientPosition = m_GameplayProxy.ServerAreaOffsetToClientPosition(endPos); mineDropItemInfo.obj.transform.position = clientPosition; mineDropComponent.SetDropItemState(DropItemState.Stay); mineDropComponent.AddEffect(true); } /// 跃迁客户端不清数据 if (m_GatherDropItemInfos.ContainsKey(key)) { m_GatherDropItemInfos.Remove(key); } m_GatherDropItemInfos.Add(key, mineDropItemInfo); }); }
/// <summary> /// 添加品质特效 /// </summary> /// <param name="key">宝箱唯一id</param> /// private void AddEffect(ulong key) { if (!m_ChestGosDic.ContainsKey(key) || m_ChestGosDic[key] == null) { return; } if (m_EffectGosDic.ContainsKey(key)) { return; } GameObject pgo = null; if (!m_ChestGosDic.TryGetValue(key, out pgo)) { return; } //if (m_BrothEffectGosDic.ContainsKey(key)) //{ // GameObject.DestroyImmediate(m_BrothEffectGosDic[key]); // m_BrothEffectGosDic.Remove(key); //} if (m_SpacecraftEntityDic.ContainsKey(key) && m_SpacecraftEntityDic[key]) { Interaction.InteractionManager.GetInstance().RegisterInteractable(m_SpacecraftEntityDic[key]); } CfgEternityProxy cfgEternityProxy = GameFacade.Instance.RetrieveProxy(ProxyName.CfgEternityProxy) as CfgEternityProxy; PackageBoxQuality?pb = cfgEternityProxy.GetPackageBoxQualityByKey(m_ChestInfoDic[key].qualityid); if (string.IsNullOrEmpty(pb.Value.BoxModel)) { return; } AssetUtil.InstanceAssetAsync(pb.Value.BoxModel, (pathOrAddress, returnObject, userData) => { if (returnObject != null) { GameObject go = (GameObject)returnObject; go.transform.SetParent(pgo.transform, false); if (m_ChestGosDic.TryGetValue(key, out pgo)) { m_EffectGosDic[key] = go; // 不懂为什么写这里,没有BoxModel就不能拾取??? //if (m_SpacecraftEntityDic[key]) // Interaction.InteractionManager.GetInstance().RegisterInteractable(m_SpacecraftEntityDic[key]); } else { GameObject.DestroyImmediate(go); } } else { Debug.LogError(string.Format("资源加载成功,但返回null, pathOrAddress = {0}", pathOrAddress)); } }); }
/// <summary> /// 添加出生或刷新特效 /// </summary> /// <param name="key">宝箱唯一id</param> /// <param name="type">1为刷新特效, 2为拾取特效 3为拾取到主角身上的特效</param> private void AddBrothOrPickEffect(ulong key, int type) { if (!m_ChestGosDic.ContainsKey(key) || m_ChestGosDic[key] == null) { return; } if (m_BrothEffectGosDic.ContainsKey(key) && type == 1) { return; } if (m_PickupEffectGosDic.ContainsKey(key) && type == 2) { return; } if (m_PickupNextEffectGosDic.ContainsKey(key) && type == 3) { return; } GameObject dropItem = null; // m_ChestGosDic[key]这样不行吗??? if (!m_ChestGosDic.TryGetValue(key, out dropItem)) { return; } CfgEternityProxy cfgEternityProxy = GameFacade.Instance.RetrieveProxy(ProxyName.CfgEternityProxy) as CfgEternityProxy; PackageBoxAttr? pb = cfgEternityProxy.GetPackageBoxAttrByModelIdAndGrade(m_ChestInfoDic[key].tid, m_ChestInfoDic[key].shipgrade); if (pb == null) { return; } if (m_MainPlayerTransform == null) { GameplayProxy gameplayProxy = GameFacade.Instance.RetrieveProxy(ProxyName.GameplayProxy) as GameplayProxy; SpacecraftEntity mainPlayer = gameplayProxy.GetMainPlayer(); m_MainPlayerTransform = (mainPlayer != null) ? mainPlayer.GetRootTransform() : null; } GameObject pgo = null; if (!m_ChestGosDic.TryGetValue(key, out pgo)) { return; } string effName = string.Empty; Transform parent = null; if (type == 1) { //effName = pb.Value.RefreshGfx; //parent = dropItem.transform; if (!string.IsNullOrEmpty(pb.Value.RefreshGfx)) { EffectController fxInstance = EffectManager.GetInstance().CreateEffect(pb.Value.RefreshGfx, EffectManager.GetEffectGroupNameInSpace(false), (EffectController effect, System.Object usedata) => { /// m_BrothEffectGosDic[key] = effect.gameObject; ///if (!string.IsNullOrEmpty(pb.Value.ContinuousGfx)) ///{ /// EffectController gfxInstance = EffectManager.GetInstance().CreateEffect(pb.Value.ContinuousGfx, EffectManager.GetEffectGroupNameInSpace(false)); /// gfxInstance.transform.SetParent(dropItem.transform, false); /// gfxInstance.SetCreateForMainPlayer(false); ///} }); fxInstance.transform.SetParent(dropItem.transform, false); fxInstance.SetCreateForMainPlayer(false); UIManager.Instance.StartCoroutine(DelayToAddEffect(key)); } return; } else if (type == 2) { /// effName = pb.Value.PickUpGfx; effName = "Effect_skill_nengliang_path"; } else if (type == 3) { /// effName = pb.Value.PickUpHfx; effName = "Effect_skill_nengliang_hit"; parent = m_MainPlayerTransform; } if (string.IsNullOrEmpty(effName)) { return; } AssetUtil.InstanceAssetAsync(effName, (pathOrAddress, returnObject, userData) => { if (returnObject != null) { GameObject go = (GameObject)returnObject; go.transform.SetParent(parent, false); if (dropItem != null) { /// 飞 if (type == 2) { pgo.SetActive(false); m_PickupEffectGosDic[key] = go; go.transform.position = pgo.transform.position; float t = Time.time; m_TweenDic[key] = go.transform.DOMove(m_MainPlayerTransform.position, 1.0f).OnComplete( () => { go.SetActive(false); m_TweenDic.Remove(key); pgo.transform.position = go.transform.position; AddBrothOrPickEffect(key, 3); } ).OnUpdate( () => { float a = m_TweenDic[key].Duration() - (Time.time - t); t = Time.time; if (a > 0) { m_TweenDic[key].ChangeEndValue(m_MainPlayerTransform.position, a, true); } } ).SetAutoKill(true); m_NeedAddUpdate += 1; //UIManager.Instance.StartCoroutine(DelayToDestory(key)); //if (m_SpacecraftEntityDic[key]) //{ // m_SpacecraftEntityDic[key].SetFocus(false); // Interaction.InteractionManager.GetInstance().UnregisterInteractable(m_SpacecraftEntityDic[key]); //} } else if (type == 3) { pgo.SetActive(false); m_PickupNextEffectGosDic[key] = go; //go.transform.position = m_MainPlayerTransform.position; m_NeedAddUpdate -= 1; UIManager.Instance.StartCoroutine(DelayToDestory(key)); } /// 不飞 /// if (type == 2) /// { /// m_PickupEffectGosDic[key] = go; /// go.transform.position = dropItem.transform.position; /// if (m_BrothEffectGosDic.ContainsKey(key)) /// { /// GameObject.DestroyImmediate(m_BrothEffectGosDic[key]); /// m_BrothEffectGosDic.Remove(key); /// } /// dropItem.SetActive(false); /// ParticleSystem p = go.GetComponentInChildren<ParticleSystem>(); /// float duration = 1.0f; /// if (p != null) /// { /// duration = p.main.duration; /// } /// UIManager.Instance.StartCoroutine(DelayToPickNext(key, duration)); /// /// /// 果果牛掰的移除缓存的逻辑,不敢动 /// UIManager.Instance.StartCoroutine(DelayToDestory(key)); /// } } else { GameObject.DestroyImmediate(go); } } else { Debug.LogError(string.Format("资源加载成功,但返回null, pathOrAddress = {0}", pathOrAddress)); } }); }
/// <summary> /// 创建掉落物 /// </summary> /// <param name="uid">怪物唯一id</param> /// <param name="pos">怪物位置</param> /// <param name="type">1为new消息, 2为死亡消息</param> public void CreateDropItem(uint uid, SpacecraftEntity spe, int type) { ulong key = uid; if (!spe) { if (m_ChestInfoDic.ContainsKey(key)) { m_ChestInfoDic.Remove(key); } if (m_SpacecraftEntityDic.ContainsKey(key)) { Debug.Log("CreateDropItem !spe m_SpacecraftEntityDic remove key:" + key); m_SpacecraftEntityDic.Remove(key); } return; } if (type == 1 && !m_SpacecraftEntityDic.ContainsKey(key)) { m_SpacecraftEntityDic.Add(key, spe); } if (!m_ChestInfoDic.ContainsKey(uid)) { return; } if (m_ChestGosDic.ContainsKey(uid)) { return; } CfgEternityProxy cfgEternityProxy = GameFacade.Instance.RetrieveProxy(ProxyName.CfgEternityProxy) as CfgEternityProxy; PackageBoxAttr? pb = cfgEternityProxy.GetPackageBoxAttrByModelIdAndGrade(m_ChestInfoDic[uid].tid, m_ChestInfoDic[uid].shipgrade); if (!pb.HasValue) { return; } int modelid = pb.Value.BoxModel; Model?mdata = m_CfgEternityProxy.GetModel(modelid); if (string.IsNullOrEmpty(mdata.Value.AssetName)) /// (mdata.Value.AssetName.Equals(string.Empty)) { Debug.LogErrorFormat("DropItem model assetName is empty modelid {0}", modelid); return; } AssetUtil.InstanceAssetAsync(mdata.Value.AssetName, (pathOrAddress, returnObject, userData) => { if (returnObject != null) { if (!spe) { Debug.Log("InstanceAssetAsync CreateDropItem !spe m_SpacecraftEntityDic remove key:" + key); GameObject.Destroy(returnObject); m_SpacecraftEntityDic.Remove(key); m_ChestInfoDic.Remove(key); return; } GameObject go = (GameObject)returnObject; go.transform.SetParent(spe.GetRootTransform(), false); if (go.transform.parent == null) { m_ChestGosDic.Remove(uid); return; } //美术不去 这玩意没有加collide需求为啥不给去? 吐个槽 xswl BoxCollider box = go.GetComponentInChildren <BoxCollider>(); if (box) { box.enabled = false; } else { Debug.LogWarning("找不到没必要的boxcollider 美术去了还是换了别的碰撞"); } spe.GetSkinRootTransform().gameObject.SetActive(false); m_ChestGosDic.Add(key, go); AddBrothOrPickEffect(key, 1); } else { Debug.LogError(string.Format("资源加载成功,但返回null, pathOrAddress = {0}", pathOrAddress)); } }); }
/// <summary> /// 执行删除和生成命令 /// </summary> private void DoUpdateUnitCommand() { int releaseCommandCount = 0; int enqueueCommandCount = 0; while (m_RuningUnitCommandCount + releaseCommandCount < Constants.MAX_RUNING_UNITCOMMAND_COUNT && m_UnitCommands.Count > enqueueCommandCount) { UnitCommand iterUnitCommand = m_UnitCommands.Dequeue(); UnitData iterUnitData = m_UnitDatas[iterUnitCommand.UnitIndex]; switch (iterUnitCommand.Command) { case CommandType.Instantiate: if (iterUnitData.HasState(UnitState.WaitRelease)) { continue; } // 防止重复实例化 else if (!iterUnitData.HasState(UnitState.Instantiated) && !iterUnitData.HasState(UnitState.Instantiating) && iterUnitData.HasState(UnitState.WaitInstantiate)) { m_RuningUnitCommandCount++; SceneUnitInfo unitInfo = m_Units[iterUnitCommand.UnitIndex]; AssetUtil.InstanceAssetAsync(m_AssetInfos[unitInfo.AssetIndex].AddressableKey , OnInstantiateUnitCompleted, AssetLoaderPriority.Default, null , new LoadUnitData(iterUnitCommand.UnitIndex, iterUnitCommand.CommandId)); iterUnitData.RemoveState(UnitState.WaitInstantiate); iterUnitData.AddState(UnitState.Instantiating); } break; case CommandType.Release: if (iterUnitData.HasState(UnitState.WaitRelease)) { if (iterUnitData.HasState(UnitState.Instantiated)) { //Debug.LogError("release:" + iterUnitData.GameObject.name); UnityObject.DestroyImmediate(iterUnitData.GameObject); iterUnitData.GameObject = null; iterUnitData.SetState(UnitState.Released); iterUnitData.ClearRef(); m_InstantiatedUnitCount--; releaseCommandCount++; } else { //Debug.LogError("未释放waitRelease:" + iterUnitData.GameObject.name); m_UnitCommands.Enqueue(iterUnitCommand); enqueueCommandCount++; } } break; default: break; } m_UnitDatas[iterUnitCommand.UnitIndex] = iterUnitData; } }