General function for facilities in Unity



  • I've got a few facilities set up on the stage, they're wearing the same violin. This violin has a function of func(). I need this function at every facility to be different. Can this be realized without imposing new violets?



  • You need to use a patter design under the title. http://metanit.com/sharp/patterns/3.1.php ♪

    Example:

    public interface IStrategy
    {
        void Algorithm();
    }
    

    public class ConcreteStrategy1 : IStrategy
    {
    public void Algorithm()
    {}
    }

    public class ConcreteStrategy2 : IStrategy
    {
    public void Algorithm()
    {}
    }

    public class Context
    {
    public IStrategy ContextStrategy { get; set; }

    public Context(IStrategy _strategy)
    {
        ContextStrategy = _strategy;
    }
    
    public void ExecuteAlgorithm()
    {
        ContextStrategy.Algorithm();
    }
    

    }

    The principles of C# in Unity3d are different, so you're going to have to use some of the other stuff, namely, inherit the Context from the other. MonoBehaviour and assign strategies through the facility inspector.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2