hecomi / uREPL

In-game powerful REPL environment for Unity3D.
http://tips.hecomi.com/entry/2015/12/05/003000
MIT License
551 stars 54 forks source link

Transform inspector shows wrong values #21

Closed slimshader closed 4 years ago

slimshader commented 5 years ago

Latest version shows incorrect rtansform valies when using Inspect(), tested on Unity 2018.4.3

image

slimshader commented 5 years ago

To clarify: it seems uREPL is missing the decimal point (making 1.73 into 173) but negative values seem to overflowed, could it be a conversion issue (possibly by default Locale)?

hecomi commented 5 years ago

I've checked it with Unity 2018.4.3f1 in both Windows and Mac, but I couldn't reproduce the bug.

スクリーンショット 2019-09-01 16 33 52

Could you provide some more information like Configulation? My setting is below:

スクリーンショット 2019-09-01 16 35 01
slimshader commented 5 years ago

Tried with uREPL 5.0 5.1 and 6.0 in Unity 2018.4.3 and 2018.4.8 in both Net Standard 2.0 and NET 4.x, problem persists for me.

hecomi commented 5 years ago

Could you check the Content Type of the Input Filed-s?

2019-09-01 (1)

I guess it accidentally changed to Integer Number from Decimal Number. If so, please fix them in Resources > uREPL > Prefabs > Output > GameObject Item, or delete uREPL directory and import .unitypackage again (I've tested from an empty scene and it had no problem).

2019-09-01 (3)
slimshader commented 5 years ago

It is Decimal Number, re-imported to fresh project multiple times. But Text if Input Fields says for example "173" where transform value is 1.73

hecomi commented 5 years ago

Sorry for giving many requests... but I'm very glad if you continue to try these items:

  1. How about inputting a float numbr like 1.234 to the position field directly?
  2. How about other InputField-s in FieldInputTest component?
2019-09-02 (1)
  1. The code that converts rotation into xyz texts is here:

https://github.com/hecomi/uREPL/blob/086f03a29223b614c9a29f3e1763f841a0fd453f/Assets/uREPL/Scripts/Gui/OutputItems/GameObjectItem.cs#L53-L59 (rotX is UnityEngine.UI.InputField)

So could you insert Debug.Log-s just after the getter in uREPL/Scripts/Gui/OutputItems/GameObjectItem.cs like this?:

...
    public Quaternion rotation
    {
        get
        {
            return Quaternion.Euler(
                float.Parse(rotX.text),
                float.Parse(rotY.text),
                float.Parse(rotZ.text));
        }
        protected set
        {
            var euler = value.eulerAngles;
            rotX.text = euler.x.ToString();
            rotY.text = euler.y.ToString();
            rotZ.text = euler.z.ToString();
            Debug.Log(euler.x.ToString()); // <=== insert
            Debug.Log(rotX.text); // <=== insert
        }
    }
...
slimshader commented 5 years ago

No problem happy to help.

As I suspected, it seems to float <-> string conversion issue. float.Parse(rotX.text) throws for me because in my Culture it expects "1,73" instead of "1.73", problem is Unity InputField with Decimal Number settings does not allow to enter "," :/

The possible solution would be to use explicit "en_us" CultureInfo when Parse()/ToString()

var x = float.Parse(str, CultureInfo.GetCultureInfo("en-US"));

this indeed parses "1.73" correctly on my machine.

The solution (and the problem) is discussed in here:

link

slimshader commented 5 years ago

Indeed, doing:

    public Vector3 position
    {
        get
        {
            return new Vector3(
                float.Parse(posX.text, CultureInfo.GetCultureInfo("en-US")),
                float.Parse(posY.text, CultureInfo.GetCultureInfo("en-US")),
                float.Parse(posZ.text, CultureInfo.GetCultureInfo("en-US")));
        }
        protected set
        {
            posX.text = value.x.ToString(CultureInfo.GetCultureInfo("en-US"));
            posY.text = value.y.ToString(CultureInfo.GetCultureInfo("en-US"));
            posZ.text = value.z.ToString(CultureInfo.GetCultureInfo("en-US"));
        }
    }

I know code is ugly and should have just write dedicated parse method (possible extension method) but it illustrates the point

fixes position values both ways:

image

hecomi commented 5 years ago

Thank you very much for giving the solution! (and I overlooked your suggestion in https://github.com/hecomi/uREPL/issues/21#issuecomment-526483494).,,

I'll fix it in the next release soon.

hecomi commented 5 years ago

I added some exntension methods that uses CultureInfo and pushed the commit. Could you check it when you have time in your environment?

slimshader commented 5 years ago

All looking good now :) Interesting artifact is only values of negative rotation values (wrapped to positive):

image

It works fine tho, just looks bit off

hecomi commented 5 years ago

The positive value comes from transform.eulerAngles directly and I haven't checked the difference between it and the rotation value in Transform inspector. For now I'll release the current version as the next one but in the future if I understand the difference (or someone tells it), I'll fix this behavior (or not depending on the reason). Thank you so much for reporting this bug and helping me fix it!