Skip to content

Instantly share code, notes, and snippets.

@ShirakawaYoshimaru
Created June 10, 2016 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShirakawaYoshimaru/fa6121e645ca08ce825e836555f181f9 to your computer and use it in GitHub Desktop.
Save ShirakawaYoshimaru/fa6121e645ca08ce825e836555f181f9 to your computer and use it in GitHub Desktop.
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