void UpdateKeyframes() { Transform keyframes = transform.Find("MainPanel/Tracks/Summary/Keyframes"); UIKeyView track = keyframes.gameObject.GetComponent <UIKeyView>(); int i = 0; foreach (var key in keys) { GameObject keyframe = keyframes.GetChild(i++).gameObject; float time = key.Key; float currentValue = (float)time; float pct = (float)(currentValue - localFirstFrame) / (float)(localLastFrame - localFirstFrame); float startX = 0.0f; float endX = timeBar.width; float posX = startX + pct * (endX - startX); Vector3 knobPosition = new Vector3(posX, -0.5f * track.height, 0.0f); if (time < LocalFirstFrame || time > LocalLastFrame) { keyframe.SetActive(false); // clip out of range keyframes } else { keyframe.SetActive(true); } keyframe.transform.localPosition = knobPosition; } }
private void OnSceneGUI() { bool hasUIElementParent = HasUIElemParent(); UIKeyView uiKeyView = target as UIKeyView; Transform T = uiKeyView.transform; Vector3 posRight = T.TransformPoint(new Vector3(+uiKeyView.width, -uiKeyView.height / 2.0f, 0)); Vector3 posBottom = T.TransformPoint(new Vector3(uiKeyView.width / 2.0f, -uiKeyView.height, 0)); Vector3 posAnchor = T.TransformPoint(uiKeyView.Anchor); float handleSize = .3f * HandleUtility.GetHandleSize(posAnchor); Vector3 snap = Vector3.one * 0.01f; EditorGUI.BeginChangeCheck(); Handles.color = Handles.xAxisColor; Vector3 newTargetPosition_right = Handles.FreeMoveHandle(posRight, Quaternion.identity, handleSize, snap, Handles.SphereHandleCap); Handles.color = Handles.yAxisColor; Vector3 newTargetPosition_bottom = Handles.FreeMoveHandle(posBottom, Quaternion.identity, handleSize, snap, Handles.SphereHandleCap); Handles.color = Handles.zAxisColor; //Vector3 newTargetPosition_anchor = hasUIElementParent ? Handles.FreeMoveHandle(posAnchor, Quaternion.identity, handleSize, snap, Handles.SphereHandleCap) : posAnchor; Vector3 newTargetPosition_anchor = Handles.FreeMoveHandle(posAnchor, Quaternion.identity, handleSize, snap, Handles.SphereHandleCap); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Change Dimensions"); Vector3 deltaRight = newTargetPosition_right - posRight; Vector3 deltaBottom = newTargetPosition_bottom - posBottom; Vector3 deltaAnchor = newTargetPosition_anchor - posAnchor; if (Vector3.SqrMagnitude(deltaRight) > Mathf.Epsilon) { //Vector3 localDeltaRight = T.InverseTransformPoint(deltaRight); //uiKeyView.RelativeLocation += new Vector3(deltaRight.x / 2.0f, 0.0f, 0.0f); uiKeyView.Width += deltaRight.x; } else if (Vector3.SqrMagnitude(deltaBottom) > Mathf.Epsilon) { //Vector3 localDeltaBottom = T.InverseTransformPoint(deltaBottom); //uiKeyView.RelativeLocation += new Vector3(0.0f, deltaBottom.y / 2.0f, 0.0f); uiKeyView.Height += -deltaBottom.y; } else if (Vector3.SqrMagnitude(deltaAnchor) > Mathf.Epsilon) { Vector3 localDeltaAnchor = T.InverseTransformVector(deltaAnchor); uiKeyView.RelativeLocation += new Vector3(localDeltaAnchor.x, localDeltaAnchor.y, 0.0f); } } }
public static void OnCreateFromHierarchy() { Transform parent = null; Transform T = UnityEditor.Selection.activeTransform; if (T != null) { parent = T; } UIKeyView.Create(new UIKeyView.CreateParams { parent = parent }); }
public static UIKeyView 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; } } UIKeyView uiKeyView = go.AddComponent <UIKeyView>(); // NOTE: also creates the MeshFilter, MeshRenderer and Collider components uiKeyView.relativeLocation = input.relativeLocation; uiKeyView.transform.parent = input.parent; uiKeyView.transform.localPosition = parentAnchor + input.relativeLocation; uiKeyView.transform.localRotation = Quaternion.identity; uiKeyView.transform.localScale = Vector3.one; uiKeyView.width = input.width; uiKeyView.height = input.height; uiKeyView.margin = input.margin; uiKeyView.thickness = input.thickness; uiKeyView.source_material = input.material; uiKeyView.baseColor.useConstant = false; uiKeyView.baseColor.reference = input.bgcolor; uiKeyView.textColor.useConstant = false; uiKeyView.textColor.reference = input.fgcolor; uiKeyView.pushedColor.useConstant = false; uiKeyView.pushedColor.reference = input.pushedColor; uiKeyView.selectedColor.useConstant = false; uiKeyView.selectedColor.reference = input.selectedColor; // Setup the Meshfilter MeshFilter meshFilter = go.GetComponent <MeshFilter>(); if (meshFilter != null) { meshFilter.sharedMesh = UIUtils.BuildRoundedBox(input.width, input.height, input.margin, input.thickness); uiKeyView.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.material != null) { // Clone the material. meshRenderer.sharedMaterial = Instantiate(input.material); Material sharedMaterial = meshRenderer.sharedMaterial; meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; meshRenderer.rendererPriority = 1; meshRenderer.renderingLayerMask = 2; // "LightLayer 1" uiKeyView.SetColor(input.bgcolor.value); } UIUtils.SetRecursiveLayer(go, "CameraHidden"); return(uiKeyView); }