Exemplo n.º 1
0
        public MemoryStream fntGetStreamBlob(BlobStructure blbBlob)
        {
            MemoryStream strStream = new MemoryStream();
            var          container = fntGetContainer(blbBlob.cntContainer);

            CloudBlockBlob cldBlockBlob = container.GetBlockBlobReference(blbBlob.fntNameStr);

            if (cldBlockBlob.Exists())
            {
                cldBlockBlob.DownloadToStream(strStream);
            }
            return(strStream);
        }
    public void CreateCollider(BlobStructure blob, string name)
    {
        GameObject obj = new GameObject(name);

        obj.AddComponent <PolygonCollider2D>();
        PolygonCollider2D poly = obj.GetComponent <PolygonCollider2D>();

        poly.SetPath(0, blob.corners);
        obj.transform.SetParent(transform);

        var currentColor = blob.color;

        for (var j = 0; j < collisionInfo.Count; j++)
        {
            if (currentColor != collisionInfo[j].color)
            {
                continue;
            }

            if (collisionInfo[j].isMagnet)
            {
                obj.AddComponent <AreaEffector2D>();
                poly.usedByEffector = true;
                var effector = obj.GetComponent <AreaEffector2D>();

                effector.forceAngle     = 25f;
                effector.forceMagnitude = 100f;
                effector.forceVariation = 5f;
            }
            else
            {
                poly.sharedMaterial = collisionInfo[j].physics;
            }
        }

        //return g;
    }
    //NOTE: to get the location of the StreamingAssets folder, Application.datapath has to be used.
    //public static string streamingAssetsPath = Application.streamingAssetsPath;
    //public static string blobImageFileName = "binary";

    public static BlobStructure[] LoadBlobs(string filePath)
    {
        Debug.Log("Looking for binary file: " + filePath);
        if (File.Exists(filePath))
        {
            BinaryReader    br;
            int             blobCount;
            BlobStructure[] readBlobs;

            try
            {
                br = new BinaryReader(new FileStream(filePath, FileMode.Open));
            }
            catch (IOException e)
            {
                Debug.LogError(e.Message + "\n Cannot read from file.");
                return(null);
            }

            try
            {
                //NOTE: scale info is sent to BlobLoaderTest. May need change.
                var throwaway = br.ReadSingle();
                blobCount = br.ReadInt32();
                //Debug.Log(" Reading " + blobCount + " blobs...");
                readBlobs = new BlobStructure[blobCount];

                for (int i = 0; i < blobCount; i++)
                {
                    //Debug.Log("Reading nr. " + (i + 1));
                    Vector2[] corners = new Vector2[4];

                    //NOTE: In Unity, positive y goes upwards, while in screen space, it is reverse.
                    int x = br.ReadInt32();
                    int y = br.ReadInt32();
                    //Debug.Log("First point: " + x + ", " + y);
                    corners[0] = new Vector2(x, -y);

                    x = br.ReadInt32();
                    y = br.ReadInt32();
                    //Debug.Log("Second point: " + x + ", " + y);
                    corners[1] = new Vector2(x, -y);

                    x = br.ReadInt32();
                    y = br.ReadInt32();
                    //Debug.Log("Third point: " + x + ", " + y);
                    corners[2] = new Vector2(x, -y);

                    x = br.ReadInt32();
                    y = br.ReadInt32();
                    //Debug.Log("Fourth point: " + x + ", " + y);
                    corners[3] = new Vector2(x, -y);

                    //NOTE: color values are uint8. They are read as bytes.
                    byte r = br.ReadByte();
                    byte g = br.ReadByte();
                    byte b = br.ReadByte();

                    //Debug.Log("Color: " + r + ", " + g + ", " + b);
                    Color color = new Color32(r, g, b, 255);

                    readBlobs[i] = new BlobStructure(corners, color);
                }
            }
            catch (IOException e)
            {
                Debug.LogError(e.Message + "\n Cannot read from file.");
                return(null);
            }

            br.Close();
            return(readBlobs);
        }
        Debug.LogError("No file found!");
        return(null);
    }