//创建炸弹 void CreateBomb(Color color) { if (objBomb != null) { return; } objBomb = new GameObject("Bomb"); objBomb.transform.parent = this.transform; float z = itemPosZ - 5; objBomb.transform.position = new Vector3(0, 0, z); SpriteRenderer objSR = objBomb.AddComponent <SpriteRenderer>(); TextureUtil.UpdateSpriteTexture(objBomb, AppRes.IMAGE_Game_Bomb); // 高亮颜色 { ShapeHighlighterController hlc = AddHighLight(objBomb); hlc.UpdateColor(color); } //添加物理特性 { Rigidbody2D bd = objBomb.AddComponent <Rigidbody2D>(); bd.gravityScale = 0; // bd.useGravity = false; bd.freezeRotation = true; bd.collisionDetectionMode = CollisionDetectionMode2D.Continuous; PolygonCollider2D collider = objBomb.AddComponent <PolygonCollider2D>(); } ShapeColorItemInfo infoItem = new ShapeColorItemInfo(); infoItem.obj = objBomb; // infoItem.objTrail = infoshape.objTrail; infoItem.id = ID_BOMB; // infoItem.color = infocolor.color; infoItem.isMain = false; infoItem.isInner = false; SetItemLock(infoItem, false); listItem.Add(infoItem); }
GameObject CreateItem(ShapeColorItemInfo info, bool isInner, Color color) { float x, y, w, h; string name = info.id + "_outer"; if (isInner) { name = info.id + "_inner"; } GameObject obj = new GameObject(name); obj.transform.parent = this.transform; RectTransform rcTran = obj.AddComponent <RectTransform>(); SpriteRenderer objSR = obj.AddComponent <SpriteRenderer>(); string pic = info.picOuter; if (isInner) { pic = info.picInner; } //Sprite sprite = LoadTexture.CreateSprieFromAsset(pic); if (Common.isWeb) { TextureUtil texutil = new TextureUtil(); info.textureHasLoad = false; texutil.UpdateSpriteTextureWeb(obj, HttpRequest.GetWebUrlOfAsset(pic), OnTextureHttpRequestFinished, info); } else { TextureUtil.UpdateSpriteTexture(obj, pic); info.textureHasLoad = true; objSR.sprite.name = info.id; } float z = itemPosZ; if (isInner) { z = itemPosZ - 1; } obj.transform.position = new Vector3(0, 0, z); bool is_add_shader = true; //color // if (Common.appKeyName != AppType.SHAPECOLOR) if (!info.isMath) { if (isInner) { is_add_shader = false; // objSR.material = new Material(shaderOutLine); // objSR.material.SetColor("_OutlineColor", color); ShapeHighlighterController hlc = AddHighLight(obj); hlc.UpdateColor(color); } } if (is_add_shader) { objSR.material = new Material(shaderColor); Material mat = objSR.material; mat.SetColor("_ColorShape", color); } //添加物理特性 if (isInner) { Rigidbody2D bd = obj.AddComponent <Rigidbody2D>(); bd.gravityScale = 0; // bd.useGravity = false; bd.freezeRotation = true; bd.collisionDetectionMode = CollisionDetectionMode2D.Continuous; PolygonCollider2D collider = obj.AddComponent <PolygonCollider2D>(); } //添加尾巴 ShapeTrail // if (isInner) // { // info.objTrail = new GameObject("trail"); // info.objTrail.transform.parent = obj.transform; // info.objTrail.transform.localPosition = Vector3.zero; // ShapeTrail trail = info.objTrail.AddComponent<ShapeTrail>(); // } return(obj); }