protected virtual void Die() { if (isDead) { return; } if (_audioSource != null && _destructionSound != null) { print("Playing DestructionSound"); AudioManager.Instance.Play(_audioSource, _destructionSound, AudioManager.AudioGroup.Other); } isDead = true; DraggableObject draggable = GetComponent <DraggableObject>(); if (draggable != null) { Destroy(draggable); } Destroy(this); //gameObject.SetActive(false); }
// Update is called once per frame void Update() { if (DraggableObject.IsPlayerDraggingObject() && selected == this) { OnRelease(); selected = null; } x = tile.x; y = tile.y; // This is ugly but it will work for now! if (selected != this) { Unmark(); if (selected != null) { selected.MarkNeighbors(new Color(0, 1, 0)); } } else { if (IsTileOccupated(tile)) { OnRelease(); selected = null; } } }
void Update() { Ray ray = Camera.main.ScreenPointToRay(gameObject.transform.position); RaycastHit hitObject; Debug.DrawRay(transform.position, ray.direction, Color.red); if (Physics.Raycast(ray, out hitObject, 100f)) { if (hitObject.transform.CompareTag("Draggable")) { Debug.Log("SELECT"); draggableObject = hitObject.transform.gameObject.GetComponent <DraggableObject>(); draggableObject.Select(); } } else { if (draggableObject != null) { Debug.Log("DESELECT"); draggableObject.Deselect(); draggableObject = null; } } }
void pictureDroped(DraggableObject obj, Vector3 position) { const float R = 0.01F; // Радиус зоны попадания на картинку GamePicture gp = (GamePicture)obj; if (gp != null) { GamePicture target = gameField.onTargetPositon(gp); if (target != null) { //картинка сопоставлена правильно (музыка, эфекты) audioController.playBubblesSound(); //gamePicturePlaces.Remove(gp); //Destroy (gp.gameObject); target.setTrueColor(); gp.reset(); checkForGameOver(); return; } else { misstakes++; } } gp.returnToPreviousPosition(); }
void pictureDroped(DraggableObject obj, Vector3 position) { GamePicture gp = (GamePicture)obj; setCurrentPicture(gp); if (gp != null) { //Перемещение в карзину Collider2D[] colliders = Physics2D.OverlapCircleAll(new Vector2(basket.position.x, basket.position.y), 0.2f); if (contanes(colliders, gp.gameObject)) { gp.reset(); setCurrentPicture(null); return; } //Перемешение на поле if (field.contanes(gp)) { noObjectsOnFieldError.active = false; return; } } gp.returnToPreviousPosition(); }
public void UseItem() { if (slotEnabled) { if (InventoryManager.instance.dragging) { if (hasItem() == false) { //ChestOrNormalUse(); AddItem(InventoryManager.instance.dragUI.item); InventoryManager.instance.AddItem(item, slotNum); InventoryManager.instance.dragUI.Placed(); } } else if (item != null && InventoryManager.instance.dragMode && !isChestSlot) { DraggableObject drag = InventoryManager.instance.dragUI; drag.BeginDrag(item); /* * Image dragImage = drag.GetComponent<Image>(); * dragImage.sprite = item.icon; * dragImage.color = new Color(dragImage.color.r, dragImage.color.g, dragImage.color.b, 1f); * drag.item = item;*/ InventoryManager.instance.RemoveItem(slotNum); SetInactiveSlot(); ClearSlot(); } else { ChestOrNormalUse(); } } }
// Use this for initialization void Start() { activateFlap.Randomize(); draggable = GetComponent <DraggableObject>(); lr = GetComponent <LineRenderer> (); }
private void OnTriggerCliked(object sender, ClickedEventArgs e) { float closestDistance = float.MaxValue; DraggableObject closestObject = null; foreach (DraggableObject draggable in draggables) { if (!draggable.IsDragged) { float distance = Vector3.Distance(draggable.transform.position, transform.position); if (distance < minDistanceToGrab && distance < closestDistance) { closestDistance = distance; closestObject = draggable; } } } if (closestObject != null) { draggedObject = closestObject; draggedObject.StartDragging(transform); renderModel.gameObject.SetActive(false); } }
public void OnMouseButtonDown(int index) { if (index != 0) { return; } if (!board.GetOrbitCamera().IsReset()) { return; } BoardObject boardObject = Instantiate(myBoardObject, transform.position, Quaternion.identity); boardObject.transform.localScale = transform.lossyScale; Destroy(boardObject.gameObject.GetComponent <Selectable>()); DraggableObject draggable = boardObject.gameObject.AddComponent <DraggableObject>(); draggable.SetBoard(board); draggable.SetArgumentLoader(argumentLoader); draggable.SetCameraInput(board.GetMouseInput()); draggable.SetOrbitCamera(board.GetOrbitCamera()); string name = boardObject.GetName(); TrackerAsset.Instance.setVar("element_type", name.ToLower()); TrackerAsset.Instance.setVar("element_name", boardObject.GetNameWithIndex().ToLower()); TrackerAsset.Instance.setVar("action", "create"); TrackerAsset.Instance.GameObject.Interacted(boardObject.GetID()); draggable.OnMouseButtonDown(index); }
private void Awake() { if (instance != null && instance != this) { Destroy(gameObject); } instance = this; }
} //end StartTouch public void EndTouch() { if (draggable != null) { draggable.EndDrag(); } draggable = null; } //end EndTouch
//droppa nella droppable area il droppable object trascinato protected void DropItem(DroppableArea d, DraggableObject draggableComponent) { draggableComponent.StopDragging(draggableComponent.CheckIfCorrectDropArea(d.GetMainType(), d.GetSubType()), d.gameObject); draggableComponent.SetDropAreaDestination(d.transform.position); draggableComponent.SetDroppableArea(d.gameObject); d.SetContainedPiece(draggableComponent.gameObject); d.SetOccupied(true); }
/* * Instantiate a the Draggable base object */ private DraggableObject CreateNewObject(DraggableObject prefab, string objectName, Vector2 initialPosition) { Vector2 center = new Vector2(RectTransform.sizeDelta.x / 2, RectTransform.sizeDelta.y / 2); var obj = (DraggableObject)Instantiate(prefab, initialPosition, prefab.transform.rotation); obj.Init(Parts.transform, this, objectName); return(obj); }
public void DropDragObject() { if (DraggableObject != null) { DraggableObject.Drop(); } DraggableObject = null; }
void OnMouseOver() { if (PauseMenu.PAUSED) { return; } if (!Game.BOARD.Contains(tile)) { return; } if (DraggableObject.IsPlayerDraggingObject()) { return; } if (IsTileOccupated(tile)) { return; } if (btnSelect.Check() == InputStates.InputState.JustPressed) { if (selected == null) { OnSelect(); selected = this; } else if (selected != this) { if ((Math.Abs((int)selected.x - (int)x) == 1 && selected.y == y) || (Math.Abs((int)selected.y - (int)y) == 1 && selected.x == x)) { if (!IsTileOccupated(selected.tile)) { //Debug.Log("§§-§§"); //Debug.Log("> T1: " + new Vector2(x, y)); //Debug.Log("> T2: " + new Vector2(selected.x, selected.y)); GameBoard.GAME_BOARD.AddTile(selected.tile, x, y); GameBoard.GAME_BOARD.AddTile(tile, selected.x, selected.y); GameBoard.GAME_BOARD.Build(); selected.OnRelease(); OnRelease(); selected = null; } } else { selected.OnRelease(); OnSelect(); selected = this; } } else { OnRelease(); selected = null; } } }
protected virtual void Start() { dragStance = DraggableObject.instance; active = true; //relevantActions = new HashSet<InputControl>(); childConstructor(); setRelevantVariables(); parent = gameObject.transform.parent.gameObject; //EventManager.instance.OnInventoryAction += handleKeyEvent; }
public void Clear() { m_currentTrackedModel = null; m_currentDraggedObject = null; m_currentDraggedObjectComp = null; m_draggingCandidate = null; m_leftButtonDown = false; m_processing = true; m_freezeTimeElapsed = 0f; }
protected void RegisterDragBehavior() { GameBoard board = FindObjectOfType <GameBoard>(); GameBoardTileBehavior dragBehavior = new GameBoardTileBehavior(board, this); DraggableObject draggableObject = GetComponent <DraggableObject>(); if (draggableObject != null) { draggableObject.behavior = dragBehavior; } }
private void OnTriggerUncliked(object sender, ClickedEventArgs e) { if (draggedObject != null) { draggedObject.StopDragging(); draggedObject = null; renderModel.gameObject.SetActive(true); } }
public void AddLetter(DraggableObject letter) { _answer[_earliestFreeSlot] = letter; for(int i=_earliestFreeSlot; i<_answer.Length; ++i) { if(_answer[_earliestFreeSlot] == null) break; _earliestFreeSlot++; } }
public void RemoveLetter(DraggableObject letter) { for(int i=0; i<_answer.Length; ++i) { if(_answer[i] == letter) { _answer[i] = null; if(i<_earliestFreeSlot) _earliestFreeSlot = i; } } }
public void RemoveLetter(DraggableObject letter) { for(int i=0; i<_currentAnswer.Length; ++i) { if(_currentAnswer[i] == letter) { _currentAnswer[i] = null; if(i<_firstFreeSlotId) _firstFreeSlotId = i; } } }
private void Start() { fullness = 0; overfull = false; filling = true; emptying = false; emptyingTimer = 0; drag = GetComponent <DraggableObject>(); textMesh = GetComponentInChildren <TextMeshPro>(); FillRender = FillBar.GetComponent <Renderer>(); updateText(); }
DraggableObject getPotentialResident() { foreach (Collider col in Physics.OverlapSphere(transform.TransformPoint(offset), radius)) { DraggableObject d = col.GetComponent <DraggableObject>(); if (d && !d.held) { return(d); } } return(null); }
public bool AddBoardObject(int x, int y, BoardObject boardObject) { if (IsInBoardBounds(x, y) && boardObject != null) { bool placed = board[x, y].PlaceObject(boardObject); if (!placed) { return(false); } if (boardObject.transform.parent != elementsParent) { boardObject.transform.SetParent(elementsParent); boardObject.SetBoard(this); } if (elementPositions != null) { string name = boardObject.GetNameAsLower(); if (!elementPositions.ContainsKey(name)) { elementPositions[name] = new List <Vector2Int>(); } elementPositions[name].Add(new Vector2Int(x, y)); boardObject.SetIndex(elementPositions[name].Count); FollowingText text = boardObject.GetComponent <FollowingText>(); if (text != null) { text.SetName(boardObject.GetNameWithIndex()); } } if (boardModifiable) { DraggableObject drag = boardObject.gameObject.GetComponent <DraggableObject>(); if (drag == null) { drag = boardObject.gameObject.AddComponent <DraggableObject>(); drag.SetBoard(this); drag.SetArgumentLoader(argLoader); drag.SetCameraInput(cameraInput); drag.SetOrbitCamera(orbitCamera); drag.SetLastPos(new Vector2Int(x, y)); } drag.SetModifiable(objectsModifiable); } return(placed); } return(false); }
//handles what happens when cards are attempted to be put onto each type of card holding location public void OnDrop(PointerEventData pointerData) { DraggableObject droppedCard = pointerData.pointerDrag.GetComponent <DraggableObject>(); CardInfo droppedCardInfo = pointerData.pointerDrag.GetComponent <CardInfo>(); //make sure card being dropped here can be moved if (droppedCard != null && droppedCard.GetComponent <DraggableObject>().canBeDragged == true && droppedCard.oldParent.GetComponent <CardDropArea>().myDropAreaType != CardDropArea.DropAreaType.FOUNDATION) { //check to make sure the move is valid if (rules.isMoveValid(this, pointerData.pointerDrag.GetComponent <CardInfo>())) { droppedCard.oldParent.GetComponent <CardDropArea>().cardStack.Pop(); droppedCard.oldParent = this.transform; //check for empty stacks if (cardStack.Count != 0) { cardStack.Peek().GetComponent <DraggableObject>().setCanBeDragged(false); } cardStack.Push(pointerData.pointerDrag); //handle each type of area switch (myDropAreaType) { case DropAreaType.TABLEAU: { droppedCard.GetComponent <DraggableObject>().setCanBeDragged(false); rules.updateStacks(); break; } case DropAreaType.FREECELL: { rules.updateStacks(); break; } case DropAreaType.FOUNDATION: { droppedCard.GetComponent <DraggableObject>().setCanBeDragged(false); Instantiate <ParticleSystem>(rules.successParticle, droppedCard.transform); rules.updateStacks(); break; } } } } //rules.updateStacks(); rules.checkForWin(); }
void Update() { if (GameController.Instance.GameState != GameStates.Game) { return; } // Search for interactive objects InteractiveObject = null; DragObject dragObject = null; IsHoverDragObject = false; RaycastHit hit; if (Physics.Raycast(mainCamera.transform.position, mainCamera.transform.TransformDirection(Vector3.forward), out hit, 2.0f)) { InteractiveObject = hit.collider.gameObject.GetComponent(typeof(IUse)) as IUse; if (InteractiveObject != null && InteractiveObject.IsActive == false) { InteractiveObject = null; } dragObject = hit.collider.GetComponent <DragObject>(); if (dragObject != null && dragObject.Rigidbody.isKinematic) { dragObject = null; } IsHoverDragObject = dragObject != null; } if ((InteractiveObject != null) && (InputController.Use)) { InteractiveObject.Use(); } if (InteractiveObject == null && dragObject != null && DraggableObject == null && InputController.Drag) { dragObject.Drag(dragPoint); DraggableObject = dragObject; } if (DraggableObject != null && InputController.Dragging == false) { DraggableObject.Drop(); DraggableObject = null; } if (DraggableObject != null && InputController.Throw) { DraggableObject.Throw(throwForce); DraggableObject = null; } }
public void AddLetter(DraggableObject letter) { _currentAnswer[_firstFreeSlotId] = letter; for(int i=_firstFreeSlotId; i<_currentAnswer.Length; ++i) { if(_currentAnswer[_firstFreeSlotId] == null) break; _firstFreeSlotId++; } if(HasWon() == true) _onWon(_desiredAnswer); }
void OnCollisionExit(Collision col) { DraggableObject d = col.gameObject.GetComponent <DraggableObject>(); if (col.gameObject == MovementController.instance.backpack) { //TempCharacterController.instance.contacts.Remove(d); MovementController.instance.contacts[this]--; Debug.Log("removing contact, new count: " + MovementController.instance.contacts[this]); } else if (d != null) { contacts[d]--; } }
public void SetUpQuestion(uint num1, uint num2, uint numBlanks) { // Validate input if (num1 < 10 || num1 > 999 || num2 < 10 || num2 > 999 || numBlanks < 1 || numBlanks > 6) { Debug.LogError("Cannot init question box with these values: " + num1 + ", " + num2 + ", " + numBlanks); return; } // Set question text m_QuestionText.text = num1.ToString() + " * " + num2.ToString() + " = ???"; // Initialize the grid of values uint[] draggableValues = m_QuestionBox.Init(num1, num2, numBlanks); // Shuffle the draggable objects array System.Random random = new System.Random(); for (int i = m_DraggableObjects.Length - 1; i > 0; i--) { int randomIndex = random.Next(0, i + 1); DraggableObject temp = m_DraggableObjects[i]; m_DraggableObjects[i] = m_DraggableObjects[randomIndex]; m_DraggableObjects[randomIndex] = temp; } // Set values of each draggable object for (int i = 0; i < m_DraggableObjects.Length; i++) { m_DraggableObjects[i].gameObject.SetActive(true); m_DraggableObjects[i].InitIfNeeded(); if (i < numBlanks) { m_DraggableObjects[i].SetValue(draggableValues[i]); } else { m_DraggableObjects[i].gameObject.SetActive(false); } } // Disable the 'next' button m_NextButton.interactable = false; // Set the current amount of points to be awarded m_CurrentQuestionPoints = SCORE_SCALE; }
private void OnTriggerEnter2D(Collider2D collider) { Ingredient ingredient = collider.GetComponent <Ingredient>(); if (ingredient != null) { AudioManager.instance.PlaySound2D("Dropped in Cauldron"); AddIngredient(ingredient); Splash(); DraggableObject effects = collider.GetComponent <DraggableObject>(); effects.DestroyEffect(); Destroy(ingredient.gameObject); } }
public void RemoveFromSlot(DraggableObject draggableObject) { for(int i=0; i<_slots.Count; ++i) { if(_slots[i].draggableObject == draggableObject) { _slots[i].draggableObject = null; _usedSlotCount--; if(OnTileRemoved != null) OnTileRemoved(draggableObject); break; } } }
private void StartDragging() { Ray mouseWorldRay = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue()); RaycastHit2D hit = Physics2D.GetRayIntersection(mouseWorldRay); if (hit.collider != null) { DraggableObject draggableObject = hit.collider.gameObject.GetComponent <DraggableObject>(); if (draggableObject != null) { draggableObject.StartDragging(); currentDragObject = draggableObject; } } }
void HandleMouse() { if (Input.GetMouseButtonDown(0)) { grabbedObject = MinigameCommon.RaycastFromMouse(typeof(DraggableObject)) as DraggableObject; if (grabbedObject != null) { grabbedObject.InHand = true; } } if (Input.GetMouseButtonUp(0) && grabbedObject != null) { grabbedObject.InHand = false; grabbedObject = null; } }
// Update is called once per frame void Update() { if (RoundManager.instance != null && RoundManager.instance.gameOver) { return; } if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow); RaycastHit hit; Debug.Log("CASTING RAY : " + ray + " on layer " + itemLayerMask); if (Physics.Raycast(ray, out hit, Mathf.Infinity, itemLayerMask)) { Debug.Log("HIT OBJECT : " + hit.collider.gameObject.name); DraggableObject d = hit.collider.gameObject.GetComponentInParent <DraggableObject>(); if (d != null && Vector3.Distance(d.transform.position, MovementController.instance.backpack.transform.position) <= maxReach) { Rigidbody r = d.GetComponent <Rigidbody>(); r.useGravity = true; r.isKinematic = false; d.mouseIsDown = true; curDraggable = d; AudioManager.instance.PlayClick(); lineRenderer.enabled = true; lineRenderer.SetPosition(0, MovementController.instance.backpack.transform.position); lineRenderer.SetPosition(1, d.transform.position); } } } else if (Input.GetMouseButtonUp(0) && curDraggable != null) { AudioManager.instance.PlayRelease(); curDraggable.mouseIsDown = false; curDraggable = null; lineRenderer.enabled = false; } else if (lineRenderer.enabled && curDraggable != null) { lineRenderer.SetPosition(0, MovementController.instance.backpack.transform.position); lineRenderer.SetPosition(1, curDraggable.transform.position); } }
public void AddToNextFreeSlot(DraggableObject draggableObject) { for(int i=0; i<_slots.Count; ++i) { if(_slots[i].draggableObject == null) { _slots[i].draggableObject = draggableObject; _usedSlotCount++; Vector3 newPos = _slots[i].transform.position; newPos.z = -1f; draggableObject.transform.position = newPos; Debug.Log("setting pos: " + draggableObject.character + " " + draggableObject.transform.position.ToString()); if(OnTileAdded != null) OnTileAdded(draggableObject); break; } } }
private DraggableObject CreateNewObject(DraggableObject prefab, string objectName, Vector2 initialPosition) { Vector2 center = new Vector2(RectTransform.sizeDelta.x / 2, RectTransform.sizeDelta.y / 2); var obj = (DraggableObject)Instantiate(prefab, initialPosition, prefab.transform.rotation); obj.Init(Parts.transform, this, objectName); return obj; }