/// <summary> /// Detect if there is any step /// </summary> /// <returns> /// Return the detected step Height, if not return zero ///</returns> private float StepDetection() { // temp hit information RaycastHit hit; Vector3 tempPostion = this.targetSphereCollider.center; var distance = 0f; // Check if there is any obstacle in front of feet if (Physics.Raycast(this.transform.position, this.transform.forward, out hit, stepSearchDistance, collisionMask)) { // if is ground in front of player // check if the step is bigger than max size // generate the position for the vertical test // position calculated based on detected distance tempPostion += this.transform.forward * Vector3.Distance(this.transform.position, hit.point); InformationPanel.DebugConsoleInput("In front step distance"); // Evaluate if the step is in range for steping up if (Physics.Raycast(tempPostion, Vector3.down, out hit, this.targetSphereCollider.height * 0.5f) && (distance = Vector3.Distance(hit.point, this.transform.position)) <= maxStepSize) {// if the vertical ray hit a objecto based on the distance from the horizontal one // and the distance from the ground pos to the vertical hit is less than step size, return the step position InformationPanel.DebugConsoleInput("valid step height"); Debug.DrawLine(this.transform.position, hit.point, Color.yellow); return(distance); } } // return 0 if not detected return(0f); }
///<Summary> /// Init Singleton instance ///</Summary> public void InitSingleton() { // Set as enable this.IsEnable = true; // calculate the canvas proportion this.inputCanvasRect = this.GetComponent <RectTransform>(); this.SafeZoneFixedToCanvas = AplicationFuncs.SafeToSafeCanvas(canvasRect: inputCanvasRect.rect); Debug.Log(SafeZoneFixedToCanvas); // calculate the area for joyDetection JoyDetectionArea = new Rect(SafeZoneFixedToCanvas.xMin, SafeZoneFixedToCanvas.yMin, SafeZoneFixedToCanvas.width * ScreenPercentDetect, SafeZoneFixedToCanvas.height); // get the joyStick REffs, knowing that has a child that is a joyBack and a child of that been the knob // back part of the joy this.joyBackImg = this.transform.GetChild(0).GetComponent <RawImage>(); this.joyBackRect = this.joyBackImg.GetComponent <RectTransform>(); // knoob part of the joy this.JoyKnobImg = this.joyBackImg.transform.GetChild(0).GetComponent <RawImage>(); this.joyKnobRect = this.JoyKnobImg.GetComponent <RectTransform>(); // Calculate the maximus radius for the joy based on size this.JoyMaxRadius = this.joyBackRect.rect.width * 0.5f - this.joyKnobRect.rect.width * 0.5f; // calculate the default related position, validating the values making joy visivel on safe area all the time this.RelatedDefaultPosition = new Vector2( JoyDetectionArea.position.x + ((JoyDetectionArea.width * positionPercent.x) < (joyBackRect.rect.width / 2f) ? (joyBackRect.rect.width / 2f) : (JoyDetectionArea.width * positionPercent.x)), JoyDetectionArea.position.y + ((JoyDetectionArea.height * positionPercent.y) < (joyBackRect.rect.height / 2f) ? (joyBackRect.rect.height / 2f) : (JoyDetectionArea.height * positionPercent.y))); // get refference to the jump button components this.jumpBtnImg = this.transform.GetChild(1).GetComponent <Image>(); this.jumpBtn = this.jumpBtnImg.GetComponent <Button>(); this.jumpBtnRct = this.jumpBtnImg.GetComponent <RectTransform>(); // calculate the jump button position based on margin and placed in safe area this.jumpBtnRct.anchoredPosition = new Vector2( SafeZoneFixedToCanvas.xMax - (SafeZoneFixedToCanvas.width * JumpPercentMargin.x + jumpBtnRct.rect.width * 0.5f), SafeZoneFixedToCanvas.yMin + SafeZoneFixedToCanvas.height * JumpPercentMargin.y + jumpBtnRct.rect.height * 0.5f); // Set joy to invisible IsJoyStickVisible = false; // Debug thats ready InformationPanel.DebugConsoleInput("Input Manager valid and Online!"); }
// On Awake check the singleton values private void Awake() { // check if the singleton exists or not if (instance == null) { instance = this; } // If exists and is different from this, destroy else if (InputManager.Instance != this) { Destroy(this); } // Display information InformationPanel.DebugConsoleInput("Input Manager Singleton validation!"); }
/// <summary> /// initial setup of this controller /// </summary> private void InitController() { // TO REMOVE - - - - - Application.targetFrameRate = 140; QualitySettings.vSyncCount = 0; // Get the reff for the physics controller physicsCharacter = GetComponentInChildren <PhysicsCharacterController>(); // get the ref of the target animator playerTargetAnimator = GetComponentInChildren <Animator>(); // Validate the reff // if fails to find the physics controller if (!physicsCharacter || !playerTargetAnimator) { // Close the aplication AplicationFuncs.CloseApp(); return; } // Debug information and initialize the parts InformationPanel.DebugConsoleInput("Physics System connected!"); physicsCharacter.InitParts(); // Define the maximum velocity physicsCharacter.SetCharacterMaxSpeed(characterMaxVelocity); // define the kill speed physicsCharacter.SetCharacterKillVelocity(this.killVelocity); // Stunted - - - - - // regist the for the stunted event physicsCharacter.stuntedDelegate += StuntedCallback; // init vars stunted = false; // Grab controller - - - - - // get ref to controller this.playerGrabController = this.GetComponentInChildren <GrabController>(); // Init with enable tag this.playerGrabController.Init(controllerState: true, lHand: ref LeftHandGO, rHand: ref RightHandGO); // Regists for jump delegate InputManager.Instance.jumpDelegate += () => { physicsCharacter.Jump(this.JumpValue); }; // regist the controller to the action event InputManager.Instance.actionDelegate += playerGrabController.ActionCallback; }
/// <summary> /// Inicia a consola de debug on screen /// </summary> private void InitConsole(TMP_Text panel) { // inicia a queue de linhjas debug_lines = new List <string>(); // limpa todo o texto presente na consola, caso exista referencia if (!panel) { Debug.LogError("debug output not setted"); return; } // atribui ao painel definido debug_field = panel; debug_field.text = String.Empty; // aprenseta que o debug foi iniciado InformationPanel.DebugConsoleInput("Started debug info"); }
/// <summary> /// Callback that is called when the player presses the action button /// </summary> public void ActionCallback() { // only runs if the controller is enable if (!isEnable) { return; } // if is enable and has a targetobject, check if is grabbing if (leftHandJoint || rightHandJoint) { // remove the joint component Destroy(leftHandJoint); Destroy(rightHandJoint); // if any hand as a object attatch, realease leftHandJoint = null; leftHandJoint = null; // enable the action trigger actionTrigger.enabled = true; //reset the rigidbody inTriggerArea.GetComponent <Rigidbody>().isKinematic = false; inTriggerArea.GetComponent <Rigidbody>().useGravity = true; // remove object from parent inTriggerArea.transform.parent = null; // reset the observed obj inTriggerArea = null; // Debug to information pannel InformationPanel.DebugConsoleInput("Realeased Object"); } // if there is notting grabbed and exist a target object else if (!leftHandJoint && !rightHandJoint && inTriggerArea) { // create joints on target obj to move hads to obj leftHandJoint = inTriggerArea.AddComponent <ConfigurableJoint>(); rightHandJoint = inTriggerArea.AddComponent <ConfigurableJoint>(); // Commun setting var tempJointDrive = new JointDrive(); tempJointDrive.positionSpring = 300f; tempJointDrive.maximumForce = Mathf.Infinity; // set Up // Left hand joint leftHandJoint.connectedBody = leftHandGO.GetComponent <Rigidbody>(); leftHandJoint.autoConfigureConnectedAnchor = false; leftHandJoint.connectedAnchor = Vector3.zero; leftHandJoint.xDrive = leftHandJoint.yDrive = leftHandJoint.zDrive = tempJointDrive; leftHandJoint.connectedMassScale = 500f; // right hand joint rightHandJoint.connectedBody = rightHandGO.GetComponent <Rigidbody>(); rightHandJoint.autoConfigureConnectedAnchor = false; rightHandJoint.connectedAnchor = Vector3.zero; rightHandJoint.xDrive = rightHandJoint.yDrive = rightHandJoint.zDrive = tempJointDrive; rightHandJoint.connectedMassScale = 500f; // obj to player // set grabbed obj to chilled inTriggerArea.transform.SetParent(this.transform); inTriggerArea.transform.localPosition += Vector3.up; inTriggerArea.GetComponent <Rigidbody>().isKinematic = true; inTriggerArea.GetComponent <Rigidbody>().useGravity = false; // deactivate the action trigger actionTrigger.enabled = false; // debug to information pannet InformationPanel.DebugConsoleInput("Oject grabbed!"); } }