Created
March 25, 2014 16:34
-
-
Save takashicompany/9765792 to your computer and use it in GitHub Desktop.
Unityでシーン内のGameObjectの共通化をInterfaceで行った例。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 共通化のインターフェース | |
public interface IMyButton | |
{ | |
void Press (); | |
} | |
// IMyButtonを実装したクラス | |
public class StartButton : MonoBehaviour, IMyButton | |
{ | |
public void Press () | |
{ | |
// Press Function... | |
} | |
} | |
// IMyButtonを実装したクラス | |
public class SelectButton : MonoBehaviour, IMyButton | |
{ | |
public void Press () | |
{ | |
// Press Function... | |
} | |
} | |
public class View : MonoBahaviour | |
{ | |
public IMyButton startButton; | |
public IMyButton selectButton; | |
void Awake () | |
{ | |
// IMyButtonインターフェースはMonoBehaviourとは何も関係がないため、 | |
// gameObjectのプロパティがないため、コンパイルエラーが起きる。 | |
startButton.gameObject.SetActive(false); | |
selectButton.gameObject.SetActive(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment