void Update() { if (CanLockType()) { if (!isLocked) { useType = Type_Use.Normal; if (interactType == Type_Interact.Mouse && Joint) { Joint.useLimits = true; GetComponent <Rigidbody>().freezeRotation = false; } } } if (dynamicType == Type_Dynamic.Door) { Angle = transform.eulerAngles.y; if (GetLockStatus()) { if (useJammedPlanks) { CheckJammed(); if (Planks.Count < 1) { isLocked = false; } } } if (interactType == Type_Interact.Mouse) { Joint.useMotor = isHolding; if (DebugAngle) { if (Joint.limits.min < -1) { Debug.Log("Angle: " + Angle + " , Door Close: " + (defaultAngle - 0.5f)); } else { Debug.Log("Angle: " + Angle + " , Door Close: " + (defaultAngle + 0.5)); } } if (Angle > 1f) { if (Joint.limits.min < -1) { if (!load) { if (Angle <= (defaultAngle - 2f) && !isOpened) { if (Open) { AudioSource.PlayClipAtPoint(Open, transform.position); } isOpened = true; } if (Angle > minCloseAngle && Angle < maxCloseAngle && Angle >= (defaultAngle - 0.5f) && isOpened) { if (Close) { AudioSource.PlayClipAtPoint(Close, transform.position); } isOpened = false; } } } else { if (Angle >= (defaultAngle + 0.5f) && !isOpened) { if (Open) { AudioSource.PlayClipAtPoint(Open, transform.position); } isOpened = true; } if (Angle <= (defaultAngle + 0.2f) && isOpened) { if (Close) { AudioSource.PlayClipAtPoint(Close, transform.position); } isOpened = false; } } } } } else if (dynamicType == Type_Dynamic.Lever) { if (reverseMove) { Angle = transform.localEulerAngles.x; } else { Angle = transform.localEulerAngles.y; } float minAngle = Angle - 2f; float maxAngle = Angle + 2f; if (interactType == Type_Interact.Mouse) { if (DebugAngle) { Debug.Log("Angle: " + Mathf.Round(Angle) + " Min: " + minAngle + " Max: " + maxAngle); } if (lockOnUp) { if (Hold) { GetComponent <Rigidbody>().isKinematic = true; GetComponent <Rigidbody>().useGravity = false; } else { GetComponent <Rigidbody>().isKinematic = false; GetComponent <Rigidbody>().useGravity = true; } } else { if (isHolding) { GetComponent <Rigidbody>().isKinematic = false; GetComponent <Rigidbody>().useGravity = false; } if (!isHolding && Hold) { GetComponent <Rigidbody>().isKinematic = true; GetComponent <Rigidbody>().useGravity = false; } else if (!Hold) { GetComponent <Rigidbody>().isKinematic = false; GetComponent <Rigidbody>().useGravity = true; } } if (!DebugAngle) { if (Angle > minAngle && Angle < maxAngle && Angle >= stopAngle) { InteractEvent?.Invoke(); if (!isPlayed && !loadSound && LeverUpSound) { Debug.Log("Lever Up: " + transform.parent.parent.gameObject.name); AudioSource.PlayClipAtPoint(LeverUpSound, transform.position, 1f); isPlayed = true; } invokeUp = true; isInvoked = true; isUp = true; Hold = true; } else { DisabledEvent?.Invoke(); invokeUp = false; isInvoked = true; isUp = false; isPlayed = false; Hold = false; } } } else { if (isUp && !isInvoked && !isOpened) { StartCoroutine(WaitEventInvoke()); isOpened = true; } } } else if (dynamicType == Type_Dynamic.Valve) { if (rotateValue >= 1f && !valveInvoked) { InteractEvent?.Invoke(); valveInvoked = true; } else if (turnSound) { StartCoroutine(ValveSounds()); turnSound = false; } } else if (dynamicType == Type_Dynamic.MovableInteract) { if (!isInvoked) { if (moveWithX) { if (minMaxMove.x < minMaxMove.y) { if (transform.localPosition.x <= InteractPos) { InteractEvent?.Invoke(); isInvoked = true; } } else if (minMaxMove.y > minMaxMove.x) { if (transform.localPosition.x >= InteractPos) { InteractEvent?.Invoke(); isInvoked = true; } } } else { if (minMaxMove.x < minMaxMove.y) { if (transform.localPosition.z >= InteractPos) { InteractEvent?.Invoke(); isInvoked = true; } } else if (minMaxMove.y > minMaxMove.x) { if (transform.localPosition.z <= InteractPos) { InteractEvent?.Invoke(); isInvoked = true; } } } } } if (!isHolding) { turnSound = true; } }
public void ParseUseType(int value) { useType = (Type_Use)value; }
void Awake() { if (dynamicType == Type_Dynamic.Door) { if (interactType == Type_Interact.Mouse) { if (GetComponent <HingeJoint>()) { Joint = GetComponent <HingeJoint>(); } else { Debug.LogError(transform.parent.gameObject.name + " requires Hinge Joint Component!"); return; } } if (GetLockStatus()) { if (interactType == Type_Interact.Mouse) { GetComponent <Rigidbody>().freezeRotation = true; Joint.useLimits = false; } isLocked = true; } else if (useType == Type_Use.Normal) { if (interactType == Type_Interact.Mouse) { GetComponent <Rigidbody>().freezeRotation = false; Joint.useLimits = true; } isLocked = false; } } else if (dynamicType == Type_Dynamic.Drawer) { IgnoreColliders.Add(PlayerController.Instance.gameObject.GetComponent <Collider>()); isLocked = useType != Type_Use.Normal; } else if (dynamicType == Type_Dynamic.Lever) { isLocked = false; } else if (dynamicType == Type_Dynamic.MovableInteract) { useType = Type_Use.Normal; interactType = Type_Interact.Mouse; isLocked = false; } if (IgnoreColliders.Count > 0) { for (int i = 0; i < IgnoreColliders.Count; i++) { Physics.IgnoreCollision(GetComponent <Collider>(), IgnoreColliders[i]); } } defaultAngle = transform.eulerAngles.y; minCloseAngle = defaultAngle - 10f; maxCloseAngle = defaultAngle + 10f; inventory = Inventory.Instance; }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.PropertyField(sp_dynamicType); Type_Dynamic dynamic = (Type_Dynamic)sp_dynamicType.enumValueIndex; Type_Use useType = (Type_Use)sp_useType.enumValueIndex; Type_Interact int_type = (Type_Interact)sp_interactType.enumValueIndex; Type_Key keyType = (Type_Key)sp_keyType.enumValueIndex; switch (dynamic) { case Type_Dynamic.Door: EditorGUILayout.PropertyField(sp_useType, new GUIContent("Use Type")); EditorGUILayout.PropertyField(sp_interactType, new GUIContent("Interact Type")); if (useType == Type_Use.Locked) { EditorGUILayout.PropertyField(sp_keyType, new GUIContent("Key Type")); if (keyType == Type_Key.Inventory) { EditorGUILayout.PropertyField(sp_keyID, new GUIContent("Inventory KeyID:")); } } EditorGUILayout.Space(); EditorGUILayout.PropertyField(sp_IgnoreColliders, new GUIContent("Ignore Colliders"), true); EditorGUILayout.PropertyField(sp_customText, new GUIContent("Custom Locked Text")); if (useType == Type_Use.Jammed) { EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Jammed Door Planks", EditorStyles.boldLabel); EditorGUILayout.PropertyField(sp_useJammedPlanks, new GUIContent("Use Planks")); EditorGUILayout.PropertyField(sp_Planks, new GUIContent("Planks"), true); } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Animation", EditorStyles.boldLabel); EditorGUILayout.PropertyField(sp_Animation, new GUIContent("Animation Object")); if (int_type == Type_Interact.Animation) { EditorGUILayout.PropertyField(sp_useAnim, new GUIContent("Open Anim")); EditorGUILayout.PropertyField(sp_backUseAnim, new GUIContent("Close Anim")); } EditorGUILayout.PropertyField(sp_knobAnim, new GUIContent("Knob Animation")); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Door Properties", EditorStyles.boldLabel); EditorGUILayout.PropertyField(sp_Open, new GUIContent("Open Sound")); EditorGUILayout.PropertyField(sp_Close, new GUIContent("Close Sound")); EditorGUILayout.PropertyField(sp_UnlockSound, new GUIContent("Unlock Sound")); EditorGUILayout.PropertyField(sp_LockedTry, new GUIContent("Locked Try Sound")); EditorGUILayout.PropertyField(sp_Volume, new GUIContent("Sound Volume")); if (int_type == Type_Interact.Mouse) { EditorGUILayout.Space(); EditorGUILayout.PropertyField(sp_useSR, new GUIContent("Use Start Rotation")); if (sp_useSR.boolValue) { EditorGUILayout.PropertyField(sp_startRot, new GUIContent("Starting Rotation")); } EditorGUILayout.PropertyField(sp_DebugAngle, new GUIContent("Debug Door Angle")); } break; case Type_Dynamic.Drawer: EditorGUILayout.PropertyField(sp_useType, new GUIContent("Use Type")); EditorGUILayout.PropertyField(sp_interactType, new GUIContent("Interact Type")); if (useType == Type_Use.Locked) { EditorGUILayout.PropertyField(sp_keyType, new GUIContent("Key Type")); if (keyType == Type_Key.Inventory) { EditorGUILayout.PropertyField(sp_keyID, new GUIContent("Inventory KeyID:")); } } EditorGUILayout.Space(); EditorGUILayout.PropertyField(sp_IgnoreColliders, new GUIContent("Ignore Colliders"), true); EditorGUILayout.PropertyField(sp_customText, new GUIContent("Custom Locked Text")); if (int_type == Type_Interact.Animation) { EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Animation", EditorStyles.boldLabel); EditorGUILayout.PropertyField(sp_Animation, new GUIContent("Animation Object")); EditorGUILayout.PropertyField(sp_useAnim, new GUIContent("Open Anim")); EditorGUILayout.PropertyField(sp_backUseAnim, new GUIContent("Close Anim")); } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Drawer Properties", EditorStyles.boldLabel); if (int_type == Type_Interact.Mouse) { EditorGUILayout.PropertyField(sp_minMaxMove, new GUIContent("Min Max Move")); EditorGUILayout.PropertyField(sp_moveWithX, new GUIContent("Move With X")); EditorGUILayout.PropertyField(sp_reverseMove, new GUIContent("Reverse Move")); EditorGUILayout.PropertyField(sp_UnlockSound, new GUIContent("Unlock Sound")); EditorGUILayout.PropertyField(sp_LockedTry, new GUIContent("Locked Try Sound")); } else { EditorGUILayout.PropertyField(sp_Open, new GUIContent("Open Sound")); EditorGUILayout.PropertyField(sp_Close, new GUIContent("Close Sound")); EditorGUILayout.PropertyField(sp_UnlockSound, new GUIContent("Unlock Sound")); EditorGUILayout.PropertyField(sp_LockedTry, new GUIContent("Locked Try Sound")); } EditorGUILayout.PropertyField(sp_Volume, new GUIContent("Sound Volume")); break; case Type_Dynamic.Lever: EditorGUILayout.PropertyField(sp_interactType, new GUIContent("Interact Type")); EditorGUILayout.Space(); EditorGUILayout.PropertyField(sp_IgnoreColliders, new GUIContent("Ignore Colliders"), true); if (int_type == Type_Interact.Animation) { EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Animation", EditorStyles.boldLabel); EditorGUILayout.PropertyField(sp_Animation, new GUIContent("Animation Object")); EditorGUILayout.PropertyField(sp_useAnim, new GUIContent("SwitchUp Anim")); EditorGUILayout.PropertyField(sp_backUseAnim, new GUIContent("SwitchDown Anim")); } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Lever Properties", EditorStyles.boldLabel); EditorGUILayout.PropertyField(sp_InteractEvent, new GUIContent("Interact Event")); EditorGUILayout.PropertyField(sp_DisabledEvent, new GUIContent("Disabled Event")); EditorGUILayout.PropertyField(sp_LeverUpSound, new GUIContent("Lever Up Sound")); EditorGUILayout.PropertyField(sp_lockOnUp, new GUIContent("Up Lock")); EditorGUILayout.PropertyField(sp_reverseMove, new GUIContent("Reverse Rotation")); if (int_type == Type_Interact.Mouse) { EditorGUILayout.PropertyField(sp_stopAngle, new GUIContent("Lever Stop Angle")); EditorGUILayout.PropertyField(sp_DebugAngle, new GUIContent("Debug Lever Angle")); } EditorGUILayout.PropertyField(sp_Volume, new GUIContent("Sound Volume")); break; case Type_Dynamic.Valve: EditorGUILayout.PropertyField(sp_IgnoreColliders, new GUIContent("Ignore Colliders"), true); EditorGUILayout.Space(); EditorGUILayout.PropertyField(sp_InteractEvent, new GUIContent("Interact Event")); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Valve Properties", EditorStyles.boldLabel); EditorGUILayout.PropertyField(sp_valveTurnSounds, new GUIContent("Turn Sounds"), true); EditorGUILayout.PropertyField(sp_Volume, new GUIContent("Turn Volume")); EditorGUILayout.PropertyField(sp_valveSoundAfter, new GUIContent("Turn Sound After")); EditorGUILayout.PropertyField(sp_valveTurnSpeed, new GUIContent("Turn Speed")); EditorGUILayout.PropertyField(sp_valveTurnTime, new GUIContent("Turn Time")); break; case Type_Dynamic.MovableInteract: EditorGUILayout.PropertyField(sp_IgnoreColliders, new GUIContent("Ignore Colliders"), true); EditorGUILayout.Space(); EditorGUILayout.PropertyField(sp_InteractEvent, new GUIContent("Interact Event")); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Movable Interact Properties", EditorStyles.boldLabel); EditorGUILayout.PropertyField(sp_minMaxMove, new GUIContent("Min Max Move")); EditorGUILayout.PropertyField(sp_InteractPos, new GUIContent("Interact Position")); EditorGUILayout.PropertyField(sp_moveWithX, new GUIContent("Move With X")); EditorGUILayout.PropertyField(sp_reverseMove, new GUIContent("Reverse Move")); break; } serializedObject.ApplyModifiedProperties(); }