Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Don't miss out on the Unite LA Keynote for the latest information from Unity! Set a reminder!
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

RPG Maker style exp curve

Discussion in 'Extensions & OnGUI' started by zafuri, Sep 30, 2018.

  1. zafuri

    zafuri

    Joined:
    Jul 24, 2017
    Posts:
    4
    Hi,

    This is my first time posting on a forum but here goes, I am looking to make a custom editor for creating a player etc. similar to RPG Maker, i have a good understanding now of how to do it but i am stuck on one part in particular. I want to create an experience curve and stats curve like in RPG Maker where it has like intractable progress bars that can set the value for each level up one by one. I understand it could mean making 99 small progress bars to reflect this however i do not know if Unity can do this or if there is a good alternative. I tried "EditorGUI.ProgressBar" which can show a value with a little math but this is not intractable. I know there is also animation curves that can be set but i don't know if this would be a suitable alternative or how to implement it. If it helps i am using a Custom Editor Window and i code in C#, i am completely self taught so there might be stuff i am completely unaware of. I would be grateful of any help or at least pointing in the right direction so i can figure something out. Thanks in advance
     

    Attached Files:

  2. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    308
    Animation curves are a good option, you should investigate those.
     
    karl_jones likes this.
  3. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    848
    @zafuri

    What @brownboot67 said - There is an example in manual, you basically add keyframes, that create a curve:
    https://docs.unity3d.com/ScriptReference/AnimationCurve-ctor.html

    It's also editable.

    Just curious - in your image I only see linear graphs (six different colors). Do you mean that it is possible to somehow drag these with mouse to change their shape? Also, having such graphs for levels sounds pretty inaccurate for leveling system if there is no numerical entry.

    If you don't need clickable / interactive graphs, you could also use Texture2D and SetPixels to draw your graph in texture, then you can set the texture to UI system image as sprite. It sounds more complicated than it is. This way you can have colorful graphs.
     
  4. zafuri

    zafuri

    Joined:
    Jul 24, 2017
    Posts:
    4
    Thank you for your replies, I have looked into the curves and while indeed i could set key frames etc it doesn't seem to be able to do what i intend.

    Those linear graphs are indeed editable by mouse and have integers that they represent. I intend for something similar, they also have a slider where you can choose whether the level up has a slow, linear or fast growth rate which makes them behave similar to the presets on the animation curve which is what made me look into them.

    the animation curve would work if it was able to save outside of the editor window instance and more importantly if i could read the values from the graph at certain keyframe points in code to set the level up integers.

    I never thought of looking at Texture2D pixels but that may be an option if i can use it on a custom window, This pic attached here shows where i am at with a character create window. This interacts with a game object in a monobehaviour script which holds lists from [system.serialisable] classes i created to hold the data. I have left the curve in for now until i find a proper work around, where the "manual EXP Curve" is ticked it brings up the "level2" int, this would instead show all level ints up to the amount the max level is set to, the idea is to allow full control over exp required (not at the stats point yet but would want something similar for them too) but while this could be a pain to do individually i would like a button (instead of "EXP Growth") to maybe control these ints based on a formula which could have different growth rates which could then be tweaked manually if required if that makes any sense..

    All the graphs are really to do is show this in a visual format
     

    Attached Files:

  5. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    848
    @zafuri

    You can get the keys of animation curve:
    https://docs.unity3d.com/ScriptReference/AnimationCurve-keys.html

    Keyframe:
    https://docs.unity3d.com/ScriptReference/Keyframe.html

    You can use evaluate to get animation curve value (y-axis position) at specific time (x-axis position):
    https://docs.unity3d.com/ScriptReference/AnimationCurve.Evaluate.html

    Edit - you can render your curve to texture (just going column by column for example), I don't see why it wouldn't work in editor window / custom inspector (but I might be wrong):

     
    Last edited: Oct 2, 2018
  6. zafuri

    zafuri

    Joined:
    Jul 24, 2017
    Posts:
    4
    Thank you for your insight, i have figured out how to read the curves and add keyframes in code, just need to figure out how to convert the graph to a texture2D like your gif shows and that should be problem solved. Your help is much appreciated as i wouldn't have got this far without it.