void Start() { mainPanel = transform.Find("MainPanel"); if (mainPanel != null) { timeBar = mainPanel.Find("TimeBar").GetComponent <UITimeBar>(); currentRange = mainPanel.Find("Range").GetComponent <UIRange>(); currentFrameLabel = mainPanel.Find("CurrentFrameLabel").GetComponent <UILabel>(); titleBar = transform.parent.Find("TitleBar").GetComponent <UILabel>(); keyframePrefab = Resources.Load <GameObject>("Prefabs/UI/DOPESHEET/Keyframe"); constantInterpolationButton = mainPanel.Find("Constant").GetComponent <UIButton>(); linearInterpolationButton = mainPanel.Find("Linear").GetComponent <UIButton>(); bezierInterpolationButton = mainPanel.Find("Bezier").GetComponent <UIButton>(); ColorUtility.TryParseHtmlString("#5985FF", out constantInterpolationColor); ColorUtility.TryParseHtmlString("#FFB600", out linearInterpolationColor); ColorUtility.TryParseHtmlString("#FF2D5E", out bezierInterpolationColor); currentRange.CurrentRange = new Vector2(GlobalState.Animation.StartFrame, GlobalState.Animation.EndFrame); localFirstFrame = GlobalState.Animation.StartFrame; localLastFrame = GlobalState.Animation.EndFrame; UpdateInterpolation(); } GlobalState.Animation.onFrameEvent.AddListener(OnFrameChanged); }
public static void OnCreateFromHierarchy() { Transform parent = null; Transform T = UnityEditor.Selection.activeTransform; if (T != null) { parent = T; } UITimeBar.Create(new UITimeBar.CreateArgs { parent = parent }); }
private void OnSceneGUI() { bool hasUIElementParent = HasUIElemParent(); UITimeBar uiTimeBar = target as UITimeBar; Transform T = uiTimeBar.transform; Vector3 posRight = T.TransformPoint(new Vector3(+uiTimeBar.width, -uiTimeBar.height / 2.0f, 0)); Vector3 posBottom = T.TransformPoint(new Vector3(uiTimeBar.width / 2.0f, -uiTimeBar.height, 0)); Vector3 posAnchor = T.TransformPoint(uiTimeBar.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 = 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) { uiTimeBar.Width += deltaRight.x; } else if (Vector3.SqrMagnitude(deltaBottom) > Mathf.Epsilon) { uiTimeBar.Height += -deltaBottom.y; } else if (Vector3.SqrMagnitude(deltaAnchor) > Mathf.Epsilon) { Vector3 localDeltaAnchor = T.InverseTransformVector(deltaAnchor); uiTimeBar.RelativeLocation += new Vector3(localDeltaAnchor.x, localDeltaAnchor.y, 0.0f); } } }
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"); }