void Start() { MeshCollider meshCollider = transform.GetComponentInChildren<MeshCollider>(); GameObject DamageTarget = Tools.GetChild(gameObject, "DamageTarget", true); DamageTarget.layer = LayerMask.NameToLayer("Interaction"); DamageTarget.tag = "DamageTarget"; TriggerController triggerController = Tools.AddComponent<TriggerController>(DamageTarget); BoxCollider boxCollider = Tools.AddComponent<BoxCollider>(DamageTarget); DamageTarget.transform.localScale = meshCollider.bounds.size; boxCollider.transform.localPosition = new Vector3(0, DamageTarget.transform.localScale.y / 2, 0); boxCollider.isTrigger = true; Rigidbody rigidbody = Tools.GetComponent<Rigidbody>(DamageTarget, true); rigidbody.isKinematic = true; rigidbody.useGravity = false; }
public override void OnTriggerIn(TriggerEvent evt) { TriggerController triggerController = evt.selfTriggerController.GetFirstKeepingTriggerController(); if (triggerController.ITriggerDelegate as RoleController && triggerController.ITriggerDelegate.gameObject.name.IndexOf("Player") >= 0) { State = 1; // fsm.SendEvent("1To1-0"); // fsm.SendEvent("AllTo1"); // if (HasCoroutine("FragileFloorController-breaking") == false) // { // DelayFunc("FragileFloorController-breaking", () => // { // State = 0; // colliderParent.SetActive(false); // }, breakingDelay); // } } }
public override void Interact() { TriggerController selfTriggerController = gameObject.GetChild("InteractiveCube").GetComponent <TriggerController>(); TriggerController otherTriggerController = selfTriggerController.GetFirstKeepingTriggerController(); if (selfTriggerController != null && otherTriggerController != null && otherTriggerController.ITriggerDelegate != null) { GameObject interactObject = otherTriggerController.ITriggerDelegate.GetGameObject(); if (interactObject.tag == "NPC") { RolePromptController rolePromptController = GetComponentInChildren <RolePromptController>(); rolePromptController.killtalk(); OnInteractAction(interactObject); AnimManager.Instance.PrintBubble("[color=#FFFFFF,#000000]fgtdfg[/color]", interactObject); } else if (interactObject.tag == "Ladder") { LadderController ladderController = interactObject.GetComponent <LadderController>(); BoxCollider boxCollider = otherTriggerController.gameObject.GetComponent <BoxCollider>(); Bounds bou = boxCollider.bounds; gameObject.layer = LayerMask.NameToLayer("Default"); if ((interactObject.transform.position.y + bou.center.y + ((bou.size.y / 2) - 1.6f)) < transform.position.y) { switch (ladderController.laddertype) { case laddertype.Left: transform.position = new Vector3(interactObject.transform.position.x + CharacterController.radius, transform.position.y - 1.6f, interactObject.transform.position.z); break; case laddertype.Right: transform.position = new Vector3(interactObject.transform.position.x - CharacterController.radius, transform.position.y - 1.6f, interactObject.transform.position.z); break; case laddertype.Center: transform.position = new Vector3(interactObject.transform.position.x, transform.position.y - 1.6f, interactObject.transform.position.z - 0.1f); break; } } else { switch (ladderController.laddertype) { case laddertype.Left: transform.position = new Vector3(interactObject.transform.position.x + CharacterController.radius, transform.position.y, interactObject.transform.position.z); break; case laddertype.Right: transform.position = new Vector3(interactObject.transform.position.x - CharacterController.radius, transform.position.y, interactObject.transform.position.z); break; case laddertype.Center: transform.position = new Vector3(interactObject.transform.position.x, transform.position.y, interactObject.transform.position.z - 0.1f); break; } } if (animatorParams.ContainsKey("ladder_type")) { _animator.SetInteger("ladder_type", (int)ladderController.laddertype); } if (animatorParams.ContainsKey("start_climb_ladder")) { _animator.SetBool("start_climb_ladder", true); } } else if (interactObject.GetComponent <IInteractable>() != null) { IInteractable interactable = interactObject.GetComponent <IInteractable>(); if (interactable.CanInteract()) { interactable.Interact(); } } else if (interactObject.GetComponent <PortalController>()) { PortalController portalController = interactObject.GetComponent <PortalController>(); if (portalController) { this.OpenPortal(portalController); } } else if (interactObject.GetComponent <FenceDoorController>()) { FenceDoorController fenceDoorController = interactObject.GetComponent <FenceDoorController>(); if (fenceDoorController) { fenceDoorController.OpenPortal(); } } else { if (interactObject != null && interactObject.Equals(null) == false) { DropItemController dropItemController = interactObject.GetComponent <DropItemController>(); if (dropItemController != null) { var itemData = ItemManager.Instance.getItemDataById <ItemData>(dropItemController.ItemId); GameManager.Instance.PickupTips("Textures/Icon/" + itemData.icon, itemData.name, itemData.count.ToString()); switch (itemData.itemType) { case ItemType.Consumable: Debug.Log("捡到消耗品 id = " + itemData.id); Destroy(interactObject); ConsumableData consumableData = ItemManager.Instance.getItemDataById <ConsumableData>(itemData.id); if (consumableData != null) { switch (consumableData.consumableUseType) { case ConsumableUseType.deposit: RoleData.AddConsumableItem(itemData.id, itemData.count); PickupConsumable(); break; case ConsumableUseType.ImmediateUse: BuffController.AddBuff(consumableData.buffId); break; } } break; case ItemType.Other: RoleData.OtherItemList.Add(itemData); dropItemController.RemoveSelf(); break; case ItemType.Equip: var weaponData = ItemManager.Instance.getItemDataById <WeaponData>(dropItemController.ItemId); if (weaponData != null) { this.JuageEquipPossessType(weaponData); } else { var equipData = ItemManager.Instance.getItemDataById <EquipData>(itemData.id); RoleData.EquipData.UseEquip(equipData, interactObject.transform.localPosition + new Vector3(Random.Range(-0.5f, 0.5f), Random.Range(1.0f, 1.5f), Random.Range(-0.5f, 0.5f))); } Destroy(interactObject); break; } } else { var interactive = interactObject.GetComponent <ITriggerDelegate>(); if (interactive != null) { Event evt = new Event(); evt.Type = EventType.Interact; evt.Data = GetGameObject(); interactive.OnEvent(evt); } } } } } }
public void ClimbLadder(float jocky) { TriggerController selfTriggerController = GetComponentInChildren <TriggerController>(); TriggerController otherTriggerController = selfTriggerController.GetFirstKeepingTriggerController(); if (selfTriggerController != null && otherTriggerController != null && otherTriggerController.ITriggerDelegate != null) { GameObject interactObject = otherTriggerController.ITriggerDelegate.GetGameObject(); LadderController ladderController = interactObject.GetComponent <LadderController>(); if (ladderController != null) { BoxCollider boxCollider = otherTriggerController.gameObject.GetComponent <BoxCollider>(); Bounds bou = boxCollider.bounds; if (jocky < 0) { // 上梯子前先转向 add by TangJian 2019/3/23 11:13 SetDirectionInt(ladderController.transform.localScale.x > 0 ? -1 : 1); if ((bou.center.y + ((bou.size.y / 2) - 2f)) < transform.position.y) { if (animatorParams.ContainsKey("ladder_type")) { _animator.SetInteger("ladder_type", (int)ladderController.laddertype); } if (animatorParams.ContainsKey("start_climb_ladder")) { _animator.SetBool("start_climb_ladder", true); } canClimbLadder = false; //gameObject.layer = LayerMask.NameToLayer("Default"); switch (ladderController.laddertype) { case laddertype.Left: transform.position = new Vector3(interactObject.transform.position.x, transform.position.y - 1.6f, interactObject.transform.position.z); break; case laddertype.Right: transform.position = new Vector3(interactObject.transform.position.x, transform.position.y - 1.6f, interactObject.transform.position.z); break; case laddertype.Center: transform.position = new Vector3(interactObject.transform.position.x, transform.position.y - 1.6f, interactObject.transform.position.z - 0.1f); break; } //sdas = true; } } else if (jocky > 0) { // 上梯子前先转向 add by TangJian 2019/3/23 11:13 SetDirectionInt(ladderController.transform.localScale.x > 0 ? -1 : 1); if ((bou.center.y + ((bou.size.y / 2) - 2f)) >= transform.position.y) { if (animatorParams.ContainsKey("ladder_type")) { _animator.SetInteger("ladder_type", (int)ladderController.laddertype); } if (animatorParams.ContainsKey("start_climb_ladder")) { _animator.SetBool("start_climb_ladder", true); } canClimbLadder = false; //gameObject.layer = LayerMask.NameToLayer("Default"); switch (ladderController.laddertype) { case laddertype.Left: transform.position = new Vector3(interactObject.transform.position.x, transform.position.y, interactObject.transform.position.z); break; case laddertype.Right: transform.position = new Vector3(interactObject.transform.position.x, transform.position.y, interactObject.transform.position.z); break; case laddertype.Center: transform.position = new Vector3(interactObject.transform.position.x, transform.position.y, interactObject.transform.position.z - 0.1f); break; } //sdas = true; } } //if (sdas) //{ // if (animatorParams.ContainsKey("ladder_type")) // _animator.SetInteger("ladder_type", (int)ladderController.laddertype); // if (animatorParams.ContainsKey("start_climb_ladder")) // _animator.SetBool("start_climb_ladder", true); // canClimbLadder = false; //} } } }
// 进入触发器 add by TangJian 2017/07/27 17:52:41 public void OnTriggerEnter(Collider other) { if (triggerMode == TriggerMode.Default) { if (isReady == false) { return; } if (TagTriggerManager.Instance.FindTirggerBool(this.gameObject.tag, other.gameObject.tag)) { //Debug.Log("OnTriggerEnter"); TriggerController otherTriggerController = other.gameObject.GetComponent <TriggerController>(); // 记录触发器 add by TangJian 2018/12/2 15:41 TriggerManager.Instance.AddRecord(this, otherTriggerController); // 获取双方代理 add by TangJian 2019/3/19 18:21 ITriggerDelegate selfITriggerDelegate = ITriggerDelegate; ITriggerDelegate otherITriggerDelegate = otherTriggerController.ITriggerDelegate; // 获得碰撞位置 add by TangJian 2019/3/19 18:21 Bounds inbounds = other.bounds.IntersectsExtend(triggerCollider.bounds); Vector3 collidePoint = inbounds.center; // 组织触发器事件 add by TangJian 2019/3/19 18:22 TriggerEvent triggerEvent = new TriggerEvent(); triggerEvent.type = TriggerEventType.NewTrigger; triggerEvent.colider = other; triggerEvent.colidePoint = collidePoint; triggerEvent.selfTriggerController = this; triggerEvent.otherTriggerController = otherTriggerController; // if (other.gameObject.tag == gameObject.tag&& other.gameObject.GetComponentInParent<RoleController>().RoleData.AttrData.isCrash) // { // gameObject.GetComponent<Rigidbody>().AddForce(collidePoint-gameObject.GetComponent<Collider>().bounds.center); // } if (selfITriggerDelegate != null) { selfITriggerDelegate.OnTriggerIn(triggerEvent); } if (OnTriggerInEvent != null) { OnTriggerInEvent(triggerEvent); } } } else if (triggerMode == TriggerMode.Transmit) { TriggerEvent triggerEvent = new TriggerEvent(); triggerEvent.colider = other; if (ITriggerDelegate != null) { ITriggerDelegate.OnTriggerIn(triggerEvent); if (OnTriggerInEvent != null) { OnTriggerInEvent(triggerEvent); } } } }
void Prompt() { selfTriggerController = parent.GetComponentInChildren <TriggerController>(); valueMonitorPool.Clear(); valueMonitorPool.AddMonitor(() => { otherTriggerController = selfTriggerController.GetFirstKeepingTriggerController(); if (otherTriggerController != null) { DoorController doorController = otherTriggerController.ITriggerDelegate as DoorController; NpcController npcController = otherTriggerController.ITriggerDelegate as NpcController; TreasureBoxController treasureBox = otherTriggerController.ITriggerDelegate as TreasureBoxController; JoystickController joystickController = otherTriggerController.ITriggerDelegate as JoystickController; DropItemController dropItemController = otherTriggerController.ITriggerDelegate as DropItemController; MagicPortalController magicPortalController = otherTriggerController.ITriggerDelegate as MagicPortalController; if (doorController != null) { if (doorController.IsClosed()) { return(0); } else { return(1); } } else if (npcController != null) { return(2); } else if (treasureBox != null) { if (treasureBox.IsOpened()) { return(3); } else { return(4); } } else if (joystickController != null) { return(5); } else if (dropItemController != null) { return(6); } else if (magicPortalController != null) { return(7); } } return(-1); }, (int from, int to) => { if (otherTriggerController != null) { GameObject interactObject = otherTriggerController.ITriggerDelegate.GetGameObject(); if (interactObject != null) { DoorController doorController = interactObject.GetComponent <DoorController>(); NpcController npcController = interactObject.GetComponent <NpcController>(); TreasureBoxController treasureBox = interactObject.GetComponent <TreasureBoxController>(); JoystickController joystickController = interactObject.GetComponent <JoystickController>(); DropItemController dropItemController = interactObject.GetComponent <DropItemController>(); MagicPortalController magicPortalController = interactObject.GetComponent <MagicPortalController>(); if (doorController != null) { if (doorController.IsClosed()) { ShowPrompt("ui://UI/key"); } else { HidePrompt(); } } else if (npcController != null) { ShowPrompt("ui://UI/talkmark"); } else if (treasureBox != null) { if (treasureBox.IsOpened()) { HidePrompt(); } else { ShowPrompt("ui://UI/Exclamatory mark"); } } else if (joystickController) { ShowPrompt("ui://UI/key"); } else if (dropItemController != null) { if (dropItemController.ItemData.pickUpMethod == PickUpMethod.Interact) { ShowPrompt("ui://UI/Exclamatory mark"); } } else if (magicPortalController != null) { ShowPrompt("ui://UI/Exclamatory mark"); } else { HidePrompt(); } } } else { HidePrompt(); } }); }
public static void RemoveRecord(this TriggerManager target, TriggerController selfTriggerController, TriggerController otherTriggerController) { List <TriggerController> gameObjects; if (target.triggerControllerDic.TryGetValue(selfTriggerController, out gameObjects)) { gameObjects.Remove(otherTriggerController); } else { Debug.Log("没有记录的触发器: name = " + selfTriggerController.name); } }
public static void AddRecord(this TriggerManager target, TriggerController selfTriggerController, TriggerController otherTriggerController) { List <TriggerController> gameObjects; if (target.triggerControllerDic.TryGetValue(selfTriggerController, out gameObjects)) { gameObjects.Add(otherTriggerController); } else { target.triggerControllerDic.Add(selfTriggerController, new List <TriggerController>() { otherTriggerController }); } }
public static List <TriggerController> GetRecordList(this TriggerManager target, TriggerController triggerController) { List <TriggerController> recordList; if (target.triggerControllerDic.TryGetValue(triggerController, out recordList)) { return(recordList); } return(null); }
public static void Add(this TriggerManager target, TriggerController triggerController) { target.triggerControllerDic.Add(triggerController, new List <TriggerController>() { }); }
private void showdropitem() { valueMonitorPool.AddMonitor((Func <TriggerController>)(() => { GameObject player = GameObject.Find("Player1"); TriggerController selfTriggerController = player.GetComponentInChildren <TriggerController>(); otherTriggerController = selfTriggerController.GetFirstKeepingTriggerController(); return(otherTriggerController); }), (TriggerController from, TriggerController to) => { if (Typedown) { if (otherTriggerController != null) { GameObject interactObject = otherTriggerController.ITriggerDelegate.GetGameObject(); if (interactObject != null) { DropItemController dropItemController = interactObject.GetComponent <DropItemController>(); DoorController doorController = interactObject.GetComponent <DoorController>(); if (dropItemController != null) { var itemData = ItemManager.Instance.getItemDataById <ItemData>(dropItemController.ItemId); if (itemData != null) { GameObject player = GameObject.Find("Player1"); RoleController roleController = player.GetComponent <RoleController>(); if (itemData is WeaponData) { AttributeShow <WeaponData>(itemData as EquipData); ShowRoleInfodown(); } else if (itemData is ArmorData) { AttributeShow <ArmorData>(itemData as EquipData); ShowRoleInfodown(); } else if (itemData is DecorationData)//现阶段物品掉落使用 { DecorationData RoleDecorationData; AttributeShow <DecorationData>(itemData as EquipData); ShowRoleInfodown(); } else { HideRoleInfodown(); } } } else if (doorController != null) { Debug.Log("door"); } } } else { HideRoleInfodown(); } } }); }