private ActionResult GenerateRedBlockViewModel(IPublishedElement item, string alias) { var block = new RedBlock(item); return(PartialView("BlockList/Components/" + alias, new PublishedElementViewModel <RedBlock, RedViewModel> { Block = block, ViewModel = new RedViewModel { DisplayTitle = !string.IsNullOrEmpty(block.Title) } })); }
public IList <Item> GetItems(Field field) { IList <Item> list = new List <Item>(); new DatFileReader(this.GetType().Assembly.GetManifestResourceStream(path)) .ReadStream_ByHexa(DatFileReader.ByPosition(Field.WIDTH, (x, y, dat) => { Item item = null; switch (dat) { case 0: break; case 1: item = new Me(field); break; case 2: item = new Snake(field); break; case 3: item = new Rmb(field); break; case 4: item = new Mush(field); break; case 5: item = new NormalStone(field); break; case 6: item = new Block(field); break; case 7: item = new BlueStone(field); break; case 8: item = new BlueBlock(field); break; case 9: item = new RedStone(field); break; case 10: item = new RedBlock(field); break; case 11: item = new GreenStone(field); break; case 12: item = new GreenBlock(field); break; case 13: item = new YellowStone(field); break; case 14: item = new YellowBlock(field); break; default: throw new Exception("データファイルが!!"); } if (item != null) { item.X = x; item.Y = y; list.Add(item); } })); return(list); }
public void OnWeaponPieceClick(int type) { // create game obeject GameObject img = new GameObject("weaponObj"); RectTransform rectTransform = img.AddComponent <RectTransform>(); img.AddComponent <CanvasRenderer>(); Image currImage = img.AddComponent <Image>(); img.transform.SetParent(craftingTable.transform); img.transform.localPosition = new Vector3(0, 0, 0); img.transform.localScale = new Vector3(1f, 1f, 1f); img.AddComponent <ClickAndDrag>(); currImage.type = Image.Type.Tiled; pieces.Add(img); switch ((WeaponPieceType)type) { case WeaponPieceType.WhiteSquare: //img.GetComponent<Image>().color = new Color32(255, 255, 255, 255); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, squareDim[0]); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, squareDim[1]); currImage.sprite = whiteSprite; break; case WeaponPieceType.WhiteRect: //currImage.color = new Color32(255, 255, 255, 255); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, rectDim[0]); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, rectDim[1]); currImage.sprite = whiteSprite; break; case WeaponPieceType.WhiteRectHort: //currImage.color = new Color32(255, 255, 255, 255); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, rectDim[1]); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, rectDim[0]); currImage.sprite = whiteSprite; break; case WeaponPieceType.BlueSquare: //currImage.color = new Color32(0, 63, 255, 255); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, squareDim[0]); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, squareDim[1]); currImage.sprite = blueSprite; img.AddComponent <BlueBlock>(); break; case WeaponPieceType.BlueRect: //currImage.color = new Color32(0, 63, 255, 255); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, rectDim[0]); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, rectDim[1]); currImage.sprite = blueSprite; img.AddComponent <BlueBlock>(); break; case WeaponPieceType.BlueRectHort: //currImage.color = new Color32(0, 63, 255, 255); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, rectDim[1]); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, rectDim[0]); currImage.sprite = blueSprite; img.AddComponent <BlueBlock>(); break; case WeaponPieceType.YellowSquare: //currImage.color = new Color32(229, 241, 24, 255); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, squareDim[0]); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, squareDim[1]); currImage.sprite = yellowSprite; img.AddComponent <YellowBlock>(); break; case WeaponPieceType.YellowRect: //currImage.color = new Color32(229, 241, 24, 255); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, rectDim[0]); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, rectDim[1]); currImage.sprite = yellowSprite; img.AddComponent <YellowBlock>(); break; case WeaponPieceType.YellowRectHort: //currImage.color = new Color32(229, 241, 24, 255); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, rectDim[1]); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, rectDim[0]); currImage.sprite = yellowSprite; img.AddComponent <YellowBlock>(); break; case WeaponPieceType.RedSquare: //currImage.color = new Color32(221, 16, 16, 255); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, squareDim[0]); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, squareDim[1]); currImage.sprite = redSprite; RedBlock blk = img.AddComponent <RedBlock>(); break; case WeaponPieceType.RedRect: //currImage.color = new Color32(221, 16, 16, 255); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, rectDim[0]); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, rectDim[1]); currImage.sprite = redSprite; blk = img.AddComponent <RedBlock>(); break; case WeaponPieceType.RedRectHort: //currImage.color = new Color32(221, 16, 16, 255); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, rectDim[1]); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, rectDim[0]); currImage.sprite = redSprite; blk = img.AddComponent <RedBlock>(); break; default: currImage.color = new Color32(217, 28, 217, 255); break; } }
public void SaveWeapon() { if (!CheckValidWeapon()) { StopAllCoroutines(); StartCoroutine(ShowErrorText("Error: Not all pieces are connected!", 1f)); return; } //clear weapon in world for (int i = 0; i < weapon.transform.childCount; i++) { Destroy(weapon.transform.GetChild(i).gameObject); } weapon.SetActive(false); GameObject temp = new GameObject("tempWeapon"); // save to weapon game object Vector3 hiltPosInWorld = hilt.transform.localPosition; GameObject hiltReal = new GameObject("hilt"); SpriteRenderer sr = hiltReal.AddComponent <SpriteRenderer>(); sr.sprite = hiltSprite; sr.drawMode = SpriteDrawMode.Sliced; sr.size = hilt.GetComponent <RectTransform>().sizeDelta; hiltReal.transform.localPosition = hiltReal.transform.localPosition + new Vector3(0f, offsetSpawnFromPlayerCenter, 0f); BoxCollider2D collider = hiltReal.AddComponent <BoxCollider2D>(); collider.size = sr.size; hiltReal.layer = LayerMask.NameToLayer("Player"); hiltReal.tag = "Player"; hiltReal.transform.SetParent(temp.transform); for (int i = 0; i < craftingTable.transform.childCount; i++) { GameObject uiChild = craftingTable.transform.GetChild(i).gameObject; if (!uiChild.Equals(hilt)) { Vector3 diff = uiChild.transform.localPosition - hiltPosInWorld; GameObject weaponComponentReal = new GameObject("weaponBlock"); SpriteRenderer wsr = weaponComponentReal.AddComponent <SpriteRenderer>(); wsr.sprite = uiChild.GetComponent <Image>().sprite; wsr.drawMode = SpriteDrawMode.Sliced; wsr.size = uiChild.GetComponent <RectTransform>().sizeDelta; Debug.Log(diff); weaponComponentReal.transform.localPosition = diff + new Vector3(0f, offsetSpawnFromPlayerCenter, 0f); BoxCollider2D weaponBox = weaponComponentReal.AddComponent <BoxCollider2D>(); weaponBox.size = wsr.size; weaponComponentReal.layer = LayerMask.NameToLayer("Player"); weaponComponentReal.tag = "Player"; weaponComponentReal.transform.SetParent(temp.transform); weaponComponentReal.transform.SetAsLastSibling(); if (uiChild.GetComponent <RedBlock>() != null) { RedBlock blk = weaponComponentReal.AddComponent <RedBlock>(); blk.RedBullet = RedBullet; } if (uiChild.GetComponent <BlueBlock>() != null) { weaponComponentReal.AddComponent <BlueBlock>(); } if (uiChild.GetComponent <YellowBlock>() != null) { weaponComponentReal.AddComponent <YellowBlock>(); } } } //finally scale down weapon to fit. temp.transform.SetParent(weapon.transform); temp.transform.localPosition = new Vector3(0f, 0f, 0f); temp.transform.localScale = new Vector3(weaponScaling, weaponScaling); temp.tag = "Player"; temp.layer = LayerMask.NameToLayer("Player"); temp.transform.localRotation = Quaternion.Euler(0, 0, 270); weapon.transform.localPosition = new Vector3(0, 0, 0); weapon.SetActive(true); Time.timeScale = 1f; this.gameObject.SetActive(false); }