Unity Mono和.Net平台浮点算法的区别

        static void TestFloat()
        {
            {
                //float speed=2.0f/20;
                float speed = 0.1f;
                float distance = 2.0f;
                long needTime = (long)(distance / speed);
                Log.Debug($"needTime={needTime}");
#if UNITY_EDITOR
                if (needTime != 19)
#else
                if (needTime != 20)//.Net服务器和安卓手机
#endif
                    Log.Warning("平台浮点算法变了");
            }
        }

        static void TestFixInt()
        {
            {
                FixInt fi2 = 20000;
                FixInt fi1 = 10000;
                if (fi1 / fi2 != 0.5f)
                {
                    Log.Warning($"TestFixInt,{fi2}/{fi1} != 0.5");
                }
            }
            {
                FixInt fi2 = 20000;
                FixInt fi1 = 10000;
                if (fi2 / fi1 != 2)
                {
                    Log.Warning($"TestFixInt,{fi2}/{fi1} != 2");
                }
            }
            {
                const long l = 20000;
                FixInt fi = new(6000);
                if (l < fi)
                {
                    Log.Warning($"TestFixInt,{l} < {fi}");
                }
            }
            {
                FixInt fi3 = new(3);
                FixInt fi5 = new(5);
                if (fi3 + 1000 < fi5)
                {
                    Log.Warning($"TestFixInt,{fi3} , {fi5}");
                }
            }
            {
                const long l = 3000;
                FixInt fi = l;
                if (fi.RawLong != l)
                {
                    Log.Warning($"TestFixInt,{fi.RawLong} != {l}");
                }
            }
        }

        static void TestGetPolygonFormation()
        {
            var points = TeamFormationComponentSystem.GetPolygonFormation(new(),
                new() { x = 230.33540344238281f, y = -0.0000019073486328125f, z = 62.280677795410156f },
                new() { x = -6.1755828857421875f, y = -0.045724689960479736f, z = 9.5355415344238281f },
                4,
                2);
            List list = new()
            {
                new(){x = 230.429f, y = 0.0f, z = 62.135f },
                new(){ x = 233.077f, y = 0.0f, z = 60.689f },
                new(){ x = 233.317f, y = 0.0f, z = 57.679f },
                new(){ x = 230.669f, y = 0.0f, z = 59.125f },
            };

            if (points.Count != list.Count)
            {
                Log.Warning($"TestGetPolygonFormation,{points} != {list}");
            }

            for (int i = 0; i 

结论
.Net和安卓手机IL2CPP算法相同
Windows下Unity的Mono算法不同,就它不同

你可能感兴趣的:(unity,.net,游戏引擎)