Skip to content

AlexKutepov/Plot-a-function-graph-in-Unity3D

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unity3D Function Graph Plotter

A lightweight solution for plotting function graphs in Unity3D using UI components.

Graph Example

Features

  • Dynamic point plotting on a 2D graph
  • Configurable axis dimensions and step counts
  • Support for negative axis values
  • TextMeshPro integration for axis labels
  • Grid lines for visual reference
  • Easy integration via prefab

Requirements

  • Unity 2020.3 LTS or newer
  • TextMeshPro package
  • UnityEngine.UI.Extensions (included)

Installation

  1. Download the latest release
  2. Import the package into your Unity project
  3. Drag GraphController.prefab from Assets/theGrahCreator/ into your scene

Configuration

Parameter Description
Axis Length X/Y Total length of each axis in units
Steps X/Y Number of divisions on each axis
Origin X/Y Starting coordinate offset
Point Prefab Visual representation of plotted points
Line Renderer UILineRenderer for connecting points

Usage

Basic Point Plotting

public GraphCreator graph;

void PlotFunction()
{
    for (float x = 0; x <= 10; x += 0.5f)
    {
        graph.InputX = x;
        graph.InputY = Mathf.Sin(x) * 5;
        graph.AddPoint();
    }
}

Input Controller

The GraphCreatorInputController component provides UI bindings:

  • AddPoint() — plots a point from input fields
  • ClearGraph() — removes all points
  • DeleteLastPoint() — removes the most recent point

Project Structure

Assets/theGrahCreator/
├── Scripts/
│   ├── MathPart/
│   │   └── GraphCreator.cs         # Core graph logic
│   ├── GraphCreatorInputController.cs
│   └── CustomParser.cs             # Number parsing utility
├── Scenes/
│   └── SampleScene.unity
├── unity-ui-extensions/            # UI Extensions library
└── GraphController.prefab

Screenshots

Standard Configuration:

Standard Graph

Negative Axis Values:

Negative Graph

API Reference

GraphCreator

Property Type Description
DataPoints List<Vector2> All plotted coordinates
PointInstances List<GameObject> Instantiated point objects
InputX float X coordinate for next point
InputY float Y coordinate for next point
Method Description
AddPoint() Plots current InputX/InputY
DeletePoint() Removes last plotted point
DeleteAllPoints() Clears the entire graph
InitializeGraph() Rebuilds axis labels

CustomParser

Method Description
ParseToDouble(string) Culture-aware string to double conversion

License

MIT License — see LICENSE.md


Построение графиков функций в Unity3D

Легковесное решение для построения графиков функций в Unity3D с использованием UI компонентов.

Возможности

  • Динамическое построение точек на 2D графике
  • Настраиваемые размеры осей и количество делений
  • Поддержка отрицательных значений осей
  • Интеграция с TextMeshPro
  • Линии сетки
  • Простая интеграция через prefab

Установка

  1. Скачайте последний релиз
  2. Импортируйте пакет в проект Unity
  3. Перетащите GraphController.prefab из Assets/theGrahCreator/ в сцену

Лицензия

MIT License — см. LICENSE.md