1
0
mirror of https://github.com/Cardidi/dotween-upm-fork.git synced 2025-12-21 01:36:05 +08:00

Added DOTweenUtils46.SwitchToRectTransform method

This commit is contained in:
Daniele Giardini 2015-06-10 18:42:24 +02:00
parent c6d84ccfda
commit 7b9cb9f7d6
26 changed files with 88 additions and 1 deletions

View File

@ -181,5 +181,16 @@
Also stores the Text as the tween's target so it can be used for filtered operations</summary>
<param name="endValue">The value to tween to</param><param name="duration">The duration of the tween</param>
</member>
<member name="T:DG.Tweening.DOTweenUtils46">
<summary>
Various utils that require Unity 4.6 or later
</summary>
</member>
<member name="M:DG.Tweening.DOTweenUtils46.SwitchToRectTransform(UnityEngine.RectTransform,UnityEngine.RectTransform)">
<summary>
Converts the anchoredPosition of the first RectTransform to the second RectTransform,
taking into consideration offset, anchors and pivot, and returns the new anchoredPosition
</summary>
</member>
</members>
</doc>

View File

@ -181,5 +181,16 @@
Also stores the Text as the tween's target so it can be used for filtered operations</summary>
<param name="endValue">The value to tween to</param><param name="duration">The duration of the tween</param>
</member>
<member name="T:DG.Tweening.DOTweenUtils46">
<summary>
Various utils that require Unity 4.6 or later
</summary>
</member>
<member name="M:DG.Tweening.DOTweenUtils46.SwitchToRectTransform(UnityEngine.RectTransform,UnityEngine.RectTransform)">
<summary>
Converts the anchoredPosition of the first RectTransform to the second RectTransform,
taking into consideration offset, anchors and pivot, and returns the new anchoredPosition
</summary>
</member>
</members>
</doc>

View File

@ -181,5 +181,16 @@
Also stores the Text as the tween's target so it can be used for filtered operations</summary>
<param name="endValue">The value to tween to</param><param name="duration">The duration of the tween</param>
</member>
<member name="T:DG.Tweening.DOTweenUtils46">
<summary>
Various utils that require Unity 4.6 or later
</summary>
</member>
<member name="M:DG.Tweening.DOTweenUtils46.SwitchToRectTransform(UnityEngine.RectTransform,UnityEngine.RectTransform)">
<summary>
Converts the anchoredPosition of the first RectTransform to the second RectTransform,
taking into consideration offset, anchors and pivot, and returns the new anchoredPosition
</summary>
</member>
</members>
</doc>

View File

@ -1,5 +1,6 @@
using System;
using System.Text;
using DG.Tweening;
using UnityEngine;
using System.Collections;
@ -7,6 +8,7 @@ public class RectTransformConversionTests : BrainBase
{
public RectTransform a, b;
public RectTransform target;
public Camera uiCam;
void Start()
{
@ -17,9 +19,21 @@ public class RectTransformConversionTests : BrainBase
target.GetWorldCorners(targetCorners);
Debug.Log("A ::::::::::::::::::::::::::::::::::::::");
Debug.Log("Corners: " + ArrayToString(aCorners));
Debug.Log("WorldToScreenPoint: position: " + RectTransformUtility.WorldToScreenPoint(uiCam, a.position) + " anchoredPosition: " + RectTransformUtility.WorldToScreenPoint(uiCam, a.anchoredPosition));
Debug.Log("B ::::::::::::::::::::::::::::::::::::::");
Debug.Log("TARGET :::::::::::::::::::::::::::::::::");
Debug.Log("Corners: " + ArrayToString(targetCorners));
Vector2 localPoint;
Vector2 aPivotDerivedOffset = new Vector2(a.rect.width * 0.5f + a.rect.xMin, a.rect.height * 0.5f + a.rect.yMin);
Vector2 screenP = RectTransformUtility.WorldToScreenPoint(uiCam, a.position);
screenP += aPivotDerivedOffset;
RectTransformUtility.ScreenPointToLocalPointInRectangle(b, screenP, uiCam, out localPoint);
Debug.Log(b.pivot + " - " + b.rect);
Vector2 bPivotDerivedOffset = new Vector2(b.rect.width * 0.5f + b.rect.xMin, b.rect.height * 0.5f + b.rect.yMin);
Debug.Log(bPivotDerivedOffset);
b.anchoredPosition = b.anchoredPosition + localPoint - bPivotDerivedOffset;
Debug.Log(b.anchoredPosition + " - " + DOTweenUtils46.SwitchToRectTransform(a, b));
}
string ArrayToString(IList list)

View File

@ -32,7 +32,7 @@ namespace DG.Tweening
public class DOTween
{
/// <summary>DOTween's version</summary>
public static readonly string Version = "1.0.785";
public static readonly string Version = "1.0.790";
///////////////////////////////////////////////
// Options ////////////////////////////////////

View File

@ -56,6 +56,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="DOTweenUtils46.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ShortcutExtensions46.cs" />
</ItemGroup>

View File

@ -0,0 +1,28 @@
// Author: Daniele Giardini - http://www.demigiant.com
// Created: 2015/06/10 18:07
using UnityEngine;
namespace DG.Tweening
{
/// <summary>
/// Various utils that require Unity 4.6 or later
/// </summary>
public static class DOTweenUtils46
{
/// <summary>
/// Converts the anchoredPosition of the first RectTransform to the second RectTransform,
/// taking into consideration offset, anchors and pivot, and returns the new anchoredPosition
/// </summary>
public static Vector2 SwitchToRectTransform(RectTransform from, RectTransform to)
{
Vector2 localPoint;
Vector2 fromPivotDerivedOffset = new Vector2(from.rect.width * 0.5f + from.rect.xMin, from.rect.height * 0.5f + from.rect.yMin);
Vector2 screenP = RectTransformUtility.WorldToScreenPoint(null, from.position);
screenP += fromPivotDerivedOffset;
RectTransformUtility.ScreenPointToLocalPointInRectangle(to, screenP, null, out localPoint);
Vector2 pivotDerivedOffset = new Vector2(to.rect.width * 0.5f + to.rect.xMin, to.rect.height * 0.5f + to.rect.yMin);
return to.anchoredPosition + localPoint - pivotDerivedOffset;
}
}
}

Binary file not shown.

Binary file not shown.

View File

@ -181,5 +181,16 @@
Also stores the Text as the tween's target so it can be used for filtered operations</summary>
<param name="endValue">The value to tween to</param><param name="duration">The duration of the tween</param>
</member>
<member name="T:DG.Tweening.DOTweenUtils46">
<summary>
Various utils that require Unity 4.6 or later
</summary>
</member>
<member name="M:DG.Tweening.DOTweenUtils46.SwitchToRectTransform(UnityEngine.RectTransform,UnityEngine.RectTransform)">
<summary>
Converts the anchoredPosition of the first RectTransform to the second RectTransform,
taking into consideration offset, anchors and pivot, and returns the new anchoredPosition
</summary>
</member>
</members>
</doc>