public override void Update(HeldObject heldObject) { if (heldObject.playerInRange) { heldObject.TransitionToState(heldObject.inRangeState); } }
void TryToUseObject(GameObject animal) { if (ObjectInHand != null) { AnimalStatistics stats = animal.GetComponent <AnimalStatistics>(); HeldObject obj = ObjectInHand.GetComponent <HeldObject>(); if (!obj.IsCarryingUnits()) { return; } float food = 0; float water = 0; switch (obj.GetTypeOfObject()) { case TypeOfObject.ResourceCollector: stats.RetrieveResourceFromAnimal(); break; case TypeOfObject.Bucket: water = (obj.IsCarryingUnits() ? obj.GetNumUnitsHeld() : 0); ConsumedPerpetualObject(); break; case TypeOfObject.Hay: food = obj.GetNumUnitsHeld(); ConsumedOneTimeUseObject(); break; } stats.GiveFoodAndWater(food, water); } }
private void MouseUp(GameObject obj) { if (Input.touchCount > 0) { return; } if (_heldObject == null) { return; } if (_heldObject.colliderGameObject != obj) { return; } _heldObject.ingredient.Release(); _heldObject.rigidbody.useGravity = true; _heldObject.rigidbody.isKinematic = false; var velocityVector = _heldObject.averageVelocity * flingVelocityFactor; _heldObject.rigidbody.transform.DOScale(_heldObject.ingredient.DefaultScale, 0.1f); _heldObject.rigidbody.AddForce(new Vector3( velocityVector.x, _heldObject.rigidbody.velocity.y, velocityVector.y )); _heldObject = null; }
void ConsumedPerpetualObject() { HeldObject obj = ObjectInHand.GetComponent <HeldObject>(); obj.ChangeObjectState(); obj.SetNumUnitsHeld(); }
private void CheckHeldItem(string itemName) { switch (itemName) { case "scrap(Clone)": held = HeldObject.scrap; HeadDisplay(headItem[0], false); audio.clip = SFX.soundClips[Random.Range(0, 6)]; audio.Play(); break; case "bolt(Clone)": held = HeldObject.bolt; HeadDisplay(headItem[1], false); audio.clip = SFX.soundClips[Random.Range(0, 6)]; audio.Play(); break; case "gear(Clone)": held = HeldObject.gear; HeadDisplay(headItem[2], false); audio.clip = SFX.soundClips[Random.Range(0, 6)]; audio.Play(); break; case "scrapbox": if (held == HeldObject.scrap) { health.vFloat += 10; held = HeldObject.nothing; state = PlayerState.empty; HeadDisplay(headItem[3], true); audio.clip = SFX.soundClips[Random.Range(0, 6)]; audio.Play(); } break; case "boltbox": if (held == HeldObject.bolt) { health.vFloat += 14; held = HeldObject.nothing; state = PlayerState.empty; HeadDisplay(headItem[3], true); audio.clip = SFX.soundClips[Random.Range(0, 6)]; audio.Play(); } break; case "gearbox": if (held == HeldObject.gear) { health.vFloat += 20; held = HeldObject.nothing; state = PlayerState.empty; HeadDisplay(headItem[3], true); audio.clip = SFX.soundClips[Random.Range(0, 6)]; audio.Play(); } break; } }
private void HandleExamining() { Examine examineObject = HeldObject.GetComponent <Examine>(); if (!examineObject) { return; } if (Input.GetKeyDown(KeyCode.Mouse1)) { if (!IsExamining) { IsExamining = true; examineObject.StartExamining(); // Disable movment and camera control during examination of object GetComponent <PlayerMovement>().enabled = false; Camera.main.GetComponent <PlayerLook>().enabled = false; } else { IsExamining = false; examineObject.StopExamining(); GetComponent <PlayerMovement>().enabled = true; Camera.main.GetComponent <PlayerLook>().enabled = true; } } }
public override void Update(HeldObject heldObject) { if (Input.GetKeyUp(KeyCode.Mouse0)) { ObjectDropped(heldObject); } }
public override void ObjectDropped(HeldObject droppedObject) { droppedObject.rb.constraints = RigidbodyConstraints.None; droppedObject.rb.useGravity = true; droppedObject.Player.DropObject(droppedObject.gameObject); droppedObject.TransitionToState(droppedObject.selectedState); }
private void SlotInteract(Slot slot) { if (heldObject == HeldObject.plant && !slot.hasPlant) { PlacePlantOnSlot(slot); levelGod.PlacePlant(slot); heldObject = HeldObject.none; return; } if (slot.hasPlant) { if (heldObject == HeldObject.none) { PickUpPlantFromSlot(slot); levelGod.PickupPlant(slot); heldObject = HeldObject.plant; } if (heldObject == HeldObject.soil) { PutDownSoil(); levelGod.ChangeSoil(slot); heldObject = HeldObject.none; } if (heldObject == HeldObject.nutrient) { PutDownNutrient(); levelGod.FeedPlant(slot); heldObject = HeldObject.none; } } }
void CollectResource(GameObject obj) { ResourceSource source = obj.GetComponent <ResourceSource>(); switch (CurrentState) { case PlayerState.EmptyHand: if (source.GetTypeOfSource() == TypeOfSource.Feed) { GameObject held = source.GetHeldObject(); if (held == null) { break; } held.GetComponent <HeldObject>().SetNumUnitsHeld(source.UnitsTakenFromSource()); PickupObject(held); } break; case PlayerState.HoldingObject: if (source.GetTypeOfSource() == TypeOfSource.Water) { HeldObject held = ObjectInHand.GetComponent <HeldObject>(); if (held.GetTypeOfObject() != TypeOfObject.Bucket || held.IsCarryingUnits()) { break; } held.SetNumUnitsHeld(source.UnitsTakenFromSource()); held.ChangeObjectState(); FindObjectOfType <AudioManager>().Play("wellSFX"); } break; } }
public override void Update(HeldObject heldObject) { if (!heldObject.playerInRange) { if (heldObject.displayImage != null) { heldObject.ToggleImage(false); } heldObject.TransitionToState(heldObject.idleState); } else { RaycastHit hit; int layerMask = 1 << 10; bool mouseOver = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 50, layerMask, QueryTriggerInteraction.Ignore); if (mouseOver && hit.transform.name == heldObject.name) { if (Input.GetKeyDown(KeyCode.Mouse0)) { ObjectPickedUp(heldObject); } } else { if (heldObject.displayImage != null) { heldObject.ToggleImage(false); } heldObject.TransitionToState(heldObject.inRangeState); } } }
private void Start() { heldObject = GetComponent <HeldObject>(); GetAllStackableObjects(); controller = FindObjectOfType <GameController>(); objectisHeld = false; Cursor.SetCursor(mouseCursor, Vector2.zero, CursorMode.Auto); }
public override void ObjectPickedUp(HeldObject pickedUpObject) { pickedUpObject.outlineObject.SetActive(false); pickedUpObject.rb.constraints = RigidbodyConstraints.FreezeRotation; pickedUpObject.rb.useGravity = false; pickedUpObject.Player.PickupObject(pickedUpObject.gameObject); pickedUpObject.TransitionToState(pickedUpObject.pickedUpState); }
public override void EnterState(HeldObject heldObject) { heldObject.outlineObject.SetActive(true); if (heldObject.displayImage != null) { heldObject.ChangeSprite(); heldObject.ToggleImage(true); } }
void PickupObjects() { //For each object dropped that is to be pickeup again after the swap use the function from the held object selected state to have player pickup object again foreach (Transform heldObject in rePickUpObjects) { //heldObject.parent = objectHolder.transform; HeldObject heldScript = heldObject.GetComponent <HeldObject>(); heldScript.CurrentState.ObjectPickedUp(heldScript); } }
// Update is called once per frame void Update() { if (Mathf.Abs(spring.currentForce.x) > dropForce | Mathf.Abs(spring.currentForce.y) > dropForce | Mathf.Abs(spring.currentForce.z) > dropForce && transform.childCount > 0) { for (int i = 0; i < transform.childCount; i++) { HeldObject heldObject = transform.GetChild(i).GetComponent <HeldObject>(); heldObject.CurrentState.ObjectDropped(heldObject); } } }
public void DropObject() { if (HeldObject) { HeldObject.transform.position = transform.position; Vector3 scale = HeldObject.transform.localScale; scale.Set(1, 1, 1); HeldObject.transform.localScale = scale; HeldObject.GetComponent <Collider>().enabled = true; HeldObject = null; } }
public override void Update(HeldObject heldObject) { if (!heldObject.playerInRange) { heldObject.TransitionToState(heldObject.idleState); } else { RaycastHit hit; int layerMask = 1 << 10; bool mouseOver = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 50, layerMask, QueryTriggerInteraction.Ignore); if (mouseOver && hit.transform.name == heldObject.name) { heldObject.TransitionToState(heldObject.selectedState); } } }
private void MouseDown(GameObject obj) { if (Input.touchCount > 0) { return; } var rb = obj.GetComponent <Rigidbody>(); if (rb == null) { return; } var ingredient = rb.gameObject.GetComponent <Ingredient>(); if (ingredient == null) { return; } if (!ingredient.CanHold()) { return; } _heldObject = new HeldObject() { colliderGameObject = obj, rigidbody = rb, ingredient = ingredient }; ingredient.Hold(); rb.useGravity = false; rb.isKinematic = true; var dest = Camera.main.ScreenToWorldPoint(new Vector3( Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.y - holdHeight )); rb.DOMove(dest, 0.1f); rb.transform.DOScale(ingredient.DefaultScale * scaleUpFactor, 0.1f); _lastMousePosition = Input.mousePosition; _lastMouseTime = Time.time; }
private void PlacePlantOnSlot(Slot slot) { var position = slot.transform.position; var plant = holding; plant.position = position; plant.rotation = Quaternion.identity; plant.parent = null; //plant.parent = slot.transform; plant.SetParent(slot.transform); Debug.Log($"parent: {plant.transform.parent.name}"); holding = null; heldObject = HeldObject.none; }
void DropHeldObjects() { //Clear list of objects to pickup after the swap has ocurred so that a new list can be built of only currently held objects rePickUpObjects.Clear(); //Only run if player is holding an object, will likely only ever hold one but want to future proof in case it gets increased later if (objectHolder.transform.childCount > 0) { for (int i = 0; i < objectHolder.transform.childCount; i++) { //Get reference to each child object in turn and if they are in a swap zone add them to list of objects to be picked up after the swap happens Transform heldObject = objectHolder.transform.GetChild(i); if (swapObjects.Contains(heldObject.gameObject)) { rePickUpObjects.Add(heldObject); } //Held objects picked up state already has code to handle how objects should be dropped so use this HeldObject heldScript = heldObject.GetComponent <HeldObject>(); heldScript.CurrentState.ObjectDropped(heldScript); } } }
public override void ObjectDropped(HeldObject droppedObject) { throw new System.NotImplementedException(); }
protected override void BuffEnded(bool wasRemoved, bool wasManual) { if (Interlocked.CompareExchange(ref BuffEndLock, 1, 0) != 0) { return; } BuffHasExpired = true; WasManuallyRemoved = wasManual; if (wasRemoved) { BuffState = (byte)EBuffState.Removed; } else { BuffState = (byte)EBuffState.Ended; } Interlocked.Exchange(ref BuffEndLock, 0); if (_buffInfo.CommandInfo != null) { foreach (BuffCommandInfo command in _buffInfo.CommandInfo) { if ((command.InvokeOn & (byte)EBuffState.Ended) > 0) { BuffEffectInvoker.InvokeCommand(this, command, Target); } } } if (EventCommands.Count > 0) { foreach (var evtpair in EventCommands) { _buffInterface.RemoveEventSubscription(this, evtpair.Item1); } } BuffHasExpired = true; BuffState = (byte)EBuffState.Removed; Player player = (Player)Caster; if (player.HeldObject != HeldObject) { Log.Error(player.Name, "Holding multiple objects!"); } else { player.HeldObject = null; } HeldObject.HolderDied(); Caster.OSInterface.RemoveEffect(0xB); SendEnded(); }
// Use this for initialization void Start() { heldObject = GetComponent <HeldObject> (); }
public override void EnterState(HeldObject heldObject) { }
private void HandleClick() { if (Input.GetKeyUp(KeyCode.E)) { Ray laser = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(laser, out hit, grabDistance)) { switch (hit.collider.tag) { case "Plant": Slot pSlot = SlotAtPlantPosition(hit); if (pSlot != null) { SlotInteract(pSlot); } break; case "Slot": Slot slot = SlotAtPosition(hit); SlotInteract(slot); break; case "NutrientRack": int nutrient = NutrientAtPosition(hit); if (heldObject == HeldObject.none) { PickUpNutrient(nutrient); heldObject = HeldObject.nutrient; return; } if (heldObject == HeldObject.nutrient) { PutDownNutrient(); heldObject = HeldObject.none; } break; case "SoilRack": int soil = SoilAtPosition(hit); if (heldObject == HeldObject.none) { PickUpSoil(soil); heldObject = HeldObject.soil; return; } if (heldObject == HeldObject.soil) { PutDownSoil(); heldObject = HeldObject.none; } break; case "Workstation": if (heldObject == HeldObject.plant) { levelGod.ExaminePlantWithWorkstation(); } break; case "Incinerator": if (heldObject == HeldObject.plant) { levelGod.DestroyPlant(holding); holding = null; heldObject = HeldObject.none; } break; default: Debug.Log("Attempting interaction with unknown object."); break; } } } }
public abstract void ObjectPickedUp(HeldObject pickedUpObject);
public override void ObjectPickedUp(HeldObject pickedUpObject) { throw new System.NotImplementedException(); }
public override void EnterState(HeldObject heldObject) { heldObject.outlineObject.SetActive(false); }
public abstract void ObjectDropped(HeldObject droppedObject);