コード例 #1
0
ファイル: ErosionBrushEditor.cs プロジェクト: TKMStudios/VR
	public void OnSceneGUI ()
	{
		script = (ErosionBrush) target;
		preset = script.preset;
		
		if (!script.paint || (Event.current.mousePosition-oldMousePos).sqrMagnitude<1f) return;

		//reading keyboard
		if (Event.current.type == EventType.keyDown)
		{
			//selecting presets with keycode
			if (script.guiSelectPresetsUsingNumkeys) 
			{
				int key = -1;
				switch (Event.current.keyCode)
				{
					//case KeyCode.Alpha1: key = 0; break;
					//case KeyCode.Alpha2: key = 2; break;
					case KeyCode.Alpha3: key = 0; break;
					case KeyCode.Alpha4: key = 1; break;
					case KeyCode.Alpha5: key = 2; break;
					case KeyCode.Alpha6: key = 3; break;
					case KeyCode.Alpha7: key = 4; break;
					case KeyCode.Alpha8: key = 5; break;
					case KeyCode.Alpha9: key = 6; break;
				}
				if (key >= 0 && key < script.presets.Length) { LoadPreset(key); script.guiSelectedPreset=key; } 
			}

			//extending brush size with keykode
			if (Event.current.keyCode == KeyCode.LeftBracket || Event.current.keyCode == KeyCode.RightBracket)
			{
				float step = (script.preset.brushSize / 10);
				step = Mathf.RoundToInt(step);
				step = Mathf.Max(1,step);

				if (Event.current.keyCode == KeyCode.LeftBracket) script.preset.brushSize -= step;
				else script.preset.brushSize += step;

				script.preset.brushSize = Mathf.Min(script.guiMaxBrushSize, script.preset.brushSize);
			}
		}

		//evaluation limitation
		//if (data.heightmapResolution-1 > 512 ||
		//	data.alphamapResolution > 512) return;

		//refreshing terrains
		script.terrains = script.GetTerrains();

		//disabling selection
		HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));

		//finding aiming ray
		Vector2 mousePos = Event.current.mousePosition;
		mousePos.y = Screen.height - mousePos.y - 40;
		Camera cam = UnityEditor.SceneView.lastActiveSceneView.camera;
		if (cam==null) return;
		Ray aimRay = cam.ScreenPointToRay(mousePos);

		//aiming terrains
		Vector3 brushPos = Vector3.zero; bool terrainsAimed = false;
		RaycastHit hit;
		for (int t=0; t<script.terrains.Length; t++)
		{
			Collider terrainCollider = script.terrains[t].GetComponent<Collider>();
			if (terrainCollider==null) continue;
			if (terrainCollider.Raycast(aimRay, out hit, Mathf.Infinity)) {brushPos=hit.point; terrainsAimed=true; }
		}
		if (!terrainsAimed) return;

		//drawing brush
		DrawBrush(brushPos, preset.brushSize, script.terrains, color:script.guiBrushColor, thickness:script.guiBrushThickness, numCorners:script.guiBrushNumCorners);
		DrawBrush(brushPos, preset.brushSize/2, script.terrains, color:script.guiBrushColor/2, thickness:script.guiBrushThickness, numCorners:script.guiBrushNumCorners);

		//repainting brush
		HandleUtility.Repaint();

		//focusing on brush
		if(Event.current.commandName == "FrameSelected")
		{ 
			Event.current.Use();
			UnityEditor.SceneView.lastActiveSceneView.LookAt( 
				brushPos, 
				UnityEditor.SceneView.lastActiveSceneView.rotation,
				preset.brushSize*6, 
				UnityEditor.SceneView.lastActiveSceneView.orthographic, 
				false);
		}

		//apply brush and undo
		if ((Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseDrag) &&
			Event.current.button == 0 &&
			!Event.current.alt)
			{
				//starting undo record
				if (Event.current.type == EventType.MouseDown && Event.current.button == 0) 
				{
					script.NewUndo();

					script.referenceUndoState = script.currentUndoState+1;
					Undo.RecordObject(script, "TS Terrain Brush");
					script.currentUndoState++;
					EditorUtility.SetDirty(script);
				}

				//recording undo
				script.AddUndo(brushPos, preset.brushSize);
					
				//apply brush
				script.ApplyBrush(brushPos, preset.brushSize);
			}
	}
