void Instaniate(DecorativeFlowerGameItemType type, GameObject gameObject, Transform parent, Vector3 pos) { GameObject go = Instantiate(gameObject); go.transform.SetParent(parent); go.transform.localPosition = pos; go.transform.localScale = Vector3.one; go.GetComponent <Image>().SetNativeSize();// go.AddComponent(typeof(DecorativeFlowerGame_FinishItem)); DecorativeFlowerGame_FinishItem tempComponent = go.GetComponent <DecorativeFlowerGame_FinishItem>(); tempComponent.Type = type; tempComponent.canvas = canvas; tempComponent.vaseRect = vaseRect; tempComponent.component = this.parent; switch (type) { case DecorativeFlowerGameItemType.AppliqueItem: this.parent._appliqueItemList.Add(go); break; case DecorativeFlowerGameItemType.DecorativeItem: this.parent._decorativeItemList.Add(go); break; } go.SetActive(true); }
/// <summary> /// 拖拽到正确区域 /// </summary> protected void Drag2SureArea(DecorativeFlowerGameItemType type, Transform parent, Vector3 screenPos) { switch (type) { case DecorativeFlowerGameItemType.SquidItem: //直接放到指定位置 //遍历固定的位置点 for (int i = 0; i < this.parent._flowerPos.Count; i++) { if (!this.parent._flowerPos[i].isEnsconce) { Instaniate(type, mouseOnImage.gameObject, this.parent._flowerPos[i].trans, Vector3.zero); this.parent._flowerPos[i].isEnsconce = true; return; } } break; case DecorativeFlowerGameItemType.AppliqueItem: //贴花自由装饰 if (this.parent._appliqueItemList.Count < this.parent._appliqueItemMaxAmount) { Instaniate(type, mouseOnImage.gameObject, parent, localPoint); } break; case DecorativeFlowerGameItemType.DecorativeItem: //装饰品自由装饰 if (this.parent._decorativeItemList.Count < this.parent._decorativeItemMaxAmount) { Instaniate(type, mouseOnImage.gameObject, parent, localPoint); } break; } }