// allocate furniture instance public bool AllocateFurnitureInstance(int index, int presentStepIndex) { int processIndex = index + (presentStepIndex * (haveFurnitureSet.Length / 3)); try { if (haveFurnitureSet[processIndex] == null || haveFurnitureSet[processIndex].Furniture == null || haveFurnitureSet[processIndex].Furniture.ID == 0) { return(false); } else { allocateFurnitureSet.Add(new FurnitureInstance(haveFurnitureSet[processIndex])); allocateFurnitureSet[allocateFurnitureSet.Count - 1].AllocateInstance(allocateFurnitureSet.Count - 1); haveFurnitureSet[processIndex] = new FurnitureInstance( ); return(true); } } catch (Exception e) { Debug.Log(e.StackTrace); Debug.Log(e.Message); return(false); } }
// constructor -> copy instance public FurnitureInstance(FurnitureInstance data) { furniture = data.Furniture; position = data.position; rotation = data.rotation; isAllocated = data.isAllocated; slotNumber = data.slotNumber; }
// public method // add furniture data -> use only data public bool AddFurnitureData(FurnitureData data) { for (int i = 0; i < haveFurnitureSet.Length; i++) { if (haveFurnitureSet[i] == null || haveFurnitureSet[i].Furniture == null || haveFurnitureSet[i].Furniture.ID == 0) { haveFurnitureSet[i] = new FurnitureInstance(data, i); return(true); } } Debug.Log("Furniture inventory is full"); return(false); }
// add furniture data -> move instance data public bool AddFurnitureData(int id) { for (int i = 0; i < ( int )haveFurnitureSet.Length; i++) { if (haveFurnitureSet[i] == null || haveFurnitureSet[i].Furniture == null || haveFurnitureSet[i].Furniture.ID == 0) { haveFurnitureSet[i] = new FurnitureInstance(DataManager.FindFurnitureDataByID(id), i); haveFurnitureSet[i].IsAllocated = false; return(true); } } Debug.Log("Furniture inventory is full"); return(false); }
// update component element -> use furniture instance public void UpdateComponentElement(FurnitureInstance data) { if (count.enabled) { count.enabled = false; } // set default if ((data == null) || (data.Furniture == null) || (data.Furniture.ID == 0)) { elementIcon.sprite = Resources.Load <Sprite>("Image/UI/ItemIcon/EmptySpace"); } // set image icon else { elementIcon.sprite = Resources.Load <Sprite>("Image/UI/FurnitureIcon/" + data.Furniture.File); } }