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; }
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 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; } }
public void loadItems() { // start setting the beginning position of the objects and the width of them xWeapon = 0.85f; // position X that the weapon will instantiate xClothes = 0.85f; // position X that the clothe will instantiate wWeapon = (prefabWeaponItem.GetMaxBounds() - prefabWeaponItem.GetMinBounds()).x; // width of the weapon object wClothes = (prefabClothesItem.GetMaxBounds() - prefabClothesItem.GetMinBounds()).x; // width of the clothe object // add default items foreach (Item defaultItem in StaticItemsList.getDefault()) { addItem(defaultItem); } // check if has objects saved if (SaveSystem.hasObject("CloakRoom_List")) { // if yes, then gets them ArrayList _itemsList = (ArrayList)SaveSystem.load("CloakRoom_List", typeof(ArrayList)); // pass through list and add which item foreach (Item item in _itemsList) { addItem(item); } } // add the empty object in the final this.addLastWeapon(); this.addLastClothes(); // the ContentLength receive the length of list scrollableWeaponArea.ContentLength = xWeapon; scrollableClothesArea.ContentLength = xClothes; }
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; }
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); }
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 ); }
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); } }
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); }
void Start() { // Read the current window bounds rectMin[0] = windowLayout.GetMinBounds(); rectMax[0] = windowLayout.GetMaxBounds(); }