Beispiel #1
0
    // Start is called before the first frame update
    void Start()
    {
        texture_loader = FindObjectOfType <sc_texture_loader>();
        filenames      = new List <string>();

        //load the example images
        for (int i = 1; i <= num_examples; i++)
        {
            filenames.Add("Example" + i);
        }
        //load all other texture names from the persistent data path
        //don't load the full textures yet as it leads to crashes
        DirectoryInfo dir = new DirectoryInfo(Application.persistentDataPath + "/");

        foreach (FileInfo file in dir.GetFiles())
        {
            if (file.Extension.Contains("png") && !file.Extension.Contains("meta"))
            {
                filenames.Add(file.Name);
            }
        }
    }
    public async void Awake()
    {
        //singelton initialization
        if (instance != null)
        {
            Destroy(this);
        }
        else
        {
            instance = this;
        }

        texture_loader = FindObjectOfType <sc_texture_loader>();
        client         = FindObjectOfType <UbiiClient>();
        textures       = new Dictionary <string, Texture2D>();
        idle_gallery   = FindObjectOfType <sc_idle_gallery>();

        //initialize tools
        foreach (sc_tool t in tools)
        {
            t.initialize();
        }


        //load uv textures
        string path = "Textures/uv_1600x2560";

        byte[] data = (Resources.Load(path) as TextAsset).bytes;

        uv_1600x2560 = new Texture2D(1600, 2560, TextureFormat.RGBAFloat, false);
        uv_1600x2560.LoadRawTextureData(data);
        uv_1600x2560.Apply();


        path = "Textures/uv_1536x2048";
        data = (Resources.Load(path) as TextAsset).bytes;

        uv_1536x2048 = new Texture2D(1536, 2048, TextureFormat.RGBAFloat, false);
        uv_1536x2048.LoadRawTextureData(data);
        uv_1536x2048.Apply();


        //connect to server
        sc_save_management.loadNetConfig(out string ip, out string port);
        client.ip   = ip;
        client.port = int.Parse(port);

        await client.InitializeClient();

        await client.Subscribe("image name", receiveImageName);

        await client.Subscribe("image size", receiveImageSize);

        await client.Subscribe("image format", receiveImageFormat);

        await client.Subscribe("image", receiveImage);

        await client.Subscribe("command", receiveCommand);

        await client.Subscribe("gallery command", receiveGalleryCommand);

        await client.Subscribe("position", receivePositionData);

        await client.Subscribe("reset canvas", reset_canvas_requested);

        await client.Subscribe("uvimage resolution", receiveUVImage_resolution);

        await client.Subscribe("color", receiveColor);

        await client.Subscribe("brush size", receive_brush_size);

        await client.Subscribe("undo", receiveUndo);

        Debug.Log("connected");
        connected = true;
    }