public void RebuildMesh(float newWidth, float newHeight, float newThickness, float newTrianglePct, float newInnerCirclePct, float newOuterCirclePct) { Color baseColor = Color.HSVToRGB(hsv.x, 1f, 1f); // pure hue color float minSide = Mathf.Min(newWidth, newHeight); MeshFilter meshFilter = gameObject.GetComponent <MeshFilter>(); Mesh theNewMesh = UIUtils.BuildHSV(minSide, minSide, newThickness, newTrianglePct, newInnerCirclePct, newOuterCirclePct, 72, baseColor); theNewMesh.name = "UIColorPickerHSV_GeneratedMesh"; meshFilter.sharedMesh = theNewMesh; width = minSide; // newWidth; height = minSide; // newHeight; thickness = newThickness; trianglePct = newTrianglePct; innerCirclePct = newInnerCirclePct; outerCirclePct = newOuterCirclePct; float w2 = width / 2.0f; float h2 = height / 2.0f; float tr = trianglePct * w2; // 3 points (A, B, C) = (HUE, WHITE, BLACK) // C // / \ // / P \ // B-----A pt_A_HUE = new Vector3(w2 + tr * Mathf.Cos(-Mathf.PI / 6.0f), -h2 + tr * Mathf.Sin(-Mathf.PI / 6.0f), -thickness); pt_B_WHITE = new Vector3(w2 - tr * Mathf.Cos(-Mathf.PI / 6.0f), -h2 + tr * Mathf.Sin(-Mathf.PI / 6.0f), -thickness); pt_C_BLACK = new Vector3(w2, -h2 + tr, -thickness); UpdateColliderDimensions(); }
public static UIColorPickerHSV Create(CreateParams input) { GameObject go = new GameObject(input.widgetName); go.tag = "UICollider"; // Find the anchor of the parent if it is a UIElement Vector3 parentAnchor = Vector3.zero; if (input.parent) { UIElement elem = input.parent.gameObject.GetComponent <UIElement>(); if (elem) { parentAnchor = elem.Anchor; } } UIColorPickerHSV uiColorPickerHSV = go.AddComponent <UIColorPickerHSV>(); uiColorPickerHSV.relativeLocation = input.relativeLocation; uiColorPickerHSV.transform.parent = input.parent; uiColorPickerHSV.transform.localPosition = parentAnchor + input.relativeLocation; uiColorPickerHSV.transform.localRotation = Quaternion.identity; uiColorPickerHSV.transform.localScale = Vector3.one; uiColorPickerHSV.width = input.width; uiColorPickerHSV.height = input.height; uiColorPickerHSV.thickness = input.thickness; uiColorPickerHSV.trianglePct = input.trianglePct; uiColorPickerHSV.innerCirclePct = input.innerCirclePct; uiColorPickerHSV.outerCirclePct = input.outerCirclePct; // Setup the Meshfilter MeshFilter meshFilter = go.GetComponent <MeshFilter>(); if (meshFilter != null) { meshFilter.sharedMesh = UIUtils.BuildHSV( input.width, input.height, input.thickness, input.trianglePct, input.innerCirclePct, input.outerCirclePct, 72, Color.red); uiColorPickerHSV.Anchor = Vector3.zero; BoxCollider coll = go.GetComponent <BoxCollider>(); if (coll != null) { Vector3 initColliderCenter = meshFilter.sharedMesh.bounds.center; Vector3 initColliderSize = meshFilter.sharedMesh.bounds.size; if (initColliderSize.z < UIElement.collider_min_depth_deep) { coll.center = new Vector3(initColliderCenter.x, initColliderCenter.y, UIElement.collider_min_depth_deep / 2.0f); coll.size = new Vector3(initColliderSize.x, initColliderSize.y, UIElement.collider_min_depth_deep); } else { coll.center = initColliderCenter; coll.size = initColliderSize; } coll.isTrigger = true; } } // Setup the MeshRenderer MeshRenderer meshRenderer = go.GetComponent <MeshRenderer>(); if (meshRenderer != null && input.hueMaterial != null && input.svMaterial != null) { meshRenderer.sharedMaterials = new Material[] { Instantiate(input.hueMaterial), Instantiate(input.svMaterial) }; meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; meshRenderer.renderingLayerMask = 1 << 1; // "LightLayer 1" } // Add a cursor GameObject hueCursor = Instantiate <GameObject>(input.hueCursorPrefab); hueCursor.transform.parent = uiColorPickerHSV.transform; hueCursor.transform.localPosition = Vector3.zero; hueCursor.transform.localRotation = Quaternion.identity; uiColorPickerHSV.hueCursor = hueCursor.transform; GameObject svCursor = Instantiate <GameObject>(input.svCursorPrefab); svCursor.transform.parent = uiColorPickerHSV.transform; svCursor.transform.localPosition = Vector3.zero; svCursor.transform.localRotation = Quaternion.identity; uiColorPickerHSV.svCursor = svCursor.transform; UIUtils.SetRecursiveLayer(go, "CameraHidden"); return(uiColorPickerHSV); }