public static void DrawTogglesGUILayout(IntVector2 size, List<IntVector2> points = null) { if (toggleStates_ == null) toggleStates_ = new Array2D<bool>(size); if( toggleStates_.size_ != size ) { // var oldStates = new Array2D<bool>(toggleStates_); toggleStates_ = new Array2D<bool>(size); //toggleStates_.Merge(oldStates); } var style = new GUIStyle(EditorStyles.toolbarButton); style.fixedWidth = 20; style.fixedHeight = 20; GUILayout.BeginVertical(); for (int y = 0; y < size.y; ++y) { GUILayout.BeginHorizontal(); for (int x = 0; x < size.x; ++x) { var pos = new IntVector2(x, y); var toggle = toggleStates_[pos]; if( toggle ) { var oldColor = GUI.color; GUI.color = Color.blue; toggleStates_[pos] = GUILayout.Toggle(toggleStates_[pos], GUIContent.none, style); GUI.color = oldColor; } else { toggleStates_[pos] = GUILayout.Toggle(toggleStates_[pos], GUIContent.none, style); } } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); }
public void Scale(IntVector2 scale) { this.x *= scale.x; this.y *= scale.y; }
public static float SqrMagnitude(IntVector2 a) { return a.x * a.x + a.y * a.y; }
public static IntVector2 Scale(IntVector2 a, IntVector2 b) { return new IntVector2(a.x * b.x, a.y * b.y); }
public static IntVector2 MoveTowards(IntVector2 current, IntVector2 target, float maxDistanceDelta) { IntVector2 a = target - current; float magnitude = a.magnitude; if (magnitude <= maxDistanceDelta || magnitude == 0f) { return target; } return current + a / magnitude * maxDistanceDelta; }
public static IntVector2 Min(IntVector2 lhs, IntVector2 rhs) { return new IntVector2(Mathf.Min(lhs.x, rhs.x), Mathf.Min(lhs.y, rhs.y)); }
public static IntVector2 Lerp(IntVector2 from, IntVector2 to, float t) { t = Mathf.Clamp01(t); return new IntVector2(from.x + (to.x - from.x) * t, from.y + (to.y - from.y) * t); }
public static float Dot(IntVector2 lhs, IntVector2 rhs) { return lhs.x * rhs.x + lhs.y * rhs.y; }
public static float Distance(IntVector2 a, IntVector2 b) { return (a - b).magnitude; }
public static IntVector2 ClampMagnitude(IntVector2 vector, float maxLength) { if (vector.sqrMagnitude > maxLength * maxLength) { return vector.normalized * maxLength; } return vector; }
// // Static Methods // public static float Angle(IntVector2 from, IntVector2 to) { return Mathf.Acos(Mathf.Clamp(IntVector2.Dot(from.normalized, to.normalized), -1f, 1f)) * 57.29578f; }
/// Convert a 2D array index to a 1D array index public static int TwoDtoOneD( IntVector2 index, int xMax ) { return TwoDtoOneD( index.x, index.y, xMax ); }
void Split( int minSize, SplitDirection dir, int position ) { int axis = dir == SplitDirection.Random ? Random.Range(0, 2) : (int)dir; int otherAxis = 1 - axis; if (position == -1) position = Random.Range(minSize, area_.size_[otherAxis] - minSize); // Debug.Log("Position: " + position); // Size of the "left over" area var remainingAreaOtherAxisSize = area_.size_[otherAxis] - position; // Size of the area inside the slice var slicedAreaOtherAxisSize = area_.size_[otherAxis] - remainingAreaOtherAxisSize; // Size of both new nodes along slice axis var axisSize = area_.size_[axis]; var remainingAreaSize = new IntVector2(); remainingAreaSize[axis] = axisSize; remainingAreaSize[otherAxis] = remainingAreaOtherAxisSize; var slicedAreaSize = new IntVector2(); slicedAreaSize[axis] = axisSize; slicedAreaSize[otherAxis] = slicedAreaOtherAxisSize; if (axis == 0) { IntRect remainingArea = new IntRect(area_.xMin_, area_.yMin_ + position, remainingAreaSize.x, remainingAreaSize.y); IntRect slicedArea = new IntRect(area_.xMin_, area_.yMin_, slicedAreaSize.x, slicedAreaSize.y); childNodes_[0] = new BSPNode(remainingArea); childNodes_[1] = new BSPNode(slicedArea); } if (axis == 1) { IntRect slicedArea = new IntRect(area_.xMin_, area_.yMin_, slicedAreaSize.x, slicedAreaSize.y); IntRect remainingArea = new IntRect(area_.xMin_ + slicedArea.w_, area_.yMin_, remainingAreaSize.x, remainingAreaSize.y); childNodes_[0] = new BSPNode(slicedArea); childNodes_[1] = new BSPNode(remainingArea); } childNodes_[0].parent_ = this; childNodes_[0].sibling_ = childNodes_[1]; childNodes_[1].sibling_ = childNodes_[0]; childNodes_[1].parent_ = this; }