Example #1
0
    public void setBaseRegion(MSBS.Region region)
    {
        Rotation       = new UnityEngine.Vector3(region.Rotation.X, region.Rotation.Y, region.Rotation.Z);
        MapStudioLayer = region.MapStudioLayer;
        Unk2C          = region.Unk2C;
        UnkA           = new short[region.UnkA.Count];
        for (int i = 0; i < UnkA.Length; i++)
        {
            UnkA[i] = region.UnkA[i];
        }
        UnkB = new short[region.UnkB.Count];
        for (int i = 0; i < UnkB.Length; i++)
        {
            UnkB[i] = region.UnkB[i];
        }
        UnkC00 = region.UnkC00;
        UnkC04 = region.UnkC04;

        if (region.Shape is MSBS.Shape.Point)
        {
            IsPoint = true;
        }
    }
Example #2
0
    internal void _Serialize(MSBS.Region region, GameObject parent)
    {
        region.Name = parent.name;

        region.Position = new System.Numerics.Vector3(parent.transform.position.x, parent.transform.position.y, parent.transform.position.z);
        //region.Rotation.X = parent.transform.eulerAngles.x;
        //region.Rotation.Y = parent.transform.eulerAngles.y;
        //region.Rotation.Z = parent.transform.eulerAngles.z;
        region.Rotation = ConvertEuler(parent.transform.rotation.eulerAngles);

        region.MapStudioLayer = MapStudioLayer;
        region.Unk2C          = Unk2C;
        for (int i = 0; i < UnkA.Length; i++)
        {
            region.UnkA.Add(UnkA[i]);
        }
        for (int i = 0; i < UnkB.Length; i++)
        {
            region.UnkB.Add(UnkB[i]);
        }
        region.UnkC00 = UnkC00;
        region.UnkC04 = UnkC04;

        if (parent.GetComponent <SphereCollider>() != null)
        {
            var col = parent.GetComponent <SphereCollider>();
            if (IsPoint)
            {
                region.Shape = new MSBS.Shape.Point();
            }
            else
            {
                MSBS.Shape.Sphere shape = new MSBS.Shape.Sphere();
                shape.Radius = col.radius;
                region.Shape = shape;
            }
        }
        else if (parent.GetComponent <BoxCollider>() != null)
        {
            var            col   = parent.GetComponent <BoxCollider>();
            MSBS.Shape.Box shape = new MSBS.Shape.Box();
            shape.Width  = col.size.x;
            shape.Height = col.size.y;
            shape.Depth  = col.size.z;
            region.Shape = shape;
        }
        else if (parent.GetComponent <CapsuleCollider>() != null)
        {
            var col = parent.GetComponent <CapsuleCollider>();
            MSBS.Shape.Cylinder shape = new MSBS.Shape.Cylinder();
            shape.Radius = col.radius;
            shape.Height = col.height;
            region.Shape = shape;
        }
        else if (parent.GetComponent <MSBSCompositeShape>() != null)
        {
            var col = parent.GetComponent <MSBSCompositeShape>();
            MSBS.Shape.Composite shape = col.Serialize();
            region.Shape = shape;
        }
        else
        {
            throw new Exception($@"Region {parent.name} has no shape. Attach a spherical, box, or capsule collider.");
        }
    }