void SetModifiedMaterial(ScaleInfo info) { if (info.ps != null && info.ps.emission.enabled) { var toUse = info.renderer.sharedMaterial; if (m_ShouldRecalculateStencil) { if (Maskable) { var rootCanvas = MaskUtilities.FindRootSortOverrideCanvas(transform); m_StencilValue = MaskUtilities.GetStencilDepth(transform, rootCanvas); } else { m_StencilValue = 0; } m_ShouldRecalculateStencil = false; } // if we have a Mask component then it will // generate the mask material. This is an optimisation // it adds some coupling between components though :( if (m_StencilValue > 0) { var maskMat = StencilMaterial.Add(toUse, (1 << m_StencilValue) - 1, StencilOp.Keep, CompareFunction.Equal, ColorWriteMask.All, (1 << m_StencilValue) - 1, 0); StencilMaterial.Remove(info.stencilMaterial); info.stencilMaterial = maskMat; toUse = info.stencilMaterial; } info.renderer.material = toUse; } }
private IEnumerable <Element> GetGridLines(ScaleInfo xScaleInfo, ScaleInfo yScaleInfo, IReadOnlyCollection <string> valueLabels) { var elements = GetVerticalGridLines(xScaleInfo); elements = elements.Concat(GetHorizontalGridLines(yScaleInfo, valueLabels)); return(elements); }
public override ScaleInfo GetScaleTypeInfo() { var i = new ScaleInfo(); i.scaleType = "Simulator"; i.commsType = ScaleCommsType.none; i.description = "Simulated Scale application"; return(i); }
public ScaleModifier(ModifierInfo info, Entity casterEntity, Entity targetEntity, Environment environment, CollectionOfInteractions modifierInteractionCollection) : base(info, casterEntity, targetEntity, environment, modifierInteractionCollection) { this.info = (ScaleInfo)info; gameObjectComponent = (GameObjectComponent)targetEntity.GetComponent <EntityGameObjectComponent>(); originalScaleValue = gameObjectComponent.GetScale(); }
public override ScaleInfo GetScaleTypeInfo() { var i = new ScaleInfo(); i.scaleType = "AD4407"; i.commsType = ScaleCommsType.serial; i.description = "A&D 4407 via serial RS232"; return(i); }
public override ScaleInfo GetScaleTypeInfo() { var i = new ScaleInfo(); i.scaleType = "Marel2200"; i.commsType = ScaleCommsType.tcp; i.description = "Marel M2200 via Ethernet"; return(i); }
// Scale 함수 public void ScaleTo(float time, Vector2 value, ref GameObject obj) { ScaleInfo info = new ScaleInfo(); info.time = time; info.value = value; info.obj = obj; info.speed.x = (value.x - obj.transform.localScale.x) / time; info.speed.y = (value.y - obj.transform.localScale.y) / time; StartCoroutine("ScaleToC", info); }
internal void CreateDataPoints(ScaleInfo xScaleInfo, ScaleInfo yScaleInfo) { var offSetX = xScaleInfo.StartOnMajor ? 0 : xScaleInfo.MinorInterval * xScaleInfo.Scale; foreach (var series in Series) { series.InitDataPoints(xScaleInfo.Scale, yScaleInfo.Scale, TopLeftX + offSetX, BottomRightY); } }
private IEnumerable <Element> GetVerticalGridLines(ScaleInfo scale) { var elements = new List <Element>(); if (!XGridLineStyle.Draw) { return(elements); } var loopStart = scale.StartOnMajor ? 0 : scale.MinorInterval; var loopEnd = scale.StartOnMajor ? scale.Max : scale.Max - scale.MinorInterval; var isMajor = scale.StartOnMajor; for (var i = loopStart; i <= loopEnd;) { var xPos = ((i) * scale.Scale) + TopLeftX; var startPos = new DataPoint(xPos, BottomRightY); var endPos = new DataPoint(xPos, TopLeftY); var className = isMajor ? "x-major-grid-line" : "x-minor-grid-line"; var draw = isMajor ? YGridLineStyle.MajorLineStyle.Draw : YGridLineStyle.MinorLineStyle.Draw; if (draw) { elements.Add(new Path( isMajor ? $"x-major--grid-{i}" : $"x-minor--grid-{i}", startPos, new[] { new StraightLine(startPos, endPos, startPos) }, null, isMajor ? XGridLineStyle.MajorLineStyle : XGridLineStyle.MinorLineStyle, new[] { className, "grid-line" }) ); } i += scale.MinorInterval; isMajor = !isMajor; } return(elements); }
internal override IEnumerable <Element> GetSvgElements(ScaleInfo xScaleInfo, ScaleInfo yScaleInfo, IReadOnlyCollection <string> valueLabels, bool drawDebug) { AssignStyles(); var elements = GetBoundingBox(); elements = elements.Concat(GetGridLines(xScaleInfo, yScaleInfo, valueLabels)); elements = elements.Concat(GetDebugElements(drawDebug)); elements = LineType == LineType.Curved ? elements.Concat(GetCurvedPaths()) : elements.Concat(GetStraightPaths()); return(elements); }
public RevertableScaleChange(TransformChangeInfos transformChangeInfos) { scaleInfos = new ScaleInfo[transformChangeInfos.changedPositions + transformChangeInfos.changedScales - transformChangeInfos.changedPosScales]; int i = 0; foreach (TransformChangeInfo info in transformChangeInfos.infos) { if (info.position.HasValue || info.scale.HasValue) { scaleInfos[i++] = new ScaleInfo(info.obj, info.part, info.position, info.scale); } } }
private IEnumerable <Element> GetHorizontalGridLines(ScaleInfo scale, IReadOnlyCollection <string> valueLabels) { var elements = new List <Element>(); if (!YGridLineStyle.Draw) { return(elements); } var loopStart = scale.MinorInterval; var loopEnd = scale.Max; for (var i = loopStart; i <= loopEnd;) { var isMajor = valueLabels.Contains(i.ToString(CultureInfo.InvariantCulture)); var yPos = BottomRightY - ((i) * scale.Scale); var startPos = new DataPoint(TopLeftX, yPos); var endPos = new DataPoint(BottomRightX, yPos); var className = isMajor ? "y-major-grid-line" : "y-minor-grid-line"; var draw = isMajor ? YGridLineStyle.MajorLineStyle.Draw : YGridLineStyle.MinorLineStyle.Draw; if (draw) { elements.Add(new Path( isMajor ? $"y-major--grid-{i}" : $"y-minor--grid-{i}", startPos, new[] { new StraightLine(startPos, endPos, startPos) }, null, isMajor ? YGridLineStyle.MajorLineStyle : YGridLineStyle.MinorLineStyle, new[] { className, "grid-line" })); } i += scale.MinorInterval; } return(elements); }
public void AddScale(GameObject go, float time, float targetScaleX, float targetScaleY, AnimatorDelegate callback = null) { var curScale = go.transform.localScale; float scaleStepX = 0; float scaleStepY = 0; if (Mathf.Abs(targetScaleX - scaleStepX) > 1e-7) { scaleStepX = (targetScaleX - curScale.x) / (time / Time.deltaTime); } if (Mathf.Abs(targetScaleY - scaleStepY) > 1e-7) { scaleStepY = (targetScaleY - curScale.y) / (time / Time.deltaTime); } var info = new ScaleInfo(go, time, scaleStepX, scaleStepY, targetScaleX, targetScaleY, callback); _scaleSet [go] = info; }
IEnumerator ScaleToC(ScaleInfo info) { info.save_time += Time.deltaTime; if (info.obj != null) { if (info.save_time < info.time) { info.obj.transform.localScale = new Vector3(info.obj.transform.localScale.x + info.speed.x * Time.deltaTime, info.obj.transform.localScale.y + info.speed.y * Time.deltaTime, info.obj.transform.localScale.z); yield return(null); StartCoroutine("ScaleToC", info); } else { info.obj.transform.localScale = new Vector3(info.value.x, info.value.y, info.obj.transform.localScale.z); } } }
private ScaleInfo CreateScaleInfo(IDictionary context, AtomicReaderContext readerContext) { var leaves = ReaderUtil.GetTopLevelContext(readerContext).Leaves; float minVal = float.PositiveInfinity; float maxVal = float.NegativeInfinity; foreach (AtomicReaderContext leaf in leaves) { int maxDoc = leaf.Reader.MaxDoc; FunctionValues vals = m_source.GetValues(context, leaf); for (int i = 0; i < maxDoc; i++) { float val = vals.SingleVal(i); if ((J2N.BitConversion.SingleToRawInt32Bits(val) & (0xff << 23)) == 0xff << 23) { // if the exponent in the float is all ones, then this is +Inf, -Inf or NaN // which don't make sense to factor into the scale function continue; } if (val < minVal) { minVal = val; } if (val > maxVal) { maxVal = val; } } } if (minVal == float.PositiveInfinity) { // must have been an empty index minVal = maxVal = 0; } var scaleInfo = new ScaleInfo { MinVal = minVal, MaxVal = maxVal }; context[this] = scaleInfo; return(scaleInfo); }
private void DrawScale() { if (canvas.Children.IndexOf(clickLine) != -1) { canvas.Children.RemoveRange(0, canvas.Children.Count - 1); } else { canvas.Children.Clear(); } totalTranslate = new TranslateTransform(); tempTranslate = new TranslateTransform(); curScaleInfo = scaleInfos[ScaleSize]; int zeroOffset = 5; //零刻度偏移 int labelValue = curScaleInfo.labelValue; int labelStep = curScaleInfo.labelStep; //数字标签刻度间隔 int scaleGap = curScaleInfo.scaleGap; //每两个刻度间的像素间隔 for (int i = 0; i <= 1000; i++) { int factor = i + (int)(-tempTranslate.X / scaleGap); Line x_scale = new Line(); x_scale.StrokeEndLineCap = PenLineCap.Square; x_scale.StrokeThickness = 0.5; x_scale.Stroke = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0)); x_scale.X1 = zeroOffset + i * scaleGap; x_scale.X2 = x_scale.X1; x_scale.Y1 = factor % labelStep == 0 ? 15 : 25; x_scale.Y2 = 30; if (i % labelStep == 0) { TextBlock scaleLabel = new TextBlock(); //scaleLabel.Width = 100; scaleLabel.Text = (labelValue * (factor / labelStep)).ToString(); //scaleLabel.HorizontalAlignment = HorizontalAlignment.Center; Canvas.SetLeft(scaleLabel, x_scale.X1); this.canvas.Children.Insert(0, scaleLabel); } this.canvas.Children.Insert(0, x_scale); } }
private void frmCalculator_Load(object sender, EventArgs e) { var client = ClientSize; foreach (Control item in this.Controls) { var location = item.Location; var size = item.Size; keyValuePairs[item] = new ScaleInfo() { LeftPercent = location.X / (float)client.Width, TopPercent = location.Y / (float)client.Height, WidthPercent = size.Width / (float)client.Width, HeightPercent = size.Height / (float)client.Height }; } }
void Start() { ParticleSystem[] psArray = gameObject.GetComponentsInChildren <ParticleSystem>(true) as ParticleSystem[]; if (psArray == null || psArray.Length <= 0) { return; } mScaleInfoArray = new ScaleInfo[psArray.Length]; for (int i = 0; i < psArray.Length; ++i) { mScaleInfoArray[i] = new ScaleInfo(); mScaleInfoArray[i].ps = psArray[i]; mScaleInfoArray[i].mOriginalScale = psArray[i].startSize; } SetSacle(); }
public void Scaler_CheckInitialState() { var scaler = new Scaler(0, 100, TEST_MIN_SIZE); ScaleInfo expectedScaleInfo = new ScaleInfo() { CurrentStart = 0, CurrentStop = 100, CurrentWidth = 100 }; scaler.CanMoveLeft.Should().Be(false); scaler.CanMoveRight.Should().Be(false); scaler.MoveRight(); var currentScaleInfo = scaler.GetCurrentScaleInfo(); currentScaleInfo.Should().BeEquivalentTo(expectedScaleInfo); scaler.MoveLeft(); currentScaleInfo = scaler.GetCurrentScaleInfo(); currentScaleInfo.Should().BeEquivalentTo(expectedScaleInfo); }
void Start() { ParticleSystem[] psArray = gameObject.GetComponentsInChildren <ParticleSystem>(true) as ParticleSystem[]; if (psArray == null || psArray.Length <= 0) { return; } mScaleInfoArray = new ScaleInfo[psArray.Length]; for (int i = 0; i < psArray.Length; ++i) { mScaleInfoArray[i] = new ScaleInfo(); var ps = psArray[i]; mScaleInfoArray[i].ps = ps; mScaleInfoArray[i].renderer = ps.GetComponent <Renderer>(); mScaleInfoArray[i].originalMaterial = mScaleInfoArray[i].renderer.sharedMaterial; mScaleInfoArray[i].mOriginalScale = psArray[i].startSize; mScaleInfoArray[i].mOriginalRealScale = ps.transform.localScale; } SetSacle(); }
internal override IEnumerable <Element> GetSvgElements(ScaleInfo scale, double dynamicOffset, double staticPos, IReadOnlyCollection <string> labels) { if (scale == null) { throw new ArgumentNullException(nameof(scale)); } if (labels == null) { throw new ArgumentNullException(nameof(labels)); } var elements = new List <Element>(); var isMinor = scale.StartOnMajor; var majorCount = 0; var lastXPos = 0.0; for (double i = 0; i <= scale.Max;) { isMinor = !isMinor; var idLabel = isMinor ? $"{Type.ToString()}-minor-tick-{i}" : $"{Type.ToString()}-major-tick-{i}"; var thisStyle = isMinor ? MinorTickStyle : MajorTickStyle; var className = isMinor ? $"{Type}-minor-tick" : $"{Type}-major-tick"; var xPos = (i * scale.Scale) + dynamicOffset; var yPos = staticPos + thisStyle.Length + LabelStyle.Size; if (thisStyle.Draw) { var startPos = new DataPoint(xPos, staticPos); var endPos = new DataPoint(xPos, staticPos + thisStyle.Length); elements.Add(new Path(idLabel, startPos, new[] { new StraightLine(startPos, endPos, endPos) }, style: thisStyle, classes: new[] { className, "tick" })); } if (!isMinor && LabelStyle.Draw) { var label = labels.ElementAt(majorCount); var labelX = xPos - ((label.Length * LabelStyle.WidthPixels) / 1.5); //split label into 2 lines elements.Add(new Text($"{label}", labelX, yPos, TextAnchor.Start, DominantBaseline.Auto, LabelStyle, new[] { $"{Type}-label", "axis-label" })); } i += scale.MinorInterval; if (!isMinor) { majorCount += 1; } lastXPos = xPos; } if (BaseLineStyle.Draw) { elements.Add(new Path( $"{Type}--baseline", new DataPoint(dynamicOffset, staticPos), new DataPoint(lastXPos, staticPos), BaseLineStyle)); } return(elements.ToArray()); }
internal abstract IEnumerable <Element> GetSvgElements(ScaleInfo scale, double dynamicOffset, double staticPos, IReadOnlyCollection <string> labels);
internal abstract IEnumerable <Element> GetSvgElements(ScaleInfo xScaleInfo, ScaleInfo yScaleInfo, IReadOnlyCollection <string> valueLabels, bool drawDebug);
void Start() { pairOfPartAndColor = new Dictionary<string, string>(); pairOfPartAndScale = new Dictionary<string, ScaleInfo>(); #region find object selectedRobot = GameObjectAgent.Instance.findChild("Object", "SelectedRobot"); parts = GameObjectAgent.Instance.findChild("Object", "Parts"); robot = GameObjectAgent.Instance.findChild("Object", "Robot"); table = GameObjectAgent.Instance.findChild("Object", "Table"); var scriptOfBot = parts.GetComponent<PartsManager>(); activePart = scriptOfBot.ActiveParts; for (int i = 0; i < parts.transform.childCount; i++) { var parentOfPart = parts.transform.GetChild(i); for(int j = 0; j < parentOfPart.childCount; j++) { var part = parentOfPart.GetChild(j); pairOfPartAndColor.Add(part.name, "color_base"); pairOfPartAndScale.Add(part.name, new ScaleInfo(2, 0)); } } #endregion find object var scrollableOfSticker = GameObjectAgent.Instance.addComponent<GUIScrollable>("UI", "2_Customizing/Frame/ScrollPanel/Sticker"); var scrollableOfColor = GameObjectAgent.Instance.addComponent<GUIScrollable>("UI", "2_Customizing/Frame/ScrollPanel/Color"); #region add event { //Parts for (int i = 0; i < nameOfParts.Length; i++) { var scrollable = GameObjectAgent.Instance.addComponent<GUIScrollable>(GUIAgent.Instance.GuiObjects["UI/2_Customizing/Frame/ScrollPanel/Parts/" + nameOfParts[i]]); scrollable.init(nameOfParts[i].ToLower()); scrollable.action = () => { if (!highlightedObject) return; if (highlightedObject.name.Contains("Sticker")) return; if (highlightedObject.parent.parent.name.CompareTo(scrollable.MinButtonName) == 0) return; var newPart = scriptOfBot.activate(scrollable.MinButtonName); if (newPart == null) return; scriptOfBot.matchJoint(); HighlightAgent.Instance.constantOnImmediate(newPart.name, Color.cyan); highlightedObject = newPart.transform.GetChild(1); }; } //Color scrollableOfColor.init("color", "bt"); scrollableOfColor.action = () => { if (!highlightedObject || highlightedObject.name.Contains("Sticker") || highlightedObject.parent.parent.name.CompareTo(scrollableOfColor.MinButtonName) == 0) return; var renderer = highlightedObject.GetComponent<SkinnedMeshRenderer>(); Color color = stringToColor(scrollableOfColor.MinButtonName); renderer.material.SetColor("_Color", color); pairOfPartAndColor[highlightedObject.parent.name] = scrollableOfColor.MinButtonName; }; // Scale EventTriggerAgent.Instance.addEvent("UI", "2_Customizing/Frame/ScrollPanel/Scale/Center/Toggle", EventTriggerType.Drag, () => { if (!highlightedObject) return; float x; float y; RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); float ang = 0; if (Physics.Raycast(ray, out hit, 100f)) { x = transform.InverseTransformPoint(hit.point).x; if (x < GUIAgent.Instance.GuiObjects["UI/2_Customizing/Frame/ScrollPanel/Scale/Left"].transform.localPosition.x) x = GUIAgent.Instance.GuiObjects["UI/2_Customizing/Frame/ScrollPanel/Scale/Left"].transform.localPosition.x; else if (x > GUIAgent.Instance.GuiObjects["UI/2_Customizing/Frame/ScrollPanel/Scale/Right"].transform.localPosition.x) x = GUIAgent.Instance.GuiObjects["UI/2_Customizing/Frame/ScrollPanel/Scale/Right"].transform.localPosition.x; y = Mathf.Sqrt(332 * 332 - x * x); ang = Mathf.Atan2(y, x) / Mathf.PI * 180 - 90; GUIAgent.Instance.GuiObjects["UI/2_Customizing/Frame/ScrollPanel/Scale/Center"].transform.rotation = Quaternion.Euler(0, 0, ang); highlightedObject.parent.localScale = new Vector3(13 - ang / 90, 13 - ang / 90, 13 - ang / 90); scriptOfBot.matchJoint(); } float minangle = 360; int closestButtonindex = 2; for (int i = 0; i < GUIAgent.Instance.GuiObjects["UI/2_Customizing/Frame/ScrollPanel/Scale/Number"].transform.childCount; i++) { var child = GUIAgent.Instance.GuiObjects["UI/2_Customizing/Frame/ScrollPanel/Scale/Number"].transform.GetChild(i); float angle = Mathf.Abs(GUIAgent.Instance.GuiObjects["UI/2_Customizing/Frame/ScrollPanel/Scale/Center"].transform.rotation.z - child.rotation.z); if (minangle > angle) { minangle = angle; closestButtonindex = i; } } for (int i = 0; i < GUIAgent.Instance.GuiObjects["UI/2_Customizing/Frame/ScrollPanel/Scale/Number"].transform.childCount; ++i) { if (closestButtonindex != i) GUIAgent.Instance.setSprite("UI", "2_Customizing/Frame/ScrollPanel/Scale/Number/Number_" + (i+1), ResourcesManager.Instance.sprites["number_" + (i + 1) + "_normal"]); else GUIAgent.Instance.setSprite("UI", "2_Customizing/Frame/ScrollPanel/Scale/Number/Number_" + (i+1), ResourcesManager.Instance.sprites["number_" + (i + 1) + "_normal"]); } var scaleInfo = new ScaleInfo(closestButtonindex, ang); pairOfPartAndScale[highlightedObject.parent.name] = scaleInfo; }); // Sticker scrollableOfSticker.init("StickerAtlas"); var stickerCamera = GameObjectAgent.Instance.findChild("Camera", "Sticker Camera").GetComponent<Camera>(); var uiCamera = GameObjectAgent.Instance.findChild("Camera", "UI Camera").GetComponent<Camera>(); for (int i = 0; i < GUIAgent.Instance.GuiObjects["UI/2_Customizing/Frame/ScrollPanel/Sticker/Panel"].transform.childCount; i++) { var button = GUIAgent.Instance.GuiObjects["UI/2_Customizing/Frame/ScrollPanel/Sticker/Panel"].transform.GetChild(i); var image = button.FindChild("Image").gameObject; var stickerParent = GameObjectAgent.Instance.findChild("Object", "Stickers/" + button.name).transform; var dummySticker = GameObjectAgent.Instance.findChild("UI", "2_Customizing/Frame/Sticker/" + button.name).transform; EventTriggerAgent.Instance.addEvent(image, EventTriggerType.Drag, () => { if (image.GetComponent<UnityEngine.UI.Image>().sprite.name.CompareTo(scrollableOfSticker.MinButtonName) != 0) return; //if (!stickerParent || stickerParent.childCount == 0) return; RaycastHit rh; Ray ray = uiCamera.ScreenPointToRay(Input.mousePosition); //Ray ray = stickerCamera.ScreenPointToRay(Input.mousePosition); //RaycastHit rh; if (Physics.Raycast(ray, out rh, Mathf.Infinity)) dummySticker.transform.localPosition = transform.InverseTransformPoint(rh.point) + new Vector3(0, 600, 0); //sticker.transform.position = new Vector3(rh.point.x, rh.point.y, 0); }); EventTriggerAgent.Instance.addEvent(image, EventTriggerType.EndDrag, () => { if (image.GetComponent<UnityEngine.UI.Image>().sprite.name.CompareTo(scrollableOfSticker.MinButtonName) != 0) return; stickerParent.GetChild(0).transform.position = new Vector3(1000, 1000, 1000); if (!stickerParent || stickerParent.childCount == 1) return; var sticker = stickerParent.GetChild(1); Ray ray = stickerCamera.ScreenPointToRay(Input.mousePosition); RaycastHit rh; if (Physics.Raycast(ray, out rh, Mathf.Infinity) && rh.transform.gameObject.layer == LayerMask.NameToLayer("Default") && !rh.transform.name.Contains("Sticker")) { var decal = sticker.GetComponent<DecalSystem.Decal>(); if (decal) { sticker.transform.position = rh.point; sticker.transform.SetParent(rh.transform); DecalSystem.DecalBuilder.BuildDecal(decal); if (rh.transform.parent.name.Contains("head")) sticker.transform.SetParent(rh.transform.parent.FindChild(Constants.stickerParent[(int)Constants.PART.HEAD])); else if (rh.transform.parent.name.Contains("arm_left")) { if (sticker.position.y > 2.3f) sticker.transform.SetParent(rh.transform.parent.FindChild(Constants.stickerParent[(int)Constants.PART.UPPPERARM_LEFT])); else sticker.transform.SetParent(rh.transform.parent.FindChild(Constants.stickerParent[(int)Constants.PART.ARM_LEFT])); } else if (rh.transform.parent.name.Contains("arm_right")) { if (sticker.position.y > 2.3f) sticker.transform.SetParent(rh.transform.parent.FindChild(Constants.stickerParent[(int)Constants.PART.UPPERARM_RIGHT])); else sticker.transform.SetParent(rh.transform.parent.FindChild(Constants.stickerParent[(int)Constants.PART.ARM_RIGHT])); } else if (rh.transform.parent.name.Contains("leg_left")) sticker.transform.SetParent(rh.transform.parent.FindChild(Constants.stickerParent[(int)Constants.PART.LEG_LEFT])); else if (rh.transform.parent.name.Contains("leg_right")) sticker.transform.SetParent(rh.transform.parent.FindChild(Constants.stickerParent[(int)Constants.PART.LEG_RIGHT])); else if (rh.transform.parent.name.Contains("body")) { if (sticker.position.y > 1f) sticker.transform.SetParent(rh.transform.parent.FindChild(Constants.stickerParent[(int)Constants.PART.UPPER_BODY])); else sticker.transform.SetParent(rh.transform.parent.FindChild(Constants.stickerParent[(int)Constants.PART.BODY])); } } } dummySticker.transform.localPosition = new Vector3(0, 3000, 0); }); } GUIAgent.Instance.addListener("UI", "2_Customizing/Title/Next", () => { if (GUIAgent.Instance.GuiObjects["UI/2_Customizing/Complete"].gameObject.activeSelf) return; for (int i = 0; i < activePart.Length; i++) { GameObjectAgent.Instance.setActive(activePart[i], false); GameObjectAgent.Instance.setActive(activePart[i], true); } GameObjectAgent.Instance.setActive(GUIAgent.Instance.GuiObjects["UI/2_Customizing/Frame"], false); GameObjectAgent.Instance.setActive(GUIAgent.Instance.GuiObjects["UI/2_Customizing/Naming"], true); }); GUIAgent.Instance.addListener("UI", "2_Customizing/Title/Prev", () => { if (GUIAgent.Instance.GuiObjects["UI/2_Customizing/Complete"].gameObject.activeSelf) return; if (GUIAgent.Instance.GuiObjects["UI/2_Customizing/Naming"].gameObject.activeSelf == true) { GameObjectAgent.Instance.setActive(GUIAgent.Instance.GuiObjects["UI/2_Customizing/Frame"], true); GameObjectAgent.Instance.setActive(GUIAgent.Instance.GuiObjects["UI/2_Customizing/Naming"], false); return; } else { //GameManager.Instance.transition(); GameObjectAgent.Instance.getComponent<GameManager>("UI").transition(); GameObjectAgent.Instance.delaySetActive(parts, false, GameManager.Close + GameManager.Delay); GameObjectAgent.Instance.delaySetActive(table, false, GameManager.Close + GameManager.Delay); GameObjectAgent.Instance.delaySetActive(gameObject, false, GameManager.Close + GameManager.Delay); GameObjectAgent.Instance.delaySetActive(GUIAgent.Instance.GuiObjects["Background/2_Customizing"], false, GameManager.Close + GameManager.Delay); GameObjectAgent.Instance.delaySetActive(GUIAgent.Instance.GuiObjects["Background/1_Lobby"], true, GameManager.Close + GameManager.Delay); GameObjectAgent.Instance.delaySetActive(GUIAgent.Instance.GuiObjects["UI/1_Lobby"], true, GameManager.Close + GameManager.Delay); } }); for (int i = 0; i < customizingPanel.Length; i++) { var nameOfPanel = customizingPanel[i]; EventTriggerAgent.Instance.addEvent("UI", "2_Customizing/Frame/Image/" + nameOfPanel , EventTriggerType.PointerClick, () => { for(int j = 0; j < customizingPanel.Length; j++) { GUIAgent.Instance.setSprite("UI", "2_Customizing/Frame/Image/" + customizingPanel[j], ResourcesManager.Instance.sprites["bt_" + customizingPanel[j].ToLower() + "_normal"]); GUIAgent.Instance.GuiObjects["UI/2_Customizing/Frame/ScrollPanel/" + customizingPanel[j]].SetActive(false); } GUIAgent.Instance.GuiObjects["UI/2_Customizing/Frame/ScrollPanel/" + nameOfPanel].SetActive(true); GUIAgent.Instance.setSprite("UI", "2_Customizing/Frame/Image/" + nameOfPanel, ResourcesManager.Instance.sprites["bt_" + nameOfPanel.ToLower() + "_select"]); if (nameOfPanel.Contains("Scale")) GameObjectAgent.Instance.setActive(GUIAgent.Instance.GuiObjects["UI/2_Customizing/Frame/FrameVignetting"], false); else GameObjectAgent.Instance.setActive(GUIAgent.Instance.GuiObjects["UI/2_Customizing/Frame/FrameVignetting"], true); }); } bool click = false; EventTriggerAgent.Instance.addEvent(GameObjectAgent.Instance.findChild("UI", "2_Customizing/Button/Left"), EventTriggerType.PointerDown, () => { click = true; }); EventTriggerAgent.Instance.addEvent(GameObjectAgent.Instance.findChild("UI", "2_Customizing/Button/Left"), EventTriggerType.UpdateSelected, () => { if (!click) return; iTween.RotateBy(parts.gameObject, iTween.Hash("y", -0.004f, "time", 0.005f)); }); EventTriggerAgent.Instance.addEvent(GameObjectAgent.Instance.findChild("UI", "2_Customizing/Button/Left"), EventTriggerType.PointerUp, () => { iTween.Stop(); click = false; }); EventTriggerAgent.Instance.addEvent(GameObjectAgent.Instance.findChild("UI", "2_Customizing/Button/Right"), EventTriggerType.PointerDown, () => { click = true; }); EventTriggerAgent.Instance.addEvent(GameObjectAgent.Instance.findChild("UI", "2_Customizing/Button/Right"), EventTriggerType.UpdateSelected, () => { if (!click) return; iTween.RotateBy(parts.gameObject, iTween.Hash("y", 0.004f, "time", 0.005f)); //iTween.RotateAdd(parts.gameObject, Vector3.down, 0.002f); }); EventTriggerAgent.Instance.addEvent(GameObjectAgent.Instance.findChild("UI", "2_Customizing/Button/Right"), EventTriggerType.PointerUp, () => { iTween.Stop(); click = false; }); GUIAgent.Instance.addListener("UI", "2_Customizing/Button/Storage", () => { GameObjectAgent.Instance.getComponent<GameManager>("UI").changerSprite(GUIAgent.Instance.GuiObjects["UI/6_Storage/Title/Prev"]); GameObjectAgent.Instance.getComponent<GameManager>("UI").changerSprite(GUIAgent.Instance.GuiObjects["UI/6_Storage/Title/Next"]); //GameManager.Instance.transition(); GameObjectAgent.Instance.getComponent<GameManager>("UI").transition(); if (selectedRobot.transform.childCount > 0) //선택 -> 창고 { nameOfSelected = selectedRobot.transform.GetChild(0).name; selectedRobot.transform.GetChild(0).SetParent(robot.transform); } GameObjectAgent.Instance.delaySetActive(gameObject, false, GameManager.Close + GameManager.Delay); GameObjectAgent.Instance.delaySetActive(selectedRobot, true, GameManager.Close + GameManager.Delay); GameObjectAgent.Instance.delaySetActive(parts, false, GameManager.Close + GameManager.Delay); GameObjectAgent.Instance.delaySetActive(robot, true, GameManager.Close + GameManager.Delay); GameObjectAgent.Instance.delaySetActive(gameObject, false, GameManager.Close + GameManager.Delay); GameObjectAgent.Instance.delaySetActive(GUIAgent.Instance.GuiObjects["Background/2_Customizing"], false, GameManager.Close + GameManager.Delay); GameObjectAgent.Instance.delaySetActive(GUIAgent.Instance.GuiObjects["UI/6_Storage"], true, GameManager.Close + GameManager.Delay); GameObjectAgent.Instance.delaySetActive("Background", "6_Storage", true, GameManager.Close + GameManager.Delay); Utility.Instance.delayAction(GameManager.Close + GameManager.Delay, () => { //되돌리기 for (int i = 0; i < parts.transform.childCount; i++) { var part = parts.transform.GetChild(i).GetChild(0); part.localScale = new Vector3(13f, 13f, 13f); part.GetChild(1).GetComponent<Renderer>().material.color = new Color(0.784f, 0.784f, 0.784f); for (int j = 0; j < Constants.stickerParent.Length; j++) { var stickerParent = part.FindChild(Constants.stickerParent[j]); for (int k = 0; k < stickerParent.childCount; k++) { var sticker = stickerParent.GetChild(k); if (!sticker.name.Contains("Sticker")) continue; var newParent = GameObjectAgent.Instance.findChild("Object", "Stickers/" + sticker.name); sticker.SetParent(newParent.transform); sticker.localPosition = new Vector3(2000, 2000, 0); } } } robot.transform.position = new Vector3(-1.3f, 0, 0); table.transform.position = new Vector3(-1.1f, -2, 0); robot.transform.rotation = Quaternion.Euler(0, 330, 0); }); var scrollableOfStorage = GameObjectAgent.Instance.addComponent<GUIScrollable>(GUIAgent.Instance.GuiObjects["UI/6_Storage/Frame/ScrollPanel/Bot"]); scrollableOfStorage.init("save_"); scrollableOfStorage.action = () => { for (int i = 0; i < robot.transform.childCount; i++) { if (selectedRobot.transform.childCount > 0) selectedRobot.transform.GetChild(0).SetParent(robot.transform); var child = robot.transform.GetChild(i).gameObject; if (child.name.CompareTo(scrollableOfStorage.MinButtonName) == 0) { child.SetActive(true); child.transform.localPosition = Vector3.zero; child.transform.localRotation = Quaternion.identity; string temp = child.name.Split('_')[1]; GUIAgent.Instance.setText("UI", "6_Storage/Panel/Name", temp); for (int j = 0; j < child.transform.childCount; j++) child.transform.GetChild(j).gameObject.SetActive(true); } else { child.SetActive(false); } } }; for (int i = 0; i < activePart.Length; i++) { if (GUIAgent.Instance.GuiObjects["UI/2_Customizing/Complete"].gameObject.activeSelf) AnimationAgent.Instance.setInteger(activePart[i].name, "State", 9); } }); var inputField = GUIAgent.Instance.GuiObjects["UI/2_Customizing/Naming"].transform.FindChild("InputField").FindChild("Text").GetComponent<UnityEngine.UI.Text>(); GUIAgent.Instance.addListener("UI", "2_Customizing/Naming/Complete", () => { GameObjectAgent.Instance.setActive(GUIAgent.Instance.GuiObjects["UI/2_Customizing/Button/Left"], false); GameObjectAgent.Instance.setActive(GUIAgent.Instance.GuiObjects["UI/2_Customizing/Button/Right"], false); parts.transform.rotation = Quaternion.identity; robot.transform.rotation = Quaternion.identity; GUIAgent.Instance.setText("UI", "2_Customizing/Complete/Panel/Text/Name", inputField.text); string botName = "save_" + inputField.text; nameOfSelected = botName; // save var obj = parts.GetComponent<PartsManager>().BotInfo; var data = Converter.Serialize(obj); PlayerPrefs.SetString(botName, data); string saved = PlayerPrefs.GetString("name", "") + botName + "/"; PlayerPrefs.SetString("name", saved); PlayerPrefs.Save(); capture(botName); robot.gameObject.SetActive(true); selectedRobot.gameObject.SetActive(true); if(selectedRobot.transform.childCount > 0) selectedRobot.transform.GetChild(0).SetParent(robot.transform); var newRobot = new GameObject(botName); newRobot.transform.SetParent(selectedRobot.transform); parts.gameObject.SetActive(false); robot.gameObject.SetActive(false); GameObjectAgent.Instance.setActive(GUIAgent.Instance.GuiObjects["UI/2_Customizing/Naming"], false); GameObjectAgent.Instance.setActive(GUIAgent.Instance.GuiObjects["UI/2_Customizing/Complete"], true); for (int i = 0; i < activePart.Length; i++) { activePart[i].transform.SetParent(newRobot.transform); AnimationAgent.Instance.setInteger(activePart[i].name, "State", 0); } }); GUIAgent.Instance.addListener("UI", "2_Customizing/Complete/Frame/Back", () => { //GameManager.Instance.transition(); GameObjectAgent.Instance.getComponent<GameManager>("UI").transition(); for (int i = 0; i < activePart.Length; i++) { if (GUIAgent.Instance.GuiObjects["UI/2_Customizing/Complete"].gameObject.activeSelf) { AnimationAgent.Instance.setInteger(activePart[i].name, "State", 9); } else activePart[i].SetActive(false); activePart[i] = null; } GameObjectAgent.Instance.delaySetActive(GUIAgent.Instance.GuiObjects["UI/1_Lobby"], true, GameManager.Close + GameManager.Delay); GameObjectAgent.Instance.delaySetActive(GUIAgent.Instance.GuiObjects["Background/1_Lobby"], true, GameManager.Close + GameManager.Delay); GameObjectAgent.Instance.delaySetActive(gameObject, false, GameManager.Close + GameManager.Delay); GameObjectAgent.Instance.delaySetActive(GUIAgent.Instance.GuiObjects["Background/2_Customizing"], false, GameManager.Close + GameManager.Delay); GameObjectAgent.Instance.delaySetActive(parts, false, GameManager.Close + GameManager.Delay); GameObjectAgent.Instance.delaySetActive(selectedRobot, false, GameManager.Close + GameManager.Delay); GameObjectAgent.Instance.delaySetActive(table, false, GameManager.Close + GameManager.Delay); }); GUIAgent.Instance.addListener("UI", "2_Customizing/Cancel", () => { if (!highlightedObject) return; var parent = GameObjectAgent.Instance.findChild("Object", "Stickers/" + highlightedObject.name); highlightedObject.SetParent(parent.transform); highlightedObject.localPosition = new Vector3(1000, 1000, 1000); GameObjectAgent.Instance.setActive(GUIAgent.Instance.GuiObjects["UI/2_Customizing/Cancel"], false); }); //GUIAgent.Instance.addListener("UI", "1_Lobby/Button", () => //{ // if (selectedRobot.transform.childCount > 0) // selectedRobot.transform.GetChild(0).SetParent(robot.transform); // string saved = PlayerPrefs.GetString("name", ""); // for (int i = 0; i < robot.transform.childCount; i++) // { // if (robot.transform.GetChild(i).name.Contains("save_") && !saved.Contains(robot.transform.GetChild(i).name)) // saved += robot.transform.GetChild(i).name + "/"; // } // if (selectedRobot.transform.childCount > 0) saved += selectedRobot.transform.GetChild(0) + "/"; // PlayerPrefs.SetString("name", saved); // //PlayerPrefs.SetString("nameOfSprite", nameOfSprite); // Application.Quit(); //}); } #endregion add event #region GameObjectAgent.Instance.setActive(gameObject, false); GameObjectAgent.Instance.setActive(GUIAgent.Instance.GuiObjects["Background/2_Customizing"], false); #endregion }
/// <summary> /// Refreshes the radial key menu. /// </summary> public void Refresh() { // Clear old buttons foreach (GameObject obj in _objects) { Destroy(obj); } _objects.Clear(); // Init radius and scale _radius = (_tr.rect.width - _baseScale / 2f) / 2f; _scale = _baseScale; // Layer one -- keys for (int i = 1; i < _numKeys; i++) // i=1 so that it skips Key.None { Key key = (Key)i; float angle = (float)i / (float)(_numKeys - 1) * _TWOPI; // Create button GameObject button = UIHelpers.MakeTextButton(key.ToString()); RectTransform tr = button.GetComponent <RectTransform>(); tr.SetParent(gameObject.GetComponent <RectTransform>()); tr.SetSideWidth(_scale); tr.AnchorAtPoint(0.5f, 0.5f); tr.anchoredPosition3D = new Vector3( _radius * Mathf.Cos(angle), _radius * Mathf.Sin(angle), 0f); tr.ResetScaleRot(); // Set button text Text text = button.GetComponentInChildren <Text>(); if (key.ToString().Contains("Sharp")) { text.text = key.ToString()[0] + "#"; } text.font = UIManager.Instance.Font; text.fontSize = (int)(_scale / 2.5f); text.color = _GRAY; // Set button image Image img = button.GetComponent <Image>(); img.sprite = UIManager.Instance.PercussionVolumeIcon; img.color = _GRAY; // Highlight if selected key if (key == MusicManager.Instance.CurrentSong.Key) { text.color = Color.white; img.color = Color.white; GameObject hl = UIHelpers.MakeImage( key.ToString() + "_SelectedHighlight"); tr = hl.GetComponent <RectTransform>(); tr.SetParent(button.GetComponent <RectTransform>()); tr.sizeDelta = ((RectTransform)(tr.parent)).sizeDelta; tr.AnchorAtPoint(0.5f, 0.5f); tr.anchoredPosition3D = Vector3.zero; tr.ResetScaleRot(); img = hl.GetComponent <Image>(); img.sprite = UIManager.Instance.CircleIcon; img.color = Color.white; } // Set button functionality button.GetComponent <Button>().onClick.AddListener(delegate { UIManager.Instance.PlayMenuClickSound(); MusicManager.Instance.CurrentSong.Key = key; Refresh(); }); // Set button show/hide Highlighted buttonHighlighted = button.AddComponent <Highlighted>(); GameObject highlight = UIHelpers.MakeImage( key.ToString() + "_Highlight"); tr = highlight.GetComponent <RectTransform>(); tr.SetParent(button.GetComponent <RectTransform>()); tr.sizeDelta = ((RectTransform)(tr.parent)).sizeDelta; tr.AnchorAtPoint(0.5f, 0.5f); tr.ResetScaleRot(); tr.anchoredPosition3D = Vector3.zero; highlight.GetComponent <Image>().sprite = UIManager.Instance.PercussionVolumeIcon; highlight.GetComponent <Image>().color = Color.white; Fadeable highlightFade = highlight.AddComponent <Fadeable>(); highlightFade.StartFaded = true; highlightFade.BlockRaycastsWhileFaded = false; highlightFade.FadeSpeed = 0.1f; buttonHighlighted.HighlightObject = highlightFade; _objects.Add(button); } // Layer two -- scales _radius *= _scaleFactor; _scale *= _scaleFactor; for (int i = 0; i < _numScales; i++) { ScaleInfo scalei = ScaleInfo.AllScales[i]; float angle = (float)i / (float)_numScales * _TWOPI; // Make scale button GameObject button = UIHelpers.MakeTextButton(scalei.Name); RectTransform tr = button.GetComponent <RectTransform>(); tr.SetParent(gameObject.GetComponent <RectTransform>()); tr.SetSideWidth(_scale); tr.AnchorAtPoint(0.5f, 0.5f); tr.ResetScaleRot(); tr.anchoredPosition3D = new Vector3( _radius * Mathf.Cos(angle), _radius * Mathf.Sin(angle), 0f); // Set button text Text text = button.GetComponentInChildren <Text>(); text.font = UIManager.Instance.Font; text.fontSize = (int)(_baseScale / 8f); text.color = _GRAY; // Set button image Image img = button.GetComponent <Image>(); img.sprite = UIManager.Instance.PercussionVolumeIcon; img.color = _GRAY; // Set highlighted button if (i == MusicManager.Instance.CurrentSong.Scale) { text.color = Color.white; img.color = Color.white; } // Set button functionality button.GetComponent <Button>().onClick.AddListener(delegate { UIManager.Instance.PlayMenuClickSound(); MusicManager.Instance.CurrentSong.Scale = scalei.ScaleIndex; Refresh(); }); // Set show/hide Highlighted buttonHighlight = button.AddComponent <Highlighted>(); GameObject highlight = UIHelpers.MakeImage( scalei.Name + "_Highlight"); tr = highlight.GetComponent <RectTransform>(); tr.SetParent(button.GetComponent <RectTransform>()); tr.sizeDelta = ((RectTransform)(tr.parent)).sizeDelta; tr.AnchorAtPoint(0.5f, 0.5f); tr.ResetScaleRot(); tr.anchoredPosition3D = Vector3.zero; highlight.GetComponent <Image>().sprite = UIManager.Instance.PercussionVolumeIcon; highlight.GetComponent <Image>().color = Color.white; Fadeable highlightFade = highlight.AddComponent <Fadeable>(); highlightFade.StartFaded = true; highlightFade.BlockRaycastsWhileFaded = false; highlightFade.FadeSpeed = 0.1f; buttonHighlight.HighlightObject = highlightFade; _objects.Add(button); } GameObject confirmButton = KeySelectConfirmButton.Instance.gameObject; // Confirm button if (MusicManager.Instance.CurrentSong.Key != Key.None && MusicManager.Instance.CurrentSong.Scale != -1) { PlayKeySound(); KeySelectConfirmButton.Instance.Show(); confirmButton.GetComponent <Button>().interactable = true; } }
void Update() { // Update mouse delta _mouseDelta = Input.mousePosition - _prevMouse; switch (GameManager.Instance.CurrentState) { // Live mode case GameManager.State.Live: CheckForPause(); MusicManager music = MusicManager.Instance; Instrument inst = music.CurrentInstrument; // If available, get current playing song Song song = null; Project project = music.CurrentProject; int songIndex = music.CurrentPlayingSong; if (!project.Empty) { song = project.Songs[songIndex]; } // Check for tempo up/down else if (Input.GetKeyDown(KeyCode.UpArrow)) { music.IncreaseTempo(); } else if (Input.GetKeyDown(KeyCode.DownArrow)) { music.DecreaseTempo(); } // Check for instrument volume up/down else if (Input.GetKeyDown(KeyCode.LeftArrow)) { AudioSource source = music.GetAudioSource(inst); if (source.volume >= _volumeChangeAmount) { source.volume -= _volumeChangeAmount; } } else if (Input.GetKeyDown(KeyCode.RightArrow)) { AudioSource source = music.GetAudioSource(inst); if (source.volume <= _volumeChangeAmount) { source.volume += _volumeChangeAmount; } } else { // Check for instruments switch foreach (var key in keyToInstrument) { if (Input.GetKeyDown(key.Key)) { SwitchInstrument(keyToInstrument[key.Key]); LiveInstrumentIcons.Instance.WakeLiveUI(); } } // Check for note presses foreach (var keyPress in keyToNote.Keys.ToList()) { if (Input.GetKeyDown(keyPress)) { int noteIndex; AudioSource source = _audioSources[keyToNote[keyPress]]; KeyManager keyManager = KeyManager.Instance; // If percussion is selected if (inst.InstrumentType == Instrument.Type.Percussion) { var percNotes = keyManager.GetNoteSet((PercussionInstrument)inst); noteIndex = percNotes.Count - 1 - keyToNote[keyPress]; if (noteIndex >= 0) { Note note = new Note(percNotes[noteIndex]); note.PlayNote(source, 1f, false); WorldManager.Instance.ShowWeatherEffect(note); } // If melodic is selected (must be a valid song) } else if (song != null && song.Scale != -1 && song.Key != Key.None) { Key key = MusicManager.Instance.CurrentSong.Key; ScaleInfo scaleType = ScaleInfo.AllScales[MusicManager.Instance.CurrentSong.Scale]; MelodicInstrument meloInst = inst as MelodicInstrument; Scale scale = KeyManager.Instance.GetScale(key, scaleType, meloInst); noteIndex = scale.NoteCount - 1 - keyToNote[keyPress]; if (noteIndex >= 0) { Note note = new Note(scale.NoteAt(noteIndex)); if (note != null) { note.PlayNote(source, 1f, true); } } // If electric bass if (inst.CodeName == "ElectricBass") { // Cause terrain deformation WorldManager.Instance.DeformRandom(); // All other melodic instruments } else { switch (inst.InstrumentFamily) { case Instrument.Family.Guitar: MusicManager.Instance.RegisterGuitarNote(); break; case Instrument.Family.Keyboard: MusicManager.Instance.RegisterKeyboardNote(); break; case Instrument.Family.Brass: MusicManager.Instance.RegisterBrassNote(); break; } } } // If key released, stop note } else if (Input.GetKeyUp(keyPress) && inst.InstrumentType != Instrument.Type.Percussion) { _audioSources[keyToNote[keyPress]].Stop(); } } } break; // Setup mode case GameManager.State.Setup: // If left mouse button released if (Input.GetMouseButtonUp(0)) { if (_selected != null) { // Call OnMouseUp() if possible if (_selected.GetComponent <DraggableButton>() != null) { _selected.GetComponent <DraggableButton>().OnMouseUp(); } } // Clear selected _selected = null; // Unfreeze scroll views UnfreezeAllScrollviews(); // Reset click position _clickPosition = Vector3.zero; // If left mouse button clicked } else if (Input.GetMouseButtonDown(0)) { // Get click position _clickPosition = Input.mousePosition; // Get selected object from EventSystem _selected = EventSystem.current.currentSelectedGameObject; // If something was clicked if (_selected != null) { // Freeze scroll views if necessary if (_selected.tag == "StopScrolling") { FreezeAllScrollviews(); } // Call OnMouseDown() if possible if (_selected.GetComponent <DraggableButton>() != null) { _selected.GetComponent <DraggableButton>().OnMouseDown(); } } // If mouse button held down or not down } else { // If held down on an object if (_selected) { // Increment frames dragged _framesDragged++; // Call Drag() if possible if (_selected.GetComponent <DraggableButton>() != null) { _selected.GetComponent <DraggableButton>().Drag(Input.mousePosition - _clickPosition); } // If no object, reset frames dragged } else { _framesDragged = 0; } } break; } // If in free camera mode if (CameraControl.Instance.CurrentState == CameraControl.State.Free) { // Space -> start car movement if (Input.GetKeyDown(KeyCode.Space)) { UIManager.Instance.SwitchToLive(); } // Left/Right -> adjust time of day else if (Input.GetKeyDown(KeyCode.LeftArrow)) { WorldManager.Instance.TimeOfDay -= Mathf.PI / 16f; } else if (Input.GetKeyDown(KeyCode.RightArrow)) { WorldManager.Instance.TimeOfDay += Mathf.PI / 16f; } } // Update prevMouse _prevMouse = Input.mousePosition; }
/// <summary> /// Initializes melodic riff editor. /// </summary> /// <param name="meloInst">Melodic instrument to use.</param> void InitializeMelodicSetup(MelodicInstrument meloInst) { _octaveParent.SetActive(true); Song song = MusicManager.Instance.CurrentSong; Instrument instrument = CurrentRiff.Instrument; // Calculate available octaves List <string> sounds = Sounds.SoundsToLoad[instrument.CodeName]; _maxOctaves = Mathf.CeilToInt((float)sounds.Count / 12f); if (_maxOctaves < _octavesShown) { _octavesShown = _maxOctaves; } // Gather key/scale info Key key = song.Key; ScaleInfo scale = ScaleInfo.AllScales[song.Scale]; // Find starting note int startIndex = meloInst.StartingNote(key); // Calculate number of notes int totalNotes = Sounds.SoundsToLoad[instrument.CodeName].Count; _numNotes = 1 + 12 * _octavesShown; // Set size of grid intersections _squareSize = new Vector2( _notePanel.rect.width / Riff.MAX_BEATS, _notePanel.rect.width / Riff.MAX_BEATS / 2f ); // Set size of buttons _buttonSize = new Vector2( (_squareSize.x - _buttonSpacing) / _volumeScale, (_squareSize.y - _buttonSpacing) / _volumeScale ); // Resize note panel float height = Mathf.Max(_squareSize.y * _numNotes, ((RectTransform)_notePanel.parent).rect.height); _notePanel.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height); // Resize beats bar _beatsBar_tr.sizeDelta = new Vector2( _notePanel.sizeDelta.x, // Use width of note panel _beatsBar_tr.sizeDelta.y // Keep default height ); // Resize note text/icon bar _iconBar_tr.sizeDelta = new Vector2( _iconBar_tr.sizeDelta.x, // Keep default width _notePanel.sizeDelta.y // Use height of note panel ); MakeBeatNumbers(_squareSize.x); // Make column backgrounds MakeGrid(_numNotes); // Make rows of note buttons for (int i = 0; i < _numNotes && i < totalNotes; i++) { string note = Sounds.SoundsToLoad[CurrentRiff.Instrument.CodeName][i + startIndex]; bool inScale = KeyManager.Instance.GetScale(key, scale, meloInst).HasNote(note); MakeMelodicButtons(note.Split('_')[1], i, note, inScale); } }
internal override IEnumerable <Element> GetSvgElements(ScaleInfo scale, double dynamicOffset, double staticPos, IReadOnlyCollection <string> labels) { if (scale == null) { throw new ArgumentNullException(nameof(scale)); } if (labels == null) { throw new ArgumentNullException(nameof(labels)); } var elements = new List <Element>(); var majorCount = labels.Count - 1; var lastYPos = 0.0; for (var i = scale.Max; i >= 0;) { var isMinor = !labels.Contains(i.ToString(CultureInfo.InvariantCulture)); var idLabel = isMinor ? $"{Type.ToString()}-minor-tick-{i}" : $"{Type.ToString()}-major-tick-{i}"; var className = isMinor ? $"{Type}-minor-tick" : $"{Type}-major-tick"; var thisStyle = isMinor ? MinorTickStyle : MajorTickStyle; var xPos = staticPos; var yPos = (i * scale.Scale) + dynamicOffset; if (thisStyle.Draw) { var startPos = new DataPoint(xPos, yPos); var endPos = new DataPoint(xPos - thisStyle.Length, yPos); elements.Add(new Path(idLabel, startPos, new[] { new StraightLine(startPos, endPos, endPos) }, style: thisStyle, classes: new[] { className, "tick" })); } if (!isMinor && LabelStyle.Draw) { var label = labels.ElementAt(majorCount); var labelX = xPos - (label.Length * LabelStyle.WidthPixels) - LabelStyle.Size; var labelY = yPos + (LabelStyle.HeightPixels / 3.1); elements.Add(new Text($"{label}", labelX, labelY, TextAnchor.Start, DominantBaseline.Auto, LabelStyle, new [] { $"{Type}-label", "axis-label" })); } i -= scale.MinorInterval; if (!isMinor) { majorCount -= 1; } lastYPos = yPos; } if (BaseLineStyle.Draw) { elements.Add(new Path( $"{Type}--baseline", new DataPoint(staticPos, (scale.Max * scale.Scale) + dynamicOffset), new DataPoint(staticPos, lastYPos), BaseLineStyle)); } return(elements.ToArray()); }
private ScaleInfo CreateScaleInfo(IDictionary context, AtomicReaderContext readerContext) { var leaves = ReaderUtil.GetTopLevelContext(readerContext).Leaves; float minVal = float.PositiveInfinity; float maxVal = float.NegativeInfinity; foreach (AtomicReaderContext leaf in leaves) { int maxDoc = leaf.Reader.MaxDoc; FunctionValues vals = source.GetValues(context, leaf); for (int i = 0; i < maxDoc; i++) { float val = vals.FloatVal(i); if ((Number.FloatToRawIntBits(val) & (0xff << 23)) == 0xff << 23) { // if the exponent in the float is all ones, then this is +Inf, -Inf or NaN // which don't make sense to factor into the scale function continue; } if (val < minVal) { minVal = val; } if (val > maxVal) { maxVal = val; } } } if (minVal == float.PositiveInfinity) { // must have been an empty index minVal = maxVal = 0; } var scaleInfo = new ScaleInfo { minVal = minVal, maxVal = maxVal }; context[this] = scaleInfo; return scaleInfo; }