/// <summary> /// 获取引导样式数据 /// </summary> /// <param name="localData"></param> /// <returns></returns> public static GuideStyleData GetGuideStyleData(GuideShowHelpData helpData) { GuideStyleData styleData = new GuideStyleData(); Vector3 targetPos = Vector3.zero; GuideDefine.LocalGuideData localData = helpData.LocalData; if (null == helpData.GuideRoot) { return(styleData); } Matrix4x4 localMatrix = helpData.GuideRoot.worldToLocalMatrix; Bounds bounds = localData.GuideTargetObjWorldBounds; float offset = GuideManager.GuidePointAtOffset; //转化为本地坐标 Vector3 min = localMatrix.MultiplyPoint3x4(bounds.min); Vector3 max = localMatrix.MultiplyPoint3x4(bounds.max); bounds = new Bounds(min, Vector3.zero); bounds.Encapsulate(max); if (helpData.StyleRoot.ContainsKey(localData.GStyle)) { switch (localData.GStyle) { case GuideDefine.GuideStyle.LeftUp: styleData.ArrowRotateAngle = 0; styleData.ArrowRight = false; targetPos.x = (bounds.max.x + bounds.min.x) / 2f; targetPos.y = bounds.min.y - offset; break; case GuideDefine.GuideStyle.Up: styleData.ArrowRotateAngle = 0; styleData.ArrowRight = false; targetPos.x = (bounds.max.x + bounds.min.x) / 2f; targetPos.y = bounds.min.y - offset; break; case GuideDefine.GuideStyle.RightUp: styleData.ArrowRotateAngle = 0; styleData.ArrowRight = true; targetPos.x = (bounds.max.x + bounds.min.x) / 2f; targetPos.y = bounds.min.y - offset; break; case GuideDefine.GuideStyle.Down: styleData.ArrowRight = false; styleData.ArrowRotateAngle = -180; targetPos.x = (bounds.max.x + bounds.min.x) / 2f; targetPos.y = bounds.max.y + offset; break; case GuideDefine.GuideStyle.LeftDown: styleData.ArrowRight = false; styleData.ArrowRotateAngle = -180; targetPos.x = (bounds.max.x + bounds.min.x) / 2f; targetPos.y = bounds.max.y + offset; break; case GuideDefine.GuideStyle.RightDown: styleData.ArrowRight = true; styleData.ArrowRotateAngle = -180; targetPos.x = (bounds.max.x + bounds.min.x) / 2f; targetPos.y = bounds.max.y + offset; break; case GuideDefine.GuideStyle.Left: styleData.ArrowRight = false; styleData.ArrowRotateAngle = -270; targetPos.x = bounds.max.x + offset; targetPos.y = (bounds.max.y + bounds.min.y) / 2f; break; case GuideDefine.GuideStyle.Right: styleData.ArrowRight = true; styleData.ArrowRotateAngle = -90; targetPos.y = (bounds.max.y + bounds.min.y) / 2f; break; } styleData.TargetRoot = helpData.StyleRoot[localData.GStyle]; styleData.TargetPos = targetPos; } return(styleData); }
/// <summary> /// 显示引导 /// </summary> /// <param name="data"></param> private void ShowGuide() { Transform ts = null; if (IsDataReady) { GuideDefine.LocalGuideData data = m_helpData.LocalData; if (null == m_helpData.LocalData.GuideTargetObj) { SilentComplete(); } if (!m_helpData.GuideRoot.gameObject.activeSelf) { m_helpData.GuideRoot.gameObject.SetActive(true); } GuideStyleData gstyleData = GuidePanel.GetGuideStyleData(m_helpData); Vector3 angle = Vector3.zero; angle.z = gstyleData.ArrowRotateAngle; UILabel desLab = null; if (null != m_trans_ArrowContent) { m_trans_ArrowContent.localEulerAngles = angle; } if (null != m_trans_PointBoxContent) { m_trans_PointBoxContent.parent = gstyleData.TargetRoot; m_trans_PointBoxContent.localPosition = Vector3.zero; } if (null != m_trans_PBLeftContent) { if (m_trans_PBLeftContent.gameObject.activeSelf == gstyleData.ArrowRight) { m_trans_PBLeftContent.gameObject.SetActive(!gstyleData.ArrowRight); } if (!gstyleData.ArrowRight) { desLab = m_label_GuideLeftContent; } } if (null != m_trans_PBRightContent) { if (m_trans_PBRightContent.gameObject.activeSelf != gstyleData.ArrowRight) { m_trans_PBRightContent.gameObject.SetActive(gstyleData.ArrowRight); } if (gstyleData.ArrowRight) { desLab = m_label_GuideRightContent; } } if (null != desLab) { desLab.text = data.Des; } if (null != data.GuideTargetObj && null != m_helpData.AttachRoot) { //备份目标对象 GameObject cloneTarget = GameObject.Instantiate(data.GuideTargetObj); cloneTarget.name = data.GuideTargetObj.name; cloneTarget.transform.parent = m_helpData.AttachRoot; cloneTarget.transform.localScale = data.GuideTargetObj.transform.localScale; cloneTarget.transform.localPosition = data.GuideTargetObj.transform.localPosition; cloneTarget.transform.localRotation = data.GuideTargetObj.transform.localRotation; cloneTarget.transform.position = data.GuideTargetObj.transform.position; m_helpData.CloneTarget = cloneTarget; //删除UIPlayerTween UIPlayTween[] tws = cloneTarget.GetComponents <UIPlayTween>(); int length = (null != tws) ? tws.Length:0; if (length > 0) { for (int i = 0; i < length; i++) { GameObject.Destroy(tws[i]); } } GuideTrigger trigger = cloneTarget.GetComponent <GuideTrigger>(); if (null == trigger) { trigger = cloneTarget.AddComponent <GuideTrigger>(); } trigger.InitTrigger(data.ID, GuideTriggerDlg); //如果没有事件触发,需要手动添加碰撞器触发引导事件 //if (data.TriggerEventType == GuideDefine.GuideTriggerEventType.None) { BoxCollider boxCollider = cloneTarget.GetComponent <BoxCollider>(); if (null == boxCollider) { boxCollider = cloneTarget.AddComponent <BoxCollider>(); boxCollider.size = data.GuideTargetObjLocalBounds.size; boxCollider.center = data.GuideTargetObjLocalBounds.center; } if (!boxCollider.enabled) { boxCollider.enabled = true; } } } if (null != m_helpData.PointBoxRoot) { if (!m_helpData.PointBoxRoot.gameObject.activeSelf) { m_helpData.PointBoxRoot.gameObject.SetActive(true); } m_helpData.PointBoxRoot.localPosition = gstyleData.TargetPos; } ShowGuideDynamicMask(m_helpData.LocalData.GuideTargetWorldPos, 1); if (null != m_trans_ConstraintAnimContent) { TweenScale tween = m_trans_ConstraintAnimContent.GetComponent <TweenScale>(); if (null != tween) { tween.ResetToBeginning(); tween.enabled = true; } } SetVisible(false); SetVisible(true); } }