public Player(int number) { this.axisManager = new AxisManager(); this.number = number; this.frame = GameObject.FindGameObjectWithTag("Frame" + this.number).GetComponent <Image>(); this.selectedCharacterImage = GameObject.FindGameObjectWithTag("SelectedCharacterImage" + this.number).GetComponent <Image>(); switch (number) { case 0: this.color = new Color(0, 0, 1F, 1F); this.xCharacterSelected = 0; this.yCharacterSelected = 2; break; case 1: this.color = new Color(1F, 0, 0, 1F); this.xCharacterSelected = 2; this.yCharacterSelected = 2; break; case 2: this.color = new Color(0, 1F, 0, 1F); this.xCharacterSelected = 0; this.yCharacterSelected = 0; break; case 3: this.color = new Color(1F, 1F, 0, 1F); this.xCharacterSelected = 2; this.yCharacterSelected = 2; break; } this.fadeAnimation = new FadeAnimation(this.color, 0.3f, 1.3f, 0.07f); }
private void SetCurrentMatrix(Vector3 mousePos) { Vector2 result = Vector2.zero; bool xHit = false; bool yHit = false; for (int i = 0; i < AxisManager.XAxis.Count; i++) { if (AxisManager.GetXAxis(i) - 1.5f <= mousePos.x && mousePos.x <= AxisManager.GetXAxis(i) + 1.5f) { xHit = true; result.x = i; break; } } for (int j = 0; j < AxisManager.YAxis.Count; j++) { if (AxisManager.GetYAxis(j) - 2.9f <= mousePos.y && mousePos.y <= AxisManager.GetYAxis(j) + 0.1f) { yHit = true; result.y = j; break; } } if (xHit && yHit) { currentMatrix = result; positionSelected = true; } }
internal static ControlOverview Open(bool onload = false) { BlockHandlerController.InitializeBuildingBlockIDs(); foreach (ControlOverview x in ACM.Instance.gameObject.GetComponents <ControlOverview>()) { Destroy(x); } var instance = ACM.Instance.gameObject.AddComponent <ControlOverview>(); instance.enabled = false; instance.windowRect.x = Screen.width - 280 - 400; instance.windowRect.y = 200; instance.RefreshOverview(); if (onload) { if (instance.AxisList.TrueForAll(name => { var axis = AxisManager.Get(name); return(axis != null && (axis.Status == AxisStatus.OK || axis.Status == AxisStatus.NotRunning)); })) { Destroy(instance); return(null); } } instance.enabled = true; return(instance); }
void Awake() { if (_this != null) Debug.LogError (this + " should be a singleton!"); _this = this; unityaxis = transform.FindChild("AlternateAxis"); cardbboardaxis = transform.FindChild("CardboardAxis"); }
/// <summary> /// Called on every frame to apply the value. /// </summary> protected virtual void Update() { if (Game.IsSimulating) { var axis = AxisManager.Get(Axis); if (Enabled && Block != null && axis != null && axis.Status == AxisStatus.OK) { Apply(axis.OutputValue); } } }
internal void SaveAxis() { if (Axis.Name == SaveName || !AxisManager.LocalAxes.ContainsKey(Axis.Name)) { Axis.Dispose(); } Axis = Axis.Clone(); Axis.editor.Open(); Axis.Name = SaveName; AxisManager.AddLocalAxis(Axis); Callback?.Invoke(Axis); Destroy(this); }
private void SpawnZombie() { if (currentGameStage.Equals(GameStage.NormalWave)) { int row = Random.Range(0, 5); Debug.Log("Spawn Zombie in row" + row); float xDelta = Random.Range(0.0f, 3.0f); Vector3 genPos = new Vector3(52.0f + xDelta, AxisManager.GetYAxis(row), AxisManager.GetZAxis(row)); Instantiate(Resources.Load("ZombieNormal"), genPos, Quaternion.identity); normalWaveZombieNum--; } else if (currentGameStage.Equals(GameStage.FinalWave)) { } }
/// <summary> /// Returns a list of all active controls on a block. /// A control is active if it is enabled and has bound an axis. /// </summary> /// <param name="GUID">GUID of the block.</param> /// <returns>Returns a list of controls.</returns> public static List <Control> GetActiveBlockControls(Guid GUID) { var list = new List <Control>(); if (Blocks.ContainsKey(GUID)) { foreach (Control c in Blocks[GUID]) { if (c.Enabled && AxisManager.Get(c.Axis) != null) { list.Add(c); } } } return(list); }
/// <summary> /// Is called on OnInitialisation to retrieve BlockHandler reference. /// If the control has no associated block, it is deleted. /// </summary> protected virtual void Initialise() { try { Block = BlockHandlerController.GetBlock(BlockGUID); var axis = AxisManager.Get(Axis); if (Enabled && Block != null && axis != null && axis.Status == AxisStatus.OK) { ClearKeys(); } } catch (BlockNotFoundException) { Block = null; ControlManager.Blocks.Remove(BlockGUID); } }
// Start is called before the first frame update void Start() { //Do_Initilize(); leftIO = new IOManager(Toggles.Length); leftIO.ToggleSet = Toggles; leftIO.Init(); leftIO.sleepTimeSet = sleepTime; for (int i = 0; i < 6; i++) { axises[i] = new AxisManager(URStore.transform.Find("Axis" + i.ToString()).gameObject); } URDateCollector.OnGetPositionSuccess += new URDateHandle.GetPositionSuccess(UpdatePositionsValue); URDateCollector.OnGetAngleSuccess += new URDateHandle.GetAngleSuccess(UpdateAnglesValue); for (int i = 0; i < 6; i++) { temp_Pos[i] = "0.0"; } //任务队列测试 if (inTest) { txIndex = URMissionList.transform.Find("Texts").transform.Find("Index").gameObject.GetComponent <Text>(); txLog = URMissionList.transform.Find("Texts").transform.Find("Log").gameObject.GetComponent <Text>(); xmlRead = new XMLRead("fangxianjia.xml"); if (xmlRead.Read()) { print("文件读取正确"); foreach (XmlElement xmlEle in xmlRead.XMLdoc.SelectSingleNode("Missions").ChildNodes) { Mission mission = new Mission(xmlEle); mission_List.Add(mission); } } else { print(xmlRead.path); print("文件路径不对"); } } }
public void DrawScaleY() { RootAxesY.Children.Clear(); waveLineImgLine.Children.Clear(); if (ViewTime <= 0 || Width <= 0) { return; } if (DataSource == null || DataSource.Items == null || DataSource.Items.Count() < 1) { return; } try { //生成Y轴刻度和文字 如果指定了y轴的文字和值,则用指定的显示 if (ScaleYDictionary != null && ScaleYDictionary.Count() > 0) { //使用指定的刻度值 double min = ScaleYDictionary.First().Key, max = ScaleYDictionary.Last().Key; if (min == max) { max = min + 1; } RootAxesY.MouseMove -= RootAxesY_MouseMove; RootAxesY.Cursor = Cursors.Arrow; var axisManager = new AxisManager(DataSource.MaxValueY, DataSource.MinValueY); axisManager.AxisMaximumValue = DataSource.MaxValueY; axisManager.AxisMinimumValue = DataSource.MinValueY; axisManager.Calculate(); var ratio = waveLineXImg.MainBoardHeight / (max - min); var IntervalRnage = ratio * axisManager.Interval; var loopNo = (int)(waveLineXImg.MainBoardHeight / IntervalRnage); for (var i = 0; i <= loopNo; i++) { var offsetY = Height - waveLineXImg.MarginBottom - IntervalRnage * i; var scaleItem = new TextBlock(); scaleItem.Width = 27; scaleItem.TextAlignment = TextAlignment.Right; scaleItem.FontSize = 9; scaleItem.Text = string.IsNullOrWhiteSpace(ScaleYDictionary[i]) ? null : ScaleYDictionary[i]; scaleItem.Margin = new Thickness(0, offsetY - 7, 0, 0); RootAxesY.Children.Add(scaleItem); var myLine = new Line(); myLine = new Line(); myLine.Stroke = ScaleYBrush; myLine.StrokeThickness = 0.2; myLine.X1 = 0; myLine.X2 = Width; myLine.Y1 = offsetY; myLine.Y2 = offsetY; waveLineImgLine.Children.Add(myLine); } } else { //用数值显示 waveLineXImg.DataSource = DataSource.Items; waveLineXImg.MinValueX = DataSource.DataTime.Date.AddHours(12); waveLineXImg.MaxValueX = waveLineXImg.MinValueX.AddHours(24); double min = minY, max = maxY; var axisManager = new AxisManager(maxY, minY); axisManager.Calculate(); if (min == max) { max = max + axisManager.Interval; min = min - axisManager.Interval; } var ratio = (Height - waveLineXImg.MarginTop - waveLineXImg.MarginBottom) / (maxY - minY); var IntervalRnage = ratio * axisManager.Interval; interval = Convert.ToSingle(axisManager.Interval); var loopNo = (int)((Height - waveLineXImg.MarginBottom) / IntervalRnage); for (var i = 0; i <= loopNo; i++) { var offsetY = Height - waveLineXImg.MarginBottom - IntervalRnage * i; var scaleItem = new TextBlock(); scaleItem.Width = 27; scaleItem.TextAlignment = TextAlignment.Right; scaleItem.FontSize = 9; scaleItem.Text = (min + axisManager.Interval * i).ToString(); scaleItem.Margin = new Thickness(0, offsetY - 7, 0, 0); RootAxesY.Children.Add(scaleItem); var myLine = new Line(); myLine = new Line(); myLine.Stroke = ScaleYBrush; myLine.StrokeThickness = 0.2; myLine.X1 = 0; myLine.X2 = Width; myLine.Y1 = offsetY; myLine.Y2 = offsetY; waveLineImgLine.Children.Add(myLine); } //end for axisManager = null; } //end if } catch (Exception e) { //LogHelper.Error(ToString(), e); //MessageBox.Show(Application.Current.MainWindow,e.Message, ResourceHelper.LoadString("Error"), MessageBoxButton.OK, MessageBoxImage.Error); } }
private void DoWindow(int id) { // Draw local axes if (AxisManager.LocalAxes.Count > 0) { localScrollPosition = GUILayout.BeginScrollView(localScrollPosition, GUILayout.Height(Mathf.Clamp(AxisManager.LocalAxes.Count * 36 + 30, 138, 246))); GUILayout.Label("LOCALLY SAVED AXES", new GUIStyle(Elements.Labels.Title) { alignment = TextAnchor.MiddleCenter }); string toBeRemoved = null; foreach (KeyValuePair <string, InputAxis> pair in AxisManager.LocalAxes) { var name = pair.Key; var axis = pair.Value; GUILayout.BeginHorizontal(); if (GUILayout.Button(name, axis.Saveable ? Elements.Buttons.Default : Elements.Buttons.Disabled)) { Callback?.Invoke(axis); Destroy(this); } if (GUILayout.Button("✎", new GUIStyle(Elements.Buttons.Default) { fontSize = 20, padding = new RectOffset(-3, 0, 0, 0) }, GUILayout.Width(30), GUILayout.MaxHeight(28))) { var Editor = ACM.Instance.gameObject.AddComponent <AxisEditorWindow>(); Editor.windowRect.x = Mathf.Clamp(windowRect.x + windowRect.width, -320 + GUI.skin.window.padding.top, Screen.width - GUI.skin.window.padding.top); Editor.windowRect.y = Mathf.Clamp(windowRect.y - 40, 0, Screen.height - GUI.skin.window.padding.top); Editor.EditAxis(axis); } if (GUILayout.Button("×", Elements.Buttons.Red, GUILayout.Width(30))) { toBeRemoved = name; } GUILayout.EndHorizontal(); } if (toBeRemoved != null) { AxisManager.RemoveLocalAxis(toBeRemoved); } GUILayout.EndScrollView(); } // Draw machine axes if (AxisManager.MachineAxes.Count > 0) { machineScrollPosition = GUILayout.BeginScrollView(machineScrollPosition, GUILayout.Height(Mathf.Clamp(AxisManager.MachineAxes.Count * 36 + 30, 138, 246))); GUILayout.Label("MACHINE EMBEDDED AXES", new GUIStyle(Elements.Labels.Title) { alignment = TextAnchor.MiddleCenter }); string toBeRemoved = null; foreach (KeyValuePair <string, InputAxis> pair in AxisManager.MachineAxes) { var name = pair.Key; var axis = pair.Value; GUILayout.BeginHorizontal(); if (GUILayout.Button(name, axis.Saveable ? Elements.Buttons.Default : Elements.Buttons.Disabled)) { Callback?.Invoke(axis); Destroy(this); } if (GUILayout.Button("✎", new GUIStyle(Elements.Buttons.Default) { fontSize = 20, padding = new RectOffset(-3, 0, 0, 0) }, GUILayout.Width(30), GUILayout.MaxHeight(28))) { var Editor = ACM.Instance.gameObject.AddComponent <AxisEditorWindow>(); Editor.windowRect.x = Mathf.Clamp(windowRect.x + windowRect.width, -320 + GUI.skin.window.padding.top, Screen.width - GUI.skin.window.padding.top); Editor.windowRect.y = Mathf.Clamp(windowRect.y - 40, 0, Screen.height - GUI.skin.window.padding.top); Editor.EditAxis(axis); } if (GUILayout.Button("×", Elements.Buttons.Red, GUILayout.Width(30))) { toBeRemoved = name; } GUILayout.EndHorizontal(); } if (toBeRemoved != null) { AxisManager.RemoveMachineAxis(toBeRemoved); } GUILayout.EndScrollView(); } if (GUILayout.Button("Create new axis", Elements.Buttons.Disabled)) { var Editor = ACM.Instance.gameObject.AddComponent <AxisEditorWindow>(); Editor.windowRect.x = Mathf.Clamp(windowRect.x + windowRect.width, -320 + GUI.skin.window.padding.top, Screen.width - GUI.skin.window.padding.top); Editor.windowRect.y = Mathf.Clamp(windowRect.y - 40, 0, Screen.height - GUI.skin.window.padding.top); Editor.CreateAxis(new SelectAxisDelegate(Callback)); Destroy(this); } // Draw close button if (!compact) { if (GUI.Button(new Rect(windowRect.width - 38, 8, 30, 30), "×", Elements.Buttons.Red)) { Destroy(this); } } }
internal static void Load() { try { // load mod configuration ACM.Instance.ModEnabled = spaar.ModLoader.Configuration.GetBool("acm-enabled", true); ACM.Instance.ModUpdaterEnabled = spaar.ModLoader.Configuration.GetBool("mod-updater-enabled", true); ACM.Instance.DBUpdaterEnabled = spaar.ModLoader.Configuration.GetBool("db-updater-enabled", true); // read input axes int count = spaar.ModLoader.Configuration.GetInt("number-of-axes", 0); for (int i = 0; i < count; i++) { string name = spaar.ModLoader.Configuration.GetString("axis-" + i + "-name", null); InputAxis axis = null; if (name != null) { var type = spaar.ModLoader.Configuration.GetString("axis-" + name + "-type", null); if (type == AxisType.Chain.ToString()) { axis = new ChainAxis(name); } if (type == AxisType.Controller.ToString()) { axis = new ControllerAxis(name); } if (type == AxisType.Custom.ToString()) { axis = new CustomAxis(name); } if (type == AxisType.Standard.ToString() || // backwards compatibility type == AxisType.Inertial.ToString() || // backwards compatibility type == AxisType.Key.ToString()) { axis = new KeyAxis(name); } if (type == AxisType.Mouse.ToString()) { axis = new MouseAxis(name); } } if (axis != null) { axis?.Load(); AxisManager.AddLocalAxis(axis); } } // refresh chain axis links foreach (var entry in AxisManager.LocalAxes) { if (entry.Value.Type == AxisType.Chain) { (entry.Value as ChainAxis).RefreshLinks(); } } } catch (Exception e) { Debug.Log("[ACM]: Error loading saved axes:"); Debug.LogException(e); } }
public void DrawAxis(Rect windowRect) { // Draw graphs Rect graphRect = new Rect( GUI.skin.window.padding.left, GUI.skin.window.padding.top + 36, windowRect.width - GUI.skin.window.padding.left - GUI.skin.window.padding.right, 20); Rect leftGraphRect = new Rect( GUI.skin.window.padding.left, GUI.skin.window.padding.top + 100, (windowRect.width - GUI.skin.window.padding.left - GUI.skin.window.padding.right) / 2 - 4, 20); Rect rightGraphRect = new Rect( GUI.skin.window.padding.left + leftGraphRect.width + 8, GUI.skin.window.padding.top + 100, (windowRect.width - GUI.skin.window.padding.left - GUI.skin.window.padding.right) / 2 - 4, 20); Util.DrawRect(graphRect, Color.gray); Util.FillRect(new Rect( graphRect.x + graphRect.width / 2, graphRect.y, 1, graphRect.height), Color.gray); Util.DrawRect(leftGraphRect, Color.gray); Util.FillRect(new Rect( leftGraphRect.x + leftGraphRect.width / 2, leftGraphRect.y, 1, leftGraphRect.height), Color.gray); Util.DrawRect(rightGraphRect, Color.gray); Util.FillRect(new Rect( rightGraphRect.x + rightGraphRect.width / 2, rightGraphRect.y, 1, rightGraphRect.height), Color.gray); var axis_a = AxisManager.Get(Axis.SubAxis1); var axis_b = AxisManager.Get(Axis.SubAxis2); float a = axis_a != null ? axis_a.OutputValue : 0; float b = axis_b != null ? axis_b.OutputValue : 0; // Draw axis value GUILayout.Label(" <color=#808080><b>" + Axis.OutputValue.ToString("0.00") + "</b></color>", new GUIStyle(Elements.Labels.Default) { richText = true, alignment = TextAnchor.MiddleLeft }, GUILayout.Height(20)); // Draw method select int i = (int)Axis.Method; int num_methods = Enum.GetValues(typeof(ChainAxis.ChainMethod)).Length; GUILayout.BeginHorizontal(); if (GUILayout.Button("<", Elements.Buttons.Default, GUILayout.Width(30))) { i--; } if (i < 0) { i += num_methods; } GUILayout.Label(Enum.GetNames(typeof(ChainAxis.ChainMethod))[i], new GUIStyle(Elements.InputFields.Default) { alignment = TextAnchor.MiddleCenter }); if (GUILayout.Button(">", Elements.Buttons.Default, GUILayout.Width(30))) { i++; } if (i == num_methods) { i = 0; } Axis.Method = (ChainAxis.ChainMethod)i; GUILayout.EndHorizontal(); // Draw sub axis values GUILayout.BeginHorizontal(GUILayout.Height(20)); GUILayout.Label(" <color=#808080><b>" + (axis_a == null ? "" : axis_a.Status == AxisStatus.OK ? a.ToString("0.00") : InputAxis.GetStatusString(axis_a.Status)) + "</b></color>", new GUIStyle(Elements.Labels.Default) { richText = true, alignment = TextAnchor.MiddleLeft }, GUILayout.MinWidth(leftGraphRect.width), GUILayout.Height(20)); GUILayout.Label(" <color=#808080><b>" + (axis_b == null ? "" : axis_b.Status == AxisStatus.OK ? b.ToString("0.00") : InputAxis.GetStatusString(axis_a.Status)) + "</b></color>", new GUIStyle(Elements.Labels.Default) { richText = true, alignment = TextAnchor.MiddleLeft, margin = new RectOffset(8, 0, 0, 0) }, GUILayout.MinWidth(rightGraphRect.width), GUILayout.Height(20)); GUILayout.EndHorizontal(); // Draw yellow lines if (Axis.Status == AxisStatus.OK) { Util.FillRect(new Rect( graphRect.x + graphRect.width / 2 + graphRect.width / 2 * Axis.OutputValue, graphRect.y, 1, graphRect.height), Color.yellow); } if (axis_a != null && Axis.Status == AxisStatus.OK) { Util.FillRect(new Rect( leftGraphRect.x + leftGraphRect.width / 2 + leftGraphRect.width / 2 * a, leftGraphRect.y, 1, leftGraphRect.height), Color.yellow); } if (axis_b != null && Axis.Status == AxisStatus.OK) { Util.FillRect(new Rect( rightGraphRect.x + rightGraphRect.width / 2 + rightGraphRect.width / 2 * b, rightGraphRect.y, 1, rightGraphRect.height), Color.yellow); } // Draw axis select buttons GUILayout.BeginHorizontal(); var buttonRect = GUILayoutUtility.GetRect(new GUIContent(" "), spaar.ModLoader.UI.Elements.Buttons.Default, GUILayout.MaxWidth(leftGraphRect.width)); if (Axis.SubAxis1 == null) { if (GUI.Button(buttonRect, "Select Input Axis", spaar.ModLoader.UI.Elements.Buttons.Disabled)) { error = null; var callback = new SelectAxisDelegate((InputAxis axis) => { try { Axis.SubAxis1 = axis.Name; } catch (InvalidOperationException e) { error = "<color=#FFFF00><b>Chain cycle error</b></color>\n" + e.Message; } }); if (popup == null) { popup = AxisSelector.Open(callback, true); } else { popup.Callback = callback; } popup.windowRect.x = windowRect.x + buttonRect.x - 8; popup.windowRect.y = windowRect.y + buttonRect.y - 8; } } else { if (GUI.Button(buttonRect, Axis.SubAxis1, axis_a != null ? axis_a.Saveable ? spaar.ModLoader.UI.Elements.Buttons.Default : spaar.ModLoader.UI.Elements.Buttons.Disabled : spaar.ModLoader.UI.Elements.Buttons.Red)) { error = null; var callback = new SelectAxisDelegate((InputAxis axis) => { try { Axis.SubAxis1 = axis.Name; } catch (InvalidOperationException e) { error = "<color=#FFFF00><b>Chain cycle error</b></color>\n" + e.Message; } }); if (popup == null) { popup = AxisSelector.Open(callback, true); } else { popup.Callback = callback; } popup.windowRect.x = windowRect.x + buttonRect.x - 8; popup.windowRect.y = windowRect.y + buttonRect.y - 8; } } if (Axis.SubAxis2 == null) { if (GUILayout.Button("Select Input Axis", spaar.ModLoader.UI.Elements.Buttons.Disabled, GUILayout.MaxWidth(rightGraphRect.width))) { error = null; var callback = new SelectAxisDelegate((InputAxis axis) => { try { Axis.SubAxis2 = axis.Name; } catch (InvalidOperationException e) { error = "<color=#FFFF00><b>Chain cycle error</b></color>\n" + e.Message; } }); if (popup == null) { popup = AxisSelector.Open(callback, true); } else { popup.Callback = callback; } popup.windowRect.x = windowRect.x + buttonRect.x - 8; popup.windowRect.y = windowRect.y + buttonRect.y - 8; } } else { if (GUILayout.Button(Axis.SubAxis2, axis_b != null ? axis_b.Saveable ? spaar.ModLoader.UI.Elements.Buttons.Default : spaar.ModLoader.UI.Elements.Buttons.Disabled : spaar.ModLoader.UI.Elements.Buttons.Red, GUILayout.MaxWidth(rightGraphRect.width))) { error = null; var callback = new SelectAxisDelegate((InputAxis axis) => { try { Axis.SubAxis2 = axis.Name; } catch (InvalidOperationException e) { error = "<color=#FFFF00><b>Chain cycle error</b></color>\n" + e.Message; } }); if (popup == null) { popup = AxisSelector.Open(callback, true); } else { popup.Callback = callback; } popup.windowRect.x = windowRect.x + buttonRect.x - 8; popup.windowRect.y = windowRect.y + buttonRect.y - 8; } } GUILayout.EndHorizontal(); // Check for mouse exit if (popup != null && !popup.ContainsMouse) { GameObject.Destroy(popup); } }
internal static void Save(MachineInfo machineInfo) { try { var axisStack = new Stack <string>(); var axisList = new List <string>(); // save all controls and collect all bound axes foreach (BlockInfo blockInfo in machineInfo.Blocks) { if (ControlManager.Blocks.ContainsKey(blockInfo.Guid)) { var controls = ControlManager.GetActiveBlockControls(blockInfo.Guid); if (controls.Count == 0) { continue; } var control_names = new List <string>(); foreach (Control c in controls) { if (!axisStack.Contains(c.Axis)) { axisStack.Push(c.Axis); } control_names.Add(c.Name); c.Save(blockInfo); } blockInfo.BlockData.Write("ac-controllist", control_names.ToArray()); } } // go through stack and save all axes and chained axes while (axisStack.Count > 0) { var a = AxisManager.Get(axisStack.Pop()); if (a == null || axisList.Contains(a.Name)) { continue; } axisList.Add(a.Name); if (a.Type == AxisType.Chain) { var chain = a as ChainAxis; axisStack.Push(chain.SubAxis1); axisStack.Push(chain.SubAxis2); } if (a.Type == AxisType.Custom) { var custom = a as CustomAxis; foreach (var linked in custom.LinkedAxes) { axisStack.Push(linked); } } a.Save(machineInfo); } // save axis list and metadata if (axisList.Count != 0) { machineInfo.MachineData.Write("ac-version", Assembly.GetExecutingAssembly().GetName().Version.ToString()); machineInfo.MachineData.Write("ac-axislist", axisList.ToArray()); } } catch (Exception e) { Debug.Log("[ACM]: Error saving machine's controls."); Debug.LogException(e); } }
internal static void Load(MachineInfo machineInfo) { try { AxisManager.MachineAxes.Clear(); ControlManager.Blocks.Clear(); // read mod version if (!machineInfo.MachineData.HasKey("ac-version")) { return; } var version = new Version(machineInfo.MachineData.ReadString("ac-version").TrimStart('v')); // version alert if (version < Assembly.GetExecutingAssembly().GetName().Version) { Debug.Log("[ACM]: " + machineInfo.Name + " was saved with mod version " + version + ".\n\tIt may not be compatible with some newer features."); } // return if no input axes are present if (!machineInfo.MachineData.HasKey("ac-axislist")) { return; } var axes = machineInfo.MachineData.ReadStringArray("ac-axislist"); // load all axes foreach (var name in axes) { InputAxis axis = null; if (!machineInfo.MachineData.HasKey("axis-" + name + "-type")) { continue; } var type = machineInfo.MachineData.ReadString("axis-" + name + "-type"); if (type == AxisType.Chain.ToString()) { axis = new ChainAxis(name); } if (type == AxisType.Controller.ToString()) { axis = new ControllerAxis(name); } if (type == AxisType.Custom.ToString()) { axis = new CustomAxis(name); } if (type == AxisType.Standard.ToString() || // backwards compatibility type == AxisType.Inertial.ToString() || // backwards compatibility type == AxisType.Key.ToString()) { axis = new KeyAxis(name); } if (type == AxisType.Mouse.ToString()) { axis = new MouseAxis(name); } if (axis != null) { axis?.Load(machineInfo); AxisManager.AddMachineAxis(axis); } } // refresh chain axis links foreach (var entry in AxisManager.MachineAxes) { if (entry.Value.Type == AxisType.Chain) { (entry.Value as ChainAxis).RefreshLinks(); } } // resolve from foreign controllers AxisManager.ResolveMachineAxes(); // load all controls foreach (BlockInfo blockInfo in machineInfo.Blocks) { if (!blockInfo.BlockData.HasKey("ac-controllist")) { continue; } var control_list = ControlManager.GetBlockControls(blockInfo.ID, blockInfo.Guid); var control_names = blockInfo.BlockData.ReadStringArray("ac-controllist"); foreach (string name in control_names) { foreach (Control c in control_list) { if (name == c.Name) { c.Load(blockInfo); } } } } ACM.Instance.LoadedMachine = true; } catch (Exception e) { Debug.Log("[ACM]: Error loading machine's controls:"); Debug.LogException(e); } }
private void DrawAxis(string axis) { GUILayout.BeginHorizontal(); var buttonRect = GUILayoutUtility.GetRect(new GUIContent(" "), Elements.Buttons.Default); var a = AxisManager.Get(axis); if (GUI.Button(buttonRect, axis, a != null ? a.Saveable ? Elements.Buttons.Default : Elements.Buttons.Disabled : Elements.Buttons.Red)) { var callback = new SelectAxisDelegate((InputAxis new_axis) => { AssignAxis(axis, new_axis.Name); }); if (popup == null) { popup = AxisSelector.Open(callback, true); } else { popup.Callback = callback; } popup.windowRect.x = windowRect.x + buttonRect.x - 8; popup.windowRect.y = windowRect.y + GUI.skin.window.padding.top + buttonRect.y - scrollPosition.y - 8; } if (a != null && GUILayout.Button("✎", new GUIStyle(Elements.Buttons.Default) { fontSize = 20, padding = new RectOffset(-3, 0, 0, 0) }, GUILayout.Width(30), GUILayout.MaxHeight(28))) { var Editor = ACM.Instance.gameObject.AddComponent <AxisEditorWindow>(); Editor.windowRect.x = Mathf.Clamp(windowRect.x + windowRect.width, -320 + GUI.skin.window.padding.top, Screen.width - GUI.skin.window.padding.top); Editor.windowRect.y = Mathf.Clamp(windowRect.y, 0, Screen.height - GUI.skin.window.padding.top); Editor.EditAxis(a, new SelectAxisDelegate((InputAxis new_axis) => { AssignAxis(axis, new_axis.Name); })); } GUILayout.EndHorizontal(); // Draw graph string text; if (a == null) { text = "NOT FOUND"; } else if (a.Status != AxisStatus.OK) { text = InputAxis.GetStatusString(a.Status); } else { text = ""; } GUILayout.Label(" <color=#808080><b>" + text + "</b></color>", new GUIStyle(Elements.Labels.Default) { richText = true, alignment = TextAnchor.MiddleLeft, margin = new RectOffset(8, 8, 8, 8) }, GUILayout.Height(20)); var graphRect = GUILayoutUtility.GetLastRect(); Util.DrawRect(graphRect, Color.gray); Util.FillRect(new Rect( graphRect.x + graphRect.width / 2, graphRect.y, 1, graphRect.height), Color.gray); if (a != null && a.Status == AxisStatus.OK) { Util.FillRect(new Rect( graphRect.x + graphRect.width / 2 + graphRect.width / 2 * a.OutputValue, graphRect.y, 1, graphRect.height), Color.yellow); } // Draw assigned controls list foreach (Control c in Controls[axis]) { GUILayout.BeginHorizontal(); if (GUILayout.Button("×", new GUIStyle(Elements.Buttons.Red) { margin = new RectOffset(8, 8, 0, 0) }, GUILayout.Width(20), GUILayout.Height(20))) { c.Axis = null; c.Enabled = false; } string block_name; try { block_name = BlockHandlerController.GetID(c.BlockGUID); } catch { block_name = "..."; } GUILayout.Label("<b>" + c.Name + "</b> for " + block_name, Elements.Labels.LogEntry); GUILayout.EndHorizontal(); } GUILayout.Box(GUIContent.none, GUILayout.Height(8)); }
/// <summary> /// Returns an axis with given name. /// Looks in machine axes first, then in locally saved axes. /// This is the preferred method. /// </summary> /// <param name="name">Name of the axis.</param> /// <returns></returns> public static InputAxis GetAxis(string name) { return(AxisManager.Get(name)); }
private void DrawControl(Control c) { // Draw control label GUILayout.Label(c.Name, Elements.Labels.Title); // Draw axis select button GUILayout.BeginHorizontal(); var buttonRect = GUILayoutUtility.GetRect(GUIContent.none, Elements.Buttons.Default); if (c.Axis == null) { if (GUI.Button(buttonRect, "Select Input Axis", Elements.Buttons.Disabled)) { var callback = new SelectAxisDelegate((InputAxis axis) => { c.Axis = axis.Name; c.Enabled = true; }); if (popup == null) { popup = AxisSelector.Open(callback, true); } else { popup.Callback = callback; } popup.windowRect.x = windowRect.x + buttonRect.x - 8; popup.windowRect.y = windowRect.y + buttonRect.y - 8; } } else { var a = AxisManager.Get(c.Axis); if (GUI.Button(buttonRect, c.Axis, a != null ? a.Saveable ? Elements.Buttons.Default : Elements.Buttons.Disabled : Elements.Buttons.Red)) { var callback = new SelectAxisDelegate((InputAxis axis) => { c.Axis = axis.Name; c.Enabled = true; }); if (popup == null) { popup = AxisSelector.Open(callback, true); } else { popup.Callback = callback; } popup.windowRect.x = windowRect.x + buttonRect.x - 8; popup.windowRect.y = windowRect.y + buttonRect.y - 8; } if (a != null && GUILayout.Button("✎", new GUIStyle(Elements.Buttons.Default) { fontSize = 20, padding = new RectOffset(-3, 0, 0, 0) }, GUILayout.Width(30), GUILayout.MaxHeight(28))) { var Editor = ACM.Instance.gameObject.AddComponent <AxisEditorWindow>(); Editor.windowRect.x = Mathf.Clamp(windowRect.x + windowRect.width, -320 + GUI.skin.window.padding.top, Screen.width - GUI.skin.window.padding.top); Editor.windowRect.y = Mathf.Clamp(windowRect.y, 0, Screen.height - GUI.skin.window.padding.top); Editor.EditAxis(a, new SelectAxisDelegate((InputAxis new_axis) => { c.Axis = new_axis.Name; })); } if (GUILayout.Button("×", Elements.Buttons.Red, GUILayout.Width(30))) { c.Enabled = false; c.Axis = null; } } GUILayout.EndHorizontal(); if (c.Enabled) { // Draw graph var axis = AxisManager.Get(c.Axis); float axis_value = axis != null ? axis.OutputValue : 0; float control_value = 0; string text; if (axis == null) { text = "NOT FOUND"; } else { if (axis_value > 0) { control_value = Mathf.Lerp(c.Center, c.Max, axis_value); } else { control_value = Mathf.Lerp(c.Center, c.Min, -axis_value); } if (axis.Status == AxisStatus.OK) { text = control_value.ToString("0.00"); } else { text = InputAxis.GetStatusString(axis.Status); } } GUILayout.Label("<color=#808080><b>" + text + "</b></color>", new GUIStyle(Elements.Labels.Default) { padding = new RectOffset(38, 38, 4, 0), richText = true, alignment = TextAnchor.MiddleLeft }, GUILayout.Height(20)); var graphRect = GUILayoutUtility.GetLastRect(); graphRect.x += 30; graphRect.height += 44; graphRect.width -= 60; Util.DrawRect(graphRect, Color.gray); Util.FillRect(new Rect( graphRect.x + graphRect.width / 2, graphRect.y, 1, graphRect.height), Color.gray); if (axis != null && axis.Status == AxisStatus.OK) { Util.FillRect(new Rect( graphRect.x + graphRect.width / 2 + graphRect.width / 2 * axis_value, graphRect.y, 1, graphRect.height), Color.yellow); } // Draw invert button if (GUI.Button(new Rect(graphRect.x + graphRect.width - 28, graphRect.y, 28, 28), "<size=24><color=#808080>⇄</color></size>", Elements.Labels.Default)) { c.Invert(); } // Draw interval input fields GUILayout.BeginHorizontal(); { var oldColor = GUI.backgroundColor; GUI.backgroundColor = new Color(0.7f, 0.7f, 0.7f, 0.7f); float min_parsed = c.Min; c.min_string = Regex.Replace( GUILayout.TextField( c.min_string, new GUIStyle(Elements.InputFields.Default) { alignment = TextAnchor.MiddleCenter }, GUILayout.Width(60)), @"[^0-9\-.]", ""); if (c.min_string != c.Min.ToString() && !c.min_string.EndsWith(".0") && !c.min_string.EndsWith(".") && c.min_string != "-" && c.min_string != "-0") { float.TryParse(c.min_string, out min_parsed); c.Min = min_parsed; c.min_string = c.Min.ToString(); } GUILayout.FlexibleSpace(); float cen_parsed = c.Center; c.cen_string = Regex.Replace( GUILayout.TextField( c.cen_string, new GUIStyle(Elements.InputFields.Default) { alignment = TextAnchor.MiddleCenter }, GUILayout.Width(60)), @"[^0-9\-.]", ""); if (c.cen_string != c.Center.ToString() && !c.cen_string.EndsWith(".0") && !c.cen_string.EndsWith(".") && c.cen_string != "-" && c.cen_string != "-0") { float.TryParse(c.cen_string, out cen_parsed); c.Center = cen_parsed; c.cen_string = c.Center.ToString(); } GUILayout.FlexibleSpace(); float max_parsed = c.Max; c.max_string = Regex.Replace( GUILayout.TextField( c.max_string, new GUIStyle(Elements.InputFields.Default) { alignment = TextAnchor.MiddleCenter }, GUILayout.Width(60)), @"[^0-9\-.]", ""); if (c.max_string != c.Max.ToString() && !c.max_string.EndsWith(".0") && !c.max_string.EndsWith(".") && c.max_string != "-" && c.max_string != "-0") { float.TryParse(c.max_string, out max_parsed); c.Max = max_parsed; c.max_string = c.Max.ToString(); } GUI.backgroundColor = oldColor; } GUILayout.EndHorizontal(); } }
void UpdatePlanting() { Vector3 mousePos = gameCam.ScreenToWorldPoint(Input.mousePosition); if (positionSelected && Input.GetMouseButtonDown(0) && planting == true && plantingType != PlantType.NotDefined) { if (sun >= ManagerDefine.GetSunNeedByPlantType(plantingType)) { string prefabName = ""; switch (plantingType) { case PlantType.Peashooter: prefabName = "Peashooter"; break; case PlantType.Sunflower: prefabName = "SunFlower"; break; case PlantType.SnowPeashooter: prefabName = "SnowPeashooter"; break; case PlantType.WallNut: prefabName = "WallNut"; break; default: prefabName = "SunFlower"; break; } Instantiate(Resources.Load(prefabName), new Vector3(AxisManager.GetXAxis((int)currentMatrix.x), AxisManager.GetYAxis((int)currentMatrix.y), AxisManager.GetZAxis((int)currentMatrix.y)), Quaternion.identity); sun -= ManagerDefine.GetSunNeedByPlantType(plantingType); planting = false; plantingType = PlantType.NotDefined; positionSelected = false; CurrentPlantCard.CanBeSelected = false; Destroy(plantingSprite.gameObject); } } else if (Input.GetMouseButtonDown(1) && planting == true && plantingType != PlantType.NotDefined) { Destroy(plantingSprite.gameObject); planting = false; plantingType = PlantType.NotDefined; positionSelected = false; } else { if (planting == true && plantingType != PlantType.NotDefined) { // Moving the plant if (plantingSprite != null) { SetCurrentMatrix(mousePos); plantingSprite.transform.position = new Vector3(AxisManager.GetXAxis((int)currentMatrix.x), AxisManager.GetYAxis((int)currentMatrix.y) - 1.4f, AxisManager.GetZAxis((int)currentMatrix.y)); } else { plantingSprite = Instantiate(Resources.Load("PlantSprite", typeof(tk2dSprite)), new Vector3(mousePos.x, mousePos.y, 6.0f), Quaternion.identity) as tk2dSprite; plantingSprite.SetSprite(ManagerDefine.GetSpriteNameByPlantType(plantingType)); } } } }