public bool CanStack(LoadableItem item, int quantity = 1) { return(this.item != null && item.CheckEqual(this.item) && nItems < maxStackSize && item.GetPrefab().GetComponent <WeaponBase>() == null && this.item.GetPrefab().GetComponent <WeaponBase>() == null && quantity + CountItems() <= maxStackSize); }
// void OnDestroy() // { // string idStr = ""; // foreach( var c in gameObject.name ) // { // if( char.IsNumber( c ) ) idStr += c; // } // int id = ( idStr.Length > 0 ? int.Parse( idStr ) : 0 ); // // var storage = transform.parent.name; // // print( storage + " " + id ); // } public void AddItem(LoadableItem item, int quantity = 1) { Assert.IsTrue(nItems + quantity <= maxStackSize); Assert.IsTrue(quantity > 0); nItems += quantity; Assert.IsTrue(item != null); Assert.IsTrue(this.item != null); Assert.IsNotNull(item.GetPrefab()); if (this.item.GetPrefab() == null) { // heldPrefab = prefab; // heldItem = Instantiate( prefab.transform.GetChild( 0 ).gameObject,itemPos ); // this.item = item; // this.item = GetComponent<LoadableItem>(); this.item.Copy(item); heldModel = Instantiate(item.GetPrefab().transform.GetChild(0).gameObject, itemPos); heldModel.transform.localPosition = new Vector3(-16.6f, -16.7f, -0.8f); heldModel.transform.localScale *= itemScaleFactor; heldModel.transform.localEulerAngles = new Vector3(39.2f, 70.5f, -12.6f); if (this.item.GetPrefab().GetComponent <WeaponBase>() == null) { heldModel.transform.localPosition += Vector3.right * (-2.6f + 16.6f); heldModel.transform.localPosition += Vector3.up * (-0.6f + 16.6f); heldModel.transform.localEulerAngles += Vector3.forward * (-58.0f - 12.6f); } var meshRend = heldModel.transform.GetComponentInChildren <MeshRenderer>(); meshRend.gameObject.layer = uiLayer; meshRend.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; } // else { UpdateCounter(); } }