Ejemplo n.º 1
0
    public static bool ApplyTerrainAnchors(this Transform transform, TerrainAnchor[] anchors, ref Vector3 pos, Quaternion rot, Vector3 scale, TerrainAnchorMode mode, SpawnFilter filter = null)
    {
        float single;
        float single1;
        float single2;

        if (anchors.Length == 0)
        {
            return(true);
        }
        float single3 = 0f;
        float single4 = Single.MinValue;
        float single5 = Single.MaxValue;

        for (int i = 0; i < (int)anchors.Length; i++)
        {
            TerrainAnchor terrainAnchor = anchors[i];
            Vector3       vector3       = Vector3.Scale(terrainAnchor.worldPosition, scale);
            vector3 = rot * vector3;
            Vector3 vector31 = pos + vector3;
            if (TerrainMeta.OutOfBounds(vector31))
            {
                return(false);
            }
            if (filter != null && filter.GetFactor(vector31) == 0f)
            {
                return(false);
            }
            terrainAnchor.Apply(out single, out single1, out single2, vector31);
            single3 = single3 + (single - vector3.y);
            single4 = Mathf.Max(single4, single1 - vector3.y);
            single5 = Mathf.Min(single5, single2 - vector3.y);
            if (single5 < single4)
            {
                return(false);
            }
        }
        if (mode != TerrainAnchorMode.MinimizeError)
        {
            pos.y = Mathf.Clamp(pos.y, single4, single5);
        }
        else
        {
            pos.y = Mathf.Clamp(single3 / (float)((int)anchors.Length), single4, single5);
        }
        return(true);
    }
Ejemplo n.º 2
0
    public static bool ApplyTerrainAnchors(
        this Transform transform,
        TerrainAnchor[] anchors,
        ref Vector3 pos,
        Quaternion rot,
        Vector3 scale,
        TerrainAnchorMode mode,
        SpawnFilter filter = null)
    {
        if (anchors.Length == 0)
        {
            return(true);
        }
        float num1 = 0.0f;
        float num2 = float.MinValue;
        float num3 = float.MaxValue;

        for (int index = 0; index < anchors.Length; ++index)
        {
            TerrainAnchor anchor    = anchors[index];
            Vector3       vector3_1 = Vector3.Scale(anchor.worldPosition, scale);
            Vector3       vector3_2 = Quaternion.op_Multiply(rot, vector3_1);
            Vector3       vector3_3 = Vector3.op_Addition(pos, vector3_2);
            if (TerrainMeta.OutOfBounds(vector3_3) || filter != null && (double)filter.GetFactor(vector3_3) == 0.0)
            {
                return(false);
            }
            float height;
            float min;
            float max;
            anchor.Apply(out height, out min, out max, vector3_3);
            num1 += height - (float)vector3_2.y;
            num2  = Mathf.Max(num2, min - (float)vector3_2.y);
            num3  = Mathf.Min(num3, max - (float)vector3_2.y);
            if ((double)num3 < (double)num2)
            {
                return(false);
            }
        }
        pos.y = mode != TerrainAnchorMode.MinimizeError ? (__Null)(double)Mathf.Clamp((float)pos.y, num2, num3) : (__Null)(double)Mathf.Clamp(num1 / (float)anchors.Length, num2, num3);
        return(true);
    }