Search Unity

Access scripting api form script in editor folder (2019.1.3)

Discussion in 'World Building' started by ProtagonistKun, May 20, 2019.

  1. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    352
    Hello,

    I wanted to try and get some procedural mesh generation into my unity engine,
    so I can have my artist friend create his rooms and fill in the floor.

    However I cant access the API from script (using ProBuilder version 4.0.5)
    the only thing i can access is UnityEngine.ProBuilder.AssetIdRemapUtility;
     
  2. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    552
  3. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    352
    I have, I used this site as a reference and implemented code to generate a simple plane.
    https://docs.unity3d.com/Packages/com.unity.probuilder@4.0/manual/api.html

    However the ProbuilderMesh could not be found. Which would lead me to believe the API might be outdated? which would surprise me since its pretty recent as far as I know.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.ProBuilder;
    3.  
    4. public class CreateFloor : MonoBehaviour
    5. {
    6.     public void Test()
    7.     {
    8.         ProBuilderMesh quad = ProBuilderMesh.Create(
    9.             new Vector3[] {
    10.                 new Vector3(0f, 0f, 0f),
    11.                 new Vector3(1f, 0f, 0f),
    12.                 new Vector3(0f, 1f, 0f),
    13.                 new Vector3(1f, 1f, 0f)
    14.             },
    15.             new Face[] { new Face(new int[] { 0, 1, 2, 1, 3, 2 } )
    16.             });
    17.     }
    18. }
    Edit: the namespace for ProBuilder is being found, but I cant seem to access any functions.

    Edit 2: In case it would matter, the script is placed in Assets/Scripts/Editor/Probuilder/CreateFloor.cs

    2019-05-22_13-35-35.png
     
    Last edited: May 22, 2019
  4. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    352
    Oh you actually have to create that asset to make it work. I assumed you meant that I needed to set up references at the top of my project... When I do this some custom inspectors stop working though...

    Edit: Ok, so I figured it out with the assembly. I had to make sure it has its own folder for the assembly. This kinda sucks though. Can I not add this to the default unity assembly? Because right now it looks like this. Is this the intended way to do it? Or more generally speaking, should I split code into assemblies to reduce the build time?
    upload_2019-5-22_17-40-39.png
     
    Last edited: May 22, 2019
  5. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    552
    Yes, right now you have to create a new folder, and an accompanying assembly definition to access the ProBuilder API. This is changing in the next update, and you will be able to access the ProBuilder namespace from the default assembly (the release will be ProBuilder 4.1.0).
     
    ProtagonistKun likes this.
  6. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    352
    thats fair enough, but honestly I think i might keep it in a separate assembly.
    I didnt know they existed so thanks for that :D