Use of Unity interface

I have always felt that the interface is a very deep thing, so I have never understood it, but I think it is very useful, such as IPointerEnterHandler interfaces, as long as they are implemented in the class, they can monitor the information. So research it today.
I checked the API of C# . Its interface is to create an interface, inherit it in the class, then instantiate the class and call the interface, but it is not the effect I want. The specific examples are as follows:

interface ISampleInterface
{
    
    
    void SampleMethod();
}

class ImplementationClass : ISampleInterface
{
    
    
    // Explicit interface member implementation:
    void ISampleInterface.SampleMethod()
    {
    
    
        // Method implementation.
    }

    static void Main()
    {
    
    
        // Declare an interface instance.
        ISampleInterface obj = new ImplementationClass();

        // Call the member.
        obj.SampleMethod();
    }
}

Then I found the interface about unity. One is to create the interface, and then the class inherits the interface. When using it, get all the components of the inherited class, and then call it uniformly. This is not the effect I want. Refer to the link .
Another way is to declare the interface in the class and then call the interface, which is very similar to the method I want, instance connection .
After checking, the idea is clearer, but it is not the effect I want. The general method should be the first method. The interface of unity should be encapsulated internally, so I can't find the place to call it.
If there is a good implementation method, you can also write it out and discuss it together.

Guess you like

Origin blog.csdn.net/qq_39353597/article/details/123518698