// static Create method follows the API convention and parent should be first argument public static OscillatorPart Create(HandleTypeEnum handleType, IDesignFace iDesignFace, PointUV pointUV, double span, double position) { var widget = new OscillatorPart(handleType, iDesignFace, pointUV, span, position); widget.Initialize(); return(widget); }
// creates a new custom object and a wrapper for it protected OscillatorPart(HandleTypeEnum handleType, IDesignFace iDesignFace, PointUV pointUV, double span, double position) : base(iDesignFace.GetAncestor <Part>()) { this.handleTypeInt = (int)handleType; this.iDesignFace = iDesignFace; this.pointUV = pointUV; this.span = span; this.position = position; }
void OnDrawGizmos() { if (Application.isPlaying) { return; } if (HandleTypeFlattened == HandleTypeFlattenedEnum.Drag) { HandleType = HandleTypeEnum.Drag; return; } if (UnityEditor.Selection.activeGameObject == gameObject) { BoundingBoxHandle[] bbhs = transform.parent.GetComponentsInChildren <BoundingBoxHandle>(); if (HandleTypeFlattened != HandleTypeFlattenedEnum.None) { HandleType = HandleTypeEnum.None; name = HandleTypeFlattened.ToString(); HandleTypeFlattenedEnum oppositeHandle = GetOpposingHandle(HandleTypeFlattened); foreach (BoundingBoxHandle bbh in bbhs) { if (bbh.HandleTypeFlattened == oppositeHandle) { Gizmos.color = Color.red; Gizmos.DrawSphere(transform.position, 0.025f); Gizmos.DrawLine(transform.position, bbh.transform.position); break; } } transform.localPosition = GetHandlePositionFromType(HandleTypeFlattened, BoundsExtentions.Axis.Y); } else { name = HandleType.ToString(); HandleTypeEnum oppositeHandle = GetOpposingHandle(HandleType); foreach (BoundingBoxHandle bbh in bbhs) { if (bbh.HandleType == oppositeHandle) { Gizmos.color = Color.red; Gizmos.DrawSphere(transform.position, 0.025f); Gizmos.DrawLine(transform.position, bbh.transform.position); break; } } transform.localPosition = GetHandlePositionFromType(HandleType); } } }
/// <summary> /// Convenience function to get an opposing handle /// This could be done by assigning an inspector value but this is cleaner /// </summary> /// <param name="type"></param> /// <returns></returns> public static HandleTypeEnum GetOpposingHandle(HandleTypeEnum type) { switch (type) { case HandleTypeEnum.Drag: default: // Only type with no opposite return(HandleTypeEnum.Drag); // Scale handles are diagonally opposing on all axis case HandleTypeEnum.Scale_LTB: return(HandleTypeEnum.Scale_RBF); case HandleTypeEnum.Scale_LTF: return(HandleTypeEnum.Scale_RBB); case HandleTypeEnum.Scale_LBF: return(HandleTypeEnum.Scale_RTB); case HandleTypeEnum.Scale_LBB: return(HandleTypeEnum.Scale_RTF); case HandleTypeEnum.Scale_RBF: return(HandleTypeEnum.Scale_LTB); case HandleTypeEnum.Scale_RBB: return(HandleTypeEnum.Scale_LTF); case HandleTypeEnum.Scale_RTB: return(HandleTypeEnum.Scale_LBF); case HandleTypeEnum.Scale_RTF: return(HandleTypeEnum.Scale_LBB); // Rotation handles are diagonally opposing on same axis case HandleTypeEnum.Rotate_LTF_RTF: return(HandleTypeEnum.Rotate_RBB_LBB); case HandleTypeEnum.Rotate_LBF_RBF: return(HandleTypeEnum.Rotate_RTB_LTB); case HandleTypeEnum.Rotate_RTB_LTB: return(HandleTypeEnum.Rotate_LBF_RBF); case HandleTypeEnum.Rotate_RBB_LBB: return(HandleTypeEnum.Rotate_LTF_RTF); } }
private object GetHandleType() { Dictionary <string, object> dictionary = new Dictionary <string, object>(); Type t = typeof(HandleTypeEnum); Array arrays = Enum.GetValues(t); for (int i = 0; i < arrays.LongLength; i++) { HandleTypeEnum status = (HandleTypeEnum)arrays.GetValue(i); FieldInfo fieldInfo = status.GetType().GetField(status.ToString()); object[] attribArray = fieldInfo.GetCustomAttributes(false); EnumDescriptionAttribute attrib = (EnumDescriptionAttribute)attribArray[0]; dictionary.Add(status.GetHashCode().ToString(), attrib.Description); } return(dictionary); }
void OnDrawGizmos() { if (UnityEditor.Selection.activeGameObject == gameObject) { BoundingBoxHandle [] bbhs = GameObject.FindObjectsOfType <BoundingBoxHandle>(); HandleTypeEnum oppositeHandle = GetOpposingHandle(HandleType); foreach (BoundingBoxHandle bbh in bbhs) { if (bbh.HandleType == oppositeHandle) { Gizmos.color = Color.red; Gizmos.DrawSphere(transform.position, 0.025f); Gizmos.DrawLine(transform.position, bbh.transform.position); break; } } } }
/// <summary> /// Convenience function used to correctly place handles. /// Helps prevent prefab corruption. /// </summary> /// <param name="type"></param> /// <returns></returns> public static Vector3 GetHandlePositionFromType(HandleTypeEnum type) { float x = 0f; float y = 0f; float z = 0f; switch (type) { case HandleTypeEnum.Drag: default: break; case HandleTypeEnum.Scale_LTB: x = -0.5f; y = 0.5f; z = 0.5f; break; case HandleTypeEnum.Scale_LTF: x = -0.5f; y = 0.5f; z = -0.5f; break; case HandleTypeEnum.Scale_LBF: x = -0.5f; y = -0.5f; z = -0.5f; break; case HandleTypeEnum.Scale_LBB: x = -0.5f; y = -0.5f; z = 0.5f; break; case HandleTypeEnum.Scale_RBF: x = 0.5f; y = -0.5f; z = -0.5f; break; case HandleTypeEnum.Scale_RBB: x = 0.5f; y = -0.5f; z = 0.5f; break; case HandleTypeEnum.Scale_RTB: x = 0.5f; y = 0.5f; z = 0.5f; break; case HandleTypeEnum.Scale_RTF: x = 0.5f; y = 0.5f; z = -0.5f; break; case HandleTypeEnum.Rotate_LTF_LTB: x = -0.5f; y = 0.5f; z = 0.0f; break; case HandleTypeEnum.Rotate_RTF_RTB: x = 0.5f; y = 0.5f; z = 0.0f; break; case HandleTypeEnum.Rotate_LTF_RTF: x = 0.0f; y = 0.5f; z = -0.5f; break; case HandleTypeEnum.Rotate_RTB_LTB: x = 0.0f; y = 0.5f; z = 0.5f; break; case HandleTypeEnum.Rotate_LBF_LBB: x = -0.5f; y = -0.5f; z = 0.0f; break; case HandleTypeEnum.Rotate_RBF_RBB: x = 0.5f; y = -0.5f; z = 0.0f; break; case HandleTypeEnum.Rotate_LBF_RBF: x = 0.0f; y = -0.5f; z = -0.5f; break; case HandleTypeEnum.Rotate_RBB_LBB: x = 0.0f; y = -0.5f; z = 0.5f; break; case HandleTypeEnum.Rotate_LTF_LBF: x = -0.5f; y = 0.0f; z = -0.5f; break; case HandleTypeEnum.Rotate_RTB_RBB: x = 0.5f; y = 0.0f; z = 0.5f; break; case HandleTypeEnum.Rotate_LTB_LBB: x = -0.5f; y = 0.0f; z = 0.5f; break; case HandleTypeEnum.Rotate_RTF_RBF: x = 0.5f; y = 0.0f; z = -0.5f; break; } return(new Vector3(x, y, z)); }
public InkVariableWatcher(string name, HandleTypeEnum types) { this.name = name; this.handleAsType |= types; }
public static ICollection <Graphic> GetGraphics(IDesignFace iDesignFace, PointUV pointUV, double span, double position, HandleTypeEnum handleType) { Debug.Assert(iDesignFace != null); Window activeWindow = Window.ActiveWindow; var graphics = new List <Graphic>(); var primitives = new List <Primitive>(); SurfaceEvaluation eval = iDesignFace.Shape.Geometry.Evaluate(pointUV); Point point = eval.Point; Direction normal = eval.Normal; double pixelSize = activeWindow.ActiveContext.GetPixelSize(point); double shaftDiameter = 4 * pixelSize; double handleDiameter = 8 * pixelSize; double handleHeight = 4 * pixelSize; Point startPoint = point - (normal * (span * (position + 1) / 2 - handleHeight)); Point endPoint = startPoint + normal * (span + 2 * handleHeight); Vector handleHalfThickness = normal * handleHeight / 2; bool isDrawingAll = handleType == HandleTypeEnum.All; var mesh = new List <Primitive>(); var style = new GraphicStyle { EnableDepthBuffer = true, LineColor = Color.DimGray, LineWidth = 1, FillColor = Color.DimGray }; switch (handleType) { case HandleTypeEnum.All: case HandleTypeEnum.Shaft: mesh.AddRange(ShapeHelper.CreateCylinderMesh(startPoint, endPoint, shaftDiameter, 8)); graphics.Add(Graphic.Create(style, mesh)); if (isDrawingAll) { goto case HandleTypeEnum.Base; } else { break; } case HandleTypeEnum.Base: mesh.AddRange(ShapeHelper.CreateCylinderMesh(point - handleHalfThickness, point + handleHalfThickness, handleDiameter, 12)); style.LineColor = Color.DodgerBlue; style.FillColor = Color.DodgerBlue; graphics.Add(Graphic.Create(style, mesh)); if (isDrawingAll) { goto case HandleTypeEnum.Start; } else { break; } case HandleTypeEnum.Start: mesh.AddRange(ShapeHelper.CreateCylinderMesh(startPoint - handleHalfThickness, startPoint + handleHalfThickness, handleDiameter, 12)); style.LineColor = Color.DarkViolet; style.FillColor = Color.DarkViolet; graphics.Add(Graphic.Create(style, mesh)); if (isDrawingAll) { goto case HandleTypeEnum.End; } else { break; } case HandleTypeEnum.End: mesh.AddRange(ShapeHelper.CreateCylinderMesh(endPoint - handleHalfThickness, endPoint + handleHalfThickness, handleDiameter, 12)); style.LineColor = Color.DarkViolet; style.FillColor = Color.DarkViolet; graphics.Add(Graphic.Create(style, mesh)); break; } return(graphics); }