Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Levels cannot load directly in unity #175

Open
thegsm opened this issue Feb 28, 2014 · 6 comments
Open

Levels cannot load directly in unity #175

thegsm opened this issue Feb 28, 2014 · 6 comments

Comments

@thegsm
Copy link
Contributor

thegsm commented Feb 28, 2014

Issue #171 works but it means it cannot be launched directly. A solution to detect whether setup was called and call if necessary can be useful for local debugging.

@elneilios
Copy link
Contributor

We can achieve this using OOP. Create a base class that any script that requires incontrol inherits from. Base class has a static boolean variable setupCalled. Base class calls Setup if setupCalled is false and sets it to true so it is only ever called once.

@thegsm
Copy link
Contributor Author

thegsm commented Mar 1, 2014

I agree on OOP, usually the approach for single initialization is the singleton Design Pattern. It's very similar to what you wrote. A class with static member and static property for the instance, so you call that class to get the instance, and on the first call it calls setup.
Inheritance is indeed useful if we have more than one class that uses it. So if there's a different script for levels, such as title and level, yes, that's the way to go.

@bobsayshilol
Copy link
Contributor

I have a way of determining if you have loaded into the level directly or from the main menu:
//"main" doesn't exist if debugin if(GameObject.Find("main")) { // we came from the main menu else // we didn't }
It's a very hacky fix, so lets hope that no-one renames the main thing

@thegsm
Copy link
Contributor Author

thegsm commented Mar 3, 2014

Yeah, I don't like hacks. Why is it necessary when we can simply have a singleton object?
It's a very simple design pattern
Check this out for an implementation in Unity http://wiki.unity3d.com/index.php/Toolbox

@bobsayshilol
Copy link
Contributor

Oh that was just a quick-fix for when I was debugin - I hope there'll be a better way implemented (like what you posted)

@Cheeseness
Copy link
Contributor

I suggested that @bobsayshilol post his approach so as to have some record what was being used where and what would need replacing/updating when refactoring was happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants