Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Seeking Guidance on Parameter-based Environment Editor Development Challenges

Discussion in 'Scripting' started by WTBA_Engineer, Jun 18, 2023.

  1. WTBA_Engineer

    WTBA_Engineer

    Joined:
    May 22, 2023
    Posts:
    13
    Hi everyone!

    I would like to create an editing program that allows designers to create environments by inputting parameters. Currently, I am facing several challenges:

    1. Every time I close the editing window, the values reset to their default values. (See Image 1)
    2. Is it possible to have a functionality where I click on an object and its corresponding settings appear in the editor interface (ObjectGenerator)?
    3. If I have objects in different orientations, such as the red, blue, and orange cubes in Image 2 (currently manually created), should I use a List to store them?
    4. Can I integrate a database with the editor program?
    5. Can the editor interface (ObjectGenerator) include dropdown menus and sortable List fields?
    Thank you all for your guidance and suggestions.
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,561
    Making editors is Really Hard Stuff(tm). Making an editor is one of the hardest possible tasks you could set before yourself. It involves elements of design, UI, UX (there's a HUGE difference between UI / UX and your questions make me think you haven't apprehended this yet), data engineering, data structuring, coding, data retrieval, querying, realtime interaction, etc.

    Answers:

    1. Learn how to serialize / save data. This is CORE to any functioning editor.

    2. Yes. Look up tutorials on selecting things and creating UI to display information about them.

    3. Every collection has a suitable purpose. This is simply Data Structures 101 learning. Start with a course on Data structures.

    IF you don't understand your data, you don't understand your problem space.

    4. Yes.

    5. Yes. Do whatever UI you think is appropriate. Design it and implement it.
     
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    1. MVC or generally separating UI from data helps. Like all of these values should be in a ScriptableObject. Next time you open the window, the SO is already there and values persist. UnityEditor namespace even has ScriptableSingleton<T> for such purpose.
    2. You probably want to look into Selection class. It gives you access to the currently selected object(s).
    3. Hard to say. That's a design decision that depends on your use case which I'm not sure of.
    4. Sure. Start with SQLite and abstract the access layer so that it'll be easy to later swap it out with another DB. By abstracting I mean avoid littering SQL statements or SQLite references all over your script(s). There should be one DatabaseAccess script that you call methods on like GetAllXXX() or UpdateRecord(value) and it knows how to construct SQL statements and passes them to the DB interface.
    5. Sure. Default list property drawers should actually already allow sorting.
     
  4. WTBA_Engineer

    WTBA_Engineer

    Joined:
    May 22, 2023
    Posts:
    13
    Sorry, I've tried to look through some information and attempted to do it myself in the past few days, which is why it took me so long to reply.

    Yes, it's quite difficult. I'm almost in tears QAQ

    I've been trying to understand what serialization is and how to serialize or save data, but I still don't quite get it. Could you please recommend any beginner-friendly tutorials?


    I want to try creating a Struct to store the size and color of each cube, so that I can retrieve the relevant information in other script. It's currently just a concept, and I'm not sure if it's feasible. Any advice?
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,561
    Everything is feasible. It's up to you to design a suitable data structure for whatever you contemplate modeling.

    You might want to take some data structures classes.

    Data in the computer is not persistent. Serialization means converting it so that it can be persisted, perhaps by a file on disk. Deserialization is the opposite.

    To me it sounds like you're just biting off more than you can chew.

    I suggest instead an iterative approach to building your skillset up:

    Ask yourself again and again, in smaller incremental steps, "Can I ...?" and then go learn how to do each part.

    Imphenzia: How Did I Learn To Make Games:

     
  6. WTBA_Engineer

    WTBA_Engineer

    Joined:
    May 22, 2023
    Posts:
    13
    I don't know why the review I wrote yesterday couldn't be displayed after I submitted it. I had to resend it.

    Sorry, I've tried to look through some information and attempted to do it myself in the past few days, which is why it took me so long to reply.

    5. I want to create a List field in the Editor Window, but I can't find the same UI interface (as a picture) that declares public List<float> List_Float; in MonoBehaviour (I try to find a List UI like the picture from this webpage )
     

    Attached Files:

  7. WTBA_Engineer

    WTBA_Engineer

    Joined:
    May 22, 2023
    Posts:
    13
    Yes, I think you're absolutely right! I was being too greedy, although part of it was due to the time constraints and pressure from my boss at work. Thank you for your advice. I will reflect on how I can gradually achieve the functionality I want. Thank you for your guidance.
     
  8. WTBA_Engineer

    WTBA_Engineer

    Joined:
    May 22, 2023
    Posts:
    13
    These things may not be needed by anyone, but there have been some rare progress, so I wanted to share them. However, my code is still bad, so it would be great if someone is willing to provide some guidance.


    As mentioned in the previous comments, you need to use serialization to save the data. Based on my region and the language I'm using, I would recommend this video (
    ). However, I still have many doubts about serialization, so I changed my previous plan to use the Editor Window approach and chose MonoBehaviour + Editor, which allows for automatic data saving. This means customizing the script under the Inspector (as shown in the picture).


    Currently, I achieve this by using data access and loading functions. Basically, when saving, I store the parameters in a script, and when calling, I read from that script.(Picture:Save_and_Load.png)


    My intention is to consider the place where cubes are placed as an area. So I'm thinking of using multiple arrays for access (Area1, Area2, etc.) or using a structure to record the data inside (a struct Area: Blocksize ... any data you want to access). The conclusion depends on your own design!


    Not yet, unfortunately.QAQ


    Solving this little problem has been my greatest sense of achievement recently!

    Dropdown menus are available by default when declaring an enum in MonoBehaviour.(Picture : 0704Enum)
    For customization:
    Code (CSharp):
    1. List<string> options = new List<string>();
    2.         foreach (var matTemp in template.MyMaterialTemplate)
    3.         {
    4.             options.Add(matTemp.Template_name);
    5.         }
    6.         template.mat_index = EditorGUILayout.Popup(template.mat_index, options.ToArray());

    Sortable lists usually appear by default when declaring List<T> or arrays in MonoBehaviour. When I posted this question, most of the custom arrays I saw didn't have the +, -, and sort buttons like the default List, and they didn't support two-dimensional arrays.So, I asked if there was a way to display them like the default List. Later, I found
    reorderableList = new ReorderableList(serializedObject, myS_Area, true, true, true, true)
    , which can create an Editor UI similar to the default array.
    As for two-dimensional arrays, I usually use
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Just2DArray : MonoBehaviour
    6. {
    7.     public int num;
    8.    
    9.     public List<Area1> MyArea;
    10.    
    11.     [System.Serializable]
    12.     public class Area1
    13.     {
    14.         public List<GameObject> BlockPrefabs;
    15.     }
    16. }
    , and it will look like [Picture: 2DArray].
    .
    I've documented this for myself and I hope it might help someone else. Since I'm not very familiar with programming, many things are based on achieving some results at the moment. So, if any experts spot any mistakes, please point them out, and I will improve. Thank you!
     

    Attached Files: