private void PaintToScreen(Vector3 position) { var mainCamera = Camera.main; if (null == mainCamera) { return; } var ray = mainCamera.ScreenPointToRay(Input.mousePosition); var start = ray.GetPoint(mainCamera.nearClipPlane); var end = ray.GetPoint(mainCamera.farClipPlane); // Paint between the start and end points switch (Paint) { case NearestOrAll.Nearest: { P3D_Paintable.ScenePaintBetweenNearest(Brush, start, end, LayerMask, GroupMask); } break; case NearestOrAll.All: { P3D_Paintable.ScenePaintBetweenAll(Brush, start, end, LayerMask, GroupMask); } break; } }
public static void ScenePaintBetweenNearest(P3D_Brush brush, Vector3 startPosition, Vector3 endPosition, int layerMask = -1, int groupMask = -1) { float num = Vector3.Distance(startPosition, endPosition); if (num != 0f) { P3D_Paintable paintable = null; P3D_Result result = null; for (int i = AllPaintables.Count - 1; i >= 0; i--) { P3D_Paintable paintable2 = AllPaintables[i]; if (P3D_Helper.IndexInMask(paintable2.gameObject.layer, layerMask)) { P3D_Tree tree = paintable2.GetTree(); if (tree != null) { Transform transform = paintable2.transform; Vector3 startPoint = transform.InverseTransformPoint(startPosition); P3D_Result result2 = tree.FindBetweenNearest(startPoint, startPoint + ((transform.InverseTransformPoint(endPosition) - startPoint).normalized * num)); if (result2 != null) { paintable = paintable2; result = result2; num *= result2.Distance01; } } } } if ((paintable != null) && (result != null)) { paintable.Paint(brush, result, groupMask); } } }
public static void ScenePaintPerpedicularNearest(P3D_Brush brush, Vector3 position, float maxDistance, int layerMask = -1, int groupMask = -1) { P3D_Paintable paintable = null; P3D_Result result = null; for (int i = AllPaintables.Count - 1; i >= 0; i--) { P3D_Paintable paintable2 = AllPaintables[i]; if (P3D_Helper.IndexInMask(paintable2.gameObject.layer, layerMask)) { P3D_Tree tree = paintable2.GetTree(); if (tree != null) { Transform transform = paintable2.transform; if (P3D_Helper.GetUniformScale(transform) != 0f) { P3D_Result result2 = tree.FindPerpendicularNearest(transform.InverseTransformPoint(position), maxDistance); if (result2 != null) { paintable = paintable2; result = result2; maxDistance *= result2.Distance01; } } } } } if (paintable != null) { paintable.Paint(brush, result, groupMask); } }
protected virtual void Update() { cooldown -= Time.deltaTime; if (cooldown <= 0.0f) { cooldown = Interval; var position = transform.position; switch (Paint) { case NearestOrAll.Nearest: { P3D_Paintable.ScenePaintPerpedicularNearest(Brush, position, MaxDistance, LayerMask, GroupMask); } break; case NearestOrAll.All: { P3D_Paintable.ScenePaintPerpedicularAll(Brush, position, MaxDistance, LayerMask, GroupMask); } break; } } }
// Called every frame protected virtual void Update() { if (!GameController.Instance.CanPaint) { return; } var mainCamera = Camera.main; if (mainCamera != null) { // The required key is down? if (Input.GetKey(Requires)) { var ray = mainCamera.ScreenPointToRay(Input.mousePosition); var start = ray.GetPoint(mainCamera.nearClipPlane); var end = ray.GetPoint(mainCamera.farClipPlane); // Paint between the start and end points switch (Paint) { case NearestOrAll.Nearest: { P3D_Paintable.ScenePaintBetweenNearest(Brush, start, end, LayerMask, GroupMask); } break; case NearestOrAll.All: { P3D_Paintable.ScenePaintBetweenAll(Brush, start, end, LayerMask, GroupMask); } break; } } } }
public static int register(P3D_Paintable paintable) { counter++; paintableToNum.Add(paintable.GetHashCode(), counter); numToPaintable.Add(counter, paintable); return(counter); }
public static void ScenePaintPerpedicularAll(P3D_Brush brush, Vector3 position, float maxDistance, int layerMask = -1, int groupMask = -1) { for (int i = AllPaintables.Count - 1; i >= 0; i--) { P3D_Paintable paintable = AllPaintables[i]; if (P3D_Helper.IndexInMask(paintable.gameObject.layer, layerMask)) { paintable.PaintPerpendicularAll(brush, position, maxDistance, groupMask); } } }
public static void ScenePaintBetweenAll(P3D_Brush brush, Vector3 startPosition, Vector3 endPosition, int layerMask = -1, int groupMask = -1) { for (int i = AllPaintables.Count - 1; i >= 0; i--) { P3D_Paintable paintable = AllPaintables[i]; if (P3D_Helper.IndexInMask(paintable.gameObject.layer, layerMask)) { paintable.PaintBetweenAll(brush, startPosition, endPosition, groupMask); } } }
// Called every frame protected virtual void Update() { if (mainCamera == null) { mainCamera = Camera.main; } if (mainCamera != null && StepSize > 0.0f) { // The required key is down? if (Input.GetKeyDown(Requires) == true) { oldMousePosition = Input.mousePosition; } // The required key is set? if (Input.GetKey(Requires) == true) { // Find the ray for this screen position var newMousePosition = (Vector2)Input.mousePosition; var stepCount = Vector2.Distance(oldMousePosition, newMousePosition) / StepSize + 1; for (var i = 0; i < stepCount; i++) { var subMousePosition = Vector2.Lerp(oldMousePosition, newMousePosition, i / stepCount); var ray = mainCamera.ScreenPointToRay(subMousePosition); var start = ray.GetPoint(mainCamera.nearClipPlane); var end = ray.GetPoint(mainCamera.farClipPlane); // This will both use Physics.Raycast and search P3D_Paintables switch (Paint) { case NearestOrAll.Nearest: { P3D_Paintable.ScenePaintBetweenNearest(Brush, start, end, LayerMask, GroupMask); } break; case NearestOrAll.All: { P3D_Paintable.ScenePaintBetweenAll(Brush, start, end, LayerMask, GroupMask); } break; } } oldMousePosition = newMousePosition; } } }
public static void ScenePaintBetweenNearestRaycast(P3D_Brush brush, Vector3 startPosition, Vector3 endPosition, int layerMask = -1, int groupMask = -1) { float maxDistance = Vector3.Distance(startPosition, endPosition); if (maxDistance != 0f) { P3D_Paintable component = null; RaycastHit hitInfo = new RaycastHit(); P3D_Result result = null; if (Physics.Raycast(startPosition, endPosition - startPosition, out hitInfo, maxDistance, layerMask)) { component = hitInfo.collider.GetComponent <P3D_Paintable>(); maxDistance = hitInfo.distance; } for (int i = AllPaintables.Count - 1; i >= 0; i--) { P3D_Paintable paintable2 = AllPaintables[i]; if (P3D_Helper.IndexInMask(paintable2.gameObject.layer, layerMask)) { P3D_Tree tree = paintable2.GetTree(); if (tree != null) { Transform transform = paintable2.transform; Vector3 startPoint = transform.InverseTransformPoint(startPosition); P3D_Result result2 = tree.FindBetweenNearest(startPoint, startPoint + ((transform.InverseTransformPoint(endPosition) - startPoint).normalized * maxDistance)); if (result2 != null) { component = paintable2; result = result2; maxDistance *= result2.Distance01; } } } } if (component != null) { if (result != null) { component.Paint(brush, result, groupMask); } else { component.Paint(brush, hitInfo, groupMask); } } } }
// Called every frame protected virtual void Update() { if (mainCamera == null) { mainCamera = Camera.main; } if (mainCamera != null) { // The required key is down? if (Input.GetKey(Requires) == true) { var ray = mainCamera.ScreenPointToRay(Input.mousePosition); P3D_Paintable.PaintBetweenNearest(ray.GetPoint(mainCamera.nearClipPlane), ray.GetPoint(mainCamera.farClipPlane), Brush, RaycastMask); } } }
private IEnumerator DelayedPaint(P3D_Paintable paintable, Vector2 uv, float distance01) { // Delay it based on how far the ray travelled to hit yield return(new WaitForSeconds(distance01 * MaxDelay)); // Make sure the paintable still exists if (paintable != null) { // Make a temp brush clone so we can alter some settings without changing our actual brush var tempBrush = Brush.GetTempClone(); // Set the opacity to be based on distance tempBrush.Opacity *= 1.0f - distance01; // Paint using our modified brush paintable.Paint(tempBrush, uv); } }
private IEnumerator DelayedPaint(P3D_Paintable paintable, Vector2 coord, float distance01) { // Delay it based on how far the ray travelled to hit yield return(new WaitForSeconds(distance01 * MaxDelay)); // Make sure the paintable still exists if (paintable != null) { // Get painter for this paintable var painter = paintable.GetPainter(); // Change painter's current brush painter.SetBrush(Brush); // Set the opacity to be based on distance painter.Opacity *= 1.0f - distance01; // Paint at the hit coordinate painter.Paint(coord); } }
// This will paint the target object every frame protected virtual void Update() { if (Start != null && End != null) { // Paint between the start and end positions switch (Paint) { case NearestOrAll.Nearest: { P3D_Paintable.ScenePaintBetweenNearest(Brush, Start.position, End.position, LayerMask, GroupMask); } break; case NearestOrAll.All: { P3D_Paintable.ScenePaintBetweenAll(Brush, Start.position, End.position, LayerMask, GroupMask); } break; } } }
public static int getNum(P3D_Paintable paintable) { return(paintableToNum[paintable.GetHashCode()]); }