private void Awake() { if (this.Root == null) { this.Root = this.GetComponent<UIRoot>(); } }
/// <summary> /// Get references to the various UI panels /// </summary> public void Initialize() { planetMenu = GameObject.FindGameObjectWithTag("PlanetMenu").GetComponent<PlanetMenuControls>(); shipDisplay = GameObject.FindGameObjectWithTag("ShipHUD").GetComponent<ShipHUDControls>(); uiRoot = GameObject.FindWithTag("UIRoot").GetComponent<UIRoot>(); labelPool = GameObject.FindWithTag("LabelPool").GetComponent<LabelPool>(); }
// Use this for initialization void Start () { mRoot = NGUITools.FindInParents<UIRoot>(this.gameObject); Init(); for (int i = 0; i < Button_SkillTypeChoise.Length; i++) { UIEventListener.Get(Button_SkillTypeChoise[i]).onClick = SkillTypeChoise; } for (int i = 0; i < Button_SkillSelect.Length; i++) { UIEventListener.Get(Button_SkillSelect[i].transform.FindChild("Button").gameObject).onClick = SkillSelect; UIEventListener.Get(Button_SkillSelect[i].transform.FindChild("Button").gameObject).onDragStart = SkillSelectDragStart; UIEventListener.Get(Button_SkillSelect[i].transform.FindChild("Button").gameObject).onDrag = SkillSelectDraging; UIEventListener.Get(Button_SkillSelect[i].transform.FindChild("Button").gameObject).onDragEnd = SkillSelectDragEnd; } for (int i = 0; i < Button_OpenClose.Length; i++) { UIEventListener.Get(Button_OpenClose[i]).onClick = OpenClose; } UIEventListener.Get(Button_HideShow).onClick = HideShow; UIEventListener.Get(Button_GoBack).onClick = GoBack; }
public void Initialize() { _panels = new List<PanelBase>(); Root = GameObject.Find("UI Root").GetComponent<UIRoot>(); Root.manualHeight = Screen.height; Root.manualWidth = Screen.width; UICamera = Root.transform.Find("UICamera").GetComponent<Camera>(); BarkPanel = UICamera.transform.Find("BarkPanel").GetComponent<BarkPanel>(); BarkPanel.Initialize(); HUDPanel = UICamera.transform.Find("HUDPanel").GetComponent<HUDPanel>(); HUDPanel.Initialize(); WindowPanel = UICamera.transform.Find("WindowPanel").GetComponent<WindowPanel>(); WindowPanel.Initialize(); DialoguePanel = UICamera.transform.Find("DialoguePanel").GetComponent<DialoguePanel>(); DialoguePanel.Initialize(); _panels.Add(DialoguePanel); _panels.Add(WindowPanel); _panels.Add(HUDPanel); _panels.Add(BarkPanel); UIStateMachine = new UIStateMachine(); UIStateMachine.Initialize(); }
private void Form_Load(object sender, EventArgs e) { { var camera = new Camera( new vec3(0, 0, 5), new vec3(), new vec3(0, 1, 0), CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height); var rotator = new SatelliteManipulater(); rotator.Bind(camera, this.glCanvas1); this.camera = camera; this.rotator = rotator; } { var simplexNoiseRenderer = new SimplexNoiseRenderer(); simplexNoiseRenderer.Name = string.Format("Pickable: [{0}]", "Sphere"); simplexNoiseRenderer.Initialize(); this.simplexNoiseRenderer = simplexNoiseRenderer; } { var UIRoot = new UIRoot(); UIRoot.Initialize(); this.uiRoot = UIRoot; var glAxis = new UIAxis(AnchorStyles.Right | AnchorStyles.Bottom, new Padding(3, 3, 3, 3), new Size(70, 70), -100, 100); glAxis.Initialize(); this.glAxis = glAxis; UIRoot.Children.Add(glAxis); } { var frmPropertyGrid = new FormProperyGrid(); frmPropertyGrid.DisplayObject(this.simplexNoiseRenderer); frmPropertyGrid.Show(); } }
private void Form_Load(object sender, EventArgs e) { { var camera = new Camera( new vec3(0, 0, 1), new vec3(0, 0, 0), new vec3(0, 1, 0), CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height); var rotator = new SatelliteManipulater(); rotator.Bind(camera, this.glCanvas1); this.camera = camera; this.rotator = rotator; } { var renderer = new AnalyzedPointSpriteRenderer(10000); renderer.Initialize(); this.renderer = renderer; } { var UIRoot = new UIRoot(); UIRoot.Initialize(); this.uiRoot = UIRoot; var glAxis = new UIAxis(AnchorStyles.Right | AnchorStyles.Bottom, new Padding(3, 3, 3, 3), new Size(70, 70), -100, 100); glAxis.Initialize(); this.glAxis = glAxis; UIRoot.Children.Add(glAxis); } { var frmPropertyGrid = new FormProperyGrid(); frmPropertyGrid.DisplayObject(this.renderer); frmPropertyGrid.Show(); this.formPropertyGrid = frmPropertyGrid; } }
private void AdjustSize() { if (this.uiRoot == null) { if (GameUIManager.mInstance != null && GameUIManager.mInstance.uiRoot != null) { this.uiRoot = GameUIManager.mInstance.uiRoot; } else { GameObject root = NGUITools.GetRoot(base.gameObject); if (root != null) { this.uiRoot = root.GetComponent<UIRoot>(); } } } if (this.uiRoot == null) { return; } base.transform.localScale /= this.oldScale; this.oldScale = 1f; int num = this.uiRoot.activeHeight * Screen.width / Screen.height; if (num < 1024) { float d = (float)num / 1024f; base.transform.localScale *= d; this.oldScale = d; } }
public void Awake() { Instance = this; _pool = new Queue<DamageNumber>(); _uiRoot = FindObjectOfType<UIRoot>(); WarmPool(); }
private void Awake() { mRoot = NGUITools.FindInParents<UIRoot>(transform); sprite = GetComponent<UISprite>(); cachedHeight = sprite.height; cachedWidth = sprite.width; cachedPos = transform.localPosition; }
private void OnEnable() { if (this.uiCamera == null) { this.uiCamera = NGUITools.FindCameraForLayer(base.gameObject.layer); } this.mRoot = NGUITools.FindInParents<UIRoot>(base.gameObject); }
/// <summary> /// Automatically find the camera responsible for drawing the widgets under this object. /// </summary> void Start () { mRoot = NGUITools.FindInParents<UIRoot>(gameObject); mIsWindows = (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsWebPlayer || Application.platform == RuntimePlatform.WindowsEditor); if (uiCamera == null) uiCamera = NGUITools.FindCameraForLayer(gameObject.layer); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // TODO: use this.Content to load your game content here SpriteFont font = Content.Load<SpriteFont>("Segoe_UI_15_Bold"); FontManager.DefaultFont = Engine.Instance.Renderer.CreateFont(font); root = new Root(); FontManager.Instance.LoadFonts(Content); }
void Awake() { UIRoot[] roots = NGUITools.FindActive<UIRoot>(); if (null != roots[0]) { _uIRoot = roots[0]; } _cardToPresent = null; _didDragPastReleaseThreshold = false; HideCarousel(true); }
/// <summary> /// Cache the root. /// </summary> void Start () { mCam = GetComponent<Camera>(); mTrans = transform; mRoot = NGUITools.FindInParents<UIRoot>(gameObject); if (rootForBounds == null) { Debug.LogError(NGUITools.GetHierarchy(gameObject) + " needs the 'Root For Bounds' parameter to be set", this); enabled = false; } }
// Retrieve references from current scene public static void SetupDisplay() { root = GameObject.Find("Root").GetComponent<UIRoot>(); topLeft = GameObject.Find("TopLeft"); top = GameObject.Find("Top"); topRight = GameObject.Find("TopRight"); left = GameObject.Find("Left"); centre = GameObject.Find("Centre"); right = GameObject.Find("Right"); bottomLeft = GameObject.Find("BottomLeft"); bottom = GameObject.Find("Bottom"); bottomRight = GameObject.Find("BottomRight"); }
/// <summary> /// Automatically find the camera responsible for drawing the widgets under this object. /// </summary> void Start () { mRoot = NGUITools.FindInParents<UIRoot>(gameObject); mNeedsHalfPixelOffset = (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsWebPlayer || Application.platform == RuntimePlatform.WindowsEditor); // Only DirectX 9 needs the half-pixel offset if (mNeedsHalfPixelOffset) mNeedsHalfPixelOffset = (SystemInfo.graphicsShaderLevel < 40); if (uiCamera == null) uiCamera = NGUITools.FindCameraForLayer(gameObject.layer); Update(); }
private void Start() { if ((this.container == null) && (this.widgetContainer != null)) { this.container = this.widgetContainer.gameObject; this.widgetContainer = null; } if (this.uiCamera == null) { this.uiCamera = NGUITools.FindCameraForLayer(base.gameObject.layer); } this.mRoot = NGUITools.FindInParents<UIRoot>(base.gameObject); this.Update(); }
private static void PreCreate () { if (m_uiRoot == null) { int uiLayer = LayerMask.NameToLayer("UI"); m_uiRootObj = new GameObject("UI Root(2D)"); m_uiRootObj.layer = uiLayer; UIRoot uiRoot = m_uiRootObj.AddComponent<UIRoot>(); { uiRoot.scalingStyle = UIRoot.Scaling.FixedSize; if ((Double)Screen.width / Screen.height < 1.49) uiRoot.manualHeight = 768; else uiRoot.manualHeight = 640; } m_cameraObj = new GameObject("Camera"); m_cameraObj.transform.parent = m_uiRootObj.transform; m_camera = m_cameraObj.AddComponent<Camera>(); { float depth = -1f; m_camera.gameObject.layer = uiLayer; m_camera.depth = depth + 1; m_camera.backgroundColor = Color.black; m_camera.cullingMask = 1 << uiLayer; //Use Simple2D Camera m_camera.orthographicSize = 1f; m_camera.orthographic = true; m_camera.nearClipPlane = -2f; m_camera.farClipPlane = 2f; m_camera.gameObject.AddComponent<UICamera>(); //m_camera.gameObject.AddComponent<UITick>(); } m_uiCamera = m_cameraObj.AddComponent<UICamera>(); m_uiRootObj.AddComponent<UIPanel>(); m_uiRoot = uiRoot; } }
void Start() { mRoot = GetComponent<UIRoot>(); if (mRoot == null) { Destroy(this); return; } // 计算基准宽高比 Base_Aspect = mRoot.manualWidth * 1.0f / mRoot.manualHeight; // 手机平台上RunOnce if (Settings.isMobilePlatform) { Update(); Destroy(this); } }
/// <summary> /// Makes sure we have a UIRoot and logs warnings if any critical controls are unassigned. /// </summary> private void FindControls() { if (uiRoot == null) uiRoot = GetComponentInChildren<UIRoot>(); nguiUIRoot = new NGUIUIRoot(uiRoot, deactivateUIRootWhenHidden); nguiQTEControls = new NGUIQTEControls(qteIndicators); SetupContinueButton(dialogue.npcSubtitle.continueButton); SetupContinueButton(dialogue.pcSubtitle.continueButton); SetupContinueButton(alert.continueButton); if (DialogueDebug.LogErrors) { if (uiRoot == null) Debug.LogError(string.Format("{0}: NGUIDialogueUI can't find UIRoot and won't be able to display dialogue.", DialogueDebug.Prefix)); if (DialogueDebug.LogWarnings) { if (dialogue.npcSubtitle.line == null) Debug.LogWarning(string.Format("{0}: NGUIDialogueUI NPC Subtitle Line needs to be assigned.", DialogueDebug.Prefix)); if (dialogue.pcSubtitle.line == null) Debug.LogWarning(string.Format("{0}: NGUIDialogueUI PC Subtitle Line needs to be assigned.", DialogueDebug.Prefix)); if (dialogue.responseMenu.buttons.Length == 0) Debug.LogWarning(string.Format("{0}: NGUIDialogueUI Response buttons need to be assigned.", DialogueDebug.Prefix)); if (alert.line == null) Debug.LogWarning(string.Format("{0}: NGUIDialogueUI Alert Line needs to be assigned.", DialogueDebug.Prefix)); } } }
private void Start() { if ((this.container == null) && (this.widgetContainer != null)) { this.container = this.widgetContainer.gameObject; this.widgetContainer = null; } this.mRoot = NGUITools.FindInParents<UIRoot>(base.gameObject); this.mNeedsHalfPixelOffset = (((Application.platform == RuntimePlatform.WindowsPlayer) || (Application.platform == RuntimePlatform.XBOX360)) || (Application.platform == RuntimePlatform.WindowsWebPlayer)) || (Application.platform == RuntimePlatform.WindowsEditor); if (this.mNeedsHalfPixelOffset) { this.mNeedsHalfPixelOffset = SystemInfo.graphicsShaderLevel < 40; } if (this.uiCamera == null) { this.uiCamera = NGUITools.FindCameraForLayer(base.gameObject.layer); } this.Update(); }
void CreateUIRoot() { GameObject uiRootobj = new GameObject("UIRoot"); UiRoot = uiRootobj.AddComponent<UIRoot>(); CBase.Assert(UiRoot); UiRoot.scalingStyle = UIRoot.Scaling.ConstrainedOnMobiles; UiRoot.manualHeight = 1920; GameObject panelRootObj = new GameObject("PanelRoot"); CTool.SetChild(panelRootObj.transform, uiRootobj.transform); Transform panelTrans = panelRootObj.transform; PanelRoot = panelRootObj.AddComponent<UIPanel>(); CBase.Assert(PanelRoot); GameObject uiCamObj = new GameObject("UICamera"); CTool.SetChild(uiCamObj.transform, UiRoot.transform); UiCamera = uiCamObj.AddComponent<UICamera>(); UiCamera.cachedCamera.cullingMask = 1 << (int)CLayerDef.UI; UiCamera.cachedCamera.clearFlags = CameraClearFlags.Depth; UiCamera.cachedCamera.orthographic = true; UiCamera.cachedCamera.orthographicSize = 1; UiCamera.cachedCamera.nearClipPlane = -2; UiCamera.cachedCamera.farClipPlane = 2; //panelTrans.gameObject.isStatic = true; foreach (UIAnchor.Side side in Enum.GetValues(typeof(UIAnchor.Side))) { GameObject anchorObj = new GameObject(side.ToString()); CTool.SetChild(anchorObj.transform, panelTrans); AnchorSide[side.ToString()] = anchorObj.transform; } GameObject nullAnchor = new GameObject("Null"); CTool.SetChild(nullAnchor.transform, panelTrans); AnchorSide["Null"] = nullAnchor.transform; AnchorSide[""] = AnchorSide[UIAnchor.Side.Center.ToString()]; // default NGUITools.SetLayer(uiRootobj, (int)CLayerDef.UI); }
private void CreateObjects() { this.mWinBg = base.transform.Find("winBG").gameObject; this.mUIRoot = NGUITools.FindInParents<UIRoot>(base.gameObject); this.mTitle = this.mWinBg.transform.Find("title").GetComponent<UILabel>(); this.mWebViewBehavior = this.mWinBg.AddComponent<WebViewBehavior>(); this.mCheckBtn = this.mWinBg.transform.Find("bottomBar/checkBtn").GetComponent<UIToggle>(); this.mCheckBtn.value = false; GameObject gameObject = this.mWinBg.transform.Find("closeBtn").gameObject; UIEventListener expr_AA = UIEventListener.Get(gameObject); expr_AA.onClick = (UIEventListener.VoidDelegate)Delegate.Combine(expr_AA.onClick, new UIEventListener.VoidDelegate(this.OnCloseClick)); GameObject gameObject2 = this.mWinBg.transform.Find("reloadBtn").gameObject; UIEventListener expr_EC = UIEventListener.Get(gameObject2); expr_EC.onClick = (UIEventListener.VoidDelegate)Delegate.Combine(expr_EC.onClick, new UIEventListener.VoidDelegate(this.OnReloadClick)); gameObject2.SetActive(false); this.mGoBackBtn = this.mWinBg.transform.Find("backBtn").gameObject; UIEventListener expr_13F = UIEventListener.Get(this.mGoBackBtn); expr_13F.onClick = (UIEventListener.VoidDelegate)Delegate.Combine(expr_13F.onClick, new UIEventListener.VoidDelegate(this.OnGoBackClick)); this.mCloseBtnSp = gameObject.GetComponent<UISprite>(); this.mBottomBar = this.mWinBg.transform.Find("bottomBar").GetComponent<UISprite>(); this.mBottomBar.gameObject.SetActive(false); }
void Start() { //如果没有为公共变量赋值 if (!camera || !root) { Transform p = transform; while (p.parent) p = p.parent; if (!camera) camera = p.GetComponentInChildren<UICamera>().camera; if (!root) root = p.GetComponent<UIRoot>(); } uiRatio = (float)uiWidth / (float)uiHeight; if (screenRatio < uiRatio) camera.orthographicSize = screenScale; else camera.orthographicSize = 1; }
private void OnDrag(Vector2 delta) { if ((this.mPressed && (UICamera.currentTouchID == this.mTouchID)) && base.enabled) { if (!this.mIsDragging) { this.mIsDragging = true; this.mParent = this.mTrans.parent; this.mRoot = NGUITools.FindInParents<UIRoot>(this.mTrans.gameObject); if (DragDropRoot.root != null) { this.mTrans.parent = DragDropRoot.root; } Vector3 localPosition = this.mTrans.localPosition; localPosition.z = 0f; this.mTrans.localPosition = localPosition; NGUITools.MarkParentAsChanged(base.gameObject); } else { this.mTrans.localPosition += (Vector3) (delta * this.mRoot.pixelSizeAdjustment); } } }
void CreateNewUI() { NGUIEditorTools.RegisterUndo("Create New UI"); // Root for the UI GameObject root = null; if (camType == CameraType.Simple2D) { root = new GameObject("UI Root (2D)"); root.AddComponent <UIRoot>(); } else { root = new GameObject((camType == CameraType.Advanced3D) ? "UI Root (3D)" : "UI Root"); root.transform.localScale = new Vector3(0.0025f, 0.0025f, 0.0025f); UIRoot uiRoot = root.AddComponent <UIRoot>(); uiRoot.automatic = false; uiRoot.manualHeight = 800; } // Assign the layer to be used by everything root.layer = layer; // Figure out the depth of the highest camera if (camType == CameraType.None) { // No camera requested -- simply add a panel UIPanel panel = NGUITools.AddChild <UIPanel>(root.gameObject); Selection.activeGameObject = panel.gameObject; } else { int mask = 1 << layer; float depth = -1f; bool clearColor = true; bool audioListener = true; List <Camera> cameras = NGUIEditorTools.FindInScene <Camera>(); foreach (Camera c in cameras) { // Choose the maximum depth depth = Mathf.Max(depth, c.depth); // Automatically exclude the specified layer mask from the camera if it can see more than that layer if (layer != 0 && c.cullingMask != mask) { c.cullingMask = (c.cullingMask & (~mask)); } // Only consider this object if it's active if (c.enabled && c.gameObject.active) { clearColor = false; } // If this camera has an audio listener, we won't need to add one if (c.GetComponent <AudioListener>() != null) { audioListener = false; } } // Camera and UICamera for this UI Camera cam = NGUITools.AddChild <Camera>(root); cam.depth = depth + 1; cam.backgroundColor = Color.grey; cam.cullingMask = mask; if (camType == CameraType.Simple2D) { cam.orthographicSize = 1f; cam.orthographic = true; cam.nearClipPlane = -2f; cam.farClipPlane = 2f; } else { cam.nearClipPlane = 0.1f; cam.farClipPlane = 4f; cam.transform.localPosition = new Vector3(0f, 0f, -700f); } // We don't want to clear color if this is not the first camera if (cameras.Count > 0) { cam.clearFlags = clearColor ? CameraClearFlags.Skybox : CameraClearFlags.Depth; } // Add an audio listener if we need one if (audioListener) { cam.gameObject.AddComponent <AudioListener>(); } // Add a UI Camera for event handling cam.gameObject.AddComponent <UICamera>(); // Anchor is useful to have UIAnchor anchor = NGUITools.AddChild <UIAnchor>(cam.gameObject); anchor.uiCamera = cam; // Since the camera was brought back 700 units above, we should bring the anchor forward 700 to compensate if (camType == CameraType.Advanced3D) { anchor.depthOffset = 700f; } // And finally -- the first UI panel UIPanel panel = NGUITools.AddChild <UIPanel>(anchor.gameObject); Selection.activeGameObject = panel.gameObject; } }
private static void InitRoot() { //根 UIRoot———————————————————————————————————— GameObject go = new GameObject("UIRoot"); Object.DontDestroyOnLoad(go); go.layer = LayerMask.NameToLayer("UI"); m_Instance = go.AddComponent <UIRoot>(); Transform rooTransform = go.transform; rooTransform.position = Vector3.zero; m_Instance.RootTransform = rooTransform; //Canvas——————————————————— GameObject canvas = CreateGameObject("Canvas", rooTransform, Vector3.zero); canvas.AddComponent <RectTransform>(); Canvas can = canvas.AddComponent <Canvas>(); m_Instance.RootCanvas = can; can.renderMode = RenderMode.ScreenSpaceCamera; can.planeDistance = 8; can.pixelPerfect = true; CanvasScaler cs = canvas.AddComponent <CanvasScaler>(); cs.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; cs.referenceResolution = mReferenceResolution; cs.screenMatchMode = CanvasScaler.ScreenMatchMode.Expand; //GraphicRaycaster———————————————————————————————————— m_Instance.mGR = canvas.AddComponent <GraphicRaycaster>(); //UICamera———————————————————————————————————— GameObject camObj = CreateGameObject("UICamera", rooTransform, Vector3.zero); Camera cam = camObj.AddComponent <Camera>(); cam.clearFlags = CameraClearFlags.Depth; // 这次设置成 2D相机 cam.orthographic = true; cam.nearClipPlane = 0.1f; cam.farClipPlane = 100; // cam.fieldOfView = 45; cam.nearClipPlane = -15f; cam.farClipPlane = 15f; can.worldCamera = cam; // cam.cullingMask = 1 << 5; cam.depth = 10; cam.allowHDR = false; m_Instance.UICamera = cam; camObj.AddComponent <AudioListener>(); camObj.AddComponent <FlareLayer>(); //EventSystem———————————————————————————————————— GameObject eventObj = CreateGameObject("EventSystem", rooTransform, Vector3.zero); eventObj.AddComponent <EventSystem>(); eventObj.AddComponent <StandaloneInputModule>(); //———————————————————————————————————— string[] sceneNames = Enum.GetNames(typeof(EF_Scenes)); m_Instance.UITransforms = new Transform[sceneNames.Length]; for (int i = 0; i < sceneNames.Length; i++) { m_Instance.UITransforms[i] = CreateUI(sceneNames[i], canvas.transform); } m_Instance.FirstUiTransform = CreateUI("FirstView", canvas.transform); }
protected override void Awake() { _instance = this; base.Awake(); IsStaticSystem = true; #if UNITY_EDITOR string ui_path = Application.dataPath + "/DownloadBundleAsset/Prefab_UI"; string[] all_file = System.IO.Directory.GetFiles(ui_path, "*.prefab", System.IO.SearchOption.AllDirectories); string asset_folder_file_name; string[] split_file_name; int start_index, length; for (int i = 0; i < all_file.Length; ++i) { all_file[i] = all_file[i].Replace("\\", "/"); start_index = all_file[i].IndexOf("Asset"); length = all_file[i].Length - start_index; asset_folder_file_name = all_file[i].Substring(start_index, length); split_file_name = asset_folder_file_name.Split('/'); if (split_file_name.Length > 1) { string[] split_dot = split_file_name[split_file_name.Length - 1].Split('.'); ui_path_name.Add(split_dot[0], asset_folder_file_name); } else { Debug.LogErrorFormat("Split File Failed : {0}", split_file_name); } } #endif UICamera uiCamera = transform.GetComponent <UICamera>(); if (uiCamera) { uiCamera.allowMultiTouch = false; } for (int index = (int)UI_MEMBER_LIST.SCENE_PANEL + 1; index < (int)UI_MEMBER_LIST.MAX_SCENE_PANEL; index++) { _scenePanels.Add((UI_MEMBER_LIST)index, null); } for (int index = (int)UI_MEMBER_LIST.SCENE_POPUP + 1; index < (int)UI_MEMBER_LIST.MAX_SCENE_POPUP; index++) { _scenePopups.Add((UI_MEMBER_LIST)index, null); } Transform[] temp = _userPanel.GetComponentsInChildren <Transform>(true); foreach (Transform tr in temp) { if (tr.parent == _userPanel.transform) { object obj = Enum.Parse(typeof(UI_MEMBER_LIST), tr.name, false); if (obj == null) { Debug.LogErrorFormat("UnKnown Common UI Prefab {0}, Add Prefab Name", tr.name); } else { _commonPanels.Add((UI_MEMBER_LIST)obj, tr.gameObject); } } } temp = _popupPanel.GetComponentsInChildren <Transform>(true); foreach (Transform tr in temp) { if (tr.parent == _popupPanel.transform) { object obj = Enum.Parse(typeof(UI_MEMBER_LIST), tr.name, false); if (obj == null) { Debug.LogErrorFormat("UnKnown Common UI Prefab {0}, Add Prefab Name", tr.name); } else { _commonPopups.Add((UI_MEMBER_LIST)obj, tr.gameObject); } } } _trScenePopup = NGUITools.AddChild(_popupPanel, false).transform; _trScenePopup.name = UI_SCENE_POPUP_NAME; _trScenePanel = NGUITools.AddChild(_userPanel, false).transform; _trScenePanel.name = UI_SCENE_PANEL_NAME; UIRoot = transform.GetComponent <UIRoot>(); }
public static void repositionButtons(int maxButtonsPerLine = -1, List <string> hiddenButtons = null) { GameObject _Base = _SysShortcut.transform.Find("Base").gameObject; GameObject _Grid = _Base.transform.Find("Grid").gameObject; UISprite _UIBase = _Base.GetComponent <UISprite>(); UIGrid _UIGrid = _Grid.GetComponent <UIGrid>(); List <Transform> children = _UIGrid.GetChildList(); int numButtons = 0; if (hiddenButtons == null) { numButtons = children.Count; } else { foreach (Transform child in children) { if (!hiddenButtons.Contains(child.name)) { numButtons++; } } } float width = _UIGrid.cellWidth; float height = width; _UIGrid.pivot = UIWidget.Pivot.TopLeft; _UIGrid.arrangement = UIGrid.Arrangement.CellSnap; _UIGrid.sorting = UIGrid.Sorting.None; _UIGrid.maxPerLine = (int)(Screen.width / (width / UIRoot.GetPixelSizeAdjustment(_Base)) * (3f / 4f)); if (maxButtonsPerLine > 0) { _UIGrid.maxPerLine = Math.Min(_UIGrid.maxPerLine, maxButtonsPerLine); } int buttonsX = Math.Min(numButtons, _UIGrid.maxPerLine); int buttonsY = Math.Max(1, (numButtons - 1) / _UIGrid.maxPerLine + 1); _UIBase.pivot = UIWidget.Pivot.TopRight; int baseMarginWidth = (int)(width * 3 / 2 + 8); int baseMarginHeight = (int)(height / 2); _UIBase.width = (int)(baseMarginWidth + width * buttonsX); _UIBase.height = (int)(baseMarginHeight + height * buttonsY + 2f); float baseOffsetHeight = baseMarginHeight * 1.5f + 2f; _UIBase.transform.localPosition = new Vector3(946f, 502f + baseOffsetHeight, 0f); _UIGrid.transform.localPosition = new Vector3(-2f - 2 * width, -baseOffsetHeight, 0f); List <string> UIButtons = new List <string>(DefaultUIButtons); if (GameMain.Instance.CMSystem.NetUse) { UIButtons.Insert(3, "Shop"); } int i = 0; for (int j = 0; j < UIButtons.Count; j++) { foreach (Transform child in children) { if (hiddenButtons != null && hiddenButtons.Contains(child.name)) { child.localPosition = new Vector3(10000, 10000); } else if (child.name == UIButtons[j]) { child.localPosition = new Vector3((i % _UIGrid.maxPerLine) * -width, (i / _UIGrid.maxPerLine) * -height, 0f); i++; } } } foreach (Transform child in children) { if (hiddenButtons != null && hiddenButtons.Contains(child.name)) { child.localPosition = new Vector3(10000, 10000); } else if (!UIButtons.Contains(child.name)) { child.localPosition = new Vector3((i % _UIGrid.maxPerLine) * -width, (i / _UIGrid.maxPerLine) * -height, 0f); i++; } } UISprite _tooltip = typeof(SystemShortcut).GetField("m_spriteExplanation", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(_SysShortcut) as UISprite; Vector3 pos = _tooltip.transform.localPosition; pos.y = _Base.transform.localPosition.y - _UIBase.height - _tooltip.height; _tooltip.transform.localPosition = pos; }
// button MainMenu public void BackMainMenu() { UIRoot.Close(gameObject); UIRoot.Load(WindowName.Win_MainMenu); }
public void UpdateNGUIText() { Font trueTypeFont = this.trueTypeFont; bool flag = trueTypeFont != null; NGUIText.fontSize = this.mPrintedSize; NGUIText.fontStyle = this.mFontStyle; NGUIText.rectWidth = this.mWidth; NGUIText.rectHeight = this.mHeight; NGUIText.regionWidth = Mathf.RoundToInt((float)this.mWidth * (this.mDrawRegion.z - this.mDrawRegion.x)); NGUIText.regionHeight = Mathf.RoundToInt((float)this.mHeight * (this.mDrawRegion.w - this.mDrawRegion.y)); NGUIText.gradient = (this.mApplyGradient && (this.mFont == null || !this.mFont.packedFontShader)); NGUIText.gradientTop = this.mGradientTop; NGUIText.gradientBottom = this.mGradientBottom; NGUIText.encoding = this.mEncoding; NGUIText.premultiply = this.mPremultiply; NGUIText.symbolStyle = this.mSymbols; NGUIText.maxLines = this.mMaxLineCount; NGUIText.spacingX = this.effectiveSpacingX; NGUIText.spacingY = this.effectiveSpacingY; NGUIText.fontScale = ((!flag) ? ((float)this.mFontSize / (float)this.mFont.defaultSize * this.mScale) : this.mScale); if (this.mFont != null) { NGUIText.bitmapFont = this.mFont; while (true) { UIFont replacement = NGUIText.bitmapFont.replacement; if (replacement == null) { break; } NGUIText.bitmapFont = replacement; } if (NGUIText.bitmapFont.isDynamic) { NGUIText.dynamicFont = NGUIText.bitmapFont.dynamicFont; NGUIText.bitmapFont = null; } else { NGUIText.dynamicFont = null; } } else { NGUIText.dynamicFont = trueTypeFont; NGUIText.bitmapFont = null; } if (flag && this.keepCrisp) { UIRoot root = base.root; if (root != null) { NGUIText.pixelDensity = ((!(root != null)) ? 1f : root.pixelSizeAdjustment); } } else { NGUIText.pixelDensity = 1f; } if (this.mDensity != NGUIText.pixelDensity) { this.ProcessText(false, false); NGUIText.rectWidth = this.mWidth; NGUIText.rectHeight = this.mHeight; NGUIText.regionWidth = Mathf.RoundToInt((float)this.mWidth * (this.mDrawRegion.z - this.mDrawRegion.x)); NGUIText.regionHeight = Mathf.RoundToInt((float)this.mHeight * (this.mDrawRegion.w - this.mDrawRegion.y)); } if (this.alignment == NGUIText.Alignment.Automatic) { UIWidget.Pivot pivot = base.pivot; if (pivot == UIWidget.Pivot.Left || pivot == UIWidget.Pivot.TopLeft || pivot == UIWidget.Pivot.BottomLeft) { NGUIText.alignment = NGUIText.Alignment.Left; } else if (pivot == UIWidget.Pivot.Right || pivot == UIWidget.Pivot.TopRight || pivot == UIWidget.Pivot.BottomRight) { NGUIText.alignment = NGUIText.Alignment.Right; } else { NGUIText.alignment = NGUIText.Alignment.Center; } } else { NGUIText.alignment = this.alignment; } NGUIText.Update(); }
private void Start() { mRoot = NGUITools.FindInParents <UIRoot>(base.gameObject); }
/// <summary> /// Perform any logic related to starting the drag & drop operation. /// </summary> protected virtual void OnDragDropStart() { // Automatically disable the scroll view if (mDragScrollView != null) { mDragScrollView.enabled = false; } // Disable the collider so that it doesn't intercept events if (mButton != null) { mButton.isEnabled = false; } else if (mCollider != null) { mCollider.enabled = false; } else if (mCollider2D != null) { mCollider2D.enabled = false; } mParent = mTrans.parent; mRoot = NGUITools.FindInParents <UIRoot>(mParent); mGrid = NGUITools.FindInParents <UIGrid>(mParent); mTable = NGUITools.FindInParents <UITable>(mParent); // Re-parent the item if (UIDragDropRoot.root != null) { mTrans.parent = UIDragDropRoot.root; } Vector3 pos = mTrans.localPosition; pos.z = 0f; mTrans.localPosition = pos; TweenPosition tp = GetComponent <TweenPosition>(); if (tp != null) { tp.enabled = false; } SpringPosition sp = GetComponent <SpringPosition>(); if (sp != null) { sp.enabled = false; } // Notify the widgets that the parent has changed NGUITools.MarkParentAsChanged(gameObject); if (mTable != null) { mTable.repositionNow = true; } if (mGrid != null) { mGrid.repositionNow = true; } }
public static float GetPixelSizeAdjustment(GameObject go) { UIRoot uIRoot = NGUITools.FindInParents <UIRoot>(go); return((!(uIRoot != null)) ? 1f : uIRoot.pixelSizeAdjustment); }
/// <summary> /// Load the specified CSV file. /// </summary> static bool LoadCSV(byte[] bytes, TextAsset asset, bool merge = false) { if (bytes == null) { return(false); } ByteReader reader = new ByteReader(bytes); // The first line should contain "KEY", followed by languages. var header = reader.ReadCSV(); // There must be at least two columns in a valid CSV file if (header.size < 2) { return(false); } header.RemoveAt(0); string[] languagesToAdd = null; if (string.IsNullOrEmpty(mLanguage)) { localizationHasBeenSet = false; } // Clear the dictionary if (!localizationHasBeenSet || (!merge && !mMerging) || mLanguages == null || mLanguages.Length == 0) { mDictionary.Clear(); mLanguages = new string[header.size]; if (!localizationHasBeenSet) { mLanguage = PlayerPrefs.GetString("Language", header.buffer[0]); localizationHasBeenSet = true; } for (int i = 0; i < header.size; ++i) { mLanguages[i] = header.buffer[i]; if (mLanguages[i] == mLanguage) { mLanguageIndex = i; } } } else { languagesToAdd = new string[header.size]; for (int i = 0; i < header.size; ++i) { languagesToAdd[i] = header.buffer[i]; } // Automatically resize the existing languages and add the new language to the mix for (int i = 0; i < header.size; ++i) { if (!HasLanguage(header.buffer[i])) { int newSize = mLanguages.Length + 1; #if UNITY_FLASH var temp = new string[newSize]; for (int b = 0, bmax = arr.Length; b < bmax; ++b) { temp[b] = mLanguages[b]; } mLanguages = temp; #else System.Array.Resize(ref mLanguages, newSize); #endif mLanguages[newSize - 1] = header.buffer[i]; var newDict = new Dictionary <string, string[]>(); foreach (var pair in mDictionary) { var arr = pair.Value; #if UNITY_FLASH temp = new string[newSize]; for (int b = 0, bmax = arr.Length; b < bmax; ++b) { temp[b] = arr[b]; } arr = temp; #else System.Array.Resize(ref arr, newSize); #endif arr[newSize - 1] = arr[0]; newDict.Add(pair.Key, arr); } mDictionary = newDict; } } } var languageIndices = new Dictionary <string, int>(); for (int i = 0; i < mLanguages.Length; ++i) { languageIndices.Add(mLanguages[i], i); } // Read the entire CSV file into memory for (;;) { var temp = reader.ReadCSV(); if (temp == null || temp.size == 0) { break; } if (string.IsNullOrEmpty(temp.buffer[0])) { continue; } AddCSV(temp, languagesToAdd, languageIndices); } if (!mMerging && onLocalize != null) { mMerging = true; OnLocalizeNotification note = onLocalize; onLocalize = null; note(); onLocalize = note; mMerging = false; } if (merge) { if (onLocalize != null) { onLocalize(); } UIRoot.Broadcast("OnLocalize"); } return(true); }
/// <summary> /// Perform any logic related to starting the drag & drop operation. /// </summary> protected virtual void OnDragDropStart () { // Automatically disable the scroll view if (mDragScrollView != null) mDragScrollView.enabled = false; // Disable the collider so that it doesn't intercept events if (mButton != null) mButton.isEnabled = false; else if (mCollider != null) mCollider.enabled = false; else if (mCollider2D != null) mCollider2D.enabled = false; mParent = mTrans.parent; mRoot = NGUITools.FindInParents<UIRoot>(mParent); mGrid = NGUITools.FindInParents<UIGrid>(mParent); mTable = NGUITools.FindInParents<UITable>(mParent); // Re-parent the item if (UIDragDropRoot.root != null) mTrans.parent = UIDragDropRoot.root; Vector3 pos = mTrans.localPosition; pos.z = 0f; mTrans.localPosition = pos; TweenPosition tp = GetComponent<TweenPosition>(); if (tp != null) tp.enabled = false; SpringPosition sp = GetComponent<SpringPosition>(); if (sp != null) sp.enabled = false; // Notify the widgets that the parent has changed NGUITools.MarkParentAsChanged(gameObject); if (mTable != null) mTable.repositionNow = true; if (mGrid != null) mGrid.repositionNow = true; }
/// <summary> /// Update NGUIText.current with all the properties from this label. /// </summary> public void UpdateNGUIText(int size, int lineWidth, int lineHeight) { Font ttf = trueTypeFont; bool isDynamic = (ttf != null); NGUIText.fontSize = mPrintedSize; NGUIText.fontStyle = mFontStyle; NGUIText.rectWidth = lineWidth; NGUIText.rectHeight = lineHeight; NGUIText.gradient = mApplyGradient; NGUIText.gradientTop = mGradientTop; NGUIText.gradientBottom = mGradientBottom; NGUIText.encoding = mEncoding; NGUIText.premultiply = mPremultiply; NGUIText.symbolStyle = mSymbols; NGUIText.maxLines = mMaxLineCount; NGUIText.spacingX = mSpacingX; NGUIText.spacingY = mSpacingY; NGUIText.fontScale = isDynamic ? mScale : ((float)mFontSize / mFont.defaultSize) * mScale * bitmapFont.pixelSize; if (mFont != null) { NGUIText.bitmapFont = mFont; for (; ;) { UIFont fnt = NGUIText.bitmapFont.replacement; if (fnt == null) { break; } NGUIText.bitmapFont = fnt; } #if DYNAMIC_FONT if (NGUIText.bitmapFont.isDynamic) { NGUIText.dynamicFont = NGUIText.bitmapFont.dynamicFont; NGUIText.bitmapFont = null; } else { NGUIText.dynamicFont = null; } #endif } #if DYNAMIC_FONT else { NGUIText.dynamicFont = ttf; NGUIText.bitmapFont = null; } if (isDynamic && keepCrisp) { UIRoot rt = root; if (rt != null) { NGUIText.pixelDensity = (rt != null) ? rt.pixelSizeAdjustment : 1f; } } #endif if (alignment == Alignment.Automatic) { Pivot p = pivot; if (p == Pivot.Left || p == Pivot.TopLeft || p == Pivot.BottomLeft) { NGUIText.alignment = Alignment.Left; } else if (p == Pivot.Right || p == Pivot.TopRight || p == Pivot.BottomRight) { NGUIText.alignment = Alignment.Right; } else { NGUIText.alignment = Alignment.Center; } } else { NGUIText.alignment = alignment; } NGUIText.Update(); }
/// <summary> /// Clear the parent rectangle reference. /// </summary> protected virtual void OnDisable () { #if UNITY_EDITOR mEnabled = false; #endif if (mParent) mParent.mChildren.Remove(this); mParent = null; mRoot = null; mRootSet = false; mParentFound = false; }
//void CreateUGUI() //{ // var canvasObj = new GameObject("UICanvas"); // UICanvas = canvasObj.AddComponent<Canvas>(); // UICanvas.renderMode = RenderMode.ScreenSpaceOverlay; // //UICanvas.worldCamera = UiCamera.cachedCamera; // canvasObj.AddComponent<GraphicRaycaster>(); // var scaler = canvasObj.AddComponent<CanvasScaler>(); // scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; // 屏幕固定大小 // scaler.referenceResolution = new Vector2(1080, 1920); // var evtSysObj = new GameObject("EventSystem"); // KTool.SetChild(evtSysObj, canvasObj); // evtSysObj.AddComponent<EventSystem>(); //} private void CreateUIRoot() { GameObject uiRootobj = GameObject.Find("NGUIRoot") ?? new GameObject("NGUIRoot"); UiRoot = uiRootobj.GetComponent <UIRoot>() ?? uiRootobj.AddComponent <UIRoot>(); Logger.Assert(UiRoot); UiRoot.scalingStyle = UIRoot.Scaling.FixedSizeOnMobiles; // 尝试将NGUI转化成跟2dToolkit镜头一致显示 UiRoot.manualHeight = 1080; //GameDef.ScreenPixelY;//(int)(GameDef.ScreenPixelY / (GameDef.ScreenPixelY / 2f / GameDef.DefaultPixelPerMeters)); // fit width! //UiRoot.manualWidth = 1920;//GameDef.ScreenPixelX; // 屏幕中间位置 //UiRoot.transform.localPosition = new Vector3(GameDef.ScreenPixelX / 2f / GameDef.DefaultPixelPerMeters, // GameDef.ScreenPixelY / 2f / GameDef.DefaultPixelPerMeters, -50); //var scale = 1 / GameDef.DefaultPixelPerMeters; //// 覆盖NGUI的Uiroot自动缩放 //UiRoot.transform.localScale = new Vector3(scale, scale, scale); //UiRoot.enabled = false; GameObject panelRootObj = new GameObject("PanelRoot"); KTool.SetChild(panelRootObj.transform, uiRootobj.transform); Transform panelTrans = panelRootObj.transform; PanelRoot = panelRootObj.AddComponent <UIPanel>(); Logger.Assert(PanelRoot); PanelRoot.generateNormals = true; var uiCamTrans = uiRootobj.transform.Find("UICamera"); GameObject uiCamObj = uiCamTrans != null ? uiCamTrans.gameObject : new GameObject("UICamera"); KTool.SetChild(uiCamObj.transform, UiRoot.transform); UiCamera = uiCamObj.GetComponent <UICamera>() ?? uiCamObj.AddComponent <UICamera>(); UiCamera.cachedCamera.cullingMask = 1 << (int)UnityLayerDef.UI; UiCamera.cachedCamera.clearFlags = CameraClearFlags.Depth; UiCamera.cachedCamera.orthographic = true; UiCamera.cachedCamera.orthographicSize = GameDef.ScreenPixelY / GameDef.DefaultPixelPerMeters / 2f; // 9.6,一屏19.2米,跟GameCamera一致 UiCamera.cachedCamera.nearClipPlane = -500; UiCamera.cachedCamera.farClipPlane = 500; foreach (UIAnchor.Side side in Enum.GetValues(typeof(UIAnchor.Side))) { GameObject anchorObj = new GameObject(side.ToString()); KTool.SetChild(anchorObj.transform, panelTrans); AnchorSide[side.ToString()] = anchorObj.transform; } GameObject nullAnchor = new GameObject("Null"); KTool.SetChild(nullAnchor.transform, panelTrans); AnchorSide["Null"] = nullAnchor.transform; AnchorSide[""] = AnchorSide[UIAnchor.Side.Center.ToString()]; // default NGUITools.SetLayer(uiRootobj, (int)UnityLayerDef.UI); PressWidget = new GameObject("PressWidget").AddComponent <UIWidget>(); NGUITools.SetLayer(PressWidget.gameObject, (int)UnityLayerDef.UI); KTool.SetChild(PressWidget.gameObject, panelRootObj); PressWidget.SetDimensions(2000, 2000); var col = PressWidget.gameObject.AddComponent <BoxCollider>(); col.size = new Vector3(2000, 2000); PressWidget.autoResizeBoxCollider = true; PressWidget.gameObject.SetActive(false); //UICamera.onDragStart = (go) => //{ // if (go != null) // 点击任意NGUI控件,出现阻挡 // PressWidget.gameObject.SetActive(true); //}; //UICamera.onPress = (go, state) => //{ // if (!state) // 点击任意NGUI控件,出现阻挡 // PressWidget.gameObject.SetActive(false); // //if (go != null) // //{ // // if (go.GetComponent<UIButton>() == null) // // { // // if (go.GetComponent<UIEventListener>() != null && go.GetComponent<UISprite>() != null) // // { // // if (Debug.isDebugBuild) // // { // // Debug.LogWarning("自动加UIButton和ButtonScale - " + go.name, go); // // } // // // 当不包含ButtonScale动画 // // // 并且拥有EventListener和UISprite! // // // 统一加上ButtonScale! // // var bScale = go.GetComponent<UIButtonScale>() ?? go.AddComponent<UIButtonScale>(); // // bScale.pressed = bScale.hover; // // bScale.hover = Vector3.one; // // var bColor = go.GetComponent<UIButton>() ?? go.AddComponent<UIButton>(); // // bColor.hover = Color.white; // // bColor.pressed = Color.white*.8f; // 小小灰 // // } // // } // //} //}; }
public void UpdateNGUIText() { Font font = trueTypeFont; bool flag = font != null; NGUIText.fontSize = mPrintedSize; NGUIText.fontStyle = mFontStyle; NGUIText.rectWidth = mWidth; NGUIText.rectHeight = mHeight; NGUIText.gradient = mApplyGradient && (mFont == null || !mFont.packedFontShader); NGUIText.gradientTop = mGradientTop; NGUIText.gradientBottom = mGradientBottom; NGUIText.encoding = mEncoding; NGUIText.premultiply = mPremultiply; NGUIText.symbolStyle = mSymbols; NGUIText.maxLines = mMaxLineCount; NGUIText.spacingX = mSpacingX; NGUIText.spacingY = mSpacingY; NGUIText.fontScale = (flag ? mScale : ((float)mFontSize / (float)mFont.defaultSize * mScale)); if (mFont != null) { NGUIText.bitmapFont = mFont; while (true) { bool flag2 = true; UIFont replacement = NGUIText.bitmapFont.replacement; if (replacement == null) { break; } NGUIText.bitmapFont = replacement; } if (NGUIText.bitmapFont.isDynamic) { NGUIText.dynamicFont = NGUIText.bitmapFont.dynamicFont; NGUIText.bitmapFont = null; } else { NGUIText.dynamicFont = null; } } else { NGUIText.dynamicFont = font; NGUIText.bitmapFont = null; } if (flag && keepCrisp) { UIRoot uIRoot = base.root; if (uIRoot != null) { NGUIText.pixelDensity = ((uIRoot != null) ? uIRoot.pixelSizeAdjustment : 1f); } } else { NGUIText.pixelDensity = 1f; } if (mDensity != NGUIText.pixelDensity) { ProcessText(legacyMode: false, full: false); NGUIText.rectWidth = mWidth; NGUIText.rectHeight = mHeight; } if (alignment == NGUIText.Alignment.Automatic) { Pivot pivot = base.pivot; if (pivot == Pivot.Left || pivot == Pivot.TopLeft || pivot == Pivot.BottomLeft) { NGUIText.alignment = NGUIText.Alignment.Left; } else if (pivot == Pivot.Right || pivot == Pivot.TopRight || pivot == Pivot.BottomRight) { NGUIText.alignment = NGUIText.Alignment.Right; } else { NGUIText.alignment = NGUIText.Alignment.Center; } } else { NGUIText.alignment = alignment; } NGUIText.Update(); }
private void ProcessText(bool legacyMode, bool full) { if (!isValid) { return; } mChanged = true; shouldBeProcessed = false; NGUIText.rectWidth = ((!legacyMode) ? base.width : ((mMaxLineWidth != 0) ? mMaxLineWidth : 1000000)); NGUIText.rectHeight = ((!legacyMode) ? base.height : ((mMaxLineHeight != 0) ? mMaxLineHeight : 1000000)); mPrintedSize = Mathf.Abs(legacyMode ? Mathf.RoundToInt(base.cachedTransform.localScale.x) : defaultFontSize); mScale = 1f; if (NGUIText.rectWidth < 1 || NGUIText.rectHeight < 0) { mProcessedText = ""; return; } bool flag = trueTypeFont != null; if (flag && keepCrisp) { UIRoot uIRoot = base.root; if (uIRoot != null) { mDensity = ((uIRoot != null) ? uIRoot.pixelSizeAdjustment : 1f); } } else { mDensity = 1f; } if (full) { UpdateNGUIText(); } if (mOverflow == Overflow.ResizeFreely) { NGUIText.rectWidth = 1000000; } if (mOverflow == Overflow.ResizeFreely || mOverflow == Overflow.ResizeHeight) { NGUIText.rectHeight = 1000000; } if (mPrintedSize > 0) { bool flag2 = keepCrisp; int num = mPrintedSize; while (num > 0) { if (flag2) { mPrintedSize = num; NGUIText.fontSize = mPrintedSize; } else { mScale = (float)num / (float)mPrintedSize; NGUIText.fontScale = (flag ? mScale : ((float)mFontSize / (float)mFont.defaultSize * mScale)); } NGUIText.Update(request: false); bool flag3 = NGUIText.WrapText(mText, out mProcessedText, keepCharCount: true); if (mOverflow == Overflow.ShrinkContent && !flag3) { if (--num <= 1) { break; } num--; continue; } if (mOverflow == Overflow.ResizeFreely) { mCalculatedSize = NGUIText.CalculatePrintedSize(mProcessedText); mWidth = Mathf.Max(minWidth, Mathf.RoundToInt(mCalculatedSize.x)); mHeight = Mathf.Max(minHeight, Mathf.RoundToInt(mCalculatedSize.y)); if ((mWidth & 1) == 1) { mWidth++; } if ((mHeight & 1) == 1) { mHeight++; } } else if (mOverflow == Overflow.ResizeHeight) { mCalculatedSize = NGUIText.CalculatePrintedSize(mProcessedText); mHeight = Mathf.Max(minHeight, Mathf.RoundToInt(mCalculatedSize.y)); if ((mHeight & 1) == 1) { mHeight++; } } else { mCalculatedSize = NGUIText.CalculatePrintedSize(mProcessedText); } if (legacyMode) { base.width = Mathf.RoundToInt(mCalculatedSize.x); base.height = Mathf.RoundToInt(mCalculatedSize.y); base.cachedTransform.localScale = Vector3.one; } break; } } else { base.cachedTransform.localScale = Vector3.one; mProcessedText = ""; mScale = 1f; } }
public void Init(HeroData data, List <TestMonster> listMonsters, UIRoot uiRoot) { //가져온 데이터를 참조합니다 this.uiRoot = uiRoot; this.data = data; this.bySelfDecreaedDelay = 0; this.byOtherDecreasedDelay = 0; this.calculatedDamage = FormulaCalculator.GetInstance().AllCalculatedDamage_Hero(data.id); this.calculatedAspd = FormulaCalculator.GetInstance().AllCalculatedAspd_Hero(data.id); this.defaultPos = this.transform.position; if (this.model == null) { this.model = this.gameObject.transform.GetChild(0).gameObject; } this.model.transform.localPosition = Vector3.zero; if (this.animator == null) { this.animator = this.gameObject.GetComponentInChildren <Animator>(); } if (this.GetComponentInChildren <EffectEvents>() != null) { this.effectEvents = this.GetComponentInChildren <EffectEvents>(); } //레이어를 Hero로 만듦 this.gameObject.layer = LayerMask.NameToLayer("Hero"); if (this.boxCollider == null) { //boxCollider를 붙입니다(Hero Merge를 위함) this.boxCollider = this.gameObject.AddComponent <BoxCollider>(); this.boxCollider.size = new Vector3(2f, 2, 2f); this.boxCollider.center = new Vector3(0, 1.2f, 0); this.boxCollider.isTrigger = true; } //몬스터 리스트 참조를 가져옵니다 this.listMonsters = listMonsters; if (uIPopup_HeroLevel == null) { NewUiPopup_HeroLevel(); } SetPositionUIPopup_Hero(); var type = 0; if (data.type < 6) { type = 1; } else if (data.type < 11) { type = 2; } else if (data.type < 16) { type = 3; } uIPopup_HeroLevel.SetLevel(type); this.ChangeBehavior(eHeroState.SEARCH); }
/// <summary> /// Find the UIPanel responsible for handling the specified transform. /// </summary> static public UIPanel Find(Transform trans, bool createIfMissing) { Transform origin = trans; UIPanel panel = null; while (panel == null && trans != null) { panel = trans.GetComponent <UIPanel>(); if (panel != null) { break; } if (trans.parent == null) { break; } trans = trans.parent; } if (createIfMissing && panel == null) { mRebuild = true; UIRoot root = NGUITools.FindInParents <UIRoot>(origin.gameObject); if (root == null && UIRoot.list.Count > 0) { root = UIRoot.list[0]; } if (root == null) { GameObject go = NGUITools.AddChild(null, false); go.name = "UI Root"; go.layer = origin.gameObject.layer; root = go.AddComponent <UIRoot>(); } panel = root.GetComponentInChildren <UIPanel>(); if (panel == null) { Camera cam = NGUITools.AddChild <Camera>(root.gameObject, false); cam.gameObject.AddComponent <UICamera>(); cam.orthographic = true; cam.orthographicSize = 1; cam.nearClipPlane = -10; cam.farClipPlane = 10; cam.clearFlags = (Camera.main != null) ? CameraClearFlags.Depth : CameraClearFlags.Color; cam.cullingMask = (1 << root.gameObject.layer); if (Camera.main != null) { Camera.main.cullingMask = (Camera.main.cullingMask & (~cam.cullingMask)); } UIAnchor anch = NGUITools.AddChild <UIAnchor>(cam.gameObject, false); panel = NGUITools.AddChild <UIPanel>(anch.gameObject, false); #if UNITY_EDITOR UnityEditor.Selection.activeGameObject = panel.gameObject; #endif } trans.parent = panel.transform; trans.localScale = Vector3.one; trans.localPosition = Vector3.zero; SetChildLayer(panel.cachedTransform, panel.cachedGameObject.layer); } return(panel); }
void Awake() { mRoot = GetComponent <UIRoot>(); }
private void ProcessText(bool legacyMode, bool full) { if (!this.isValid) { return; } this.mChanged = true; this.shouldBeProcessed = false; float num = this.mDrawRegion.z - this.mDrawRegion.x; float num2 = this.mDrawRegion.w - this.mDrawRegion.y; NGUIText.rectWidth = ((!legacyMode) ? base.width : ((this.mMaxLineWidth == 0) ? 1000000 : this.mMaxLineWidth)); NGUIText.rectHeight = ((!legacyMode) ? base.height : ((this.mMaxLineHeight == 0) ? 1000000 : this.mMaxLineHeight)); NGUIText.regionWidth = ((num == 1f) ? NGUIText.rectWidth : Mathf.RoundToInt((float)NGUIText.rectWidth * num)); NGUIText.regionHeight = ((num2 == 1f) ? NGUIText.rectHeight : Mathf.RoundToInt((float)NGUIText.rectHeight * num2)); this.mPrintedSize = Mathf.Abs((!legacyMode) ? this.defaultFontSize : Mathf.RoundToInt(base.cachedTransform.get_localScale().x)); this.mScale = 1f; if (NGUIText.regionWidth < 1 || NGUIText.regionHeight < 0) { this.mProcessedText = string.Empty; return; } bool flag = this.trueTypeFont != null; if (flag && this.keepCrisp) { UIRoot root = base.root; if (root != null) { this.mDensity = ((!(root != null)) ? 1f : root.pixelSizeAdjustment); } } else { this.mDensity = 1f; } if (full) { this.UpdateNGUIText(); } if (this.mOverflow == UILabel.Overflow.ResizeFreely) { NGUIText.rectWidth = 1000000; NGUIText.regionWidth = 1000000; } if (this.mOverflow == UILabel.Overflow.ResizeFreely || this.mOverflow == UILabel.Overflow.ResizeHeight) { NGUIText.rectHeight = 1000000; NGUIText.regionHeight = 1000000; } if (this.mPrintedSize > 0) { bool keepCrisp = this.keepCrisp; for (int i = this.mPrintedSize; i > 0; i--) { if (keepCrisp) { this.mPrintedSize = i; NGUIText.fontSize = this.mPrintedSize; } else { this.mScale = (float)i / (float)this.mPrintedSize; NGUIText.fontScale = ((!flag) ? ((float)this.mFontSize / (float)this.mFont.defaultSize * this.mScale) : this.mScale); } NGUIText.Update(false); bool flag2 = NGUIText.WrapText(this.mText, out this.mProcessedText, true); if (this.mOverflow != UILabel.Overflow.ShrinkContent || flag2) { if (this.mOverflow == UILabel.Overflow.ResizeFreely) { this.mCalculatedSize = NGUIText.CalculatePrintedSize(this.mProcessedText); this.mWidth = Mathf.Max(this.minWidth, Mathf.RoundToInt(this.mCalculatedSize.x)); if (num != 1f) { this.mWidth = Mathf.RoundToInt((float)this.mWidth / num); } this.mHeight = Mathf.Max(this.minHeight, Mathf.RoundToInt(this.mCalculatedSize.y)); if (num2 != 1f) { this.mHeight = Mathf.RoundToInt((float)this.mHeight / num2); } if ((this.mWidth & 1) == 1) { this.mWidth++; } if ((this.mHeight & 1) == 1) { this.mHeight++; } } else if (this.mOverflow == UILabel.Overflow.ResizeHeight) { this.mCalculatedSize = NGUIText.CalculatePrintedSize(this.mProcessedText); this.mHeight = Mathf.Max(this.minHeight, Mathf.RoundToInt(this.mCalculatedSize.y)); if (num2 != 1f) { this.mHeight = Mathf.RoundToInt((float)this.mHeight / num2); } if ((this.mHeight & 1) == 1) { this.mHeight++; } } else { this.mCalculatedSize = NGUIText.CalculatePrintedSize(this.mProcessedText); } if (legacyMode) { base.width = Mathf.RoundToInt(this.mCalculatedSize.x); base.height = Mathf.RoundToInt(this.mCalculatedSize.y); base.cachedTransform.set_localScale(Vector3.get_one()); } break; } if (--i <= 1) { break; } } } else { base.cachedTransform.set_localScale(Vector3.get_one()); this.mProcessedText = string.Empty; this.mScale = 1f; } if (full) { NGUIText.bitmapFont = null; NGUIText.dynamicFont = null; } }
/// <summary> /// Anchor the object to the appropriate point. /// </summary> void Update() { if (mAnim != null && mAnim.enabled && mAnim.isPlaying) { return; } bool useCamera = false; if (panelContainer != null) { if (panelContainer.clipping == UIDrawCall.Clipping.None) { // Panel has no clipping -- just use the screen's dimensions float ratio = (mRoot != null) ? (float)mRoot.activeHeight / Screen.height * 0.5f : 0.5f; mRect.xMin = -Screen.width * ratio; mRect.yMin = -Screen.height * ratio; mRect.xMax = -mRect.xMin; mRect.yMax = -mRect.yMin; } else { // Panel has clipping -- use it as the mRect Vector4 pos = panelContainer.clipRange; mRect.x = pos.x - (pos.z * 0.5f); mRect.y = pos.y - (pos.w * 0.5f); mRect.width = pos.z; mRect.height = pos.w; } } else if (widgetContainer != null) { // Widget is used -- use its bounds as the container's bounds Transform t = widgetContainer.cachedTransform; Vector3 ls = t.localScale; Vector3 lp = t.localPosition; Vector3 size = widgetContainer.relativeSize; Vector3 offset = widgetContainer.pivotOffset; offset.y -= 1f; offset.x *= (widgetContainer.relativeSize.x * ls.x); offset.y *= (widgetContainer.relativeSize.y * ls.y); mRect.x = lp.x + offset.x; mRect.y = lp.y + offset.y; mRect.width = size.x * ls.x; mRect.height = size.y * ls.y; } else if (uiCamera != null) { useCamera = true; mRect = uiCamera.pixelRect; } else { return; } float cx = (mRect.xMin + mRect.xMax) * 0.5f; float cy = (mRect.yMin + mRect.yMax) * 0.5f; Vector3 v = new Vector3(cx, cy, 0f); if (side != Side.Center) { if (side == Side.Right || side == Side.TopRight || side == Side.BottomRight) { v.x = mRect.xMax; } else if (side == Side.Top || side == Side.Center || side == Side.Bottom) { v.x = cx; } else { v.x = mRect.xMin; } if (side == Side.Top || side == Side.TopRight || side == Side.TopLeft) { v.y = mRect.yMax; } else if (side == Side.Left || side == Side.Center || side == Side.Right) { v.y = cy; } else { v.y = mRect.yMin; } } float width = mRect.width; float height = mRect.height; v.x += relativeOffset.x * width; v.y += relativeOffset.y * height; if (useCamera) { if (uiCamera.orthographic) { v.x = Mathf.Round(v.x); v.y = Mathf.Round(v.y); v.x += pixelOffset.x / UIRoot.GetPixelSizeAdjustment(this.gameObject); v.y += pixelOffset.y / UIRoot.GetPixelSizeAdjustment(this.gameObject); if (halfPixelOffset && mNeedsHalfPixelOffset) { v.x -= 0.5f; v.y += 0.5f; } } v.z = uiCamera.WorldToScreenPoint(mTrans.position).z; v = uiCamera.ScreenToWorldPoint(v); } else { v.x = Mathf.Round(v.x); v.y = Mathf.Round(v.y); v.x += pixelOffset.x / UIRoot.GetPixelSizeAdjustment(this.gameObject); v.y += pixelOffset.y / UIRoot.GetPixelSizeAdjustment(this.gameObject); if (panelContainer != null) { v = panelContainer.cachedTransform.TransformPoint(v); } else if (widgetContainer != null) { Transform t = widgetContainer.cachedTransform.parent; if (t != null) { v = t.TransformPoint(v); } } v.z = mTrans.position.z; } // Wrapped in an 'if' so the scene doesn't get marked as 'edited' every frame if (mTrans.position != v) { mTrans.position = v; } if (runOnlyOnce && Application.isPlaying) { Destroy(this); } }
void Start() { UIRoot.Show(gameObject); backButton.onClick.AddListener(DeactivateGameMenu); }
public static UIPanel CreateUI(Transform trans, bool advanced3D, int layer) { UIRoot uIRoot = (!(trans != null)) ? null : FindInParents <UIRoot>(trans.gameObject); if (uIRoot == null && UIRoot.list.Count > 0) { foreach (UIRoot item in UIRoot.list) { if (item.gameObject.layer == layer) { uIRoot = item; break; } } } if (uIRoot != null) { UICamera componentInChildren = uIRoot.GetComponentInChildren <UICamera>(); if (componentInChildren != null && componentInChildren.GetComponent <Camera>().orthographic == advanced3D) { trans = null; uIRoot = null; } } if (uIRoot == null) { GameObject gameObject = AddChild(null, undo: false); uIRoot = gameObject.AddComponent <UIRoot>(); if (layer == -1) { layer = LayerMask.NameToLayer("UI"); } if (layer == -1) { layer = LayerMask.NameToLayer("2D UI"); } gameObject.layer = layer; if (advanced3D) { gameObject.name = "UI Root (3D)"; uIRoot.scalingStyle = UIRoot.Scaling.Constrained; } else { gameObject.name = "UI Root"; uIRoot.scalingStyle = UIRoot.Scaling.Flexible; } } UIPanel uIPanel = uIRoot.GetComponentInChildren <UIPanel>(); if (uIPanel == null) { Camera[] array = FindActive <Camera>(); float num = -1f; bool flag = false; int num2 = 1 << uIRoot.gameObject.layer; foreach (Camera camera in array) { if (camera.clearFlags == CameraClearFlags.Color || camera.clearFlags == CameraClearFlags.Skybox) { flag = true; } num = Mathf.Max(num, camera.depth); camera.cullingMask &= ~num2; } Camera camera2 = AddChild <Camera>(uIRoot.gameObject, undo: false); camera2.gameObject.AddComponent <UICamera>(); camera2.clearFlags = ((!flag) ? CameraClearFlags.Color : CameraClearFlags.Depth); camera2.backgroundColor = Color.grey; camera2.cullingMask = num2; camera2.depth = num + 1f; if (advanced3D) { camera2.nearClipPlane = 0.1f; camera2.farClipPlane = 4f; camera2.transform.localPosition = new Vector3(0f, 0f, -700f); } else { camera2.orthographic = true; camera2.orthographicSize = 1f; camera2.nearClipPlane = -10f; camera2.farClipPlane = 10f; } AudioListener[] array2 = FindActive <AudioListener>(); if (array2 == null || array2.Length == 0) { camera2.gameObject.AddComponent <AudioListener>(); } uIPanel = uIRoot.gameObject.AddComponent <UIPanel>(); } if (trans != null) { while (trans.parent != null) { trans = trans.parent; } if (IsChild(trans, uIPanel.transform)) { uIPanel = trans.gameObject.AddComponent <UIPanel>(); } else { trans.parent = uIPanel.transform; trans.localScale = Vector3.one; trans.localPosition = Vector3.zero; SetChildLayer(uIPanel.cachedTransform, uIPanel.cachedGameObject.layer); } } return(uIPanel); }
/// <summary> /// Helper function that figures out the pixel size adjustment for the specified game object. /// </summary> static public float GetPixelSizeAdjustment(GameObject go) { UIRoot root = NGUITools.FindInParents <UIRoot>(go); return((root != null) ? root.pixelSizeAdjustment : 1f); }
/// <summary> /// Cache the root. /// </summary> void Start() { mRoot = NGUITools.FindInParents <UIRoot>(gameObject); }
private void InitAreaList(Vector4 minBorder, Vector4 maxBorder) { // 先计算出屏幕上有效的NGUI坐标范围 UIRoot uiRoot = GameObject.Find("UI Root").GetComponent <UIRoot>(); if (uiRoot == null) { Debug.LogError("uiRoot is null"); return; } int screenW = Screen.width; int screenH = Screen.height; float logicW = uiRoot.manualWidth; float logicH = uiRoot.manualHeight; float ratio = (float)screenW / (float)screenH; if (uiRoot.fitHeight) { logicW = logicH * ratio; mSnowLocalScaleFactor = (float)screenH / logicH; } else { logicH = logicW / ratio; mSnowLocalScaleFactor = (float)screenW / logicW; } mScreenSize = new Vector2(logicW, logicH); // 对该范围分割成多个小区域,用于随机位置使用 Vector4 temp = new Vector4(mScreenSize.x, mScreenSize.x, mScreenSize.y, mScreenSize.y); temp *= 0.5f; mSafeAreaMin = Vector4.Scale(minBorder, temp); mSafeAreaMax = Vector4.Scale(maxBorder, temp); mAreaList = new List <Vector4>(8); // 1 2 3 // 4 5 // 6 7 8 Vector4 a1 = new Vector4(mSafeAreaMax.x, mSafeAreaMin.x, mSafeAreaMin.w, mSafeAreaMax.w); mAreaList.Add(a1); Vector4 a2 = new Vector4(mSafeAreaMin.x, mSafeAreaMin.y, mSafeAreaMin.w, mSafeAreaMax.w); mAreaList.Add(a2); Vector4 a3 = new Vector4(mSafeAreaMin.y, mSafeAreaMax.y, mSafeAreaMin.w, mSafeAreaMax.w); mAreaList.Add(a3); Vector4 a4 = new Vector4(mSafeAreaMax.x, mSafeAreaMin.x, mSafeAreaMin.z, mSafeAreaMin.w); mAreaList.Add(a4); Vector4 a5 = new Vector4(mSafeAreaMin.y, mSafeAreaMax.y, mSafeAreaMin.z, mSafeAreaMin.w); mAreaList.Add(a5); Vector4 a6 = new Vector4(mSafeAreaMax.x, mSafeAreaMin.x, mSafeAreaMax.z, mSafeAreaMin.z); mAreaList.Add(a6); Vector4 a7 = new Vector4(mSafeAreaMin.x, mSafeAreaMin.y, mSafeAreaMax.z, mSafeAreaMin.z); mAreaList.Add(a7); Vector4 a8 = new Vector4(mSafeAreaMin.y, mSafeAreaMax.y, mSafeAreaMax.z, mSafeAreaMin.z); mAreaList.Add(a8); }
/// <summary> /// Create a new UI. /// </summary> static public UIPanel CreateUI(Transform trans, bool advanced3D, int layer) { // Find the existing UI Root UIRoot root = (trans != null) ? NGUITools.FindInParents <UIRoot>(trans.gameObject) : null; if (root == null && UIRoot.list.Count > 0) { root = UIRoot.list[0]; } // If no root found, create one if (root == null) { GameObject go = NGUITools.AddChild(null, false); root = go.AddComponent <UIRoot>(); // Automatically find the layers if none were specified if (layer == -1) { layer = LayerMask.NameToLayer("UI"); } if (layer == -1) { layer = LayerMask.NameToLayer("2D UI"); } go.layer = layer; if (advanced3D) { go.name = "UI Root (3D)"; root.scalingStyle = UIRoot.Scaling.FixedSize; } else { go.name = "UI Root"; root.scalingStyle = UIRoot.Scaling.PixelPerfect; } } // Find the first panel UIPanel panel = root.GetComponentInChildren <UIPanel>(); if (panel == null) { // Find other active cameras in the scene Camera[] cameras = NGUITools.FindActive <Camera>(); float depth = -1f; bool colorCleared = false; int mask = (1 << root.gameObject.layer); for (int i = 0; i < cameras.Length; ++i) { Camera c = cameras[i]; // If the color is being cleared, we won't need to if (c.clearFlags == CameraClearFlags.Color || c.clearFlags == CameraClearFlags.Skybox) { colorCleared = true; } // Choose the maximum depth depth = Mathf.Max(depth, c.depth); // Make sure this camera can't see the UI c.cullingMask = (c.cullingMask & (~mask)); } // Create a camera that will draw the UI Camera cam = NGUITools.AddChild <Camera>(root.gameObject, false); cam.gameObject.AddComponent <UICamera>(); cam.clearFlags = colorCleared ? CameraClearFlags.Depth : CameraClearFlags.Color; cam.backgroundColor = Color.grey; cam.cullingMask = mask; cam.depth = depth + 1f; if (advanced3D) { cam.nearClipPlane = 0.1f; cam.farClipPlane = 4f; cam.transform.localPosition = new Vector3(0f, 0f, -700f); } else { cam.orthographic = true; cam.orthographicSize = 1; cam.nearClipPlane = -10; cam.farClipPlane = 10; } // Make sure there is an audio listener present AudioListener[] listeners = NGUITools.FindActive <AudioListener>(); if (listeners == null || listeners.Length == 0) { cam.gameObject.AddComponent <AudioListener>(); } // Add a panel to the root panel = root.gameObject.AddComponent <UIPanel>(); #if UNITY_EDITOR UnityEditor.Selection.activeGameObject = panel.gameObject; #endif } if (trans != null) { // Find the root object while (trans.parent != null) { trans = trans.parent; } if (NGUITools.IsChild(trans, panel.transform)) { // Odd hierarchy -- can't reparent panel = trans.gameObject.AddComponent <UIPanel>(); } else { // Reparent this root object to be a child of the panel trans.parent = panel.transform; trans.localScale = Vector3.one; trans.localPosition = Vector3.zero; SetChildLayer(panel.cachedTransform, panel.cachedGameObject.layer); } } return(panel); }
public static UIPanel CreateUI(Transform trans, bool advanced3D, int layer) { UIRoot uIRoot = (!(trans != null)) ? null : NGUITools.FindInParents <UIRoot>(trans.gameObject); if (uIRoot == null && UIRoot.list.Count > 0) { uIRoot = UIRoot.list[0]; } if (uIRoot == null) { GameObject gameObject = NGUITools.AddChild(null, false); uIRoot = gameObject.AddComponent <UIRoot>(); if (layer == -1) { layer = LayerMask.NameToLayer("UI"); } if (layer == -1) { layer = LayerMask.NameToLayer("2D UI"); } gameObject.layer = layer; if (advanced3D) { gameObject.name = "UI Root (3D)"; uIRoot.scalingStyle = UIRoot.Scaling.FixedSize; } else { gameObject.name = "UI Root"; uIRoot.scalingStyle = UIRoot.Scaling.PixelPerfect; } } UIPanel uIPanel = uIRoot.GetComponentInChildren <UIPanel>(); if (uIPanel == null) { Camera[] array = NGUITools.FindActive <Camera>(); float num = -1f; bool flag = false; int num2 = 1 << uIRoot.gameObject.layer; for (int i = 0; i < array.Length; i++) { Camera camera = array[i]; if (camera.clearFlags == CameraClearFlags.Color || camera.clearFlags == CameraClearFlags.Skybox) { flag = true; } num = Mathf.Max(num, camera.depth); camera.cullingMask &= ~num2; } Camera camera2 = NGUITools.AddChild <Camera>(uIRoot.gameObject, false); camera2.gameObject.AddComponent <UICamera>(); camera2.clearFlags = ((!flag) ? CameraClearFlags.Color : CameraClearFlags.Depth); camera2.backgroundColor = Color.grey; camera2.cullingMask = num2; camera2.depth = num + 1f; if (advanced3D) { camera2.nearClipPlane = 0.1f; camera2.farClipPlane = 4f; Vector3 zero = Vector3.zero; zero.z = -700f; camera2.transform.localPosition = zero; } else { camera2.orthographic = true; camera2.orthographicSize = 1f; camera2.nearClipPlane = -10f; camera2.farClipPlane = 10f; } AudioListener[] array2 = NGUITools.FindActive <AudioListener>(); if (array2 == null || array2.Length == 0) { camera2.gameObject.AddComponent <AudioListener>(); } uIPanel = uIRoot.gameObject.AddComponent <UIPanel>(); } if (trans != null) { while (trans.parent != null) { trans = trans.parent; } if (NGUITools.IsChild(trans, uIPanel.transform)) { uIPanel = trans.gameObject.AddComponent <UIPanel>(); } else { trans.parent = uIPanel.transform; trans.localScale = Vector3.one; trans.localPosition = Vector3.zero; NGUITools.SetChildLayer(uIPanel.cachedTransform, uIPanel.cachedGameObject.layer); } } return(uIPanel); }
void Awake() { Instance = this; titleView.gameObject.SetActive(false); scoreView.gameObject.SetActive(false); }
public NGUIUIRoot(UIRoot uiRoot, bool deactivateWhenHidden) { this.uiRoot = uiRoot; this.deactivateWhenHidden = deactivateWhenHidden; }
/// <summary> /// Show the popup list dialog. /// </summary> public virtual void Show() { if (enabled && NGUITools.GetActive(gameObject) && mChild == null && isValid && items.Count > 0) { mLabelList.Clear(); StopCoroutine("CloseIfUnselected"); // Ensure the popup's source has the selection UICamera.selectedObject = (UICamera.hoveredObject ?? gameObject); mSelection = UICamera.selectedObject; source = mSelection; if (source == null) { Debug.LogError("Popup list needs a source object..."); return; } mOpenFrame = Time.frameCount; // Automatically locate the panel responsible for this object if (mPanel == null) { mPanel = UIPanel.Find(transform); if (mPanel == null) { return; } } // Calculate the dimensions of the object triggering the popup list so we can position it below it Vector3 min; Vector3 max; // Create the root object for the list mChild = new GameObject("Drop-down List"); mChild.layer = gameObject.layer; if (separatePanel) { if (GetComponent <Collider>() != null) { Rigidbody rb = mChild.AddComponent <Rigidbody>(); rb.isKinematic = true; } else if (GetComponent <Collider2D>() != null) { Rigidbody2D rb = mChild.AddComponent <Rigidbody2D>(); rb.isKinematic = true; } var panel = mChild.AddComponent <UIPanel>(); panel.depth = 1000000; panel.sortingOrder = mPanel.sortingOrder; } current = this; var pTrans = mPanel.cachedTransform; Transform t = mChild.transform; t.parent = pTrans; Transform rootTrans = pTrans; if (separatePanel) { var root = mPanel.GetComponentInParent <UIRoot>(); if (root == null && UIRoot.list.Count != 0) { root = UIRoot.list[0]; } if (root != null) { rootTrans = root.transform; } } // Manually triggered popup list on some other game object if (openOn == OpenOn.Manual && mSelection != gameObject) { startingPosition = UICamera.lastEventPosition; min = pTrans.InverseTransformPoint(mPanel.anchorCamera.ScreenToWorldPoint(startingPosition)); max = min; t.localPosition = min; startingPosition = t.position; } else { Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(pTrans, transform, false, false); min = bounds.min; max = bounds.max; t.localPosition = min; startingPosition = t.position; } StartCoroutine("CloseIfUnselected"); var f = fitScale; t.localRotation = Quaternion.identity; t.localScale = new Vector3(f, f, f); int depth = separatePanel ? 0 : NGUITools.CalculateNextDepth(mPanel.gameObject); // Add a sprite for the background if (background2DSprite != null) { UI2DSprite sp2 = mChild.AddWidget <UI2DSprite>(depth); sp2.sprite2D = background2DSprite; mBackground = sp2; } else if (atlas != null) { mBackground = NGUITools.AddSprite(mChild, atlas as INGUIAtlas, backgroundSprite, depth); } else { return; } bool placeAbove = (position == Position.Above); if (position == Position.Auto) { UICamera cam = UICamera.FindCameraForLayer(mSelection.layer); if (cam != null) { Vector3 viewPos = cam.cachedCamera.WorldToViewportPoint(startingPosition); placeAbove = (viewPos.y < 0.5f); } } mBackground.pivot = UIWidget.Pivot.TopLeft; mBackground.color = backgroundColor; // We need to know the size of the background sprite for padding purposes Vector4 bgPadding = mBackground.border; mBgBorder = bgPadding.y; mBackground.cachedTransform.localPosition = new Vector3(0f, placeAbove ? bgPadding.y * 2f - overlap : overlap, 0f); // Add a sprite used for the selection if (highlight2DSprite != null) { UI2DSprite sp2 = mChild.AddWidget <UI2DSprite>(++depth); sp2.sprite2D = highlight2DSprite; mHighlight = sp2; } else if (atlas != null) { mHighlight = NGUITools.AddSprite(mChild, atlas as INGUIAtlas, highlightSprite, ++depth); } else { return; } float hlspHeight = 0f, hlspLeft = 0f; if (mHighlight.hasBorder) { hlspHeight = mHighlight.border.w; hlspLeft = mHighlight.border.x; } mHighlight.pivot = UIWidget.Pivot.TopLeft; mHighlight.color = highlightColor; float labelHeight = activeFontSize * activeFontScale; float lineHeight = labelHeight + padding.y; float x = 0f, y = placeAbove ? bgPadding.y - padding.y - overlap : -padding.y - bgPadding.y + overlap; float contentHeight = bgPadding.y * 2f + padding.y; List <UILabel> labels = new List <UILabel>(); // Clear the selection if it's no longer present if (!items.Contains(mSelectedItem)) { mSelectedItem = null; } // Run through all items and create labels for each one for (int i = 0, imax = items.Count; i < imax; ++i) { string s = items[i]; UILabel lbl = NGUITools.AddWidget <UILabel>(mChild, mBackground.depth + 2); lbl.name = i.ToString(); lbl.pivot = UIWidget.Pivot.TopLeft; lbl.bitmapFont = bitmapFont as INGUIFont; lbl.trueTypeFont = trueTypeFont; lbl.fontSize = fontSize; lbl.fontStyle = fontStyle; lbl.text = isLocalized ? Localization.Get(s) : s; lbl.modifier = textModifier; lbl.color = textColor; lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x - lbl.pivotOffset.x, y, -1f); lbl.overflowMethod = UILabel.Overflow.ResizeFreely; lbl.alignment = alignment; lbl.symbolStyle = NGUIText.SymbolStyle.Colored; lbl.keepCrispWhenShrunk = UILabel.Crispness.Never; //I still don't get why this option exists if it always looks like butts if it's turned on ~digi labels.Add(lbl); contentHeight += lineHeight; y -= lineHeight; x = Mathf.Max(x, lbl.printedSize.x); // Add an event listener UIEventListener listener = UIEventListener.Get(lbl.gameObject); listener.onHover = OnItemHover; listener.onPress = OnItemPress; listener.onClick = OnItemClick; listener.parameter = s; // Move the selection here if this is the right label if (mSelectedItem == s || (i == 0 && string.IsNullOrEmpty(mSelectedItem))) { Highlight(lbl, true); } // Add this label to the list mLabelList.Add(lbl); } // The triggering widget's width should be the minimum allowed width x = Mathf.Max(x, (max.x - min.x) - (bgPadding.x + padding.x) * 2f); float cx = x; Vector3 bcCenter = new Vector3(cx * 0.5f, -labelHeight * 0.5f, 0f); Vector3 bcSize = new Vector3(cx, (labelHeight + padding.y), 1f); // Run through all labels and add colliders for (int i = 0, imax = labels.Count; i < imax; ++i) { UILabel lbl = labels[i]; NGUITools.AddWidgetCollider(lbl.gameObject); lbl.autoResizeBoxCollider = false; BoxCollider bc = lbl.GetComponent <BoxCollider>(); if (bc != null) { bcCenter.z = bc.center.z; bc.center = bcCenter; bc.size = bcSize; } else { BoxCollider2D b2d = lbl.GetComponent <BoxCollider2D>(); #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 b2d.center = bcCenter; #else b2d.offset = bcCenter; #endif b2d.size = bcSize; } } int lblWidth = Mathf.RoundToInt(x); x += (bgPadding.x + padding.x) * 2f; y -= bgPadding.y; // Scale the background sprite to envelop the entire set of items mBackground.width = Mathf.RoundToInt(x); mBackground.height = Mathf.RoundToInt(contentHeight); // Set the label width to make alignment work for (int i = 0, imax = labels.Count; i < imax; ++i) { UILabel lbl = labels[i]; lbl.overflowMethod = UILabel.Overflow.ShrinkContent; lbl.width = lblWidth; } // Scale the highlight sprite to envelop a single item float scaleFactor = 2f; var atl = atlas as INGUIAtlas; if (atl != null) { scaleFactor *= atl.pixelSize; } float w = x - (bgPadding.x + padding.x) * 2f + hlspLeft * scaleFactor; float h = labelHeight + hlspHeight * scaleFactor; mHighlight.width = Mathf.RoundToInt(w); mHighlight.height = Mathf.RoundToInt(h); // If the list should be animated, let's animate it by expanding it if (isAnimated) { AnimateColor(mBackground); if (Time.timeScale == 0f || Time.timeScale >= 0.1f) { float bottom = y + labelHeight; Animate(mHighlight, placeAbove, bottom); for (int i = 0, imax = labels.Count; i < imax; ++i) { Animate(labels[i], placeAbove, bottom); } AnimateScale(mBackground, placeAbove, bottom); } } // If we need to place the popup list above the item, we need to reposition everything by the size of the list if (placeAbove) { var bgY = bgPadding.y * f; min.y = max.y - bgPadding.y * f; max.y = min.y + (mBackground.height - bgPadding.y * 2f) * f; max.x = min.x + mBackground.width * f; t.localPosition = new Vector3(min.x, max.y - bgY, min.z); } else { max.y = min.y + bgPadding.y * f; min.y = max.y - mBackground.height * f; max.x = min.x + mBackground.width * f; } var absoluteParent = mPanel; // UIRoot.list[0].GetComponent<UIPanel>(); for (;;) { var p = absoluteParent.parent; if (p == null) { break; } var pp = p.GetComponentInParent <UIPanel>(); if (pp == null) { break; } absoluteParent = pp; } if (pTrans != null) { min = pTrans.TransformPoint(min); max = pTrans.TransformPoint(max); min = absoluteParent.cachedTransform.InverseTransformPoint(min); max = absoluteParent.cachedTransform.InverseTransformPoint(max); var adj = UIRoot.GetPixelSizeAdjustment(gameObject); min /= adj; max /= adj; } // Ensure that everything fits into the panel's visible range var offset = absoluteParent.CalculateConstrainOffset(min, max); var pos = t.localPosition + offset; pos.x = Mathf.Round(pos.x); pos.y = Mathf.Round(pos.y); t.localPosition = pos; t.parent = rootTrans; } else { OnSelect(false); } }
/// <summary> /// Automatically find the camera responsible for drawing the widgets under this object. /// </summary> void Start() { if (container == null && widgetContainer != null) { container = widgetContainer.gameObject; widgetContainer = null; #if UNITY_EDITOR UnityEditor.EditorUtility.SetDirty(this); #endif } mRoot = NGUITools.FindInParents<UIRoot>(gameObject); mNeedsHalfPixelOffset = (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.XBOX360 || Application.platform == RuntimePlatform.WindowsWebPlayer || Application.platform == RuntimePlatform.WindowsEditor); // Only DirectX 9 needs the half-pixel offset if (mNeedsHalfPixelOffset) mNeedsHalfPixelOffset = (SystemInfo.graphicsShaderLevel < 40); if (uiCamera == null) uiCamera = NGUITools.FindCameraForLayer(gameObject.layer); Update(); }
protected override JSONObject ExportResource(ExportPreset preset) { WXHierarchyContext hierarchyContext = new WXHierarchyContext(preset, prefabPath); hierarchyContext.prefab2dType = typeof(WXNGUITree); // 初始化输出的JSON对象 JSONObject prefabJSONObject = new JSONObject(JSONObject.Type.OBJECT); JSONObject metaJson = new JSONObject(JSONObject.Type.OBJECT); prefabJSONObject.AddField("meta", metaJson); // 填充meta metaJson.AddField("name", exportName); metaJson.AddField("type", "2D"); if (exportAsScene) { JSONObject configJson = new JSONObject(JSONObject.Type.OBJECT); metaJson.AddField("config", configJson); JSONObject resolutionJson = new JSONObject(JSONObject.Type.ARRAY); UIRoot uiRoot = getUIRoot(prefabRoot); if (uiRoot != null) { Debug.Log("uiRoot is"); // var a = JsonUtility.ToJson(uiRoot, true); // Debug.Log(a); // Debug.Log(uiRoot.activeHeight); // Debug.Log(uiRoot.manualWidth); // Debug.Log(uiRoot.manualHeight); UIRoot.Scaling scalingStyle = uiRoot.scalingStyle; configJson.AddField("scalingStyle", (int)scalingStyle); configJson.AddField("manualWidth", uiRoot.manualWidth); configJson.AddField("manualHeight", uiRoot.manualHeight); configJson.AddField("minimumHeight", uiRoot.minimumHeight); configJson.AddField("maximumHeight", uiRoot.maximumHeight); configJson.AddField("fitWidth", uiRoot.fitWidth); configJson.AddField("fitHeight", uiRoot.fitHeight); configJson.AddField("adjustByDPI", uiRoot.adjustByDPI); configJson.AddField("shrinkPortraitUI", uiRoot.shrinkPortraitUI); if (scalingStyle == UIRoot.Scaling.Flexible) { // 目前引擎没有对Flexible这种情况的支持,所以默认先导出一个假定的resolution resolutionJson.Add(uiRoot.activeHeight); resolutionJson.Add(uiRoot.activeHeight); } else { resolutionJson.Add(uiRoot.manualWidth); resolutionJson.Add(uiRoot.manualHeight); } } else { // 无root情况,使用默认大小 resolutionJson.Add(1280); resolutionJson.Add(720); } configJson.AddField("resolution", resolutionJson); } // 开始遍历 WXEntity rootEntity = hierarchyContext.IterateGameObject(prefabRoot); prefabJSONObject.AddField("gameObjectList", hierarchyContext.GetGameObjectListJSON()); prefabJSONObject.AddField("componentList", hierarchyContext.GetComponentListJSON()); JSONObject editorInfo = new JSONObject(JSONObject.Type.OBJECT); editorInfo.AddField("assetVersion", 2); prefabJSONObject.AddField("editorInfo", editorInfo); //Debug.Log("Export Prefab " + prefabPath + " " + hierarchyContext.resourceList.Count); foreach (string resource in hierarchyContext.resourceList) { AddDependencies(resource); } return(prefabJSONObject); }
/// <summary> /// Automatically find the camera responsible for drawing the widgets under this object. /// </summary> void Start () { if (container == null && widgetContainer != null) { container = widgetContainer.gameObject; widgetContainer = null; #if UNITY_EDITOR NGUITools.SetDirty(this); #endif } mRoot = NGUITools.FindInParents<UIRoot>(gameObject); if (uiCamera == null) uiCamera = NGUITools.FindCameraForLayer(gameObject.layer); Update(); mStarted = true; }
public static void Test() { ConfigurationManager.Initialize("../../../../config/RC.UI.Test/RC.UI.Test.root"); UIRoot root = new UIRoot(); Assembly xnaPlugin = Assembly.Load("RC.UI.XnaPlugin, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"); root.LoadPlugins(xnaPlugin); root.InstallPlugins(); DynamicString.RegisterResolver("RC.UI.UIWorkspace.PixelScaling", delegate() { return("2;2"); }); UIResourceManager.LoadResourceGroup("RC.App.SplashScreen"); UIResourceManager.LoadResourceGroup("RC.App.CommonResources"); UISprite mouseIcon = root.GraphicsPlatform.SpriteManager.LoadSprite("..\\..\\..\\..\\sprites\\pointers\\normal_pointer.png", new RCIntVector(2, 2)); mouseIcon.TransparentColor = new RCColor(255, 0, 255); mouseIcon.Upload(); UIPointer pointer = new UIPointer(mouseIcon, new RCIntVector(0, 0)); display = new TestUIObject(new RCIntVector(2, 2), new RCIntVector(0, 0), new RCIntRectangle(0, 0, 400, 300)); workspace = new MySensitiveAnimObject(new RCIntVector(40, 50), new RCIntRectangle(0, 0, 320, 200), "Workspace", RCColor.Gray, RCColor.Gray); display.Attach(workspace); MyButton button = new MyButton(new RCIntVector(5, 12), new RCIntVector(60, 20), RCColor.Brown, RCColor.Yellow, RCColor.White, "MyButton"); //button.MouseSensor.Enter += delegate(UISensitiveObject sender) { Console.WriteLine("BUTTON ENTER"); }; //button.MouseSensor.Move += delegate(UISensitiveObject sender, UIMouseEventArgs args) { Console.WriteLine("BUTTON MOVE"); }; //button.MouseSensor.Leave += delegate(UISensitiveObject sender) { Console.WriteLine("BUTTON LEAVE"); }; MyCheckbox checkbox = new MyCheckbox(new RCIntVector(70, 12), new RCIntVector(80, 20), RCColor.Red, RCColor.Green, RCColor.LightRed, RCColor.LightGreen, RCColor.White, "MyCheckbox"); MyDropdownSelector selector = new MyDropdownSelector(new RCIntVector(5, 50), new RCIntVector(60, 20), new string[4] { "option0", "option1", "option2", "option3" }, RCColor.WhiteHigh, RCColor.Red, RCColor.Green, RCColor.LightGreen, RCColor.LightBlue, RCColor.Gray); //selector.MouseSensor.Enter += delegate(UISensitiveObject sender) { Console.WriteLine("SELECTOR ENTER"); }; //selector.MouseSensor.Move += delegate(UISensitiveObject sender, UIMouseEventArgs args) { Console.WriteLine("SELECTOR MOVE"); }; //selector.MouseSensor.Leave += delegate(UISensitiveObject sender) { Console.WriteLine("SELECTOR LEAVE"); }; MySlider sliderHorz = new MySlider(new RCIntVector(5, 80), new RCIntVector(80, 10), new UISlider.Settings() { Alignment = UISlider.Alignment.Horizontal, IntervalLength = 10, SliderBottom = 3, SliderLeft = 1, SliderRight = 1, SliderTop = 3, TimeBetweenTrackings = 300, TrackingValueChange = 3, TrackPos = new RCIntVector(10, 5), TrackSize = new RCIntVector(60, 1) }, RCColor.Green, RCColor.LightGreen, RCColor.White); MySlider sliderVert = new MySlider(new RCIntVector(5, 100), new RCIntVector(10, 80), new UISlider.Settings() { Alignment = UISlider.Alignment.Vertical, IntervalLength = 10, SliderBottom = 1, SliderLeft = 3, SliderRight = 3, SliderTop = 1, TimeBetweenTrackings = 300, TrackingValueChange = 3, TrackPos = new RCIntVector(5, 10), TrackSize = new RCIntVector(60, 1) }, RCColor.Green, RCColor.LightGreen, RCColor.White); workspace.Attach(button); workspace.Attach(checkbox); workspace.Attach(selector); workspace.Attach(sliderHorz); workspace.Attach(sliderVert); workspace.AttachSensitive(button); workspace.AttachSensitive(checkbox); workspace.AttachSensitive(selector); workspace.AttachSensitive(sliderHorz); workspace.AttachSensitive(sliderVert); button.Pressed += delegate(UISensitiveObject sender) { TraceManager.WriteAllTrace("BUTTON PRESSED", TraceManager.GetTraceFilterID("RC.UI.Test.Info")); checkbox.IsEnabled = !checkbox.IsEnabled; }; checkbox.CheckedStateChanged += delegate(UISensitiveObject sender) { TraceManager.WriteAllTrace("CHECKBOX STATE CHANGED", TraceManager.GetTraceFilterID("RC.UI.Test.Info")); button.IsEnabled = checkbox.IsChecked; }; selector.SelectedIndexChanged += delegate(UISensitiveObject sender) { TraceManager.WriteAllTrace("SELECTED INDEX CHANGED", TraceManager.GetTraceFilterID("RC.UI.Test.Info")); }; sliderHorz.SelectedValueChanged += delegate(UISensitiveObject sender) { TraceManager.WriteAllTrace(string.Format("SELECTED VALUE CHANGED (horizontal): {0}", sliderHorz.SelectedValue), TraceManager.GetTraceFilterID("RC.UI.Test.Info")); }; sliderVert.SelectedValueChanged += delegate(UISensitiveObject sender) { TraceManager.WriteAllTrace(string.Format("SELECTED VALUE CHANGED (vertical): {0}", sliderVert.SelectedValue), TraceManager.GetTraceFilterID("RC.UI.Test.Info")); }; UIMouseManager mouseMgr = new UIMouseManager(workspace); mouseMgr.SetDefaultMousePointer(pointer); root.GraphicsPlatform.RenderManager.Attach(display); root.GraphicsPlatform.RenderLoop.Start(new RCIntVector(800, 600)); root.Dispose(); }