Пример #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();
            });
        }
    }
Пример #2
0
    void RenderObject(IsoObjectModel objModel, Layer layer)
    {
        GameObject obj = new GameObject("obj");

        obj.transform.position = objModel.position;
        obj.transform.rotation = objModel.rotation;
        obj.transform.SetParent(layer.gameObject.transform);


        IsoObject isoObj = obj.AddComponent <IsoObject> ();

        isoObj.FilePath = objModel.ImgFilePath;
        isoObj.offset   = objModel.offset;
        layer.AddPositionData(obj.transform.position, obj);
        // Read image;
        SpriteRenderer renderer = obj.AddComponent <SpriteRenderer> ();

        renderer.sortingOrder = objModel.SortingOrder;
        Sprite result = resources.Find(x => x.path == isoObj.FilePath).Sprite;

        result          = Ultils.ChangeOffset(result, isoObj.offset);
        renderer.sprite = result;

        obj.AddComponent <PolygonCollider2D> ();
    }
    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();
        });
    }
Пример #4
0
    public static IEnumerator LoadItemMenuImage(string url, Action <Sprite> callback)
    {
        Texture2D texture = null;
        WWW       www     = new WWW("file:///" + url);

        yield return(www);

        texture = www.texture;

        Sprite sprite = Ultils.ChangeOffset(texture);

        callback(sprite);
    }
Пример #5
0
    public IEnumerator LoadItemMenuImg(string url, Action <DownloadedResource> callback)
    {
        Texture2D texture = null;
        WWW       www     = new WWW("file:///" + url);

        yield return(www);

        texture = www.texture;
        if (www.error != null)
        {
            errorText += "File not found: " + url + "\r\n";
        }
        Sprite             sprite = Ultils.ChangeOffset(texture);
        DownloadedResource rs     = new DownloadedResource(url, sprite);

        callback(rs);
    }