public class StartGameCommand : Command{[Inject]public IGameTimer timer{get;set;}[Inject(ContextKeys.CONTEXT_VIEW)]public GameObject contextView { get; set; }public override void Execute(){timer.Start();GameObject go = new GameObject();go.name = "ShipView";go.AddComponent<ShipView>();go.transform.parent = contextView.transform;go = new GameObject();go.name = "EnemyView";go.AddComponent<EnemyView>();go.transform.parent = contextView.transform;}}
GameObject latestGO;internal void init(){latestGO = Instantiate(Resources.Load("ship")) as GameObject;GameObject go = latestGO;go.name = "ship";go.transform.parent = gameObject.transform;go.AddComponent<ClickDetector>();ClickDetector clicker = go.GetComponent<ClickDetector>() as ClickDetector;clicker.dispatcher.AddListener(ClickDetector.CLICK, onClick);}



原文:http://www.cnblogs.com/klk321123/p/7094228.html