public void RebuildMesh(float newWidth, float newHeight, float newThickness) { MeshFilter meshFilter = gameObject.GetComponent <MeshFilter>(); Mesh theNewMesh = UIUtils.BuildBoxEx(newWidth, newHeight, newThickness); theNewMesh.name = "UIColorPickerAlpha_GeneratedMesh"; meshFilter.sharedMesh = theNewMesh; width = newWidth; height = newHeight; thickness = newThickness; UpdateColliderDimensions(); }
public override void RebuildMesh() { // TIME TICKS ?? // ... // BASE MeshFilter meshFilter = gameObject.GetComponent <MeshFilter>(); Mesh theNewMesh = UIUtils.BuildBoxEx(width, height, thickness); theNewMesh.name = "UITimeBar_GeneratedMesh"; meshFilter.sharedMesh = theNewMesh; UpdateColliderDimensions(); UpdateTimeBarPosition(); }
public static void Create(CreateArgs 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; } } UITimeBar uiTimeBar = go.AddComponent <UITimeBar>(); // NOTE: also creates the MeshFilter, MeshRenderer and Collider components uiTimeBar.relativeLocation = input.relativeLocation; uiTimeBar.transform.parent = input.parent; uiTimeBar.transform.localPosition = parentAnchor + input.relativeLocation; uiTimeBar.transform.localRotation = Quaternion.identity; uiTimeBar.transform.localScale = Vector3.one; uiTimeBar.width = input.width; uiTimeBar.height = input.height; uiTimeBar.thickness = input.thickness; uiTimeBar.minValue = input.min_slider_value; uiTimeBar.maxValue = input.max_slider_value; uiTimeBar.currentValue = input.cur_slider_value; uiTimeBar.baseColor.useConstant = false; uiTimeBar.baseColor.reference = input.background_color; // Setup the Meshfilter MeshFilter meshFilter = go.GetComponent <MeshFilter>(); if (meshFilter != null) { // TODO: new mesh, with time ticks texture meshFilter.sharedMesh = UIUtils.BuildBoxEx(input.width, input.height, input.thickness); uiTimeBar.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_shallow) { coll.center = new Vector3(initColliderCenter.x, initColliderCenter.y, UIElement.collider_min_depth_shallow / 2.0f); coll.size = new Vector3(initColliderSize.x, initColliderSize.y, UIElement.collider_min_depth_shallow); } else { coll.center = initColliderCenter; coll.size = initColliderSize; } coll.isTrigger = true; } } // Setup the MeshRenderer MeshRenderer meshRenderer = go.GetComponent <MeshRenderer>(); if (meshRenderer != null && input.background_material != null) { // Clone the material. meshRenderer.sharedMaterial = Instantiate(input.background_material); meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; meshRenderer.renderingLayerMask = (1 << 3); uiTimeBar.SetColor(input.background_color.value); } // KNOB GameObject K = new GameObject("Knob"); uiTimeBar.knob = K.transform; UIUtils.SetRecursiveLayer(go, "CameraHidden"); }
public static UIColorPickerPreview CreateUIColorPickerPreview( string objectName, Transform parent, Vector3 relativeLocation, float width, float height, float thickness, Material material) { GameObject go = new GameObject(objectName); go.tag = "UICollider"; // Find the anchor of the parent if it is a UIElement Vector3 parentAnchor = Vector3.zero; if (parent) { UIElement elem = parent.gameObject.GetComponent <UIElement>(); if (elem) { parentAnchor = elem.Anchor; } } UIColorPickerPreview uiColorPickerPreview = go.AddComponent <UIColorPickerPreview>(); uiColorPickerPreview.relativeLocation = relativeLocation; uiColorPickerPreview.transform.parent = parent; uiColorPickerPreview.transform.localPosition = parentAnchor + relativeLocation; uiColorPickerPreview.transform.localRotation = Quaternion.identity; uiColorPickerPreview.transform.localScale = Vector3.one; uiColorPickerPreview.width = width; uiColorPickerPreview.height = height; uiColorPickerPreview.thickness = thickness; // TODO : Re-enable // Setup the Meshfilter MeshFilter meshFilter = go.GetComponent <MeshFilter>(); if (meshFilter != null) { meshFilter.sharedMesh = UIUtils.BuildBoxEx(width, height, thickness); uiColorPickerPreview.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 && material != null) { meshRenderer.sharedMaterial = Instantiate(material); meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; meshRenderer.renderingLayerMask = 2; // "LightLayer 1" } UIUtils.SetRecursiveLayer(go, "CameraHidden"); return(uiColorPickerPreview); }