Giter VIP home page Giter VIP logo

unity-ui-polygon's Introduction

Unity-UI-Polygon

Polygon renderer for the new Unity UI

This is a graphic control for drawing polygons in the UI System.

[UI > Extensions > Primitives > UI Polygon]

I wrote this script as an addition to the extension project for the new Unity UI system mantained by Simon "ddreaper" Jackson (https://bitbucket.org/ddreaper/unity-ui-extensions) and because I needed to draw an hexagon in one of my games ui.

I really recommend to try out the Unity UI Extensions, but this script works also on its own: just import it in your Unity project.

Usage

Make sure that "UIPolygon.cs" in imported in your project folder.

Add the Canvas:

Create an empty object:

Add the script to the empty object:

Edit the polygon properties as you like!

Edit your polygon

Examples:

Need help?

Contact me here!

unity-ui-polygon's People

Contributors

ciaccodavide avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unity-ui-polygon's Issues

Adding a license

Hi,

would be nice if you could add a license (preferably MIT), so I can actually use your awesome project.

Have a nice day!
Felix

updating parameters via script

hello @CiaccoDavide

I'm trying to change thickness and rotation from scripting and also from itween component.
Values are changing but not reflecting on the shape, they only reflect when I'm using the Inspector's sliders directly with the mouse.

I changed void Update method to public void Update and calling it from the script, but still not working.

Can you give some tips on how to change the parameters from code?

Thank you

Marlus

Doesn't seem to be working under 2020 LTS

As the title states, the plugin doesn't seem to work for me using unity 2020. No errors seemingly, but no matter what settings i change, it just displays a transparent ui element.

Colored Slices

I made a patch to have Colored Slices

GitHub Logo

commit 5b9b86c9125e1bcbb57a878285ca29d7897501e8
Author: Jorjon <[email protected]>
Date:   Tue Dec 20 20:40:36 2016 -0300

    Added the ability to specify a color for each slide

diff --git a/UIPolygon.cs b/UIPolygon.cs
index 845e0f6..81ff3ec 100644
--- a/UIPolygon.cs
+++ b/UIPolygon.cs
@@ -19,6 +19,7 @@ namespace UnityEngine.UI.Extensions
         [Range(0, 1)]
         public float[] VerticesDistances = new float[3];
         private float size = 0;
+        public Color[] colors = new Color[3];
 
         public override Texture mainTexture
         {
@@ -69,7 +70,7 @@ namespace UnityEngine.UI.Extensions
                 size = rectTransform.rect.width;
             thickness = (float)Mathf.Clamp(thickness, 0, size / 2);
         }
-        protected UIVertex[] SetVbo(Vector2[] vertices, Vector2[] uvs)
+        protected UIVertex[] SetVbo(Vector2[] vertices, Vector2[] uvs, Color color)
         {
             UIVertex[] vbo = new UIVertex[4];
             for (int i = 0; i < vertices.Length; i++)
@@ -102,6 +103,11 @@ namespace UnityEngine.UI.Extensions
                 VerticesDistances = new float[vertices];
                 for (int i = 0; i < vertices - 1; i++) VerticesDistances[i] = 1;
             }
+            if (colors.Length != sides)
+            {
+                colors = new Color[sides];
+                for (int i = 0; i < sides; i++) colors[i] = Color.white;
+            }
             // last vertex is also the first!
             VerticesDistances[vertices - 1] = VerticesDistances[0];
             for (int i = 0; i < vertices; i++)
@@ -129,7 +135,7 @@ namespace UnityEngine.UI.Extensions
                 }
                 prevX = pos1;
                 prevY = pos2;
-                vh.AddUIVertexQuad(SetVbo(new[] { pos0, pos1, pos2, pos3 }, new[] { uv0, uv1, uv2, uv3 }));
+                vh.AddUIVertexQuad(SetVbo(new[] { pos0, pos1, pos2, pos3 }, new[] { uv0, uv1, uv2, uv3 }, (i == 0 ? Color.white : colors[i - 1]) * color));
             }
         }
     } 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.