简体   繁体   中英

Compiler is refusing to compile correct code in Unity3d C#

I just added an integer argument to a function definition and added an integer to the only instance where the function is called. an error is generated:

CustomShaderEditor.cs(44,46): error CS1501: No overload for method UpdateTexture' takes 0' arguments

I don't know how to cope with an error of this kind, I would love some advice.

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;
    }   




}

UpdateTexture( i ); //'=-='error is for this line

This is not the problem with your code. There is a problem somewhere else. Make sure to save the new code and see whether your old code is still the one being used instead of the new code. Also re-start Unity. If these fails, dump your whole code here for further help because what you have now is NOT the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM