Esempio n. 1
0
    void RenderMenuItem(IsoLayerModel data, GameObject parent, Layer belongLayer)
    {
        for (int i = 0; i < data.FactoryModel.Count; i++)
        {
            GameObject item = new GameObject("item");
            ImportItemManager.AddRightClickEvent(item);

            // Add image component.
            Image   imgItem = item.AddComponent <Image> ();
            string  url     = data.FactoryModel [i].filePath;
            Vector2 offset  = data.FactoryModel [i].offset;
            Sprite  result  = resources.Find(x => x.path == url).Sprite;
            result         = Ultils.ChangeOffset(result, offset);
            imgItem.sprite = result;

            AddRatioFitter(item, imgItem);
            SetItemParent(parent, item);
            IsoObjectFactory factory = item.AddComponent <IsoObjectFactory> ();
            factory.FilePath = url;
            factory.offset   = offset;
            belongLayer.isoFactories.Add(factory);

            UnityEngine.UI.Button btnItem = item.AddComponent <UnityEngine.UI.Button> ();
            btnItem.onClick.AddListener(() => {
                ImportItemManager.loadedImage = btnItem.image.sprite;
                IsoObjectFactory.instance     = factory;
                belongLayer.NewObject();
            });
        }
    }
    public void AddItem()
    {
        GameObject item    = new GameObject("item");
        Image      imgItem = item.AddComponent <Image> ();

        AddRightClickEvent(item);

        UnityEngine.UI.Button btnItem = item.AddComponent <UnityEngine.UI.Button> ();

        Sprite sprite = Ultils.ChangeOffset(texture);

        imgItem.sprite = sprite;
        AspectRatioFitter ratioFitter = item.AddComponent <AspectRatioFitter> ();

        ratioFitter.aspectRatio = sprite.rect.width / sprite.rect.height;
        ratioFitter.aspectMode  = AspectRatioFitter.AspectMode.HeightControlsWidth;

        item.transform.SetParent(currentButtonContainer.transform, false);
        item.transform.localScale    = Vector3.one;
        item.transform.localPosition = Vector3.zero;
        IsoObjectFactory factory = item.AddComponent <IsoObjectFactory> ();

        factory.FilePath = path;
        factory.offset   = PivotEditForm.realSpriteOffset;

        IsoLayerManager.currentLayer.isoFactories.Add(factory);
        btnItem.onClick.AddListener(() => {
            loadedImage = btnItem.image.sprite;
            IsoObjectFactory.instance = factory;
            IsoLayerManager.currentLayer.NewObject();
        });
    }
Esempio n. 3
0
    IsoObjectFactory AddObjectFactory(string url, Vector2 offset, GameObject item)
    {
        IsoObjectFactory factory = item.AddComponent <IsoObjectFactory> ();

        factory.FilePath = url;
        factory.offset   = offset;
        return(factory);
    }
 public IsoFactoryModel(IsoObjectFactory factory)
 {
     this.filePath = factory.FilePath;
     this.offset   = factory.offset;
 }
 void Awake()
 {
     instance = this;
 }