Ejemplo n.º 1
0
        public byte[] Serialize()
        {
            int length = 4; // Volume

            length += 2;    // Hull count

            for (int i = 0; i < Parts.Length; i++)
            {
                length += 12; // Offset
                length += 2;  // Vertex count
                length += Parts[i].Vertices.Length * 12;
                length += 2;  // Triangle count
                length += Parts[i].Indices.Length * 2;
            }

            byte[] data = new byte[length];
            int    pos  = 0;

            Utils.FloatToBytes(Volume, data, pos);
            pos += 4;

            Utils.UInt16ToBytes((ushort)Parts.Length, data, pos);
            pos += 2;

            for (int i = 0; i < Parts.Length; i++)
            {
                HullPart part = Parts[i];

                part.Offset.ToBytes(data, pos);
                pos += 12;

                Utils.UInt16ToBytes((ushort)part.Vertices.Length, data, pos);
                pos += 2;

                for (int j = 0; j < part.Vertices.Length; j++)
                {
                    Vector3 v = part.Vertices[j];

                    v.ToBytes(data, pos);
                    pos += 12;
                }

                Utils.UInt16ToBytes((ushort)part.Indices.Length, data, pos);
                pos += 2;

                for (int j = 0; j < part.Indices.Length; j++)
                {
                    ushort index = (ushort)part.Indices[j];

                    Utils.UInt16ToBytes(index, data, pos);
                    pos += 2;
                }
            }

            return(data);
        }
Ejemplo n.º 2
0
        public static ConvexHullSet Deserialize(byte[] data)
        {
            int pos = 0;

            ConvexHullSet hullSet = new ConvexHullSet();

            hullSet.Volume = Utils.BytesToFloat(data, pos);
            pos           += 4;

            ushort partCount = Utils.BytesToUInt16(data, pos);

            pos += 2;

            hullSet.Parts = new HullPart[partCount];

            for (int i = 0; i < partCount; i++)
            {
                HullPart part = new HullPart();

                part.Offset = new Vector3(data, pos);
                pos        += 12;

                ushort vertexCount = Utils.BytesToUInt16(data, pos);
                pos += 2;

                part.Vertices = new Vector3[vertexCount];
                for (int j = 0; j < vertexCount; j++)
                {
                    Vector3 v = new Vector3(data, pos);
                    pos += 12;

                    part.Vertices[j] = v;
                }

                ushort indexCount = Utils.BytesToUInt16(data, pos);
                pos += 2;

                part.Indices = new int[indexCount];
                for (int j = 0; j < indexCount; j++)
                {
                    ushort index = Utils.BytesToUInt16(data, pos);
                    pos += 2;

                    part.Indices[j] = index;
                }

                hullSet.Parts[i] = part;
            }

            return(hullSet);
        }
Ejemplo n.º 3
0
    public void Init(TankSchematic tankSchematic)
    {
        tankGOConstructor.Init(tankSchematic);

        Hull = new HullPart(tankSchematic.HullSchematic, this);

        int count      = 0;
        int validCount = 0;

        foreach (WeaponPartSchematic weaponSchematic in tankSchematic.WeaponSchematics)
        {
            if (weaponSchematic != null)
            {
                RectTransform rect = tankGOConstructor.weaponGOs[validCount].GetComponent <RectTransform>();
                Vector2       dir  = tankSchematic.HullSchematic.OrigWeaponDirs[count];

                Vector2 weaponFireOffset = dir.normalized * rect.sizeDelta.y;

                // Then create weapon representation and add to hull
                WeaponPart part = new WeaponPart(weaponSchematic, weaponFireOffset, this);
                Hull.AddWeaponAtIdx(part, count);

                validCount += 1;
            }
            count += 1;
        }

        boxCollider.size = tankSchematic.HullSchematic.Size;

        float totalWeight = calculateTotalWeight() / 10f;

        this.body.mass = totalWeight;

        this.body.angularDrag = Hull.Schematic.AngularDrag;

        MaxArmour = calculateTotalArmour();

        ResetState();

        DisableMovement = false;

        initialized = true;
    }
Ejemplo n.º 4
0
Archivo: Mesh.cs Proyecto: thoys/simian
        public static ConvexHullSet Deserialize(byte[] data)
        {
            int pos = 0;

            ConvexHullSet hullSet = new ConvexHullSet();
            hullSet.Volume = Utils.BytesToFloat(data, pos);
            pos += 4;

            ushort partCount = Utils.BytesToUInt16(data, pos);
            pos += 2;

            hullSet.Parts = new HullPart[partCount];

            for (int i = 0; i < partCount; i++)
            {
                HullPart part = new HullPart();

                part.Offset = new Vector3(data, pos);
                pos += 12;

                ushort vertexCount = Utils.BytesToUInt16(data, pos);
                pos += 2;

                part.Vertices = new Vector3[vertexCount];
                for (int j = 0; j < vertexCount; j++)
                {
                    Vector3 v = new Vector3(data, pos);
                    pos += 12;

                    part.Vertices[j] = v;
                }

                ushort indexCount = Utils.BytesToUInt16(data, pos);
                pos += 2;

                part.Indices = new int[indexCount];
                for (int j = 0; j < indexCount; j++)
                {
                    ushort index = Utils.BytesToUInt16(data, pos);
                    pos += 2;

                    part.Indices[j] = index;
                }

                hullSet.Parts[i] = part;
            }

            return hullSet;
        }