public void DrawDOTweenSpringConfig(DOTweenSpring tw) { if (DOTweenUtilEditor.DrawHeader("DOTweener")) { EditorGUIUtility.labelWidth = 110; EditorGUILayout.BeginHorizontal("AS TextArea", GUILayout.MinHeight(10f)); GUILayout.BeginVertical(); GUILayout.Space(5); GUI.changed = false; AnimationCurve animationCurve = EditorGUILayout.CurveField("Animation Curve", tw.AnimationCurves, GUILayout.Width(250), GUILayout.Height(30)); DG.Tweening.Ease easeType = (DG.Tweening.Ease)EditorGUILayout.EnumPopup("Ease Type", tw.EaseType, GUILayout.Width(250f)); if (easeType != DG.Tweening.Ease.Unset) { EditorGUILayout.HelpBox("(PS: AnimationCurve won't work unless EasyType is Unset)", MessageType.Info); } float duration = EditorGUILayout.FloatField("Duration", tw.Duration, GUILayout.Width(250f)); float startDelay = EditorGUILayout.FloatField("Start Delay", tw.StartDelay, GUILayout.Width(250f)); bool ignoreTimeScale = EditorGUILayout.Toggle("Ignore TimeScale", tw.IgnoreTimeScale); if (GUI.changed) { tw.AnimationCurves = animationCurve; tw.EaseType = easeType; tw.Duration = duration; tw.StartDelay = startDelay; tw.IgnoreTimeScale = ignoreTimeScale; } GUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); GUILayout.Space(5); } if (DOTweenUtilEditor.DrawHeader("Tweener Event")) { GUI.changed = false; EditorGUILayout.BeginHorizontal("AS TextArea", GUILayout.MinHeight(10f)); GUILayout.BeginVertical(); GUILayout.Space(5); EditorGUILayout.PropertyField(serializedObject.FindProperty("OnDOTweenStart")); EditorGUILayout.PropertyField(serializedObject.FindProperty("OnDOTweenComplete")); if (GUI.changed) { serializedObject.ApplyModifiedProperties(); } GUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); GUILayout.Space(5); } GUILayout.Space(5); }
public static DOTweenSpring CreateInstance(RectTransform rect) { DOTweenSpring tempTweenerSpring = rect.GetComponent <DOTweenSpring>(); if (null == tempTweenerSpring) { tempTweenerSpring = rect.gameObject.AddComponent <DOTweenSpring>(); } return(tempTweenerSpring); }
protected DOTweenSpring GetRectChildrenTweener(RectTransform rect) { DOTweenSpring tweener; if (m_RectChildrenTweener.TryGetValue(rect, out tweener) == false) { tweener = DOTweenSpring.CreateInstance(rect); if (tweener.IsController == false) { tweener.Init(this, false); m_RectChildrenTweener.Add(rect, tweener);//cache one } } return(tweener); }
public override void OnInspectorGUI() { if (null != Selection.objects && Selection.objects.Length > 1) { return; } DOTweenSpring tw = target as DOTweenSpring; DYLayoutGroup layoutGroup; layoutGroup = tw.GetComponent <DYLayoutGroup>(); if (null == layoutGroup) { layoutGroup = tw.AttachedLayoutGroup; if (null == layoutGroup) { layoutGroup = tw.GetComponentInParent <DYLayoutGroup>(); tw.Init(layoutGroup, false); } if (null != layoutGroup) { EditorGUILayout.HelpBox("This is control by LayoutGroup Controller", MessageType.Info, true); if (GUILayout.Button("Switch to Controller")) { DOTweenSpring controller = layoutGroup.SpringController; Selection.activeGameObject = controller.gameObject; } } else//can not find layoutGtoup, so just use for self { DrawDOTweenSpringConfig(tw); } } else { DrawDOTweenSpringConfig(tw); } }
public void Init(DYLayoutGroup layoutGroup, bool isController) { if (_layoutGroup != layoutGroup) { _layoutGroup = layoutGroup; } if (_isController != isController) { _isController = isController || null != this.GetComponent <DYLayoutGroup>(); } if (null == _layoutGroup) { return; } _springController = _layoutGroup.SpringController; if (this.transform.parent != _layoutGroup.transform && this.transform != _layoutGroup.transform) { Debug.LogWarningFormat("当前GameObject({0})不处于其管理的LayoutGrouop({1})下?!这将可能引起异常!", this.name, _layoutGroup.transform.name); } }
protected void SetChildAlongAxis(RectTransform rect, int axis, float pos, float size, bool isTweenMove, bool isAutoMove, bool ignoreScale) { if (false == isTweenMove) { SetChildAlongAxis(rect, axis, pos, size); return; } Vector4 tempPosNSize = new Vector4( rect.anchoredPosition.x - rect.sizeDelta.x * rect.pivot.x, rect.sizeDelta.x, -(rect.anchoredPosition.y + rect.sizeDelta.y * rect.pivot.y), rect.sizeDelta.y); if (ignoreScale) { if ((axis == 1?tempPosNSize.w:tempPosNSize.y) != size) { SetChildAlongAxis(rect, axis, (axis == 1?tempPosNSize.z:tempPosNSize.x), size); } } //pos and size did not change(当前位置与目标位置的比较) if ((axis == 1 && tempPosNSize.z == pos && tempPosNSize.w == size) || (axis == 0 && tempPosNSize.x == pos && tempPosNSize.y == size)) { return; } DOTweenSpring tempTweenSpring = GetRectChildrenTweener(rect); Vector4 targetPosNSize = axis == 1 ? new Vector4(tempTweenSpring.EndValule.x, tempTweenSpring.EndValule.y, pos, size) : new Vector4(pos, size, tempTweenSpring.EndValule.z, tempTweenSpring.EndValule.w); //当前位置与Tween的目标位置比较(若当前正在缓动到正确的位置,则略过下面多余的判断) if ((targetPosNSize - tempPosNSize).sqrMagnitude < 0.01f) { return; } //说明当前layout需要更新!(尚未完成更新或者未开始更新) if (false == m_NeedReposition) { m_NeedReposition = true; } if (isAutoMove == true) { ResetPosition(); } if (false == RepositionNow) { return; } if (tempTweenSpring.IsPlaying()) { if (tempTweenSpring.EndValule != targetPosNSize)//pos change while tweening { tempTweenSpring.Kill(); } } if (tempTweenSpring.IsKilled()) { //DYDYLogger.LogFormat("SetChildAlongAxis object={0} targetPosNSize={1} originPosNSize={2}", rect.name, targetPosNSize, tempPosNSize); tempTweenSpring.BeginTween( tempPosNSize, targetPosNSize, (x) => { tempPosNSize = x; SetChildAlongAxis(rect, 1, tempPosNSize.z, tempPosNSize.w); SetChildAlongAxis(rect, 0, tempPosNSize.x, tempPosNSize.y); }); } }