Created
June 10, 2016 19:42
-
-
Save ShirakawaYoshimaru/fa6121e645ca08ce825e836555f181f9 to your computer and use it in GitHub Desktop.
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
using UnityEngine; | |
using UnityEngine.UI; | |
using System; | |
//使い方 | |
public class TestScript : MonoBehaviour | |
{ | |
void Start () | |
{ | |
Decoratable cake = new CreamDecorator (new ChocoDecorator (new CakeDecorator (new Cake ("スススススス")))); | |
cake.Show (); | |
} | |
} | |
//デコレーションできるようにする | |
public abstract class Decoratable | |
{ | |
public abstract string GetItem (); | |
public void Show () | |
{ | |
Debug.Log (GetItem ()); | |
} | |
} | |
//ベースとなるもの | |
public class Cake : Decoratable | |
{ | |
string baseCake; | |
public Cake (string baseCake) | |
{ | |
this.baseCake = baseCake; | |
} | |
public override string GetItem () | |
{ | |
return baseCake; | |
} | |
} | |
//デコレーションするやつ。チョコ塗ってくれる | |
public class ChocoDecorator : Decoratable | |
{ | |
Decoratable decoratable; | |
public ChocoDecorator (Decoratable decorable) | |
{ | |
this.decoratable = decorable; | |
} | |
public override string GetItem () | |
{ | |
return "黒黒黒黒黒黒\n" + decoratable.GetItem () + "\n黒黒黒黒黒黒"; | |
} | |
} | |
//デコレーションするやつ。苺塗ってくれる | |
public class CakeDecorator : Decoratable | |
{ | |
Decoratable decoratable; | |
public CakeDecorator (Decoratable decorable) | |
{ | |
this.decoratable = decorable; | |
} | |
public override string GetItem () | |
{ | |
return "苺苺苺苺苺苺\n" + decoratable.GetItem (); | |
} | |
} | |
//デコレーションするやつ。生クリーム塗ってくれる | |
public class CreamDecorator : Decoratable | |
{ | |
Decoratable decoratable; | |
public CreamDecorator (Decoratable decorable) | |
{ | |
this.decoratable = decorable; | |
} | |
public override string GetItem () | |
{ | |
return "生生生生生生\n" + decoratable.GetItem (); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment