// Start is called before the first frame update void Start() { mode = PlayerPrefs.GetInt("difficulty"); if (mode == (int)Difficulty.difficulty.hard) { amountCreators = 5; creator1 = Instantiate(creator, new Vector3(0f, 7f, 0f), Quaternion.identity); creator2 = Instantiate(creator, new Vector3(1.15f, 7f, 0f), Quaternion.identity); creator3 = Instantiate(creator, new Vector3(-1.15f, 7f, 0f), Quaternion.identity); creator4 = Instantiate(creator, new Vector3(2.4f, 7f, 0f), Quaternion.identity); creator5 = Instantiate(creator, new Vector3(-2.4f, 7f, 0f), Quaternion.identity); InvokeRepeating("SetLetters", 1f, 4f); } else if (mode == (int)Difficulty.difficulty.medium) { amountCreators = 4; creator1 = Instantiate(creator, new Vector3(.667f, 7f, 0f), Quaternion.identity); creator2 = Instantiate(creator, new Vector3(-.667f, 7f, 0f), Quaternion.identity); creator3 = Instantiate(creator, new Vector3(2f, 7f, 0f), Quaternion.identity); creator4 = Instantiate(creator, new Vector3(-2f, 7f, 0f), Quaternion.identity); InvokeRepeating("SetLetters", 1f, 5f); } else { amountCreators = 3; creator1 = Instantiate(creator, new Vector3(0f, 7f, 0f), Quaternion.identity); creator2 = Instantiate(creator, new Vector3(2f, 7f, 0f), Quaternion.identity); creator3 = Instantiate(creator, new Vector3(-2f, 7f, 0f), Quaternion.identity); InvokeRepeating("SetLetters", 1f, 7f); } }
public void ShowSample() { var objectCreatedByFactoryMethod = Creator1.FactoryMethod(); var otherMethodResult = new Creator1().OtherStuff(); Console.WriteLine($"FactoryMethod owner can have other methods: {otherMethodResult}"); }
// Start is called before the first frame update void Start() { numberAudio = GetComponent <AudioSource>(); mode = PlayerPrefs.GetInt("difficulty"); type = PlayerPrefs.GetInt("operation"); if (mode == (int)Difficulty.difficulty.hard) { amountCreators = 5; creator1 = Instantiate(creator, new Vector3(0f, 7f, 0f), Quaternion.identity); creator2 = Instantiate(creator, new Vector3(1.15f, 7f, 0f), Quaternion.identity); creator3 = Instantiate(creator, new Vector3(-1.15f, 7f, 0f), Quaternion.identity); creator4 = Instantiate(creator, new Vector3(2.4f, 7f, 0f), Quaternion.identity); creator5 = Instantiate(creator, new Vector3(-2.4f, 7f, 0f), Quaternion.identity); InvokeRepeating("SetNumbers", 1f, 4f); } else if (mode == (int)Difficulty.difficulty.medium) { amountCreators = 4; creator1 = Instantiate(creator, new Vector3(.667f, 7f, 0f), Quaternion.identity); creator2 = Instantiate(creator, new Vector3(-.667f, 7f, 0f), Quaternion.identity); creator3 = Instantiate(creator, new Vector3(2f, 7f, 0f), Quaternion.identity); creator4 = Instantiate(creator, new Vector3(-2f, 7f, 0f), Quaternion.identity); InvokeRepeating("SetNumbers", 1f, 5f); } else { amountCreators = 3; creator1 = Instantiate(creator, new Vector3(0f, 7f, 0f), Quaternion.identity); creator2 = Instantiate(creator, new Vector3(2f, 7f, 0f), Quaternion.identity); creator3 = Instantiate(creator, new Vector3(-2f, 7f, 0f), Quaternion.identity); InvokeRepeating("SetNumbers", 1f, 7f); } }
public static void Main(String[] args) { //定义出两个工厂 AbstractCreator creator1 = new Creator1(); AbstractCreator creator2 = new Creator2(); //产生A1对象 AbstractProductA a1 = creator1.CreateProductA(); //产生A2对象 AbstractProductA a2 = creator2.CreateProductA(); //产生B1对象 AbstractProductB b1 = creator1.CreateProductB(); //产生B2对象 AbstractProductB b2 = creator2.CreateProductB(); a1.DoSomething(); a2.DoSomething(); b1.DoSomething(); b2.DoSomething(); /* * 然后在这里就可以为所欲为了... */ }