Esempio n. 1
0
    public XUIMidMsgAnimator PoolGet()
    {
        XUIMidMsgAnimator msgInstance = null;

        if (m_MsgTempllatePool.Count > 0)
        {
            msgInstance = m_MsgTempllatePool.Pop();
        }

        if (msgInstance == null)
        {
            GameObject newGameObj = GameObject.Instantiate(MsgTemplate) as GameObject;
            msgInstance = newGameObj.GetComponent <XUIMidMsgAnimator>();
            if (msgInstance == null)
            {
                msgInstance = newGameObj.AddComponent <XUIMidMsgAnimator>();
            }
            msgInstance.transform.SetParent(this.transform);
            msgInstance.UICtrler = this;
        }

        KTool.ResetLocalTransform(msgInstance.transform);
        msgInstance.gameObject.SetActive(true);

        return(msgInstance);
    }
Esempio n. 2
0
        public static void CreateNewUI()
        {
#if UNITY_5 || UNITY_2017_1_OR_NEWER
            var currentScene = EditorSceneManager.GetActiveScene().path;
#else
            var currentScene = EditorApplication.currentScene;
#endif
            GameObject mainCamera = GameObject.Find("Main Camera");
            if (mainCamera != null)
            {
                GameObject.DestroyImmediate(mainCamera);
            }

            var uiName = Path.GetFileNameWithoutExtension(currentScene);
            if (String.IsNullOrEmpty(uiName) || GameObject.Find(uiName) != null) // default use scene name, if exist create random name
            {
                uiName = "NewUI_" + Path.GetRandomFileName();
            }
            GameObject uiObj = new GameObject(uiName);
            uiObj.layer = (int)UnityLayerDef.UI;
            uiObj.AddComponent <UIWindowAsset>();

            var uiPanel = new GameObject("Image").AddComponent <Image>();
            uiPanel.transform.parent = uiObj.transform;
            KTool.ResetLocalTransform(uiPanel.transform);

            var canvas = uiObj.AddComponent <Canvas>();
            canvas.renderMode = RenderMode.ScreenSpaceOverlay;
            uiObj.AddComponent <CanvasScaler>();
            uiObj.AddComponent <GraphicRaycaster>();

            if (GameObject.Find("EventSystem") == null)
            {
                var evtSystemObj = new GameObject("EventSystem");
                evtSystemObj.AddComponent <EventSystem>();
                evtSystemObj.AddComponent <StandaloneInputModule>();
#if UNITY_4
                evtSystemObj.AddComponent <TouchInputModule>();
#endif
            }

            if (GameObject.Find("Camera") == null)
            {
                GameObject cameraObj = new GameObject("Camera");
                cameraObj.layer = (int)UnityLayerDef.UI;

                Camera camera = cameraObj.AddComponent <Camera>();
                camera.clearFlags       = CameraClearFlags.Skybox;
                camera.depth            = 0;
                camera.backgroundColor  = Color.grey;
                camera.cullingMask      = 1 << (int)UnityLayerDef.UI;
                camera.orthographicSize = 1f;
                camera.orthographic     = true;
                camera.nearClipPlane    = -2f;
                camera.farClipPlane     = 2f;

                camera.gameObject.AddComponent <AudioListener>();
            }

            Selection.activeGameObject = uiObj;
        }
