コード例 #1
0
    // Start is called before the first frame update
    async void Start()
    {
//        var a1Tex = new Texture2D(2, 2, TextureFormat.Alpha8, false, false);
//        a1Tex.SetPixel(0, 0, new Color32(0, 0, 0, 0 | 0));
//        a1Tex.SetPixel(1, 0, new Color32(0, 0, 0, 1 | (1 << 6)));
//        a1Tex.SetPixel(0, 1, new Color32(0, 0, 0, 2 | (2 << 6)));
//        a1Tex.SetPixel(1, 1, new Color32(0, 0, 0, 3 | (3 << 6)));
//        a1Tex.filterMode = FilterMode.Point;
//        a1Tex.wrapMode = TextureWrapMode.Clamp;
//        a1Tex.Apply();
//
//        var a2Tex = new Texture2D(2, 2, TextureFormat.Alpha8, false, false);
//        a2Tex.SetPixel(0, 0, new Color32(0,0,0,0));
//        a2Tex.SetPixel(1, 0, new Color32(0,0,0,0));
//        a2Tex.SetPixel(0, 1, new Color32(0,0,0,0));
//        a2Tex.SetPixel(1, 1, new Color32(0,0,0,0));
//        a2Tex.filterMode = FilterMode.Point;
//        a2Tex.wrapMode = TextureWrapMode.Clamp;
//        a2Tex.Apply();


        var stageMetadata = await stageMetadataRef.LoadAssetAsync().Task;


        var a1Tex = stageMetadata.A1Tex;
        var a2Tex = stageMetadata.A2Tex;

        rawImage.materialForRendering.SetTexture(A1Tex, a1Tex);
        rawImage.materialForRendering.SetTexture(A2Tex, a2Tex);

        using var stream = new MemoryStream(stageMetadata.RawStageData.bytes);
        var formatter = new BinaryFormatter();

        stageData = (StageData)formatter.Deserialize(stream);
        stream.Close();

        var colorUintArray =
            new[] { BlackConvert.GetC(new Color32(0, 0, 0, 255)) } // 팔레트의 0번째는 언제나 검은색으로, 아웃라인 전용으로 예약되어 있다.
        .Concat(stageData.CreateColorUintArray())
        .ToArray();

        if (colorUintArray.Length > 64)
        {
            Debug.LogError("Maximum palette size 64 exceeded.");
        }
        else
        {
            var paletteArray = colorUintArray.Select(BlackConvert.GetColor).ToArray();
            rawImage.materialForRendering.SetColorArray(Palette, paletteArray);

//            rawImage.material.SetColorArray(Palette, new List<Color>
//            {
//                Color.red, Color.green, Color.blue, Color.white
//            });
        }

        rawImage.materialForRendering.SetInt(IslandIndex, 0);

        InvokeRepeating(nameof(IncreaseIslandIndex), 5.0f, 0.01f);
    }
コード例 #2
0
ファイル: PaletteButtonGroup.cs プロジェクト: gasbank/black
    public void CreatePalette(StageData inStageData)
    {
        DestroyAllPaletteButtons();

        var colorUintArray = inStageData.CreateColorUintArray();
        var paletteIndex   = 0;

        paletteButtonList.Clear();
        foreach (var colorUint in colorUintArray)
        {
            if ((colorUint & 0x00ffffff) == 0x00ffffff)
            {
                Debug.LogError("CRITICAL ERROR: Palette color cannot be WHITE!!!");
            }
            var paletteButton = Instantiate(paletteButtonPrefab, transform).GetComponent <PaletteButton>();
            paletteButton.SetColor(colorUint);
            paletteIndexbyColor[colorUint] = paletteIndex;
            paletteButton.ColorIndex       = paletteIndex + 1;
            paletteIndex++;
            paletteButtonList.Add(paletteButton);
        }

        // 첫 번째 팔레트 기본 선택 상태
        if (paletteButtonList.Count > 0)
        {
            paletteButtonList[0].Check = true;
        }

        stageData = inStageData;
    }
コード例 #3
0
    public void Initialize(StageMetadata stageMetadata)
    {
        // Material 인스턴스 런타임에 복제 생성한다.

        if (targetMeshRenderer != null)
        {
            targetMeshRenderer.material = Instantiate(targetMeshRenderer.material);
            targetMaterial = targetMeshRenderer.material;
        }

        if (targetRawImage != null)
        {
            targetRawImage.material = Instantiate(targetRawImage.material);
            targetMaterial          = targetRawImage.material;
        }

        if (targetMaterial == null)
        {
            Debug.LogError("Target material null");
            return;
        }

        var a1Tex = stageMetadata.A1Tex;
        var a2Tex = stageMetadata.A2Tex;

        targetMaterial.SetTexture(A1Tex, a1Tex);
        targetMaterial.SetTexture(A2Tex, a2Tex);

        using var stream = new MemoryStream(stageMetadata.RawStageData.bytes);
        var formatter = new BinaryFormatter();

        stageData = (StageData)formatter.Deserialize(stream);
        stream.Close();

        var colorUintArray =
            new[] { BlackConvert.GetC(new Color32(0, 0, 0, 255)) } // 팔레트의 0번째는 언제나 검은색으로, 아웃라인 전용으로 예약되어 있다.
        .Concat(stageData.CreateColorUintArray())
        .ToArray();

        if (colorUintArray.Length > 64)
        {
            Debug.LogError("Maximum palette size 64 exceeded.");
        }
        else
        {
            var paletteArray = colorUintArray.Select(BlackConvert.GetColor).ToArray();
            targetMaterial.SetColorArray(Palette, paletteArray);

            var     paletteTex = new Texture2D(64, 1, TextureFormat.RGBA32, false);
            Color[] paddedPaletteArray;
            if (paletteArray.Length < 64)
            {
                paddedPaletteArray = paletteArray.Concat(Enumerable.Repeat(Color.black, 64 - paletteArray.Length))
                                     .ToArray();
            }
            else
            {
                paddedPaletteArray = paletteArray;
            }

            paletteTex.SetPixels(paddedPaletteArray);
            paletteTex.filterMode = FilterMode.Point;
            paletteTex.wrapMode   = TextureWrapMode.Clamp;
            paletteTex.Apply();

            targetMaterial.SetTexture(PaletteTex, paletteTex);
        }

        ClearAndEnqueueIslandIndex(0);

        targetMaterial.SetFloat(FullRender, fullRender ? 1 : 0);

        if (targetImageQuadCamera != null)
        {
            targetImageQuadCamera.ClearCameraOnce();
        }
    }