簡體   English   中英

編譯器拒絕在 Unity3d C# 中編譯正確的代碼

[英]Compiler is refusing to compile correct code in Unity3d C#

我剛剛在函數定義中添加了一個整數參數,並在調用該函數的唯一實例中添加了一個整數。 產生一個錯誤:

CustomShaderEditor.cs(44,46):錯誤 CS1501:方法UpdateTexture' takes沒有重載, UpdateTexture' takes 0 個參數

我不知道如何處理這種錯誤,我希望得到一些建議。

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System;

public class CustomShader : MonoBehaviour 
{

    public int numTiles = 10;
    public GameObject RenderGameObject;
    public GameObject[] gamObjectClones;    
    public Texture2D ComputeTexture;    
    public ComputeShader ComputeShader; 
    ComputeBuffer wavBuffer ;
    ComputeBuffer computeBuffer ;

    void Start () 
    {
        ResetTexture();
        gamObjectClones = new GameObject[numTiles];
        for (int i=0; i<numTiles; i++)
        {
            gamObjectClones[i] = (GameObject)Instantiate(RenderGameObject, new Vector3(i * 10.0f, 0, 0), Quaternion.identity);
        }

    }

    void Update ()  
    {
        RefreshComputeShaderMaterial();
    }   

    public void RefreshComputeShaderMaterial()
    {       
        for (int i=0; i<numTiles; i++)
        {

            UpdateTexture(  10 );           


            Material m = gamObjectClones[i].GetComponent<Renderer>().sharedMaterial;

            if (m.HasProperty("_DataTexture"))
            {
                m.SetTexture("_DataTexture", ComputeTexture);
            }
        }   
    }

    public void ResetTexture()
    {
        int BufferSize = ComputeTexture.width * ComputeTexture.height;
        Color[] ColorBuffer = new Color[BufferSize];
        ComputeTexture.SetPixels(ColorBuffer);
        ComputeTexture.Apply();
    }

    public void SetupTexture()
    {
        int BufferSize = ComputeTexture.width * ComputeTexture.height;
        Color[] ColorBuffer = ComputeTexture.GetPixels();

        for (int i=0; i<BufferSize; i++)
        {
            if ((i&31)==31)
            {
                ColorBuffer[i] = Color.white;
            }
        }

        ComputeTexture.SetPixels(ColorBuffer);
        ComputeTexture.Apply();
    }   

    public void UpdateTexture( int tile )
    {
        int csi;
        csi = ComputeShader.FindKernel("computeGameOfLife");

        if (csi>-1)
        {
            var ran = UnityEngine.Random.Range(1f,100f);

            int BufferSize = ComputeTexture.width * ComputeTexture.height;
            Vector4[] TextureBuffer = new Vector4[BufferSize];
            Color  [] ColorBuffer   = ComputeTexture.GetPixels();

            for (int i=0; i<BufferSize; i++)
            {
                TextureBuffer[i].x = 0;//Mathf.Sin(i/10f);
                TextureBuffer[i].y = 0;
                TextureBuffer[i].z = 0;
                TextureBuffer[i].w = 0;
            }

            computeBuffer = new ComputeBuffer(BufferSize, sizeof(float) * 4);
            computeBuffer.SetData(TextureBuffer);
            ComputeShader.SetBuffer(csi, "DataTexture", computeBuffer);

            //////////////////// patch
            int sBufferSize = 88000 ;
            float[] sTextureBuffer = new float[sBufferSize] ;

            for (int i = 0 ; i < sBufferSize ; i++)
            {
                sTextureBuffer[ i ] = Mathf.Sin( i / ran + 20*Mathf.Sin(i/1000)  ) ;
            }

            ReleaseBuffers();
            print( " sin " + sTextureBuffer[23]);
            wavBuffer = new ComputeBuffer(sBufferSize, sizeof(float)  ) ;
            wavBuffer.SetData(sTextureBuffer);
            ComputeShader.SetBuffer(csi, "re", wavBuffer) ;
             //wavBuffer.Release() ;
            /////////////////////

            ComputeShader.Dispatch(csi, 1, 1, 1);           
            computeBuffer.GetData (TextureBuffer);
            computeBuffer.Release();

            for (int i=0; i<BufferSize; i++)
            {
                ColorBuffer[i].r = TextureBuffer[i].x;
                ColorBuffer[i].g = TextureBuffer[i].y;
                ColorBuffer[i].b = TextureBuffer[i].z;
                ColorBuffer[i].a = TextureBuffer[i].w;
            }

            ComputeTexture.SetPixels(ColorBuffer);
            ComputeTexture.Apply();
        }
    }

    public void ReleaseBuffers() {
        if (wavBuffer != null) wavBuffer.Release();
        wavBuffer = null;
    }   




}

更新紋理( i ); //'=='錯誤是針對這一行的

這不是您的代碼的問題。 別的地方有問題。 確保保存新代碼並查看您的舊代碼是否仍然是正在使用的代碼而不是新代碼。 也重新啟動Unity。 如果這些失敗,請將您的整個代碼轉儲到此處以獲得進一步幫助,因為您現在擁有的不是問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM