protected override void BuidUI() { m_txtFps = this.MainGO.FindChildComponentRecursive <Text>("txtFps"); RectTransform rectTrans = this.MainGO.FindChildComponentRecursive <RectTransform>("JoystickRect"); m_cBaseTrans = this.MainGO.FindChildComponentRecursive <RectTransform>("JoystickBase"); m_cMoveTrans = this.MainGO.FindChildComponentRecursive <RectTransform>("JoystickMove"); m_cBtnSkillTest = this.MainGO.FindChildRecursive("btnSkillTest"); GameObject joystickGO = this.MainGO.FindChildRecursive("Joystick"); m_cJoystick = joystickGO.AddComponentOnce <UIJoystick>(); m_cJoystick.Init(rectTrans, m_cBaseTrans, m_cMoveTrans, m_cBaseTrans.rect.width / 2f, true); minDirLen = m_cBaseTrans.rect.width * 0.1f; m_cJoystick.OnBegin += OnJoystickBegin; m_cJoystick.OnMove += OnJoystickMove; m_cJoystick.OnEnd += OnJoystickEnd; m_cJoystick.AddKeyCode(KeyCode.A, Vector2.left); m_cJoystick.AddKeyCode(KeyCode.D, Vector2.right); m_cJoystick.AddKeyCode(KeyCode.W, Vector2.up); m_cJoystick.AddKeyCode(KeyCode.S, Vector2.down); //m_cJoystick.enabled = false; SetJoystickActive(false); UIEventTrigger.Get(m_cBtnSkillTest).AddListener(EventTriggerType.PointerClick, OnClick); //TouchDispatcher.instance.touchBeganListeners += OnTouch; }
void InitSingleton() { gameObject.AddComponentOnce <ConsoleLogger>(); gameObject.AddComponentOnce <ResourceSys>(); bool directLoadMode = true; #if !UNITY_EDITOR || BUNDLE_MODE directLoadMode = false; #endif ResourceSys.Instance.Init(directLoadMode, "Assets/ResourceEx"); gameObject.AddComponentOnce <UpdateScheduler>(); gameObject.AddComponentOnce <TouchDispatcher>(); //初始化对象池 GameObject goPool = new GameObject(); goPool.name = "GameObjectPool"; GameObject.DontDestroyOnLoad(goPool); goPool.AddComponentOnce <ResourceObjectPool>(); goPool.AddComponentOnce <PrefabPool>(); goPool.AddComponentOnce <BattleResPool>(); goPool.AddComponentOnce <BattleEffectPool>(); GameObject uiGO = GameObject.Find("UIRoot/Views").gameObject; GameObject.DontDestroyOnLoad(uiGO); uiGO.AddComponentOnce <ViewSys>(); gameObject.AddComponentOnce <FPSMono>(); ResetObjectPool <List <int> > .Instance.Init(4, (List <int> lst) => { lst.Clear(); }); ResetObjectPool <HashSet <Vector2Int> > .Instance.Init(10, (HashSet <Vector2Int> lst) => { lst.Clear(); }); ResetObjectPool <List <DataComponent> > .Instance.Init(10, (List <DataComponent> lst) => { lst.Clear(); }); ResetObjectPool <HashSet <Entity> > .Instance.Init(10, (HashSet <Entity> lst) => { lst.Clear(); }); ResetObjectPool <Dictionary <int, int> > .Instance.Init(5, (Dictionary <int, int> dic) => { dic.Clear(); }); }
//初始化所有单例 protected void InitSingleton() { gameObject.AddComponentOnce <NetSys>(); if (netMode == GameNetMode.Network) { NetSys.Instance.CreateChannel(NetChannelType.Game, NetChannelModeType.Tcp); } else if (netMode == GameNetMode.StandAlone) { NetSys.Instance.CreateChannel(NetChannelType.Game, NetChannelModeType.StandAlone); gameObject.AddComponentOnce <ClientServer>(); ClientServer.Instance.StartServer(); } gameObject.AddComponentOnce <FrameSyncSys>(); gameObject.AddComponentOnce <ResourceSys>(); ResourceSys.Instance.Init(true, "Assets/ResourceEx"); gameObject.AddComponentOnce <UpdateScheduler>(); gameObject.AddComponentOnce <TouchDispatcher>(); //初始化对象池 GameObject goPool = new GameObject(); goPool.name = "GameObjectPool"; GameObject.DontDestroyOnLoad(goPool); goPool.AddComponentOnce <GameObjectPool>(); //初始化特效池 GameObject sceneEffectPool = new GameObject(); sceneEffectPool.name = "SceneEffectPool"; GameObject.DontDestroyOnLoad(sceneEffectPool); sceneEffectPool.AddComponentOnce <SceneEffectPool>(); GameObject uiEffectPool = new GameObject(); uiEffectPool.name = "UIEffectPool"; GameObject.DontDestroyOnLoad(uiEffectPool); uiEffectPool.AddComponentOnce <UIEffectPool>(); GameObject uiGO = transform.Find("UIContainer").gameObject; uiGO.AddComponentOnce <ViewSys>(); gameObject.AddComponentOnce <FPSMono>(); }