Esempio n. 3
0
        public static void CreateNewUI()
        {
#if UNITY_5_3_OR_NEWER
            var currentScene = EditorSceneManager.GetActiveScene().path;
#else
            var currentScene = EditorApplication.currentScene;
#endif
            GameObject mainCamera = GameObject.Find("Main Camera");
            if (mainCamera != null)
            {
                GameObject.DestroyImmediate(mainCamera);
            }

            var uiName = Path.GetFileNameWithoutExtension(currentScene);
            if (String.IsNullOrEmpty(uiName) || GameObject.Find(uiName) != null) // default use scene name, if exist create random name
            {
                uiName = "NewUI_" + Path.GetRandomFileName();
            }
            GameObject uiObj = new GameObject(uiName);
            uiObj.layer = (int)UnityLayerDef.UI;
            uiObj.AddComponent <UIWindowAsset>();

            var uiPanel = new GameObject("Image").AddComponent <Image>();
            uiPanel.transform.parent = uiObj.transform;
            KTool.ResetLocalTransform(uiPanel.transform);

            var canvas = uiObj.AddComponent <Canvas>();
            canvas.renderMode = RenderMode.ScreenSpaceOverlay;
            CanvasScaler canvasScaler = uiObj.AddComponent <CanvasScaler>();
            uiObj.AddComponent <GraphicRaycaster>();
            //NOTE canvas的分辨率读取AppEngine的设置
            var uiSize       = new Vector2(1280, 720);
            var uiResolution = AppEngine.GetConfig("KEngine.UI", "UIResolution");
            if (!string.IsNullOrEmpty(uiResolution))
            {
                var sizeArr = uiResolution.Split(',');
                if (sizeArr.Length >= 2)
                {
                    uiSize = new Vector2(sizeArr[0].ToInt32(), sizeArr[1].ToInt32());
                }
            }
            canvasScaler.uiScaleMode         = CanvasScaler.ScaleMode.ScaleWithScreenSize;
            canvasScaler.referenceResolution = uiSize;
            canvasScaler.screenMatchMode     = CanvasScaler.ScreenMatchMode.Expand;

            if (GameObject.Find("EventSystem") == null)
            {
                var evtSystemObj = new GameObject("EventSystem");
                evtSystemObj.AddComponent <EventSystem>();
                evtSystemObj.AddComponent <StandaloneInputModule>();
#if !UNITY_5_3_OR_NEWER
                evtSystemObj.AddComponent <TouchInputModule>();
#endif
            }

            if (GameObject.Find("Camera") == null)
            {
                GameObject cameraObj = new GameObject("Camera");
                cameraObj.layer = (int)UnityLayerDef.UI;

                Camera camera = cameraObj.AddComponent <Camera>();
                camera.clearFlags       = CameraClearFlags.Skybox;
                camera.depth            = 0;
                camera.backgroundColor  = Color.grey;
                camera.cullingMask      = 1 << (int)UnityLayerDef.UI;
                camera.orthographicSize = 1f;
                camera.orthographic     = true;
                camera.nearClipPlane    = -2f;
                camera.farClipPlane     = 2f;

                camera.gameObject.AddComponent <AudioListener>();
            }

            Selection.activeGameObject = uiObj;
        }
Esempio n. 4
0
        public static void CreateNewUI(PanelType panelType)
        {
#if UNITY_5 || UNITY_2017_1_OR_NEWER
            var currentScene = EditorSceneManager.GetActiveScene().path;
#else
            var currentScene = EditorApplication.currentScene;
#endif
            GameObject mainCamera = GameObject.Find("Main Camera");
            if (mainCamera != null)
            {
                GameObject.DestroyImmediate(mainCamera);
            }

            var uiName = Path.GetFileNameWithoutExtension(currentScene);
            if (string.IsNullOrEmpty(uiName) || GameObject.Find(uiName) != null) // default use scene name, if exist create random name
            {
                uiName = "UI" + Path.GetRandomFileName();
            }

            GameObject uiObj = new GameObject(uiName);
            uiObj.layer = (int)UnityLayerDef.UI;
            var windowAsset = uiObj.AddComponent <UIWindowAsset>();
            windowAsset.IsUIEditor = true;
            windowAsset.PanelType  = panelType;
            if (panelType != PanelType.NormalUI)
            {
                windowAsset.MoneyBar     = MoneyBarType.None;
                windowAsset.IsShowTabBar = false;
                windowAsset.TabBarId     = 0;
            }

            var uiPanel = new GameObject("Image").AddComponent <Image>();
            uiPanel.transform.SetParent(uiObj.transform);
            KTool.ResetLocalTransform(uiPanel.transform);

            var canvas = uiObj.AddComponent <Canvas>();
            canvas.renderMode = RenderMode.ScreenSpaceCamera;
            CanvasScaler canvasScaler = uiObj.AddComponent <CanvasScaler>();
            uiObj.AddComponent <GraphicRaycaster>();

            canvasScaler.uiScaleMode         = CanvasScaler.ScaleMode.ScaleWithScreenSize;
            canvasScaler.referenceResolution = AppConfig.UIResolution;
            canvasScaler.screenMatchMode     = CanvasScaler.ScreenMatchMode.Expand;

            if (GameObject.Find("EventSystem") == null)
            {
                var evtSystemObj = new GameObject("EventSystem");
                evtSystemObj.AddComponent <EventSystem>();
                evtSystemObj.AddComponent <StandaloneInputModule>();
#if UNITY_4
                evtSystemObj.AddComponent <TouchInputModule>();
#endif
            }

            Camera camera;
            var    go = GameObject.Find("UICamera");
            if (go == null)
            {
                GameObject cameraObj = new GameObject("UICamera");
                cameraObj.layer = (int)UnityLayerDef.UI;

                camera                  = cameraObj.AddComponent <Camera>();
                camera.clearFlags       = CameraClearFlags.Skybox;
                camera.depth            = 0;
                camera.backgroundColor  = Color.grey;
                camera.cullingMask      = 1 << (int)UnityLayerDef.UI;
                camera.orthographicSize = 1f;
                camera.orthographic     = true;
                camera.nearClipPlane    = 0.3f;
                camera.farClipPlane     = 1000f;

                camera.gameObject.AddComponent <AudioListener>();
            }
            else
            {
                camera = go.GetComponent <Camera>();
            }

            canvas.worldCamera         = camera;
            Selection.activeGameObject = uiObj;
        }