void ClearPickup() { //pickupIn = 0; pickupButton = null; pickupDescriptor = null; pickupPosition = Vector3.zero; renderer.enabled = false; }
public ActionBarInfo SpawnChild(ActionBarInitialization ButtonInformation) { //Assign Button Size ActionBarButtonClone.transform.GetChild(0).transform.localScale = new Vector3(ButtonSize.x, ButtonSize.y, 1F); //Add Button as a child to the Action Bar Row ActionBarButton button = NGUITools.AddChild(this.gameObject, ActionBarButtonClone).GetComponentInChildren <ActionBarButton>(); //Assign MISC Information to Items/Spells if (ButtonInformation.Info.Stackable == true) { ButtonInformation.Info.Stack = ButtonInformation.Stacks; } if (ButtonInformation.Info.SeperateInstance == true) { button.SetInfo(Clone(ButtonInformation)); } else { if (ButtonInformation.isEmpty == false) { if (ButtonInformation.InfoNumber < ActionBarItem.Instance.ItemList.Count) { button.SetInfo(ActionBarItem.Instance.ItemList[ButtonInformation.InfoNumber]); //Assign the Spell/Item Information } else { Debug.LogWarning(gameObject.name + " is attempting to Assign Spell that no longer exists!"); button.SetInfo(null); } } else { button.SetInfo(null); } } //button.DisplayOneStack = ButtonInformation.DisplayOneStack; button.HotKey = ButtonInformation.HotKey; //Assign the Hotkey if (ActionBarSettings.Instance.HotKeyDictionary.ContainsKey(button.HotKey)) { button.HotKeyLabel.text = ActionBarSettings.Instance.HotKeyDictionary[button.HotKey]; } else //Check Keycode to see if it is None { button.HotKeyLabel.text = ""; //Assign Text to Blank since it has no Hotkey } button.isEmpty = ButtonInformation.isEmpty; button.isLocked = ButtonInformation.isLocked; button.isCloneOnPickup = ButtonInformation.isCloneOnPickup; button.BarRow = GetComponent <ActionBarRow>(); //Assign Parent Row ActionBarSettings.Instance.Buttons.Add(button); //Keep track of all buttons ButtonList.Add(button); //Add button to list ActionBarGrid.Reposition(); return(button.Info); }
void DecloneWithinGroup(ActionBarButton from, ActionBarButton to, ActionBarDescriptor descriptor) { if (to.Row.RemoveCloneWithinGroup && descriptor.Buttons.Count > 0 && descriptor.ItemGroup == to.ItemGroup) { foreach (ActionBarButton button in descriptor.Buttons.ToArray()) { if (button.ItemGroup == to.ItemGroup) { button.RemoveDescriptor(); } } } }
bool RaycastButton(out ActionBarButton button) { Ray ray = ActionBarCamera.Instance.camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, float.MaxValue, 1 << gameObject.layer)) { button = hit.transform.GetComponent <ActionBarButton>(); return(button != null); } button = null; return(false); }
void Update() { Vector2 position = Vector2.zero; if (anchor) { position = CalculateAnchorScreenPosition(); } else { position = transform.position; } SetPosition(Mathf.RoundToInt(position.x), Mathf.RoundToInt(position.y)); // Check button presses for (int i = 0; i < Mathf.Min(buttonSettings.Length, buttons.Length); ++i) { ActionBarButton b = buttons[i]; ActionBarButtonSettings k = buttonSettings[i]; if (k != null && b != null) { if (Input.GetKeyDown(k.PrimaryKey) && ActionBarInput.CheckModifierKeys_Down(k.PrimaryModifiers)) { b.Overlay = true; } else if (Input.GetKeyDown(k.SecondaryKey) && ActionBarInput.CheckModifierKeys_Down(k.SecondaryModifiers)) { b.Overlay = true; } else if (Input.GetKeyUp(k.PrimaryKey) && ActionBarInput.CheckModifierKeys_Up(k.PrimaryModifiers)) { b.Press(); } else if (Input.GetKeyUp(k.SecondaryKey) && ActionBarInput.CheckModifierKeys_Up(k.SecondaryModifiers)) { b.Press(); } if (!b.Pressed && !Input.GetKey(k.PrimaryKey) && !Input.GetKey(k.SecondaryKey)) { b.Overlay = false; } } } }
ActionBarButton CreateButton() { // Create our new game object GameObject go = new GameObject("ActionBarButton"); // Add components go.AddComponent <MeshFilter>(); go.AddComponent <MeshRenderer>(); go.transform.parent = transform; // Init ActionBarButton button = go.AddComponent <ActionBarButton>(); button.Init(this); return(button); }
void InitButtons() { ActionBarButton[] newButtons = new ActionBarButton[buttonSettings.Length]; if (newButtons.Length > buttons.Length) { for (int i = 0; i < buttons.Length; ++i) { newButtons[i] = buttons[i]; } for (int i = buttons.Length; i < newButtons.Length; ++i) { newButtons[i] = CreateButton(); } } else { for (int i = 0; i < newButtons.Length; ++i) { newButtons[i] = buttons[i]; } for (int i = newButtons.Length; i < buttons.Length; ++i) { GameObject.Destroy(buttons[i]); } } buttons = newButtons; if (ActionBarSettings.Instance.DisplayKeybindings) { for (int i = 0; i < buttons.Length; ++i) { buttons[i].Label = buttonSettings[i].ToString(); } } }
bool RaycastButton(out ActionBarButton button) { Ray ray = ActionBarCamera.Instance.camera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, float.MaxValue, 1 << gameObject.layer)) { button = hit.transform.GetComponent<ActionBarButton>(); return button != null; } button = null; return false; }
void PlacePickedup() { ActionBarButton button; if (pickupDescriptor != null && RaycastButton(out button)) { if (button.Locked || button.Row.Excludes(pickupDescriptor.ItemGroup) || (pickupButton != null && button.Row.Excludes(pickupButton.ItemGroup))) { // Return button if (pickupButton != null) { pickupButton.SetDescriptor(pickupDescriptor); } // Clear ClearPickup(); } else { if (button.Empty) { // Check if we need to clone this DecloneWithinGroup(pickupButton, button, pickupDescriptor); // Set buttons descriptor button.SetDescriptor(pickupDescriptor); // Clear ClearPickup(); } else { // Descriptor already on the button if (ReferenceEquals(button.Descriptor, pickupDescriptor)) { ClearPickup(); } // Only if we're not putting a one back in the same place else { // Check if we need to clone this DecloneWithinGroup(pickupButton, button, pickupDescriptor); // Check if we can stack this shit! if (button.Descriptor.Stackable && pickupDescriptor.Stackable && button.Descriptor.ItemGroup == pickupDescriptor.ItemGroup && button.Descriptor.ItemType == pickupDescriptor.ItemType) { // Add one to stack button.Descriptor.Stack += pickupDescriptor.Stack; // Remove ClearPickup(); } else { // Switch the descriptor and pickup the old one Pickup(button.SetDescriptor(pickupDescriptor)); // We need to clear this, since we already placed something in this button // We cant revert if users places it somewhere else pickupButton = null; } } } } } else { // Clear ClearPickup(); } }
void OnGUI() { switch (currentState) { case TutorialStates.State.Off: case TutorialStates.State.Done: break; case TutorialStates.State.Pause: DoPause(); break; case TutorialStates.State.Selection: Texture2D text = new Texture2D(1, 1); Color col = Color.blue; col.a = .25f; text.SetPixel(1, 1, col); text.Apply(); GUI.DrawTexture(box, text); GUI.TextArea(new Rect(Screen.width / 2 - 125, Screen.height / 2 - 50, 275, 150), "Multiple cells can be selected at a time by clicking and dragging around them.\nOnce selected, cells can be ordered to move by right clicking the desired location. \nSelect both of the cells in the chest now.", tutorialMessageStyle); if (gC.selected.Count >= 2) { //currentState = TutorialStates.State.Done; currentState = TutorialStates.State.Move; } break; case TutorialStates.State.Move: GUI.TextArea(new Rect(Screen.width / 2 - 87, Screen.height / 2 - 50, 175, 50), "Right click on a part of the body to move the selected cells.", tutorialMessageStyle); if (gC.firstMouse) { currentState = TutorialStates.State.Unpause; } break; case TutorialStates.State.Finish: GUI.Window(0, new Rect(Screen.width / 2 - 125, Screen.height / 2 - 50, 250, 150), FinishDialog, "Finished Tutorial", tutorialMessageStyle); break; case TutorialStates.State.Unpause: GUI.TextArea(new Rect(Screen.width / 2 - 87, Screen.height / 2 - 50, 175, 50), "Now unpause the game to continue.\n (space key)", tutorialMessageStyle); if (!gC.IsPaused()) { currentState = TutorialStates.State.HeartRate; } break; case TutorialStates.State.HeartRate: GUI.Window(0, new Rect(175, 60, 250, 150), HeartRateDialog, "Heart Rate Slider"); break; case TutorialStates.State.EnergyBar: GUI.Window(0, new Rect(250, 10, 250, 150), EnergyDialog, "Energy Bar"); break; case TutorialStates.State.Production: GUI.Window(0, new Rect(200, Screen.height - 325, 250, 150), ProductionDialog, "Production"); break; case TutorialStates.State.PlateProduction: //GUI.Window(0, new Rect(220, Screen.height - 160, 250, 150), PlateProductionDialog, "Production"); //gC.actionBarPrefab.GetComponentInChildren<ActionBarButton>(); ActionBarButton ab = gC.actionBarPrefab.transform.Find("platelet_Button").GetComponent <ActionBarButton>(); if (counter < 30) { ab.renderer.material.color = Color.yellow; } else if (counter < 60) { ab.renderer.material.color = Color.white; } else { counter = 0; } //SetAlphaOfBody(0.3f); counter++; GUI.TextArea(new Rect(125, Screen.height - 200, 250, 150), "Platelets are used to clot wounds as they appear.\nTo create new platelets, either press the platelet button or press the 'W' key.\nCreate a platelet now.", tutorialMessageStyle); if (gC.plateletProduction > 0) { //currentState = TutorialStates.State.Done; //SetAlphaOfBody(1.0f); ab.renderer.material.color = Color.white; currentState = TutorialStates.State.WBCProduction; counter = 0; } break; case TutorialStates.State.WBCProduction: //GUI.Window(0, new Rect(300, Screen.height - 160, 250, 150), WBCProductionDialog, "Production"); GUI.TextArea(new Rect(125, Screen.height - 290, 250, 150), "B Cells, a type of white blood cell, are used to combat diseases as they enter the body.\nTo create new B Cells, either press the B Cell button or press the 'Q' key.\n\nCreate a B-Cell now.", tutorialMessageStyle); ActionBarButton wb = gC.actionBarPrefab.transform.Find("whitebloodcell_Button").GetComponent <ActionBarButton>(); if (counter < 30) { wb.renderer.material.color = Color.yellow; } else if (counter < 60) { wb.renderer.material.color = Color.white; } else { counter = 0; } counter++; if (gC.whiteBloodProduction > 0) { //currentState = TutorialStates.State.Done; currentState = TutorialStates.State.PlateCombat; wb.renderer.material.color = Color.white; counter = 0; } break; case TutorialStates.State.PlateCombat: GUI.Window(0, new Rect(Screen.width / 2 - 125, Screen.height / 2 - 50, 250, 150), PlateCombatDialog, "Combat", tutorialMessageStyle); break; case TutorialStates.State.WBCCombat: GUI.Window(0, new Rect(Screen.width / 2 - 125, Screen.height / 2 - 50, 250, 150), WBCCombatDialog, "Combat", tutorialMessageStyle); break; case TutorialStates.State.Commence: GUI.Window(0, new Rect(Screen.width / 2 - 125, Screen.height / 2 - 50, 250, 75), CommenceDialog, "Tutorial", tutorialMessageStyle); break; } }