void doLoadData() { prefabItem.transform.parent = null; DoSetActive(prefabItem.transform, false); // Disable the prefab item // don't want it visible when the game is running, as it is in the scene prefabItem.transform.parent = null; DoSetActive(prefabItem.transform, false); // Add a bunch of items to the manual list // You will need to parent the object manually and then calculate the step float x = 0; float w = (prefabItem.GetMaxBounds() - prefabItem.GetMinBounds()).y; for (int i = 0; i < lst.Count; ++i) { tk2dUILayout layout = Instantiate(prefabItem) as tk2dUILayout; layout.transform.parent = manualScrollableArea.contentContainer.transform; layout.transform.localPosition = new Vector3(0, x, 0); DoSetActive(layout.transform, true); CustomizeListObject(layout.transform, (i + 1), lst[i].Name, lst[i].Coin, lst[i].Second); x -= w; } }
protected override void GetItems(Transform t) { tk2dUILayout objLayout = t.GetComponent <tk2dUILayout>(); if (objLayout != null) { tk2dUILayoutItem curItem = null; foreach (var item in My.layoutItems) { if (t.gameObject == item.gameObj) { curItem = item; curItem.inLayoutList = true; break; } } if (curItem == null) { curItem = new tk2dUILayoutItem(); } itemsList.Add(curItem); curItem.layout = objLayout; curItem.gameObj = t.gameObject; } if (objLayout == null) { for (int i = 0; i < t.childCount; ++i) { GetItems(t.GetChild(i)); } } }
protected virtual void GetItems(Transform t) { tk2dBaseSprite objSprite = t.GetComponent <tk2dBaseSprite>(); tk2dUIMask objMask = t.GetComponent <tk2dUIMask>(); tk2dUILayout objLayout = t.GetComponent <tk2dUILayout>(); tk2dUILayoutItem curItem = null; foreach (var item in My.layoutItems) { if (t.gameObject == item.gameObj) { curItem = item; curItem.inLayoutList = true; break; } } if (curItem == null) { curItem = new tk2dUILayoutItem(); } itemsList.Add(curItem); curItem.sprite = objSprite; curItem.UIMask = objMask; curItem.layout = objLayout; curItem.gameObj = t.gameObject; if (objLayout == null) { for (int i = 0; i < t.childCount; ++i) { GetItems(t.GetChild(i)); } } }
public void loadTutorial() { // start setting the beginning position of the objects and the width of them // position X that the tutorial will instantiate float _xTutorial = 7f, // width of the tutorial object. Here it was used Y because the object is with rotation 90 _wTutorial = (prefabTutorial.GetMaxBounds() - prefabTutorial.GetMinBounds()).y; foreach (Item tutorial in this.getTutorials()) { // instantiates the prefabTutorial tk2dUILayout _layout = Instantiate(prefabTutorial) as tk2dUILayout; // changes the parent _layout.transform.parent = scrollableTutorialArea.contentContainer.transform; // and changes the position _layout.transform.localPosition = new Vector3(_xTutorial, 0, 0); // fills the tutorial informations _layout.transform.GetChild(0).GetComponent <tk2dSprite>().SetSprite(tutorial.Image); _layout.transform.GetChild(0).GetChild(0).GetComponent <tk2dTextMesh>().text = tutorial.Name; _layout.transform.GetChild(1).GetComponent <tk2dTextMesh>().text = CurrentLanguage.language == LanguageType.Portuguese ? tutorial.DescriptionPT : tutorial.DescriptionEN; // sum the position with the width to other item _xTutorial += _wTutorial; } // the ContentLength receive the length of list scrollableTutorialArea.ContentLength = _xTutorial; }
void Start() { // Disable the prefab item // don't want it visible when the game is running, as it is in the scene prefabItem.transform.parent = null; DoSetActive(prefabItem.transform, false); // How many items do we need to buffer? itemStride = (prefabItem.GetMaxBounds() - prefabItem.GetMinBounds()).x; maxVisibleItems = Mathf.CeilToInt(scrollableArea.VisibleAreaLength / itemStride) + 1; // Buffer the prefabs that we will need float x = 0; for (int i = 0; i < maxVisibleItems; ++i) { tk2dUILayout layout = Instantiate(prefabItem) as tk2dUILayout; layout.transform.parent = scrollableArea.contentContainer.transform; layout.transform.localPosition = new Vector3(x, 0, 0); DoSetActive(layout.transform, false); unusedContentItems.Add(layout.transform); x += itemStride; } // Add some items to the List SetItemCount(100); }
void UpdateChildren() { tk2dUILayoutContainerSizer sizer = (tk2dUILayoutContainerSizer)target; Transform t = sizer.transform; allActive = true; for (int i = 0; i < t.childCount; ++i) { Transform c = t.GetChild(i); tk2dUILayout layout = c.GetComponent <tk2dUILayout>(); if (layout == null) { hasNonLayouts = true; break; } } foreach (tk2dUILayoutItem item in itemsList) { if (!item.inLayoutList) { allActive = false; } } }
private void addClothes(Item item) { // instantiates the prefabClothesItem tk2dUILayout _layout = Instantiate(prefabClothesItem) as tk2dUILayout; // changes the parent _layout.transform.parent = scrollableClothesArea.contentContainer.transform; // and changes the position _layout.transform.localPosition = new Vector3(xClothes, 0, 0); // fills the clothe informations _layout.gameObject.AddComponent <Clothes>().init(item); // gets the tk2dUIItem Component to set some informations tk2dUIItem _uiItem = _layout.gameObject.AddComponent <tk2dUIItem>(); // set message target _uiItem.sendMessageTarget = _layout.gameObject; // set the method that will call _uiItem.SendMessageOnClickMethodName = "chooseClothes"; // set this informations _uiItem.InternalSetIsChildOfAnotherUIItem(true); _uiItem.isHoverEnabled = true; // sum the position with the width to other item xClothes += wClothes; }
public void loadCharacters() { // start setting the beginning position of the objects and the width of them // position X that the character will instantiate float _xCharacter = 5.5f, // width of the character object. Here it was used Y because the object is with rotation 90 _wCharacter = (prefabCharacter.GetMaxBounds() - prefabCharacter.GetMinBounds()).y; foreach (Item character in this.getCharacters()) { // instantiates the prefabCharacter tk2dUILayout _layout = Instantiate(prefabCharacter) as tk2dUILayout; // changes the parent _layout.transform.parent = scrollableCharacterArea.contentContainer.transform; // and changes the position _layout.transform.localPosition = new Vector3(_xCharacter, 0, 0); // fills the character informations _layout.transform.GetChild(0).GetComponent <tk2dSprite>().SetSprite(character.Image); _layout.transform.GetChild(1).GetComponent <tk2dTextMesh>().text = CurrentLanguage.language == LanguageType.Portuguese ? character.DescriptionPT : character.DescriptionEN; // sum the position with the width to other item _xCharacter += _wCharacter; } // the ContentLength receive the length of list scrollableCharacterArea.ContentLength = _xCharacter; }
public void AddLayoutAtIndex(tk2dUILayout layout, tk2dUILayoutItem item, int index) { item.gameObj = layout.gameObject; item.layout = layout; base.layoutItems.Insert(index, item); layout.gameObject.transform.parent = base.transform; base.Refresh(); }
public void coResizeLayout(tk2dUILayout screenLay) { Vector3 minFrom = _UICamera.ScreenToWorldPoint(new Vector3(0, 0, -3)); Vector3 maxFrom = _UICamera.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, -3)); screenLay.SetBounds(minFrom, maxFrom); ///layout.SetBounds( min, max ); }
public void AddLayout(tk2dUILayout layout, tk2dUILayoutItem item) { item.gameObj = layout.gameObject; item.layout = layout; base.layoutItems.Add(item); layout.gameObject.transform.parent = base.transform; base.Refresh(); }
public void loadStoreItems() { // get items list to buy ArrayList _staticItemsList = StaticItemsList.get(); // used to load the items list bought ArrayList _cloakRoomList = new ArrayList(); // check if there are objects if (SaveSystem.hasObject("CloakRoom_List")) { // if there are, load them _cloakRoomList = (ArrayList)SaveSystem.load("CloakRoom_List", typeof(ArrayList)); } float _y = 0.0f; // position Y that the item will instantiate float _h = (prefabItem.GetMaxBounds() - prefabItem.GetMinBounds()).y; // height of the item object // pass every item of list foreach (Item item in _staticItemsList) { // it compares if this item was already bought if (!compareList(_cloakRoomList, item)) { // instantiates the prefabItem tk2dUILayout _layout = Instantiate(prefabItem) as tk2dUILayout; // changes the parent _layout.transform.parent = scrollableArea.contentContainer.transform; // and changes the position _layout.transform.localPosition = new Vector3(0, _y, 0); // fills the store item informations _layout.gameObject.AddComponent <StoreItem>().init(item); // add and get the tk2dUIItem Component to set some informations tk2dUIItem _uiItem = _layout.transform.FindChild("BlackSquare").FindChild("BuyButton").gameObject.AddComponent <tk2dUIItem>(); // set message target _uiItem.sendMessageTarget = _layout.gameObject; // set the method that will call _uiItem.SendMessageOnClickMethodName = "buyItem"; // set this informations _uiItem.InternalSetIsChildOfAnotherUIItem(true); _uiItem.isHoverEnabled = true; // sum the position with the heigth to other item _y -= _h; } } // the ContentLength receive the heigth of list scrollableArea.ContentLength = Mathf.Abs(_y); }
public void AddLayoutAtIndex(tk2dUILayout layout, tk2dUILayoutItem item, int index) { item.gameObj = layout.gameObject; item.layout = layout; layoutItems.Insert(index, item); layout.gameObject.transform.parent = transform; Refresh(); }
public void AddLayout(tk2dUILayout layout, tk2dUILayoutItem item) { item.gameObj = layout.gameObject; item.layout = layout; layoutItems.Add(item); layout.gameObject.transform.parent = transform; Refresh(); }
public void RemoveLayout(tk2dUILayout layout) { foreach (var item in layoutItems) { if (item.layout == layout) { layoutItems.Remove(item); layout.gameObject.transform.parent = null; break; } } Refresh(); }
protected IEnumerator coResizeLayout( tk2dUILayout layout, Vector3 min, Vector3 max, float time ) { Vector3 minFrom = layout.GetMinBounds(); Vector3 maxFrom = layout.GetMaxBounds(); for (float t = 0; t < time; t += tk2dUITime.deltaTime) { float nt = Mathf.SmoothStep(0, 1, Mathf.Clamp01( t / time )); Vector3 currMin = Vector3.Lerp( minFrom, min, nt ); Vector3 currMax = Vector3.Lerp( maxFrom, max, nt ); layout.SetBounds( currMin, currMax ); yield return 0; } layout.SetBounds( min, max ); }
public void RemoveLayout(tk2dUILayout layout) { foreach (var item in layoutItems) { if (item.layout == layout) { layoutItems.Remove(item); layout.gameObject.transform.parent = null; break; } } Refresh(); }
private void addLastClothes() { // instantiates the prefabWeaponItem tk2dUILayout _lastLayout = Instantiate(prefabClothesItem) as tk2dUILayout; // changes the parent _lastLayout.transform.parent = scrollableClothesArea.contentContainer.transform; // and changes the position _lastLayout.transform.localPosition = new Vector3(xClothes, 0, 0); // sum the position with the width to other item xClothes += wClothes; }
IEnumerator AddSomeItemsAuto() { int numToAdd = Random.Range(1, 5); for (int i = 0; i < numToAdd; ++i) { tk2dUILayout layout = Instantiate(prefabItem) as tk2dUILayout; autoScrollableArea.ContentLayoutContainer.AddLayoutAtIndex(layout, tk2dUILayoutItem.FixedSizeLayoutItem(), autoScrollableArea.ContentLayoutContainer.ItemCount - 1); DoSetActive(layout.transform, true); CustomizeListObject(layout.transform); yield return(new WaitForSeconds(0.2f)); } }
protected IEnumerator coResizeLayout(tk2dUILayout layout, Vector3 min, Vector3 max, float time) { Vector3 minFrom = layout.GetMinBounds(); Vector3 maxFrom = layout.GetMaxBounds(); for (float t = 0; t < time; t += tk2dUITime.deltaTime) { float nt = Mathf.SmoothStep(0, 1, Mathf.Clamp01(t / time)); Vector3 currMin = Vector3.Lerp(minFrom, min, nt); Vector3 currMax = Vector3.Lerp(maxFrom, max, nt); layout.SetBounds(currMin, currMax); yield return(0); } layout.SetBounds(min, max); }
IEnumerator AddSomeItemsManual() { float x = lastListItem.transform.localPosition.x; float w = (prefabItem.GetMaxBounds() - prefabItem.GetMinBounds()).x; int numToAdd = Random.Range(1, 5); for (int i = 0; i < numToAdd; ++i) { tk2dUILayout layout = Instantiate(prefabItem) as tk2dUILayout; layout.transform.parent = manualScrollableArea.contentContainer.transform; layout.transform.localPosition = new Vector3(x, 0, 0); DoSetActive(layout.transform, true); CustomizeListObject(layout.transform); x += w; lastListItem.transform.localPosition = new Vector3(x, lastListItem.transform.localPosition.y, 0); manualScrollableArea.ContentLength = x + (lastListItem.GetMaxBounds() - lastListItem.GetMinBounds()).x; yield return(new WaitForSeconds(0.2f)); } }
void Start() { // Disable the prefab item // don't want it visible when the game is running, as it is in the scene prefabItem.transform.parent = null; DoSetActive(prefabItem.transform, false); // Add a bunch of items to the manual list // You will need to parent the object manually and then calculate the step float x = 0; float w = (prefabItem.GetMaxBounds() - prefabItem.GetMinBounds()).x; for (int i = 0; i < 10; ++i) { tk2dUILayout layout = Instantiate(prefabItem) as tk2dUILayout; layout.transform.parent = manualScrollableArea.contentContainer.transform; layout.transform.localPosition = new Vector3(x, 0, 0); DoSetActive(layout.transform, true); CustomizeListObject(layout.transform); x += w; } lastListItem.transform.localPosition = new Vector3(x, lastListItem.transform.localPosition.y, 0); x += (lastListItem.GetMaxBounds() - lastListItem.GetMinBounds()).x; manualScrollableArea.ContentLength = x; // And some initial entries to the automatic layout list // ContentLayoutContainer.AddLayoutAtIndex inserts the layout at a position at the index // The main difference is that we don't need to calculate offset correctly - we simply insert // as needed and the layout container deals with the rest. for (int i = 0; i < 10; ++i) { tk2dUILayout layout = Instantiate(prefabItem) as tk2dUILayout; autoScrollableArea.ContentLayoutContainer.AddLayoutAtIndex(layout, tk2dUILayoutItem.FixedSizeLayoutItem(), autoScrollableArea.ContentLayoutContainer.ItemCount - 1); DoSetActive(layout.transform, true); CustomizeListObject(layout.transform); } }
void Start() { _layout = GetComponent <tk2dUILayout>(); }
public void addPlate(tk2dUILayout element) { m_plateLayout.AddLayout(element, tk2dUILayoutItem.FixedSizeLayoutItem()); element.transform.position = m_plateLayout.transform.position; m_childs.Add(element); }