UnityEngine Çizim Sınıfı C #

Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
const keytr = require('keytr.js');
Banlı Üye
Katılım
15 Ağu 2018
Mesajlar
542
Tepki puanı
138
Yaş
26
7 HİZMET YILI
:yazı:

Unity C # için küçük bir Çizim Sınıfı yazdım:
Bunu Unity Hack'inizde yeni bir .cs dosyasına koydum.

C#:
/////////////////////// KEYTR.cs //////////////////
using System;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;


namespace KEYTR
{

    class DrawDevice
    {

        public static Material lineMaterial;
        public static bool intialized = false;
        private static float CorrectY(float value)
        {

            return (Screen.height / 2 - value) + Screen.height / 2;

        }   
        public static void DrawLine(Vector2 pointA, Vector2 pointB, Color color)
        {

            lineMaterial.SetPass(0);
            GL.Begin(1);
            GL.Color(color);
            GL.Vertex3(pointA.x, pointA.y, 0f);
            GL.Vertex3(pointB.x, pointB.y, 0f);
            GL.End();

        }
        public static void DrawRect(Vector2 Point, int width,int height,Color color)
        {         
            DrawLine(Point, new Vector2(Point.x + width, Point.y),color);
            DrawLine(Point, new Vector2(Point.x, Point.y + height), color);
            DrawLine(new Vector2(Point.x + width, Point.y + height), new Vector2(Point.x + width, Point.y), color);
            DrawLine(new Vector2(Point.x + width, Point.y + height), new Vector2(Point.x, Point.y + height), color);
        }
        public static void DrawTriangle(Vector2 Point, int left, int right, int height, Color color)
        {

            DrawLine(Point, new Vector2(Point.x - left, Point.y + height), color);
            DrawLine(Point, new Vector2(Point.x + right, Point.y + height), color);
            DrawLine(new Vector2(Point.x - left, Point.y + height), new Vector2(Point.x + right, Point.y + height), color);

        }
        public static void DrawCross(Vector2 Point, int width, int height, Color color)
        {

            DrawLine(new Vector2(Point.x - width, Point.y), new Vector2(Point.x + width, Point.y),color);
            DrawLine(new Vector2(Point.x, Point.y - height), new Vector2(Point.x, Point.y + height), color);

        }
        public static void DrawCircle(Vector2 Point, int radius, Color color)
        {

             double PI = 3.1415926535;
             double i, x1, y1;
             double angle;
          

             for (i = 0; i < 360; i += 1)
             {
                 angle = i;
                 x1 = radius * Math.Cos(angle * PI / 180);
                 y1 = radius * Math.Sin(angle * PI / 180);
                 DrawLine(new Vector2(Point.x + Convert.ToSingle(x1), Point.y + Convert.ToSingle(y1)),new Vector2(Point.x + 1 + Convert.ToSingle(x1), Point.y + 1 + Convert.ToSingle(y1)),color);
             }
          

        }
        public static void DrawFont(Vector2 Point,int width,int height, string txt,Color color)
        {
            Color old = GUI.contentColor;
            GUI.contentColor = color;
            GUI.Label(new Rect(Point.x, Point.y, width, height), txt);
            GUI.contentColor = old;
        }
        public static void FillRGB(Vector2 point, float width, float height, Color color, float alpha)
        {

            Texture2D rgb = new Texture2D(1, 1);

            Color fillColor = color;
            fillColor.a = alpha;
            var fillColorArray =  rgb.GetPixels();

            for (var i = 0; i < fillColorArray.Length; ++i)
            {
                fillColorArray[i] = fillColor;
            }

            rgb.SetPixels(fillColorArray);
            rgb.Apply();
            GUI.DrawTexture(new Rect(point.x, point.y, width, height), rgb);

          
          
        } 
        public static void Intialize()
        {

            lineMaterial = new Material("Shader \"Lines/Colored Blended\" {SubShader { Pass {   BindChannels { Bind \"Color\",color }   Blend SrcAlpha OneMinusSrcAlpha   ZWrite Off Cull Off Fog { Mode Off }} } }");
            lineMaterial.hideFlags = HideFlags.HideAndDontSave;
            lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;

            intialized = true;

        }

    }

}

:kullan:

Nasıl başlatılır?

C#:
if (DrawDevice.intialized == false) DrawDevice.Intialize ();

Nasıl kullanılır:

C#:
DrawDevice.DrawLine (yeni Vector2 (20,20), yeni Vector2 (200,200), Color.Red);
 
Tony Stark Kurtarıcınız Olacak!
Banlı Üye
Katılım
25 Eyl 2018
Mesajlar
207
Tepki puanı
73
Yaş
26
7 HİZMET YILI
Ellerine Sağlık :)
 
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Üst