Ejemplo n.º 1
0
    void OnServerInitialized()
    {
        var paintbrush = Network.Instantiate(paintbrushPrefab, Vector3.zero, Quaternion.identity, 0) as GameObject;

        paintbrush.transform.SetParent(transform, false);

        race      = paintbrush.GetComponent <RaceController>();
        race.Laps = GamePresets.Laps;

        SpawnPlayer();

        var brush = paintbrush.GetComponent <PaintBrush>();

        var mapSize = Ruler.Measure();

        if (GamePresets.Colorful)
        {
            for (int i = 0; i < initialSplashes; i++)
            {
                brush.Paint(
                    Random.insideUnitSphere * mapSize.x / 2,
                    initialSplashColors[Random.Range(0, initialSplashColors.Length)],
                    Random.Range(
                        (int)(initialSplashSize.x * PaintBrush.SCALE_FACTOR),
                        (int)(initialSplashSize.y * PaintBrush.SCALE_FACTOR)
                        )
                    );
            }
        }
    }
Ejemplo n.º 2
0
    protected override void Awake()
    {
        base.Awake();
        networkView.stateSynchronization = NetworkStateSynchronization.Off;

        if (useComputeShader)
        {
            rPaintTexture = new RenderTexture(TEXTURE_SIZE, TEXTURE_SIZE, 8);
            rPaintTexture.enableRandomWrite = true;
            rPaintTexture.Create();
            computeShader.SetTexture(0, "Result", rPaintTexture);
        }
        else
        {
            _paintTexture = new Texture2D(TEXTURE_SIZE, TEXTURE_SIZE, TextureFormat.ARGB32, false);
            _paintTexture.SetPixels(0, 0, TEXTURE_SIZE, TEXTURE_SIZE, Enumerable.Repeat(Color.clear, TEXTURE_SIZE * TEXTURE_SIZE).ToArray());
            _dirty = true;
        }

        var   mapSize   = Ruler.Measure();
        float maxLength = Mathf.Max(mapSize.x, mapSize.y);

        if (_adaptiveScale)
        {
            SCALE_FACTOR = TEXTURE_SIZE / maxLength;
        }

        Debug.Log("Scale factor: " + SCALE_FACTOR);

        if (useComputeShader)
        {
            Shader.SetGlobalTexture("_PaintTexture", rPaintTexture);
        }
        else
        {
            Shader.SetGlobalTexture("_PaintTexture", _paintTexture);
        }

        Shader.SetGlobalFloat("_PaintScale", SCALE_FACTOR);
        Shader.SetGlobalFloat("_GlossinessPaint", 0.7f);
        Shader.SetGlobalFloat("_MetallicPaint", 0.7f);
        Shader.SetGlobalFloat("_TextureWidth", TEXTURE_SIZE);
    }