Example #1
0
	public override void OnInspectorGUI () {
		LODSwitcher switcher = target as LODSwitcher;
		base.OnInspectorGUI(); // Show default GUI

		// And add a field to test the LOD level
		int oldLevel = switcher.GetLODLevel();
		if(!Application.isPlaying) {
			int newLevel = EditorGUILayout.IntSlider("LOD level", oldLevel, 0, switcher.MaxLODLevel());
			if(newLevel != oldLevel) {
				switcher.SetLODLevel(newLevel);
				if(moveCameWithLOD) {
					if(newLevel > 0) Camera.main.transform.position = switcher.NearestCameraPositionForLOD(newLevel);
					else Camera.main.transform.position = oldCamPosition;
				}
			}
		} else {
			EditorGUILayout.IntField("Currently using LOD level", oldLevel);
		}

		if(!Application.isPlaying) {
			bool newBool = EditorGUILayout.Toggle("Move camera with LOD", moveCameWithLOD);
			if(newBool != moveCameWithLOD) {
				moveCameWithLOD = newBool;
				if(moveCameWithLOD) {
					oldCamPosition = Camera.main.transform.position;
					int lodLevel = switcher.GetLODLevel();
					if(lodLevel > 0) {
						Camera.main.transform.position = switcher.NearestCameraPositionForLOD(lodLevel);
					}
				} else {
					Camera.main.transform.position = oldCamPosition;
				}
			}
		}
	}
Example #2
0
 private void SetLOD(int aLod)
 {
     this.lodSetting = aLod;
     aLod--;
     LODSwitcher[] componentsInChildren = this.scenes[this.currentScene].GetComponentsInChildren <LODSwitcher>();
     LODSwitcher[] array = componentsInChildren;
     for (int i = 0; i < array.Length; i++)
     {
         LODSwitcher lODSwitcher = array[i];
         if (aLod < 0)
         {
             lODSwitcher.ReleaseFixedLODLevel();
         }
         else
         {
             lODSwitcher.SetFixedLODLevel(aLod);
         }
     }
 }
 private void GetStats()
 {
     Mesh[] meshes = this.clickedObject.GetMeshes(false);
     this.totSubMeshes = 0;
     this.totTriangles = 0;
     if (meshes != null)
     {
         Mesh[] array = meshes;
         for (int i = 0; i < array.Length; i++)
         {
             Mesh mesh = array[i];
             if (mesh != null)
             {
                 this.totSubMeshes += mesh.subMeshCount;
                 this.totTriangles += mesh.GetTriangleCount();
             }
         }
     }
     if (this.clickedObject != this.currentScene)
     {
         LODSwitcher firstComponentInChildren = this.clickedObject.GetFirstComponentInChildren <LODSwitcher>();
         if (firstComponentInChildren)
         {
             this.lodLevel = firstComponentInChildren.GetLODLevel();
         }
         else
         {
             this.lodLevel = -1;
         }
     }
     else
     {
         this.lodLevel = -1;
     }
     if (this.frameCount > 0)
     {
         this.displayFPS = Mathf.Lerp(this.displayFPS, this.frameTotTime / (float)this.frameCount, 0.5f);
     }
     this.frameTotTime = 0f;
     this.frameCount   = 0;
 }