• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by CManzione · Feb 23, 2016 at 02:22 PM · cs0103

CS 0103 UnityEditor does not exist in the current context

Need some help here. I'm using a point cloud viewer and Oculus Camera Rig.

I'm getting the following compiler error CS 0103 UnityEditor does not exist in the current context

Here is the code.

 using UnityEngine;
 using System.Collections;
 using System.IO;
 
 public class PointCloudManager : MonoBehaviour {
 
     // File
     public string dataPath;
     private string filename;
     public Material matVertex;
 
     // GUI
     private float progress = 0;
     private string guiText;
     private bool loaded = false;
 
     // PointCloud
     private GameObject pointCloud;
 
     public float scale = 1;
     public bool invertYZ = false;
     public bool forceReload = false;
 
     public int numPoints;
     public int numPointGroups;
     private int limitPoints = 65000;
 
     private Vector3[] points;
     private Color[] colors;
     private Vector3 minValue;
 
     
     void Start () {
         // Create Resources folder
         createFolders ();
 
         // Get Filename
         filename = Path.GetFileName(dataPath);
 
         loadScene ();
     }
 
 
 
     void loadScene(){
         // Check if the PointCloud was loaded previously
         if(!Directory.Exists (Application.dataPath + "/Resources/PointCloudMeshes/" + filename)){
             UnityEditor.AssetDatabase.CreateFolder ("Assets/Resources/PointCloudMeshes", filename);
             loadPointCloud ();
         } else if (forceReload){
             UnityEditor.FileUtil.DeleteFileOrDirectory(Application.dataPath + "/Resources/PointCloudMeshes/" + filename);
             UnityEditor.AssetDatabase.Refresh();
             UnityEditor.AssetDatabase.CreateFolder ("Assets/Resources/PointCloudMeshes", filename);
             loadPointCloud ();
         } else
             // Load stored PointCloud
             loadStoredMeshes();
     }
     
     
     void loadPointCloud(){
         // Check what file exists
         if (File.Exists (Application.dataPath + dataPath + ".off")) 
             // load off
             StartCoroutine ("loadOFF", dataPath + ".off");
         else 
             Debug.Log ("File '" + dataPath + "' could not be found"); 
         
     }
     
     // Load stored PointCloud
     void loadStoredMeshes(){
 
         Debug.Log ("Using previously loaded PointCloud: " + filename);
 
         GameObject pointGroup = Instantiate(Resources.Load ("PointCloudMeshes/" + filename)) as GameObject;
 
         loaded = true;
     }
     
     // Start Coroutine of reading the points from the OFF file and creating the meshes
     IEnumerator loadOFF(string dPath){
 
         // Read file
         StreamReader sr = new StreamReader (Application.dataPath + dPath);
         sr.ReadLine (); // OFF
         string[] buffer = sr.ReadLine ().Split(); // nPoints, nFaces
         
         numPoints = int.Parse (buffer[0]);
         points = new Vector3[numPoints];
         colors = new Color[numPoints];
         minValue = new Vector3();
         
         for (int i = 0; i< numPoints; i++){
             buffer = sr.ReadLine ().Split ();
 
             if (!invertYZ)
                 points[i] = new Vector3 (float.Parse (buffer[0])*scale, float.Parse (buffer[1])*scale,float.Parse (buffer[2])*scale) ;
             else
                 points[i] = new Vector3 (float.Parse (buffer[0])*scale, float.Parse (buffer[2])*scale,float.Parse (buffer[1])*scale) ;
             
             if (buffer.Length >= 5)
                 colors[i] = new Color (int.Parse (buffer[3])/255.0f,int.Parse (buffer[4])/255.0f,int.Parse (buffer[5])/255.0f);
             else
                 colors[i] = Color.cyan;
 
             // Relocate Points near the origin
             //calculateMin(points[i]);
 
             // GUI
             progress = i *1.0f/(numPoints-1)*1.0f;
             if (i%Mathf.FloorToInt(numPoints/20) == 0){
                 guiText=i.ToString() + " out of " + numPoints.ToString() + " loaded";
                 yield return null;
             }
         }
 
         
         // Instantiate Point Groups
         numPointGroups = Mathf.CeilToInt (numPoints*1.0f / limitPoints*1.0f);
 
         pointCloud = new GameObject (filename);
 
         for (int i = 0; i < numPointGroups-1; i ++) {
             InstantiateMesh (i, limitPoints);
             if (i%10==0){
                 guiText = i.ToString() + " out of " + numPointGroups.ToString() + " PointGroups loaded";
                 yield return null;
             }
         }
         InstantiateMesh (numPointGroups-1, numPoints- (numPointGroups-1) * limitPoints);
 
         //Store PointCloud
         UnityEditor.PrefabUtility.CreatePrefab ("Assets/Resources/PointCloudMeshes/" + filename + ".prefab", pointCloud);
 
         loaded = true;
     }
 
     
     void InstantiateMesh(int meshInd, int nPoints){
         // Create Mesh
         GameObject pointGroup = new GameObject (filename + meshInd);
         pointGroup.AddComponent<MeshFilter> ();
         pointGroup.AddComponent<MeshRenderer> ();
         pointGroup.GetComponent<Renderer>().material = matVertex;
 
         pointGroup.GetComponent<MeshFilter> ().mesh = CreateMesh (meshInd, nPoints, limitPoints);
         pointGroup.transform.parent = pointCloud.transform;
 
 
         // Store Mesh
         UnityEditor.AssetDatabase.CreateAsset(pointGroup.GetComponent<MeshFilter> ().mesh, "Assets/Resources/PointCloudMeshes/" + filename + @"/" + filename + meshInd + ".asset");
         UnityEditor.AssetDatabase.SaveAssets ();
         UnityEditor.AssetDatabase.Refresh();
     }
 
     Mesh CreateMesh(int id, int nPoints, int limitPoints){
         
         Mesh mesh = new Mesh ();
         
         Vector3[] myPoints = new Vector3[nPoints]; 
         int[] indecies = new int[nPoints];
         Color[] myColors = new Color[nPoints];
 
         for(int i=0;i<nPoints;++i) {
             myPoints[i] = points[id*limitPoints + i] - minValue;
             indecies[i] = i;
             myColors[i] = colors[id*limitPoints + i];
         }
 
 
         mesh.vertices = myPoints;
         mesh.colors = myColors;
         mesh.SetIndices(indecies, MeshTopology.Points,0);
         mesh.uv = new Vector2[nPoints];
         mesh.normals = new Vector3[nPoints];
 
 
         return mesh;
     }
 
     void calculateMin(Vector3 point){
         if (minValue.magnitude == 0)
             minValue = point;
 
 
         if (point.x < minValue.x)
             minValue.x = point.x;
         if (point.y < minValue.y)
             minValue.y = point.y;
         if (point.z < minValue.z)
             minValue.z = point.z;
     }
 
     void createFolders(){
         if(!Directory.Exists (Application.dataPath + "/Resources/"))
             UnityEditor.AssetDatabase.CreateFolder ("Assets", "Resources");
 
         if (!Directory.Exists (Application.dataPath + "/Resources/PointCloudMeshes/"))
             UnityEditor.AssetDatabase.CreateFolder ("Assets/Resources", "PointCloudMeshes");
     }
 
 
     void OnGUI(){
 
 
         if (!loaded){
             GUI.BeginGroup (new Rect(Screen.width/2-100, Screen.height/2, 400.0f, 20));
             GUI.Box (new Rect (0, 0, 200.0f, 20.0f), guiText);
             GUI.Box (new Rect (0, 0, progress*200.0f, 20), "");
             GUI.EndGroup ();
         }
     }
 
 }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

error CS0103: The name `renderer' does not exist in the current context 2 Answers

error even after following simple tutorial 1 Answer

Error cs0103: the name unityEngine don't exist in the current context 2 Answers

Error CS0103 UnityEngine does not exist 3 Answers

error cs0103 unity the name text does not exist in the current context and same for the button what can i do plz someone help Asap 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges