Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        bool clickDetected = false;
        Vector3 touchPosition;

        // Detect click and calculate touch position
        if (isTouchDevice) {
            clickDetected = (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began);
            touchPosition = Input.GetTouch(0).position;
        } else {
            clickDetected = (Input.GetMouseButtonDown(0));
            touchPosition = Input.mousePosition;
        }
        // Detect clicks
        if ( clickDetected ) {
            // Check if the GameObject is clicked by casting a
            // Ray from the main camera to the touched position
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit = new RaycastHit();
            // Cast a ray of distance 100, and check if this
            // collider is hit
            if ( collider.Raycast(ray, out hit, 100.0f) ) {
                // Log a debug message
                Debug.Log ( "Moving the target" );
                // Move the target forward
                transform.Translate (Vector3.forward * speed);
                // Rotate the target along the y-axis
                transform.Rotate(Vector3.up * rotateSpeed);
            } else {
                // Clear the debug message
                Debug.Log ("");
            }
        }
    }
Exemplo n.º 2
0
 public static ArkCrossEngine.RaycastHit RayCastHitFromUnity(CrossEngineImpl.RaycastHit hit)
 {
     ArkCrossEngine.RaycastHit retHit = new ArkCrossEngine.RaycastHit();
     retHit.normal = Vec3FromUnity(hit.normal);
     retHit.point  = Vec3FromUnity(hit.point);
     return(retHit);
 }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        // if the player presses down spacebar, then...
        if ( Input.GetKeyDown( KeyCode.Space ) ) {

            // go through the entire list of fish, and for each fish, set that fish's destination to 0, 0, 0
            foreach ( Fish currentFish in fishList ) {
                currentFish.destination = Vector3.zero;
            }

        }

        // constructing initial ray struct
        Ray ray = Camera.main.ScreenPointToRay( Input.mousePosition );
        RaycastHit rayHit = new RaycastHit(); // reserving space in memory for this

        // do NOT use "Collider.Raycast", which only casts against that collider
        if ( Physics.Raycast( ray, out rayHit, 100000f ) ) {
            Vector3 newDestination = rayHit.point;

            // go through the entire list called "fishList", and for each fish, it sets destination
            foreach ( Fish currentFish in fishList ) {
                currentFish.destination = newDestination;
            }
        }
    }
Exemplo n.º 4
0
    void FixedUpdate()
    {
        //		foreach (GameObject, mouseObject in GameManager.allTheMice, GameManager.alltheMice) {
        for (int i=0; i<GameManager.allTheMice.Count; i++) {

            GameObject mouseTransform = GameManager.allTheMice[i];
            Vector3 directionToMouse = mouseTransform.transform.position - transform.position;
            float angle = Vector3.Angle (directionToMouse, transform.forward);

            if (angle < 90f) {
                Ray catRay = new Ray (transform.position, directionToMouse);
                RaycastHit catRayHitInfo = new RaycastHit ();

                if (Physics.Raycast (catRay, out catRayHitInfo, 30f)) {
                    Debug.DrawRay (catRay.origin, catRay.direction);

                    if (catRayHitInfo.collider.tag == "Mouse") {

                        if (catRayHitInfo.distance < 3f) {
                            GameManager.allTheMice.Remove(mouseTransform);
                            Destroy (mouseTransform);
                            eating.Play();
                        }
                        else {
                            rbodyCat.AddForce (directionToMouse.normalized * 1000f);
                            boss1.Play();
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount > 0 && Time.timeSinceLevelLoad > 0.25)
        {
            //Debug.Log("Click: touch detected!");

            for (int i = 0; i < Input.touchCount; i++)
            {
                Touch touch = Input.GetTouch(i);
                Ray ray = Camera.main.ScreenPointToRay(touch.position);
                RaycastHit hit = new RaycastHit();

                if (touch.phase == TouchPhase.Began)
                {

                    if (Physics.Raycast(ray, out hit, (float)1000))
                    {
                        if (hit.collider.gameObject == gameObject)
                        {
                            //handle
                            OnMouseDown();
                        }
                    }

                } //if began

            } //if touch exist

        }
    }
Exemplo n.º 6
0
    public void add_node(Vector3 pos, int prev_node_id, RaycastHit hit)
    {
        int current_selected_node = get_selected_node ();
        if (current_selected_node >= 0) {
            int tmp_id = nodes.Count;
            GameObject tmp = (GameObject)Instantiate (node_template, pos, Quaternion.identity);
            tmp.gameObject.GetComponent<node>().node_const(pos, tmp_id ,prev_node_id, true);
            tmp.gameObject.GetComponent<node>().is_base_node = false;
            tmp.gameObject.transform.rotation = Quaternion.FromToRotation(Vector3.down, hit.normal);
            nodes.Add (tmp);
            //nodes[tmp_id].gameObject.GetComponent<node>().node_const(pos ,tmp_id, get_selected_node (), true);
            last_added_wp = tmp_id;

          //MANAGE RES -> connect to res with node

            foreach (GameObject r in GameObject.FindGameObjectsWithTag(vars.res_tag))
          {

        if (!r.GetComponent<ressource>().is_node_connected && r.GetComponent<ressource>().circle_holder.gameObject.GetComponent<selection_circle>().is_point_in_circle(pos) && r.GetComponent<ressource>().circle_holder.gameObject.GetComponent<selection_circle>().enabled)
        {
          			r.gameObject.GetComponent<ressource>().is_node_connected = true;
                    get_node_with_intern_node_id(tmp_id).connected_with_res = true;
                    get_node_with_intern_node_id(tmp_id).connected_res_id = r.GetComponent<ressource>().ressource_id;
                    get_node_with_intern_node_id(tmp_id).node_pos = r.gameObject.GetComponent<ressource>().ressource_pos;
          GameObject.Find("RES_SELECTION_UI").GetComponent<res_selection_ui_manager>().update_res_selection_ui();
        }

          }

            Instantiate(scout_ant_prefab);
        } else {
            Debug.LogError("NODE KONNTE NICHT ERSTELLT WERDEN KA KEINER SELEKTOER WURDE");
        }
    }
Exemplo n.º 7
0
 // Update is called once per frame
 void Update()
 {
     Ray playerRay = new Ray (transform.position + new Vector3(0f, 30, 0f), transform.forward);
     RaycastHit hit = new RaycastHit();
     if (Physics.Raycast (playerRay, out hit, 100f)) {
         //npcTextPrefab.text = "LOL";
         Debug.DrawRay ( playerRay.origin, playerRay.direction * hit.distance, Color.blue);
         //if the item the raycast is hitting the TV
         if (hit.transform.gameObject.tag == "TV") {
             //if player has object required to interact with TV then...
             if (girlItems.ContainsKey ("Scissors")) {
                 if (Input.GetKeyDown (KeyCode.G)) {
                     Destroy (hit.transform.gameObject);
                     Destroy (transform.Find ("Scissors").gameObject);
                     girlItems.Remove ("Scissors");
                     //Destroy
                 }
             }
         }
         if ( hit.transform.gameObject.tag == "toilet" ) {
             if (girlItems.ContainsKey("Cake")) {
                 if ( Input.GetKeyDown (KeyCode.E) ) {
                     Destroy (hit.transform.gameObject);
                     Destroy (transform.Find ("Cake").gameObject);
                     girlItems.Remove ("Cake");
                 }
             }
         }
     }
 }
    static void RaycastHit_lightmapCoord(JSVCall vc)
    {
        UnityEngine.RaycastHit _this = (UnityEngine.RaycastHit)vc.csObj;
        var result = _this.lightmapCoord;

        JSApi.setVector2S((int)JSApi.SetType.Rval, result);
    }
    static void RaycastHit_transform(JSVCall vc)
    {
        UnityEngine.RaycastHit _this = (UnityEngine.RaycastHit)vc.csObj;
        var result = _this.transform;

        JSMgr.datax.setObject((int)JSApi.SetType.Rval, result);
    }
    static void RaycastHit_triangleIndex(JSVCall vc)
    {
        UnityEngine.RaycastHit _this = (UnityEngine.RaycastHit)vc.csObj;
        var result = _this.triangleIndex;

        JSApi.setInt32((int)JSApi.SetType.Rval, (System.Int32)(result));
    }
    static void RaycastHit_textureCoord2(JSVCall vc)
    {
        UnityEngine.RaycastHit _this = (UnityEngine.RaycastHit)vc.csObj;
        var result = _this.textureCoord2;

        JSApi.setVector2S((int)JSApi.SetType.Rval, result);
    }
Exemplo n.º 12
0
        public bool Raycast(Vector3 origin, Vector3 direction, out Uniject.RaycastHit hitinfo, float distance, int layerMask)
        {
            UnityEngine.RaycastHit unityHit = new UnityEngine.RaycastHit();
            bool result = UnityEngine.Physics.Raycast(origin, direction, out unityHit, distance, layerMask);

            if (result)
            {
                TestableGameObject    testable = null;
                UnityGameObjectBridge bridge   = unityHit.collider.gameObject.GetComponent <UnityGameObjectBridge>();
                if (null != bridge)
                {
                    testable = bridge.wrapping;
                }

                hitinfo = new RaycastHit(unityHit.point,
                                         unityHit.normal,
                                         unityHit.barycentricCoordinate,
                                         unityHit.distance,
                                         unityHit.triangleIndex,
                                         unityHit.textureCoord,
                                         unityHit.textureCoord2,
                                         unityHit.lightmapCoord,
                                         testable,
                                         unityHit.collider);
            }
            else
            {
                hitinfo = new RaycastHit();
            }

            return(result);
        }
Exemplo n.º 13
0
    // Update is called once per frame
    void Update()
    {
        //vector from position to center of asteriod
            //interpolate position in a vector towords the orign at the rate of gravity by time?
            Vector3 targetPosition = new Vector3(gravityCenter.x-transform.position.x,gravityCenter.y-transform.position.y,gravityCenter.z-transform.position.z).normalized;
            //shall we keep its orentation?
            //keep it unit based
            //and apply interpolation to new position
            transform.position += targetPosition*(Time.smoothDeltaTime*mainGravity)*movementFriction;
            //TODO: have a max fall rate? this would help avoid collision errors i think and make it smoother

        if(GetComponent<BoxCollider>())
        {
            BoxCollider collider;
            collider = GetComponent<BoxCollider>();

            //sends a ray down
            RaycastHit hit = new RaycastHit();
            //need to change this so it still looks even if it hit an ignore

            if(Physics.Raycast(transform.position, -transform.up,out hit, 1000))
            {

                //sees if the object is bellow the ground
                if(hit.distance   < collider.size.y/2)
                {
                    //makes it so the object cant go bellow the ground
                    transform.position +=  transform.up*((collider.size.y/2) - hit.distance);
                }
            }
        }
    }
Exemplo n.º 14
0
        public bool Raycast(Vector3 origin, Vector3 direction, out Uniject.RaycastHit hitinfo, float distance, int layerMask)
        {
            UnityEngine.RaycastHit unityHit = new UnityEngine.RaycastHit();
            bool result = UnityEngine.Physics.Raycast(origin.ToUnity(), direction.ToUnity(), out unityHit, distance, layerMask);

            if (result)
            {
                IGameObject testable = null;
                var         bridge   = unityHit.collider.gameObject.GetComponent <UnityBridgeComponent>();
                if (null != bridge)
                {
                    testable = bridge.GameObject;
                }

                hitinfo = new RaycastHit(unityHit.point.ToUniject(),
                                         unityHit.normal.ToUniject(),
                                         unityHit.barycentricCoordinate.ToUniject(),
                                         unityHit.distance,
                                         unityHit.triangleIndex,
                                         unityHit.textureCoord.ToUniject(),
                                         unityHit.textureCoord2.ToUniject(),
                                         unityHit.lightmapCoord.ToUniject(),
                                         testable,
                                         unityHit.collider.ToUniject());
            }
            else
            {
                hitinfo = new RaycastHit();
            }

            return(result);
        }
    public override void DoPolish()
    {
        vectorToPlayer = Camera.main.transform.position - transform.position - Vector3.Project (Camera.main.transform.position - transform.position,Vector3.up);
        vectorToPlayer.Normalize ();

        Vector3 cameraRelativeVelocity = Vector3.Project (rigidbody.velocity  ,Camera.main.transform.right);

        if(interpolateCamera){
            //Focus camera on ball. Ideally this code would be in a proper CameraController class. However, for the purposes of this exercise, we are keeping all relevant code in one single file.
            Camera.main.transform.rotation = Quaternion.Lerp (Camera.main.transform.rotation,Quaternion.LookRotation(transform.position + cameraRelativeVelocity*cameraHorizontalOffsetPerSpeed + Camera.main.transform.up*cameraVerticalOffSet - Camera.main.transform.position,Vector3.up),cameraInterpolationStrength*Time.deltaTime);
        }else{
            //Focus camera on ball.
            Camera.main.transform.rotation = Quaternion.LookRotation(transform.position + cameraRelativeVelocity*cameraHorizontalOffsetPerSpeed+ Camera.main.transform.up*cameraVerticalOffSet - Camera.main.transform.position,Camera.main.transform.up);
        }

        if(follow){
            Vector3 desiredPosition = transform.position + vectorToPlayer*distanceToPlayer + Vector3.up*height;

            Vector3 dir = desiredPosition - transform.position;
            float distanceToCamera = dir.magnitude;
            dir.Normalize ();

            RaycastHit hit = new RaycastHit();
            if (Physics.Raycast (transform.position, dir,out hit,distanceToCamera + distanceToWall,cameraCollisionLayers )) {
                Vector3 point = hit.point - dir*distanceToWall;
                desiredPosition = point + Vector3.up*(1 - (point - transform.position).magnitude/distanceToPlayer)*10;
            }
            Camera.main.transform.position =Vector3.Lerp (Camera.main.transform.position ,desiredPosition,cameraMovementStrength*Time.deltaTime);
        }
    }
Exemplo n.º 16
0
    public void RemoveTouch(Tuio.Touch t)
    {
        // Not most recent touch?
        if (curTouch.TouchId != t.TouchId) return;

        // Check it's not expired
        //if (Time.time - t.TimeAdded > maxHeldTime) return;

        // Over the movement threshold?
        Vector2 curTouchPos = new Vector2(
                t.TouchPoint.x / (float)_screenWidth,
                t.TouchPoint.y / (float)_screenHeight);
        if (Vector2.Distance(curTouchPos, originalPos) > 0.003f) return;

        // Check if the touch still hits the same collider
        RaycastHit h = new RaycastHit();
        bool hit = origCollider.Raycast(getRay(t), out h, Mathf.Infinity);
        if (!hit) return;

        // Do the click
        gameObject.SendMessage("Click", h, SendMessageOptions.DontRequireReceiver);
        foreach (GameObject g in NotifyObjects)
        {
            g.SendMessage("Click", h, SendMessageOptions.DontRequireReceiver);
        }
    }
Exemplo n.º 17
0
    //Fixed Update is called every __ seconds, Edit Project Settings Time Fixed TimeStamp
    //Movement
    void FixedUpdate()
    {
        if (Input.GetKey (KeyCode.UpArrow)){
            GetComponent<Rigidbody>().AddForce(GetComponent<Transform>().forward *2f, ForceMode.VelocityChange);
        }

        if (Input.GetKey (KeyCode.LeftArrow)) {
            GetComponent<Rigidbody>().AddForce(GetComponent<Transform>().right *2f, ForceMode.VelocityChange);
            //transform.Rotate(new Vector3(0f,-5f,0f));
        }
        if (Input.GetKey (KeyCode.RightArrow)) {
            GetComponent<Rigidbody>().AddForce(GetComponent<Transform>().right *-2f, ForceMode.VelocityChange);
            //transform.Rotate(new Vector3(0f,5f,0f));
        }

        //transform.position = GetComponent<Transform>
        Ray ray = new Ray (transform.position, -Vector3.up);
        //to know where and what the raycast hit , we have to store that impact info
        RaycastHit rayHit = new RaycastHit (); //Blank Container for Info

        if (Physics.Raycast (ray, out rayHit, 1.1f))
        {
            if (Input.GetKey (KeyCode.RightShift))
            {
                GetComponent<Rigidbody> ().AddForce (new Vector3 (0f, 5000f, 0f), ForceMode.Acceleration);
                Debug.Log (rayHit.point);
                //Destroy (rayHit.collider.gameObject);
            }
        }
    }
Exemplo n.º 18
0
        public static bool IntersectRayMesh2(Ray ray, Mesh mesh, Matrix4x4 matrix, out RaycastHitEx raycastHit)
        {
            raycastHit          = default(RaycastHitEx);
            raycastHit.isHit    = false;
            raycastHit.distance = Mathf.Infinity;
            raycastHit.ray      = ray;

            UnityEngine.RaycastHit unityRaycastHit = default(UnityEngine.RaycastHit);

            if (Utility.IntersectRayMesh != null &&
                Utility.IntersectRayMesh(ray, mesh, matrix, out unityRaycastHit))
            {
                raycastHit.isHit         = true;
                raycastHit.point         = unityRaycastHit.point;
                raycastHit.normal        = unityRaycastHit.normal.normalized;
                raycastHit.ray           = ray;
                raycastHit.triangleIndex = unityRaycastHit.triangleIndex;
                raycastHit.textureCoord  = unityRaycastHit.textureCoord;
                raycastHit.distance      = unityRaycastHit.distance;

                raycastHit.barycentricCoordinate.x = unityRaycastHit.barycentricCoordinate.x;
                raycastHit.barycentricCoordinate.y = unityRaycastHit.barycentricCoordinate.y;

                Matrix4x4 normal_WToL_Matrix = matrix.transpose.inverse;
                raycastHit.localNormal = normal_WToL_Matrix.MultiplyVector(raycastHit.normal).normalized;
                raycastHit.localPoint  = matrix.inverse.MultiplyPoint(raycastHit.point);

                return(true);
            }

            return(false);
        }
Exemplo n.º 19
0
    void OnPress(bool isOver)
    {
        if (isOver)
        {
        }
        else
        {
           
            Camera camera = GameObject.Find("MogoMainUI").transform.GetChild(0).GetComponentInChildren<Camera>();
            BoxCollider bc = transform.GetComponentInChildren<BoxCollider>();

            RaycastHit hit = new RaycastHit();

            if (bc.Raycast(camera.ScreenPointToRay(Input.mousePosition), out hit, 10000.0f))
            {
                if (DebugUIDict.ButtonTypeToEventUp[transform.name] == null)
                {
                    LoggerHelper.Error("No ButtonTypeToEventUp Info");
                    return;
                }

                EventDispatcher.TriggerEvent(DebugUIDict.ButtonTypeToEventUp[transform.name]);
            }
        }

    }
Exemplo n.º 20
0
    void OnGUI()
    {
        //message to the player if he is dead
        if(dead){

        GUI.Box(new Rect(200, 300, 190, 50), "You died..Respawn in.. "+displaytime);
        }

        //raycast for close units and shopping
        RaycastHit hit = new RaycastHit();
        if(playertarget&attackrange){
        if(Physics.Linecast(playertarget.transform.position, attackrange.transform.position, out hit)){
            shop shop=(shop)hit.transform.GetComponent("shop");
             orderai ai=(orderai)hit.transform.GetComponent("orderai");

            if(ai){
                if(ai.enableaiorder){}
                else{
                GUI.Box(new Rect(200, 300, 150, 50), "Press E To Give Orders!");
                    if(Input.GetKey(KeyCode.E)) ai.enableaiorder=true;
            }
            }

            if(shop){
                if(shop.menuactive){}
                else{
                    GUI.Box(new Rect(200, 300, 150, 50), "Press E To Shop!");
                    if(Input.GetKey(KeyCode.E)) shop.menuactive=true;
                }
                }
            }
        }
    }
Exemplo n.º 21
0
	public void TakeHit(float damage, RaycastHit hit) {
		health -= damage;

		if (health <= 0 && !dead) {
			Die();
		}
	}
Exemplo n.º 22
0
    // Update is called once per frame
    void Update()
    {
        RaycastHit hit = new RaycastHit ();

        if (this.collider.Raycast (new Ray (Camera.main.ScreenToWorldPoint (Input.mousePosition), Camera.main.transform.forward), out hit, 1000.0f)) {
            last = down;
            down = Input.GetMouseButtonDown (0) || Input.GetMouseButton (0);
            Vector3 position = this.transform.position + new Vector3 (0f, 6.0f - this.transform.localScale.y / 2.0f, 0.0f);
            position.y = Camera.main.ScreenToWorldPoint (Input.mousePosition).y;
            Vector3 posmouse = Camera.main.ScreenToWorldPoint (Input.mousePosition);
            if (jumper != null)
                posmouse.z = jumper.transform.position.z;

            if (!last && down) {
                if (remember.Item == null && jumper != null && (posmouse - jumper.transform.position).magnitude < 1.0) {
                    remember.Item = jumper;
                    jumper = null;
                } else if (remember.Item != null && jumper != null && (posmouse - jumper.transform.position).magnitude < 1.0) {
                    GameObject temp = jumper;
                    jumper = remember.Item;
                    remember.Item.transform.position = position;
                    remember.Item.rigidbody.velocity = Vector3.zero;
                    remember.Item = temp;
                } else if (remember.Item != null && jumper == null) {
                    remember.Item.transform.position = position;
                    remember.Item.rigidbody.velocity = Vector3.zero;
                    remember.Item = null;
                    jumper = remember.Item;
                }
            }
        }
    }
Exemplo n.º 23
0
 public override void OnGazeEnter(RaycastHit hit)
 {
     if(gazeModel.isEyeTrackerRunning)
     {
         OnEnterBehaviour();
     }
 }
Exemplo n.º 24
0
    void Bullets(RaycastHit[] rays,Transform origin,float piercingFactor,float range,float bullets)
    {
        if(shooting)
        {
            for(int i=0;i<bullets;i++)
            {
                Physics.Raycast(origin.position,origin.forward,out rays[i],range*piercingFactor);
            }
            for(int i=0;i<bullets;i++)
            {

                Debug.Log("Rays["+i+"] transfprm:"+rays[i].transform.tag+" count:"+tempcount++);
                if(piercingFactor>0)
                {
                switch (rays[i].transform.tag) {
                    default:

                        piercingFactor=0;
                        impacts[currentImpact].transform.position = rays[i].point;
                        impacts[currentImpact].GetComponent<ParticleSystem>().Play();
                        shooting=false;
                        break;
                    case "Enemy":
                        //reduce enem's health

                        //subtract piercing factor using hardness of object
                        //piercingFactor-=rays[i].gameObject.hardness;
                        piercingFactor-=1;

                        Bullet(rays[i],rays[i].transform,piercingFactor,gun.range,gun.bullets);
                        break;
                    case "Passable":
                        //subtract piercing factor using hardness of object
                        //piercingFactor-=rays[i].gameObject.hardness;
                        piercingFactor-=1;

                        impacts[currentImpact].transform.position = rays[i].point;
                        impacts[currentImpact].GetComponent<ParticleSystem>().Play();

                        Bullet(rays[i],rays[i].transform,piercingFactor,gun.range,gun.bullets);
                        break;
                    case "Impenetrable":
                        piercingFactor=0;

                        impacts[currentImpact].transform.position = rays[i].point;
                        impacts[currentImpact].GetComponent<ParticleSystem>().Play();
                        shooting=false;
                        break;
                    }

                    if(++currentImpact >= maxImpacts)
                        currentImpact = 0;
                    if(!shooting || piercingFactor==0)
                        break;
                }
                else
                    shooting=false;
            }
        }
    }
Exemplo n.º 25
0
    // Update is called once per frame
    void Update()
    {
        var ray = new Ray();
        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        var hit = new RaycastHit();
        if (Input.GetMouseButtonDown(0))
            if (collider.Raycast(ray, out hit, 100.0f))
            {
                this.startPos = this.parent.transform.position;

                this.timer = 0;
                this.onMove = true;
                this.superScript.updateY((int)Mathf.Abs(_position/7));

            }

        if (this.onMove)
        {
            this.moveOn();
            this.timer += Time.deltaTime * this._speed;
        }
        if (this.timer >= 1) this.onMove = false;

        if (collider.Raycast(ray, out hit, 100.0f))
        {
            Debug.DrawLine(ray.origin, hit.point, Color.green, 1);
          //  texte.material.color = new Color(01 / 255, 47 / 255, 98 / 2);
        }
        else
        {
           // texte.material.color = Color.white;
        }
    }
Exemplo n.º 26
0
    static int SetCustomInput(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(FairyGUI.Stage), typeof(UnityEngine.RaycastHit), typeof(bool)))
            {
                FairyGUI.Stage         obj  = (FairyGUI.Stage)ToLua.ToObject(L, 1);
                UnityEngine.RaycastHit arg0 = (UnityEngine.RaycastHit)ToLua.ToObject(L, 2);
                bool arg1 = LuaDLL.lua_toboolean(L, 3);
                obj.SetCustomInput(ref arg0, arg1);
                ToLua.Push(L, arg0);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(FairyGUI.Stage), typeof(UnityEngine.Vector2), typeof(bool)))
            {
                FairyGUI.Stage      obj  = (FairyGUI.Stage)ToLua.ToObject(L, 1);
                UnityEngine.Vector2 arg0 = ToLua.ToVector2(L, 2);
                bool arg1 = LuaDLL.lua_toboolean(L, 3);
                obj.SetCustomInput(arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: FairyGUI.Stage.SetCustomInput"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Exemplo n.º 27
0
    // Update is called once per frame
    void Update()
    {
        if ( Input.GetKeyDown( KeyCode.Space ) ) {
            // a for() loop iterates through a collection and does stuff to each item
            foreach ( Fish fish in fishList ) {
                // fish.destination = Vector3.zero;
                fish.SetNewDestination( Vector3.zero );
            }
        }

        // the usual way to generate a ray
        // Ray ray = new Ray( transform.position, transform.forward );

        // generate a ray based on our mouse position on our screen
        if ( Input.GetMouseButton( 0 ) ) {
            Ray ray = Camera.main.ScreenPointToRay( Input.mousePosition );
            RaycastHit rayHit = new RaycastHit();

            if ( Physics.Raycast( ray, out rayHit, 1000f ) ) {
                //    Debug.Log( rayHit.point );
                foreach ( Fish fish in fishList ) {
                    fish.SetNewDestination( rayHit.point );
                }
            }
        }
    }
Exemplo n.º 28
0
    void Update()
    {
        if(Input.GetMouseButtonDown( 0 ))
        {
            if(cam)
            {
                ray = cam.ScreenPointToRay( Input.mousePosition );
            }else{
                ray = Camera.main.ScreenPointToRay( Input.mousePosition );
            }

            RaycastHit rayHit = new RaycastHit();

            if( Physics.Raycast(ray, out rayHit, 100f) )
            {
                if(rayHit.transform.gameObject.layer == 11)
                {
                    rayHit.transform.gameObject.GetComponent<LoadSceneButton>().StartLoading();

                }else if( rayHit.transform.gameObject.layer == 12)
                {
                    rayHit.transform.gameObject.GetComponent<OtherButton>().SetClicked();
                    rayHit.transform.gameObject.GetComponent<OtherButton>().Execute();
                }
            }
        }
    }
Exemplo n.º 29
0
 void FixedUpdate()
 {
     foreach (GameObject cat in GameManager.catList) {
         Vector3 directionToCat = cat.transform.position - transform.position;
         //if ( Vector3.Angle(transform.forward, directionToCat) < 180f) {
         Ray butterflyRay = new Ray(transform.position, directionToCat);
         RaycastHit butterflyRayHitInfo = new RaycastHit();
         if (Physics.Raycast(butterflyRay, out butterflyRayHitInfo, 100f)) {
             //Debug.DrawRay (butterflyRay.origin, directionToCat * butterflyRayHitInfo.distance, Color.red);
             //Debug.Log ("see");
             if (butterflyRayHitInfo.collider.tag == "Cat") {
                 //Debug.Log ("see");
                 Ray ray_corner_check = new Ray(transform.position, -transform.forward);
                 // if cat is in front && within front detection range
                 //     if not cornered
                 //          turn around
                 if ( Vector3.Angle(transform.forward, directionToCat) < frontal_detection_cone && butterflyRayHitInfo.distance < frontal_detection_range ) {
                     //Debug.Log ("see");
                     if (!Physics.Raycast(ray_corner_check, check_cornered_distance)) {
                         transform.Rotate(0f, 180f, 0f);
                     }
                 }
                 // if cat is within circular detection range
                 //     panic
                 if ( butterflyRayHitInfo.distance < circular_detection_range) {
                     //Debug.Log("panic");
                     GetComponent<Rigidbody>().AddForce(-directionToCat.normalized * panic_speed);
                 }
             }
             //}
         }
     }
 }
        /// <summary>
        /// Read the data using the reader.
        /// </summary>
        /// <param name="reader">Reader.</param>
        public override object Read(ISaveGameReader reader)
        {
            UnityEngine.RaycastHit raycastHit = new UnityEngine.RaycastHit();
            foreach (string property in reader.Properties)
            {
                switch (property)
                {
                case "point":
                    raycastHit.point = reader.ReadProperty <UnityEngine.Vector3> ();
                    break;

                case "normal":
                    raycastHit.normal = reader.ReadProperty <UnityEngine.Vector3> ();
                    break;

                case "barycentricCoordinate":
                    raycastHit.barycentricCoordinate = reader.ReadProperty <UnityEngine.Vector3> ();
                    break;

                case "distance":
                    raycastHit.distance = reader.ReadProperty <System.Single> ();
                    break;
                }
            }
            return(raycastHit);
        }
Exemplo n.º 31
0
 //private int MaskLayer; // excludes hits to only objects here.
 //private float RayDistance;
 public HitManager(Camera asSeenByCamera)
 {
     Hit = new RaycastHit();
     //RayDistance = Mathf.Infinity;
     //MaskLayer = Physics.kDefaultRaycastLayers;
     SetHitCamera(asSeenByCamera);
 }
Exemplo n.º 32
0
 // Update is called once per frame
 void Update()
 {
     //create raycast
     Ray playerRay = new Ray (transform.position, transform.forward);
     RaycastHit hit = new RaycastHit();
     if (Physics.Raycast (playerRay, out hit, 10f)) {
         Debug.DrawRay ( playerRay.origin, playerRay.direction * hit.distance, Color.red);
         if (hit.transform.gameObject.tag == "Throwable2") {
             npcTextPrefab3.text = "Press K to pick scissors up";
             //if player one presses G
             if (holdingObject2 == false && Input.GetKeyDown (KeyCode.K)) {
                 npcTextPrefab3.text = "Press K to throw";
                 guy2.instance.picked2= true;
                 holdingObject2 = true;
                 hit.transform.parent = transform;
             }
             else if (holdingObject2 == true && Input.GetKeyDown (KeyCode.K)) {
                 holdingObject2 = false;
                 guy2.instance.donezo2= true;
                 hit.transform.parent = null;
                 hit.transform.GetComponent<Rigidbody>().constraints &= ~RigidbodyConstraints.FreezePosition;
             }
             hit.transform.GetComponent<Rigidbody>().AddForce (hit.transform.forward * 2000);
         }
         else {
             npcTextPrefab3.text = "";
         }
     }
 }
Exemplo n.º 33
0
        /// <summary>
        /// Returns the position next to the side you pressed on.
        /// </summary>
        public static Vector3 GetPositionNextToHoveredTile () {

            Event e = Event.current;

            Ray ray = SceneView.lastActiveSceneView.camera.ScreenPointToRay(new Vector3(
                e.mousePosition.x, Screen.height - e.mousePosition.y - 36, 0)); //Upside-down and offset a little because of menus

            RaycastHit hit = new RaycastHit();

            if (Physics.Raycast(ray, out hit, 1000.0f)) {

                if (hit.collider.gameObject.GetComponent<ChunkObjectData>()) {

                    return hit.collider.gameObject.transform.position + hit.normal;

                }
                else {

                    Debug.LogWarning("The location you want to paint at is not on the same chunk as selected.");

                }

            }
            else {

                return new Vector3(0, 9000, 0);

            }

            return new Vector3(0, 9000, 0);

        }
    // Use this for initialization
    void Start()
    {
        float rad = 0;
        float ang = 0;

        for (int i = 0; i < Random.Range(50,100); ++i)
        {
            rad = Random.Range(0.0f, 250.0f);
            ang = Random.Range(0.0f, Mathf.PI * 2.0f);

            RaycastHit hit = new RaycastHit();
            Vector3 top = new Vector3(Mathf.Cos(ang) * rad + 1600, 1000, Mathf.Sin(ang) * rad + 600);
            Ray ray = new Ray(top, new Vector3(0, -1, 0));
            Physics.Raycast(ray, out hit);

            GameObject nodeInst = Instantiate(node, hit.point, new Quaternion()) as GameObject;
            Node nodeInstNode = nodeInst.GetComponent<NodeTest>().node;
            nodeInstNode.cultyness = Random.Range(-100, 100);
            nodeInstNode.farmyness = Random.Range(-100, 100);
            nodeInstNode.mournyness = Random.Range(-100, 100);
            nodeInstNode.religyness = Random.Range(-100, 100);
            nodeInstNode.socialness = Random.Range(-100, 100);
            nodeInstNode.wanderyness = Random.Range(-100, 100);

            if (Random.Range(0,5) <= 1)
            {
                nodeInstNode.sleepyness = true;
            }
        }
    }
Exemplo n.º 35
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Vector3 directionToMouse = mouse.position - transform.position;
        float angle = Vector3.Angle(transform.forward, directionToMouse);

        if (angle < 90f) {

            Ray catRay = new Ray (transform.position, directionToMouse);
            RaycastHit catRayHitInfo = new RaycastHit();

            if (Physics.Raycast (catRay, out catRayHitInfo, 100f))
            {
                if(catRayHitInfo.collider.tag == "Mouse" )
                {
                    failed.Play();
                    if(catRayHitInfo.distance <= 5)
                {
                        arrow.Play();
                        Destroy (mouse.gameObject);
                }
                    else{

                        rbody.AddForce (directionToMouse.normalized * 1000f);

                    }
                }
            }
        }
    }
Exemplo n.º 36
0
    // Update is called once per frame
    void Update()
    {
        //click to place cat or mouse
        Ray mouseRay = Camera.main.ScreenPointToRay (Input.mousePosition);
        RaycastHit mouseRayHit = new RaycastHit();

        //Left click instantiates cat
        if (Input.GetMouseButtonDown (0))
        {
            if (Physics.Raycast (mouseRay, out mouseRayHit, 100f))
            {
                GameObject newCatClick = (GameObject) Instantiate (catPrefab, mouseRayHit.point, Quaternion.Euler (0f, 0f, 0f));
                listOfMice.Add (newCatClick);
            }
        }

        //Right click instantiates mouse
        if (Input.GetMouseButtonDown (1))
        {
            if (Physics.Raycast (mouseRay, out mouseRayHit, 100f))
            {
                GameObject newMouseClick = (GameObject) Instantiate (mousePrefab, mouseRayHit.point, Quaternion.Euler (0f, 0f, 0f));
                listOfMice.Add (newMouseClick);

            }
        }
    }
Exemplo n.º 37
0
    void OnSceneGUI()
    {
        Event e = Event.current;
        wpScript = (RCCAIWaypointsContainer)target;

        if(e != null){

            if(e.isMouse && e.shift && e.type == EventType.MouseDown){

                Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                RaycastHit hit = new RaycastHit();
                if (Physics.Raycast(ray, out hit, 5000.0f)) {

                    Vector3 newTilePosition = hit.point;

                    GameObject wp = new GameObject("Waypoint " + wpScript.waypoints.Count.ToString());

                    wp.transform.position = newTilePosition;
                    wp.transform.SetParent(wpScript.transform);

                    GetWaypoints();

                }

            }

            if(wpScript)
                Selection.activeGameObject = wpScript.gameObject;

        }

        GetWaypoints();
    }
Exemplo n.º 38
0
    void Update()
    {
        if (Input.GetKey(KeyCode.L)) {
            if (!L_downflag) {
                L_downflag=true;
                if (dlight.shadows==LightShadows.None) {
                    dlight.shadows=LightShadows.Soft;
                } else {
                    dlight.shadows=LightShadows.None;
                }
            }
        } else {
            L_downflag=false;
        }

        Material mat=grass.renderer.material;
        Collider col=grass.collider;

        Ray ray = new Ray(rigidbody.position+Vector3.up, -Vector3.up);
        RaycastHit hit=new RaycastHit();
        if (col.Raycast(ray, out hit, 100f)) {
            float dmp=Mathf.Clamp(1-(rigidbody.position.y-0.3042075f)/0.35f,0,1);
            Vector4 pos=new Vector4(hit.textureCoord.x, hit.textureCoord.y, dmp*dmp, 0);
            mat.SetVector("_ballpos", pos);
            rigidbody.drag=dmp*1.0f;
            float v=rigidbody.velocity.magnitude*5.0f;
            dmp/=(v<1) ? 1 : v;
            rigidbody.angularDrag=dmp*1.0f;
        }
    }
Exemplo n.º 39
0
	public void Move(RaycastHit hit){
		this.gameObject.GetComponent<Animator> ().SetBool ("Walking", true);
		this.gameObject.GetComponent<NavMeshAgent> ().destination = hit.point;
		//Debug.Log ("Stop Working");
		CurTask = Task.Moving;

	}
Exemplo n.º 40
0
 // Checks for a collision with each part of each player and returns the number of the player that was hit last
 int Raycasting(Ray ray)
 {
     RaycastHit info = new RaycastHit();
     foreach (Transform child in Player1)
     {
         ray = new Ray(transform.position, child.position - transform.position);
         if (Physics.Raycast (ray, out info, 2.3f) && info.transform == Player1)
             return 1;
     }
     foreach (Transform child in Player2)
     {
         ray = new Ray (transform.position, child.position - transform.position);
         if (Physics.Raycast (ray, out info, 2.3f) && info.transform == Player2)
             return 2;
     }
     foreach (Transform child in Player3)
     {
         ray = new Ray (transform.position, child.position - transform.position);
         if (Physics.Raycast (ray, out info, 2.3f) && info.transform == Player3)
             return 3;
     }
     foreach (Transform child in Player4)
     {
         ray = new Ray (transform.position, child.position - transform.position);
         if (Physics.Raycast (ray, out info, 2.3f) && info.transform == Player4)
             return 4;
     }
     return lastHit;
 }
Exemplo n.º 41
0
 static public int constructor(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.RaycastHit o;
         o = new UnityEngine.RaycastHit();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Exemplo n.º 42
0
        public static bool Linecast(ArkCrossEngine.Vector3 start, ArkCrossEngine.Vector3 end, out ArkCrossEngine.RaycastHit hitInfo, int layerMask)
        {
            CrossEngineImpl.RaycastHit uhit = new CrossEngineImpl.RaycastHit();
            bool castResult = CrossEngineImpl.Physics.Linecast(Helper.Vec3ToUnity(start), Helper.Vec3ToUnity(end), out uhit, layerMask);

            hitInfo = Helper.RayCastHitFromUnity(uhit);
            return(castResult);
        }
Exemplo n.º 43
0
        public static bool Raycast(ArkCrossEngine.Vector3 origin, ArkCrossEngine.Vector3 direction, out ArkCrossEngine.RaycastHit hitInfo, float distance, int layerMask)
        {
            CrossEngineImpl.RaycastHit uhit = new CrossEngineImpl.RaycastHit();
            bool castResult = CrossEngineImpl.Physics.Raycast(Helper.Vec3ToUnity(origin), Helper.Vec3ToUnity(direction), out uhit, distance, layerMask);

            hitInfo = Helper.RayCastHitFromUnity(uhit);
            return(castResult);
        }
 /// <summary>
 /// Write the specified value using the writer.
 /// </summary>
 /// <param name="value">Value.</param>
 /// <param name="writer">Writer.</param>
 public override void Write(object value, ISaveGameWriter writer)
 {
     UnityEngine.RaycastHit raycastHit = (UnityEngine.RaycastHit)value;
     writer.WriteProperty("point", raycastHit.point);
     writer.WriteProperty("normal", raycastHit.normal);
     writer.WriteProperty("barycentricCoordinate", raycastHit.barycentricCoordinate);
     writer.WriteProperty("distance", raycastHit.distance);
 }
Exemplo n.º 45
0
        public static bool Raycast(ArkCrossEngine.Ray ray, out ArkCrossEngine.RaycastHit hit)
        {
            CrossEngineImpl.RaycastHit uhit = new CrossEngineImpl.RaycastHit();
            bool castResult = CrossEngineImpl.Physics.Raycast(Helper.RayToUnity(ray), out uhit);

            hit = Helper.RayCastHitFromUnity(uhit);
            return(castResult);
        }
Exemplo n.º 46
0
 static public int set_normal(IntPtr l)
 {
     UnityEngine.RaycastHit o = (UnityEngine.RaycastHit)checkSelf(l);
     UnityEngine.Vector3    v;
     checkType(l, 2, out v);
     o.normal = v;
     setBack(l, o);
     return(0);
 }
Exemplo n.º 47
0
 static public int set_barycentricCoordinate(IntPtr l)
 {
     UnityEngine.RaycastHit o = (UnityEngine.RaycastHit)checkSelf(l);
     UnityEngine.Vector3    v;
     checkType(l, 2, out v);
     o.barycentricCoordinate = v;
     setBack(l, o);
     return(0);
 }
Exemplo n.º 48
0
    static public int set_distance(IntPtr l)
    {
        UnityEngine.RaycastHit o = (UnityEngine.RaycastHit)checkSelf(l);
        float v;

        checkType(l, 2, out v);
        o.distance = v;
        setBack(l, o);
        return(0);
    }
Exemplo n.º 49
0
        protected override bool HitDetailCondition(UnityEngine.RaycastHit hit)
        {
            GameObject       obj  = hit.collider.gameObject;
            MonsterBreedData data = DataManagerM.Instance.getMonsterDataManager().getBreedDate(obj);

            if (data.breedItem == _playerController.playerAttribute.handMaterialId)
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 50
0
    static int SetCustomInput(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes <UnityEngine.RaycastHit, bool>(L, 2))
            {
                FairyGUI.Stage         obj  = (FairyGUI.Stage)ToLua.CheckObject <FairyGUI.Stage>(L, 1);
                UnityEngine.RaycastHit arg0 = StackTraits <UnityEngine.RaycastHit> .To(L, 2);

                bool arg1 = LuaDLL.lua_toboolean(L, 3);
                obj.SetCustomInput(ref arg0, arg1);
                ToLua.Push(L, arg0);
                return(1);
            }
            else if (count == 3 && TypeChecker.CheckTypes <UnityEngine.Vector2, bool>(L, 2))
            {
                FairyGUI.Stage      obj  = (FairyGUI.Stage)ToLua.CheckObject <FairyGUI.Stage>(L, 1);
                UnityEngine.Vector2 arg0 = ToLua.ToVector2(L, 2);
                bool arg1 = LuaDLL.lua_toboolean(L, 3);
                obj.SetCustomInput(arg0, arg1);
                return(0);
            }
            else if (count == 4 && TypeChecker.CheckTypes <UnityEngine.RaycastHit, bool, bool>(L, 2))
            {
                FairyGUI.Stage         obj  = (FairyGUI.Stage)ToLua.CheckObject <FairyGUI.Stage>(L, 1);
                UnityEngine.RaycastHit arg0 = StackTraits <UnityEngine.RaycastHit> .To(L, 2);

                bool arg1 = LuaDLL.lua_toboolean(L, 3);
                bool arg2 = LuaDLL.lua_toboolean(L, 4);
                obj.SetCustomInput(ref arg0, arg1, arg2);
                ToLua.Push(L, arg0);
                return(1);
            }
            else if (count == 4 && TypeChecker.CheckTypes <UnityEngine.Vector2, bool, bool>(L, 2))
            {
                FairyGUI.Stage      obj  = (FairyGUI.Stage)ToLua.CheckObject <FairyGUI.Stage>(L, 1);
                UnityEngine.Vector2 arg0 = ToLua.ToVector2(L, 2);
                bool arg1 = LuaDLL.lua_toboolean(L, 3);
                bool arg2 = LuaDLL.lua_toboolean(L, 4);
                obj.SetCustomInput(arg0, arg1, arg2);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: FairyGUI.Stage.SetCustomInput"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Exemplo n.º 51
0
    public UnityEngine.Vector3 GetStartTouchToWorldPoint()
    {
        if (null == UnityEngine.Camera.main)
        {
            return(UnityEngine.Vector3.zero);
        }
        float skill_blear_radius = 0.5f;

        UnityEngine.Vector3    start_touch_worldpos = UnityEngine.Vector3.zero;
        UnityEngine.Vector3    start_touch_pos      = new UnityEngine.Vector3(startPosition.x, startPosition.y, 0);
        UnityEngine.Ray        ray = UnityEngine.Camera.main.ScreenPointToRay(start_touch_pos);
        UnityEngine.RaycastHit hitInfo;

        SkillController player_skill_ctrl = null;

        if (null != player_skill_ctrl)
        {
            SkillInputData skill_input_data = player_skill_ctrl.GetSkillInputData(SkillTags);
            if (null != skill_input_data)
            {
                skill_blear_radius = skill_input_data.targetChooseRange;
            }
        }
        if (UnityEngine.Physics.Raycast(ray, out hitInfo, 200f, m_TerrainAndCharacterLayer))
        {
            start_touch_worldpos = hitInfo.point;
            UnityEngine.GameObject go = ArkCrossEngine.LogicSystem.PlayerSelf;
            if (null != go)
            {
                UnityEngine.Vector3 srcPos    = go.transform.position;
                UnityEngine.Vector3 targetPos = start_touch_worldpos;
                float length = UnityEngine.Vector3.Distance(srcPos, targetPos);
                UnityEngine.RaycastHit airWallHitInfo = new UnityEngine.RaycastHit();
                int airWallLayermask          = 1 << UnityEngine.LayerMask.NameToLayer("AirWall");
                UnityEngine.Vector3 direction = (targetPos - srcPos).normalized;
                if (UnityEngine.Physics.Raycast(go.transform.position, direction, out airWallHitInfo, length, airWallLayermask))
                {
                    UnityEngine.BoxCollider bc = airWallHitInfo.collider.gameObject.GetComponent <UnityEngine.BoxCollider>();
                    if (null != bc && !bc.isTrigger)
                    {
                        start_touch_worldpos = airWallHitInfo.point;
                    }
                }
            }
            UnityEngine.Collider[] hitObjs = UnityEngine.Physics.OverlapSphere(start_touch_worldpos, skill_blear_radius, m_CharacterLayer);
            if (hitObjs.Length > 0)
            {
                start_touch_worldpos = hitObjs[0].gameObject.transform.position;
            }
        }

        return(start_touch_worldpos);
    }
Exemplo n.º 52
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.RaycastHit o;
         o = new UnityEngine.RaycastHit();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 53
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.RaycastHit o;
         o = new UnityEngine.RaycastHit();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Exemplo n.º 54
0
 static int GetCollider(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         DummyBehavior          obj = (DummyBehavior)ToLua.CheckObject(L, 1, typeof(DummyBehavior));
         UnityEngine.RaycastHit o   = obj.GetCollider();
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemplo n.º 55
0
 static int CompareRayCastHit(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         UnityEngine.RaycastHit arg0 = (UnityEngine.RaycastHit)ToLua.CheckObject(L, 1, typeof(UnityEngine.RaycastHit));
         UnityEngine.RaycastHit arg1 = (UnityEngine.RaycastHit)ToLua.CheckObject(L, 2, typeof(UnityEngine.RaycastHit));
         int o = UnGfx.CompareRayCastHit(arg0, arg1);
         LuaDLL.lua_pushinteger(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemplo n.º 56
0
 static public int RaycastHitNormalXYZ_s(IntPtr l)
 {
     try
     {
         UnityEngine.RaycastHit self = (UnityEngine.RaycastHit)checkSelf(l);
         var v = self.normal;
         LuaDLL.lua_pushnumber(l, v.x);
         LuaDLL.lua_pushnumber(l, v.y);
         LuaDLL.lua_pushnumber(l, v.z);
         return(3);
     }
     catch (Exception e)
     {
         return(error(l, e));
     }
 }
 static void RaycastHit_barycentricCoordinate(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.RaycastHit _this = (UnityEngine.RaycastHit)vc.csObj;
         var result = _this.barycentricCoordinate;
         JSApi.setVector3S((int)JSApi.SetType.Rval, result);
     }
     else
     {
         UnityEngine.Vector3    arg0  = (UnityEngine.Vector3)JSApi.getVector3S((int)JSApi.GetType.Arg);
         UnityEngine.RaycastHit _this = (UnityEngine.RaycastHit)vc.csObj;
         _this.barycentricCoordinate = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
 static void RaycastHit_distance(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.RaycastHit _this = (UnityEngine.RaycastHit)vc.csObj;
         var result = _this.distance;
         JSApi.setSingle((int)JSApi.SetType.Rval, (System.Single)(result));
     }
     else
     {
         System.Single          arg0  = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg);
         UnityEngine.RaycastHit _this = (UnityEngine.RaycastHit)vc.csObj;
         _this.distance = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
Exemplo n.º 59
0
    public UnityEngine.Vector3 GetTouchToAirWallWorldPoint()
    {
        if (null == UnityEngine.Camera.main)
        {
            return(UnityEngine.Vector3.zero);
        }
        UnityEngine.Vector3    cur_touch_worldpos = UnityEngine.Vector3.zero;
        UnityEngine.Vector3    cur_touch_pos      = new UnityEngine.Vector3(position.x, position.y, 0);
        UnityEngine.Ray        ray = UnityEngine.Camera.main.ScreenPointToRay(cur_touch_pos);
        UnityEngine.RaycastHit hitInfo;

        int layermask = 1 << UnityEngine.LayerMask.NameToLayer("Terrains");

        if (UnityEngine.Physics.Raycast(ray, out hitInfo, 200f, layermask))
        {
            cur_touch_worldpos = hitInfo.point;
            UnityEngine.GameObject go = ArkCrossEngine.LogicSystem.PlayerSelf;
            if (null != go)
            {
                UnityEngine.Vector3 srcPos    = go.transform.position;
                UnityEngine.Vector3 targetPos = cur_touch_worldpos;
                float length = UnityEngine.Vector3.Distance(srcPos, targetPos);
                UnityEngine.RaycastHit airWallHitInfo = new UnityEngine.RaycastHit();
                int airWallLayermask          = 1 << UnityEngine.LayerMask.NameToLayer("AirWall");
                UnityEngine.Vector3 direction = (targetPos - srcPos).normalized;
                if (UnityEngine.Physics.Raycast(go.transform.position, direction, out airWallHitInfo, length, airWallLayermask))
                {
                    UnityEngine.BoxCollider bc = airWallHitInfo.collider.gameObject.GetComponent <UnityEngine.BoxCollider>();
                    if (null != bc && !bc.isTrigger)
                    {
                        cur_touch_worldpos = airWallHitInfo.point;
                    }
                }
            }
        }
        return(cur_touch_worldpos);
    }
Exemplo n.º 60
0
        public override void OnUpdate()
        {
            //downforce
            if (stickyFeet && vessel.Landed)
            {
                Rigidbody rigidBody = vessel.rootPart.rb;
                if (rigidBody == null)
                {
                    Debug.Log("rigidBody is null");
                    return;
                }

                UnityEngine.RaycastHit hitInfo = new UnityEngine.RaycastHit();
                var mask = 1 << 15;
                if (Physics.Raycast(this.part.transform.position, -this.part.transform.up, out hitInfo, 1.4f, mask))
                {
                    //this.part.rigidbody.AddForce(-15*this.part.transform.up);
                    rigidBody.AddForceAtPosition(-15 * this.part.transform.up, this.vessel.CoM);

                    //this.part.rigidbody.AddRelativeTorque(-20 * this.vessel.angularMomentum);
                    rigidBody.AddRelativeTorque(-20 * this.vessel.angularMomentum);
                }

                if (vessel.Landed)
                {
                    if (vessel.srf_velocity.magnitude > maxSpeed)
                    {
                        rigidBody.AddForce(-2 * rigidBody.velocity);
                    }
                    if (vessel.ctrlState.wheelThrottle == 0)
                    {
                        rigidBody.AddForce(-2 * rigidBody.velocity);
                    }
                }
            }
        }