コード例 #2
0
	public void OnSceneGUI ()
	{
		script = (ErosionBrush) target;
		preset = script.preset;
		
		if (!script.paint || (Event.current.mousePosition-oldMousePos).sqrMagnitude<1f) return;

		//reading keyboard
		if (Event.current.type == EventType.keyDown)
		{
			//selecting presets with keycode
			if (script.guiSelectPresetsUsingNumkeys) 
			{
				int key = -1;
				switch (Event.current.keyCode)
				{
					//case KeyCode.Alpha1: key = 0; break;
					//case KeyCode.Alpha2: key = 2; break;
					case KeyCode.Alpha3: key = 0; break;
					case KeyCode.Alpha4: key = 1; break;
					case KeyCode.Alpha5: key = 2; break;
					case KeyCode.Alpha6: key = 3; break;
					case KeyCode.Alpha7: key = 4; break;
					case KeyCode.Alpha8: key = 5; break;
					case KeyCode.Alpha9: key = 6; break;
				}
				if (key >= 0 && key < script.presets.Length) { LoadPreset(key); script.guiSelectedPreset=key; } 
			}

			//extending brush size with keykode
			if (Event.current.keyCode == KeyCode.LeftBracket || Event.current.keyCode == KeyCode.RightBracket)
			{
				float step = (script.preset.brushSize / 10);
				step = Mathf.RoundToInt(step);
				step = Mathf.Max(1,step);

				if (Event.current.keyCode == KeyCode.LeftBracket) script.preset.brushSize -= step;
				else script.preset.brushSize += step;

				script.preset.brushSize = Mathf.Min(script.guiMaxBrushSize, script.preset.brushSize);
			}
		}

		//evaluation limitation
		//if (data.heightmapResolution-1 > 512 ||
		//	data.alphamapResolution > 512) return;

		//refreshing terrains
		script.terrains = script.GetTerrains();

		//disabling selection
		HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));

		//finding aiming ray
		Vector2 mousePos = Event.current.mousePosition;
		mousePos.y = Screen.height - mousePos.y - 40;
		Camera cam = UnityEditor.SceneView.lastActiveSceneView.camera;
		if (cam==null) return;
		Ray aimRay = cam.ScreenPointToRay(mousePos);

		//aiming terrains
		Vector3 brushPos = Vector3.zero; bool terrainsAimed = false;
		RaycastHit hit;
		for (int t=0; t<script.terrains.Length; t++)
		{
			Collider terrainCollider = script.terrains[t].GetComponent<Collider>();
			if (terrainCollider==null) continue;
			if (terrainCollider.Raycast(aimRay, out hit, Mathf.Infinity)) {brushPos=hit.point; terrainsAimed=true; }
		}
		if (!terrainsAimed) return;

		//drawing brush
		DrawBrush(brushPos, preset.brushSize, script.terrains, color:script.guiBrushColor, thickness:script.guiBrushThickness, numCorners:script.guiBrushNumCorners);
		DrawBrush(brushPos, preset.brushSize/2, script.terrains, color:script.guiBrushColor/2, thickness:script.guiBrushThickness, numCorners:script.guiBrushNumCorners);

		//repainting brush
		HandleUtility.Repaint();

		//focusing on brush
		if(Event.current.commandName == "FrameSelected")
		{ 
			Event.current.Use();
			UnityEditor.SceneView.lastActiveSceneView.LookAt( 
				brushPos, 
				UnityEditor.SceneView.lastActiveSceneView.rotation,
				preset.brushSize*6, 
				UnityEditor.SceneView.lastActiveSceneView.orthographic, 
				false);
		}

		//apply brush and undo
		if ((Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseDrag) &&
			Event.current.button == 0 &&
			!Event.current.alt)
			{
				//starting undo record
				if (Event.current.type == EventType.MouseDown && Event.current.button == 0) 
				{
					script.NewUndo();

					script.referenceUndoState = script.currentUndoState+1;
					Undo.RecordObject(script, "TS Terrain Brush");
					script.currentUndoState++;
					EditorUtility.SetDirty(script);
				}

				//recording undo
				script.AddUndo(brushPos, preset.brushSize);
					
				//apply brush
				script.ApplyBrush(brushPos, preset.brushSize);
			}

		//pirate version limitation
		if (false)//(script.applyCount >= 1000)
		{
			EditorUtility.DisplayDialog("Erosion Brush", "Arrrr! You are using the special Erosion Brush: Pirate Edition. " +
			"This means that you have downloaded this plugin not from the official Unity Asset Store page but from an unknown (and probably very suspicious) location. Good job!\n\n" + 
			"Now that you have proved yourself a dashing pirate, as cool as Jack Sparrow (oops, Captain Jack Sparrow) or Jethro Flint, think about buying the product. You'll get: \n" +
			" - regular updates without any headaches;\n" +
			" - full source code;\n" +
			" - removal of this annoying message;\n" +
			" - and no bitcoin mining in the background! (ps: it wasn't me who inserted the miner in the dll, it was probably the guy you downloaded this version from).",
			"To Store", "Close"); 
			script.applyCount = 0;
		}
	}