//ride and unride op public void Ride(uint id, bool syncToServer, System.Action finishCallback = null) { if (SceneHelp.Instance.CanRide == false) { return; } //检查坐骑资源是否存在 DBGrowSkin db_skin = DBManager.Instance.GetDB <DBGrowSkin>(); DBGrowSkin.DBGrowSkinItem skin_item = null; if (db_skin != null) { skin_item = db_skin.GetOneItem(GameConst.GROW_TYPE_RIDE, id); } if (skin_item != null) { if (ClientModel.HasExistResourceActorId(skin_item.ActorId) == false) { return;//不存在资源 } } mDirtyRideId = (int)id; mRideFinishCallback = finishCallback; if (mOwner is LocalPlayer && syncToServer) { //C2SShowRide pack = new C2SShowRide(); //pack.state = 1; //NetClient c = null; //if(SceneHelp.Instance.IsInMainmap()) //{ // c = NetClient.GetBaseClient(); //} //else // c = NetClient.GetCrossClient(); //c.SendData<C2SShowRide>(NetMsg.MSG_SHOW_RIDE, pack); } }
//only directly called for local player, initiative ride private IEnumerator RideAync() { mOriginalScale = Vector3.one; if (this == null || this.IsDestroy || mOwner == null || mOwner.IsDestroy) { yield break; } if (mOwner.mVisibleCtrl != null && mOwner.mVisibleCtrl.VisibleMode != EVisibleMode.Visible) { yield break; } if (mOwner.mAvatarCtrl == null) { yield break; } if (mCurrentRideId == mDirtyRideId) { mDirtyRideId = -1; yield break; } //test some situation if (!TestRide()) { yield break; } mCurrentRideId = (uint)mDirtyRideId; mDirtyRideId = -1; DBGrowSkin db_skin = DBManager.Instance.GetDB <DBGrowSkin>(); DBGrowSkin.DBGrowSkinItem skin_item = null; if (db_skin != null) { skin_item = db_skin.GetOneItem(GameConst.GROW_TYPE_RIDE, mCurrentRideId); } if (skin_item != null) { if (ClientModel.HasExistResourceActorId(skin_item.ActorId) == false) { yield break;//不存在资源 } } mIsprocessingRide = true; //clone rider if (mRiderActor != null) { if (mRiderActor.transform != null) { mRiderActor.transform.parent = null; } } else { mRiderActor = ClientModel.CreateClientModelByClone(mOwner, null); if (this == null || this.IsDestroy || mOwner == null || mOwner.IsDestroy || mRiderActor == null || mRiderActor.IsDestroy) { mIsprocessingRide = false; yield break; } // 设置坐骑的阴影状态 var rider_shadow_behavior = mRiderActor.GetBehavior <ShadowBehavior>(); var owner_shadow_behavior = mOwner.GetBehavior <ShadowBehavior>(); if (rider_shadow_behavior != null && owner_shadow_behavior != null) { if (owner_shadow_behavior.ShadowType == ShadowType.REAL_SHADOW) { rider_shadow_behavior.ShadowType = ShadowType.REAL_SHADOW; } else { rider_shadow_behavior.ShadowType = ShadowType.NONE; } rider_shadow_behavior.RealShadow = owner_shadow_behavior.RealShadow; } while (this != null && this.IsDestroy == false && mRiderActor != null && mRiderActor.IsDestroy == false && (mRiderActor.mAvatarCtrl == null || mRiderActor.mAvatarCtrl.IsLoading(true))) { if (mOwner == null || mOwner.IsDestroy) { mIsprocessingRide = false; yield break; } yield return(null); } } if (this == null || this.IsDestroy) { yield break; } if (mOwner == null || mOwner.IsDestroy || mOwner.mAvatarCtrl == null) { mIsprocessingRide = false; yield break; } // DBGrowSkin db_skin = DBManager.Instance.GetDB<DBGrowSkin>(); // DBGrowSkin.DBGrowSkinItem skin_item = null; //if(db_skin != null) //skin_item = db_skin.GetOneItem(GameConst.GROW_TYPE_RIDE, mCurrentRideId); mGrowSkinItem = skin_item; if (skin_item != null && mOwner != null && mOwner.IsDestroy == false && mOwner.mAvatarCtrl != null) { string prefab_name = RoleHelp.GetPrefabName(skin_item.ActorId, mOwner.mAvatarCtrl.IsLocalPlayerModel()); if (string.IsNullOrEmpty(prefab_name)) { mOwner.mAvatarCtrl.ModelPrefab = null; mIsprocessingRide = false; yield break; } else { mOwner.mAvatarCtrl.ModelPrefab = prefab_name; } } else { mIsprocessingRide = false; yield break; } if (ActorManager.Instance == null) { mIsprocessingRide = false; yield break; } yield return(ActorManager.Instance.StartCoroutine(mOwner.mAvatarCtrl.LoadAsync_public())); while (this != null && this.IsDestroy == false && mOwner != null && mOwner.IsDestroy == false && mOwner.mAvatarCtrl != null && mOwner.mAvatarCtrl.IsLoading(true)) { yield return(null); } if (this == null || this.IsDestroy) { yield break; } if (mOwner == null || mOwner.IsDestroy || mOwner.transform == null) { mIsprocessingRide = false; yield break; } if (skin_item != null && mOwner != null && mOwner.IsDestroy == false && mOwner.mAvatarCtrl != null) { mOriginalScale = mOwner.mAvatarCtrl.ModelScale; mOwner.mAvatarCtrl.ModelScale = RoleHelp.GetPrefabScale(skin_item.ActorId); } //mount Transform mountPoint = xc.ui.ugui.UIHelper.FindChildInHierarchy(mOwner.transform, AvatarCtrl.MOUNT_POINT_NAME); if (mountPoint == null) { Debug.LogError(string.Format("mount point not found for {0}", AvatarCtrl.MOUNT_POINT_NAME, mCurrentRideId)); //mount rider mIsprocessingRide = false; yield break; } float height = mountPoint.position.y - mOwner.transform.position.y; if (mRiderActor != null && mRiderActor.transform != null) { mRiderActor.transform.parent = mountPoint; mRiderActor.transform.position = mountPoint.position; mRiderActor.transform.localEulerAngles = new Vector3(0, 0, 0); mRiderActor.mAvatarCtrl.ResetElfinObject(); mRiderActor.mAvatarCtrl.ResetSuitPos(); } //animate mRideAnim = ANIMATION_RIDE; if (mOwner.IsWalking()) { mOwner.Play(Actor.EAnimation.walk); } else { mOwner.Play(Actor.EAnimation.idle); } //mOwner.PlayLastAnimation_real(); //mOwner.Play("idle"); for (int index = 1; index < 3; ++index) { yield return(null); } if (this == null || this.IsDestroy) { yield break; } //mount rider mIsprocessingRide = false; if (mOwner == null || mOwner.IsDestroy || mOwner.transform == null || mRiderActor == null || mRiderActor.transform == null) { yield break; } mountPoint = xc.ui.ugui.UIHelper.FindChildInHierarchy(mOwner.transform, AvatarCtrl.MOUNT_POINT_NAME); Transform bip_transform = xc.ui.ugui.UIHelper.FindChildInHierarchy(mRiderActor.transform, "Bip001"); if (mountPoint != null && bip_transform != null) { mRiderActor.transform.localPosition = mountPoint.InverseTransformVector(mountPoint.position - bip_transform.position); } //VocationInfo info = DBVocationInfo.Instance.GetVocationInfo((byte)mOwner.VocationID); string idle_action_name = GetIdleActionWhenRidingName(); Vector3 mount_offset = DBVocationMountInfo.Instance.GetMountOffset((byte)mOwner.VocationID, idle_action_name); if (mount_offset.magnitude > 0.001f) { mRiderActor.transform.localPosition = mount_offset; } mOwner.ResetEffect(); if (mOwner.MoveImplement != null) { mOwner.MoveImplement.OnResLoaded(); } mOwner.OnModelChanged(); if (mRiderActor.mAvatarCtrl != null) { mRiderActor.mAvatarCtrl.SetLayer(mOwner.GetLayer()); } if (mRideFinishCallback != null) { mRideFinishCallback(); mRideFinishCallback = null; } }