Can't access an class enum outside my class....why?

In one script class I have this:

public class PatternManager : MonoBehaviour
{
    private int m_nMax = 5;
    private int m_nColRowStart = 0;
    private bool m_bChangePattern = true;
    private float m_fDeltaTime = 0.0f;

    public enum enPattern {NONE, CORNERS, X, ROWS, COLS, FULL};

In another script class I am trying to re-use that enum like this:

publicclassSaveButtonManager:MonoBehaviour
{
     publicSpritem_spritePressed,m_spriteUnpressed;
     publicGameObjectm_gameobjPatternManager,m_gameobjOptions,m_gameobjBingo;

     //private enumenPattern{NONE,CORNERS,X,ROWS,COLS,FULL};
     //private enPatternm_enPattern=enPattern.NONE;
     private m_gameobjPatternManager.enPattern m_enPattern;

Except that m_gameobjPatternManager.enPattern is highlighted in red which means that monodevelop aint happy.

So is there anyway that I can make this work?

I tried multiple inheritance but Unity/Monodevelope does not like that either…at least not on Monobehaviour classes.

I would prefer not to have to re-define the same enum in all the script classes in which I wish to use it!

So the enum “enPattern” does not belong to an instance of PatternManager because it is part of the class definition, not an actual thing that takes up memory for each instance.

You should be able to do it by using the class name instead.

private PatternManager.enPattern m_enPattern; // Gives an instance of PatternManager a place to store the enum defined in the PatternManager class definition.

On further reading it appears you are supposed to create a seperate cs file and put the enum in there like this:

public enum PatternEnum
{
    NONE,
    CORNERS,
    X,
    ROWS,
    COLS,
    FULL
}

And then do this:

public class PatternManager : MonoBehaviour
{
    private int m_nMax = 5;
    private int m_nColRowStart = 0;
    private bool m_bChangePattern = true;
    private float m_fDeltaTime = 0.0f;

    private PatternEnum m_enPattern = PatternEnum.NONE;

That seems to work in monodevelop at least but when I go back to unity their are compile errors:
Assets/PatternManager/PatternManager.cs(3,7): error CS0138: `PatternEnum’ is a type not a namespace. A using namespace directive can only be applied to namespaces

So " using PatternEnum;" is not the correct way of ‘including’ PatternEnum.cs.

How do you do it?

C++ ‘include’ does not appear to be a key word in Unity C#.

Your PatternEnum.cs does not declare a namespace. That means, your PatternEnum is part of the global namespace and is automatically “used”; no using keyword needed. It’s namespace is really global:: PatternEnum, but no need to put “using global;” since that is automatic for everything.

Just remove the “using PatternEnum;

You can also define several things in one file - so your PatternEnum can be next to your PatternManager:

public class PatternManager { 
    ...
}

public enum PatternEnum {
    ...
}

If that’s a good idea or not is another matter entirely.

What you did the first time around made your PatternEnum into a nested enum. You can also nest classes and interfaces and whatnot:

public class Foo {
    
    //Refered to as Foo.Bar outside of Foo
    public class Bar {

    }
    
    //Foo.MyEnum outside of Foo
    public enum MyEnum {

    }

    //Foo.ISomething
    public interface ISomething {

    }
}

Generally do this only for things that are directly tied to the class you’re nesting them in.