Hi Aren,
Second message of the day ahah.
We had some weird problem on our project with the new Vector3.SqrMagnitude you made in UIGrid.ResetPosition.
Here is our setup:
-UIGrid
-Transform
----Widget
----Widget
----Widget
----Widget
When we do our animation, we want each widget to be repositioned. To do so, we use the AddWidget from UIGrid to parent it to the grid.
After that we call UIGrid.Reposition().
Since we have checked animate smoothly, the widget is smoothly going to the Zero point under the grid.
Everything fine.
Then, 0.3 second after the first one have been add to the grid, we resize the grid and we add another widget and call reposition too.
Everything is fine when the framerate is stable.
But when it's not stable, the first widget almost always stays stuck in the center of the grid. Calling Reposition when the framerate is more stable doesn't replace it correctly.
The only way I made it to work is by disabling the Vector3.SqrMagnitude.
In our setup the grid have a width of 175, the widget is stuck in 0,0,0 and the SpringPosition wants to move it to x:-1750 instead of x:-350, but it doesn't move anyway.
This is our code calling doing the animation:
private IEnumerator DrawCardsAsync(){
for (int i = 0; i < _result.bonusesActivated.Length; i++){
cards[i].Init(_result.bonusesActivated[i],GridToRepositionAfterContentUpdate.transform);
GridToUpdateWithBonuses.ExecuteUpdateAction();
GridToRepositionAfterContentUpdate.Reposition();
yield return new WaitForSeconds
(0
.3f
); }
}
ExcuteUpdateAction is in this script:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[ExecuteInEditMode]
public class UIGridFollowsResize : MonoBehaviour
{
private UIWidget m_Widget;
private UIPanel m_Panel;
private UIGrid m_uiGrid;
public float numOfColumns = 4.0f;
public float numOfRows = 3.0f;
private List
<Transform
> m_childList
= new List
<Transform
>();
void Start()
{
m_Widget = GetComponent<UIWidget>();
m_uiGrid = GetComponent<UIGrid>();
}
public void updateGrid()
{
if (m_uiGrid == null) return;
float newHeight;
float newWidth;
float newScale;
if (numOfRows > 0)
{
newHeight = m_Widget.height / numOfRows;
}else{
newHeight = 0;
}
newWidth = m_Widget.width / numOfColumns;
m_uiGrid.cellWidth = newWidth ;
m_uiGrid.cellHeight = newHeight;
m_childList = m_uiGrid.GetChildList();
foreach (Transform child in m_childList)
{
UIWidget childWidget = child.GetComponent<UIWidget>();
if((newWidth - (AMTools.isHD ? 80f : 40f)) / childWidget.width < (newHeight - (AMTools.isHD ? 60f : 30f)) / childWidget.height){
newScale = (newWidth - (AMTools.isHD ? 80f : 40f)) / childWidget.width;
}else{
newScale = (newHeight - (AMTools.isHD ? 60f : 30f)) / childWidget.height;
}
child.localScale = Vector3.one * newScale;
}
}
void Update()
{
if (m_Panel == null) m_Panel = m_Widget.panel;
}
public void ExecuteUpdateAction(){
updateGrid();
}
public bool update = false;
void OnValidate(){
if(update == true){
updateGrid();
update = false;
}
}
}
Init is doing this with the transform(and other thing but not related to the transform):
public void Init(APIJSON.SHOP.CARDHOLDER.BonusesActivated bonus, Transform moveParentingTo){
_bonus = bonus;
Debug.Log("Bonus:" + JsonUtility.ToJson(_bonus));
if(firstParent == null){
firstParent = this.transform.parent;
}
moveParentingTo.GetComponent<UIGrid>().AddChild(this.transform);
this.gameObject.SetActive(true);
}
To simulate the hiccups of the device we made a dirty function:
int nbLags = 0;
private IEnumerator LagsPeriodically()
{
int i = 0;
while (i < 1000)
{
Debug.Log("LOG");
i++;
}
nbLags++;
yield return new WaitForSeconds
(0
.4f
); if (nbLags < 5)
{
StartCoroutine(LagsPeriodically());
}else{
nbLags = 0;
}
}
Can you take a look at it and tell us if you have the same problem?