Unity-UI-Extensions / com.unity.uiextensions

https://unity-ui-extensions.github.io/
1.26k stars 135 forks source link

UIPolygon does not render properly until something is changed #116

Closed SimonDarksideJ closed 2 years ago

SimonDarksideJ commented 2 years ago

Issue created by Jakov Duzevic as Bitbucket Issue #​116 on 2017.02.09 21:08. Setting some values using UIPolygon's DrawPolygon method does not make it update as expected. One of the parent's of a gameobject that holds UIPolygon is not active before the assignment and gets gameobject.SetActive(true) just before this method is called on UIPolygon:


Polygon.DrawPolygon(values.Length, normalizedValues, 270);

UIPolygon component gets the values set. It shows in the editor. But the lines are not updated until you try to change something on that component or gameobject.

polygon.gif

SimonDarksideJ commented 2 years ago

On 2017.02.09 21:26 Jakov Duzevic modified issue: attachment changed /ddreaper/unity-ui-extensions/issues/attachments/116/ddreaper/unity-ui-extensions/1486675598.71/116/UIPolygonBug.zipUIPolygonBug.zip

SimonDarksideJ commented 2 years ago

On 2017.02.09 21:26, Jakov Duzevic commented: I've added a minimal project for reproducing a part of this bug. Just one scene with a minimal script that shows that polygon is not updated after values are set.

SimonDarksideJ commented 2 years ago

On 2017.02.10 12:14, @SimonDarksideJ commented: Sounds like it's related to the SetDirty() requirements for line rendering that has been pointed out with the other primitive controls. Will investigate. Thanks for the detailed repo and that GIF looks awesome :D

SimonDarksideJ commented 2 years ago

On 2017.02.10 15:55, @SimonDarksideJ commented: Confirmed, if you add "Polygon.SetAllDirty();" after the "Polygon.DrawPolygon()" call, it draws correctly. This is because it tells the UI System to re-render the UI Component. The editor does this by default in the background.

I'm doing a review to each primitive controls to ensure the VALUE and Draw functions include this by default to avoid confusion.

Please confirm and close :D

SimonDarksideJ commented 2 years ago

On 2017.02.10 16:48, @SimonDarksideJ commented: Updated all primitive controls in source, try out the new version and you should not need to use the "SetAllDirty" method now as it's done for you on changing any property.

SimonDarksideJ commented 2 years ago

On 2017.02.10 20:56, Jakov Duzevic commented: I am still experiencing some issues. I think that the main cause of my problem is got something to do with parent being not active before the vertices are set. Attached bug reproducing minimal project is not replicating the same problem. Could you try to use this code to get the same problem?


using UnityEngine;
using UnityEngine.UI.Extensions;

public class BugScript : MonoBehaviour
{
    public GameObject Parent;
    public UIPolygon Polygon;

    public void Awake()
    {
        Parent.SetActive(false);
    }
    public void Start()
    {
        Invoke("Test", 1f);
    }

    public void Test()
    {
        Debug.Log("Polygon should change now, right?");
        Parent.SetActive(true);
        Polygon.DrawPolygon(6, new[] { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.1f }, 270f);
        Polygon.SetVerticesDirty();
        Polygon.fill = false;
    }
}
SimonDarksideJ commented 2 years ago

On 2017.02.10 21:02, Jakov Duzevic commented: I get this kind of behaviour polygon2.gif

and I would want to see this form:

Target.PNG

SimonDarksideJ commented 2 years ago

On 2017.02.11 11:40, @SimonDarksideJ commented: Interesting but found the issue in the end and your screenshot says it all. You pass into the DrawPolygon call the following parameters:

Polygon.DrawPolygon(6, new[] { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.1f }, 270f);

Stating 6 sides and 6 verticies, however, your object only has 5 sides drawn between the 6 points, which the script sees as an error and resets the verticies as a result.

Polygon.DrawPolygon(5, new[] { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.1f }, 270f);

The above call which does the same as the screenshot works and it also rotated to 270 degrees.

Hope that helps.

SimonDarksideJ commented 2 years ago

On 2017.02.21 12:53, @SimonDarksideJ commented: Updated by @jakovd Okay, one more try. This code works good but if I comment out those two lines I get a situation that is replicating my project's behaviour better. And then it does not work. Do you know what would make Polygon not work if it was not active in hierarchy before the call to DrawPolygon?


using UnityEngine;
using UnityEngine.UI.Extensions;

public class BugScript : MonoBehaviour
{
    public GameObject Parent;
    public UIPolygon Polygon;

    public void Awake()
    {
        //Parent.SetActive(false);
    }
    public void Start()
    {
        Invoke("Test", 1f);
    }

    public void Test()
    {
        //Parent.SetActive(true);
        Debug.Log("DrawPolygon called");
        Polygon.DrawPolygon(5, new[] { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.1f }, 270f);
    }
}

With commented lines: 80307779-works[1].gif

With lines uncommented, it does not work as expected: 883583807-doesnotwork[1].gif

By the way, gifs are recorded using Gif screen recorder. Highly recommended for its simplicity.

SimonDarksideJ commented 2 years ago

On 2017.03.06 16:24, @SimonDarksideJ commented: Fix to Primitive Base to ensure the control is redrawn when it's enabled, resolves #116

Referenced by 49806ebb441a

SimonDarksideJ commented 2 years ago

On 2017.03.06 16:24 @SimonDarksideJ modified issue: status changed newresolved

SimonDarksideJ commented 2 years ago

On 2017.03.06 16:26, s commented: Sorry for the delay in getting back to you @jakovd Just pushed a fix for the issue above. Simply put, if you want it to re-draw onEnable, you need to also call SetAllDirty.

Extended the PrimitiveBase control that is the base control for all primitives with this capability. Have a test and get back to me please.

SimonDarksideJ commented 2 years ago

On 2022.03.30 10:59, Alexander Urbannuke commented: Still facing with that problem.