Esempio n. 1
0
    static void OffMeshLinkData_offMeshLink(JSVCall vc)
    {
        UnityEngine.OffMeshLinkData _this = (UnityEngine.OffMeshLinkData)vc.csObj;
        var result = _this.offMeshLink;

        JSMgr.datax.setObject((int)JSApi.SetType.Rval, result);
    }
Esempio n. 2
0
    static void OffMeshLinkData_linkType(JSVCall vc)
    {
        UnityEngine.OffMeshLinkData _this = (UnityEngine.OffMeshLinkData)vc.csObj;
        var result = _this.linkType;

        JSApi.setEnum((int)JSApi.SetType.Rval, (int)result);
    }
	// Update is called once per frame
	void Update () {
		if (agent.enabled) agent.SetDestination (targetPosition.position);
		//destination = agent.destination; //For debugging with the Inspector
		destination = agent.path.corners[1];
		status = agent.path.status;
		data = agent.nextOffMeshLinkData;

		if (agent.isOnOffMeshLink && linkTime == 0) {
			linkTime = Time.time;
		}

		if (controller.controllable) {
			if (Vector3.Distance (targetPosition.position, gameObject.transform.position) > agent.stoppingDistance) {
				//controller.xin = (targetPosition.position.x - gameObject.transform.position.x);
				//controller.zin = (targetPosition.position.z - gameObject.transform.position.z);
				controller.xin = Mathf.Max (Mathf.Min ((agent.path.corners [1].x - gameObject.transform.position.x), 1f), -1f);
				controller.zin = Mathf.Max (Mathf.Min ((agent.path.corners [1].z - gameObject.transform.position.z), 1f), -1f);
			} else
				controller.xin = controller.zin = 0;
			
			if (agent.path.corners [1].y - gameObject.transform.position.y > 0.5) {
				agent.enabled = false;
				controller.jumpin = 1;

			} else if (controller.GroundCheck ()) {
				agent.enabled = true;
				controller.jumpin = 0;
			}

			if (Time.time - linkTime >= .5 && linkTime != 0) {
				agent.enabled = false;
				linkTime = 0;
			}
		} else {
			controller.xin = controller.zin = 0;
		}

		var nav = GetComponent<NavMeshAgent>(); //Debug Path Line
		if( nav == null || nav.path == null )
			return;
		
		var line = this.GetComponent<LineRenderer>();
		if( line == null )
		{
			line = this.gameObject.AddComponent<LineRenderer>();
			line.material = new Material( Shader.Find( "Sprites/Default" ) ) { color = Color.yellow };
			line.SetWidth( 0.5f, 0.5f );
			line.SetColors( Color.yellow, Color.yellow );
		}
		
		var path = nav.path;
		
		line.SetVertexCount( path.corners.Length );
		
		for( int i = 0; i < path.corners.Length; i++ )
		{
			line.SetPosition( i, path.corners[ i ] );
		}

	}
        public void DoJump()
        {
            agent.Stop(true);

            if (!traversingLink)
            {
                animator.CrossFade(jumpState, 0);
                currLink = agent.currentOffMeshLinkData;
                start = agent.transform.position;
                end = currLink.endPos;
                NavMeshHit hit;
                NavMesh.SamplePosition(end, out hit, 1, 1);
                end = hit.position;
                traversingLink = true;
                return;
            }
            agent.transform.LookAt(new Vector3(end.x, agent.transform.position.y, end.z));
            AnimatorStateInfo info = animator.GetCurrentAnimatorStateInfo(0);

            if (info.IsName(jumpState) && !animator.IsInTransition(0))
            {
                float tlerp = info.normalizedTime;
                var newPos = Vector3.Lerp(start, end, tlerp);
                newPos.y += 0.6f * Mathf.Sin(Mathf.PI * info.normalizedTime);
                agent.transform.position = newPos;

            }

            if (!info.IsName(jumpState) && !animator.IsInTransition(0) || Vector3.Distance(agent.transform.position, end) < 0.3f)
            {
                traversingLink = false;
                agent.CompleteOffMeshLink();
                agent.Resume();
            }
        }
Esempio n. 5
0
    static void OffMeshLinkData_endPos(JSVCall vc)
    {
        UnityEngine.OffMeshLinkData _this = (UnityEngine.OffMeshLinkData)vc.csObj;
        var result = _this.endPos;

        JSApi.setVector3S((int)JSApi.SetType.Rval, result);
    }
Esempio n. 6
0
    static void OffMeshLinkData_activated(JSVCall vc)
    {
        UnityEngine.OffMeshLinkData _this = (UnityEngine.OffMeshLinkData)vc.csObj;
        var result = _this.activated;

        JSApi.setBooleanS((int)JSApi.SetType.Rval, (System.Boolean)(result));
    }
	static public int constructor(IntPtr l) {
		try {
			UnityEngine.OffMeshLinkData o;
			o=new UnityEngine.OffMeshLinkData();
			pushValue(l,true);
			pushValue(l,o);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.OffMeshLinkData o;
         o = new UnityEngine.OffMeshLinkData();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.OffMeshLinkData o;
         o = new UnityEngine.OffMeshLinkData();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.OffMeshLinkData o;
         o=new UnityEngine.OffMeshLinkData();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
Esempio n. 11
0
    static int get_nextOffMeshLinkData(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.NavMeshAgent    obj = (UnityEngine.NavMeshAgent)o;
            UnityEngine.OffMeshLinkData ret = obj.nextOffMeshLinkData;
            ToLua.PushValue(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index nextOffMeshLinkData on a nil value" : e.Message));
        }
    }
        void DoGetOffMeshLinkData()
        {
            if (_agent == null)
            {
                return;
            }

            if (!_agent.isOnOffMeshLink)
            {
                return;
            }

            OffMeshLinkData link = new OffMeshLinkData();

            link = _agent.currentOffMeshLinkData;// .GetCurrentOffMeshLinkData(out link);
            if(!startPos.IsNone)
            {
                startPos.Value = link.startPos;
            }

            if(!endPos.IsNone)
            {
                endPos.Value = link.endPos;
            }

            if(!activated.IsNone)
            {
                activated.Value = link.activated;
            }

            if(!OffMeshlinkType.IsNone)
            {
                switch(link.linkType)
                {
                    case OffMeshLinkType.LinkTypeManual:
                        OffMeshlinkType.Value = "manual";
                        break;
                    case OffMeshLinkType.LinkTypeDropDown:
                        OffMeshlinkType.Value = "dropDown";
                        break;
                    case OffMeshLinkType.LinkTypeJumpAcross:
                        OffMeshlinkType.Value = "jumpAcross";
                        break;
                }
            }
        }
Esempio n. 13
0
    void Update()
    {
        if (agent.isOnOffMeshLink){
            if (!traversingLink) {
                currLink = agent.currentOffMeshLinkData;

                anim.SetTrigger(jumpHash);
                traversingLink = true;
            } else if (!anim.IsInTransition(0)) {
                if(anim.GetCurrentAnimatorStateInfo(0).tagHash != jumpHash) {
                    agent.CompleteOffMeshLink();
                    agent.Resume();
                    agent.nextPosition = currLink.endPos;
                    traversingLink = false;
                }
            }
        } else {
            anim.SetFloat("MoveSpeed", agent.velocity.magnitude);
        }
    }
        void DoGetOffMeshLinkData()
        {
            if (_agent == null)
            {
                return;
            }

            if (!_agent.isOnOffMeshLink)
            {
                return;
            }

            OffMeshLinkData link = new OffMeshLinkData();

            link = _agent.currentOffMeshLinkData;
            if(!startPos.IsNone)
            {
                startPos.Value = link.startPos;
            }

            if(!endPos.IsNone)
            {
                endPos.Value = link.endPos;
            }

            if(!activated.IsNone)
            {
                activated.Value = link.activated;
            }

            if(!valid.IsNone)
            {
                valid.Value = link.valid;
            }

            if(!OffMeshlinkType.IsNone)
            {
                switch(link.linkType)
                {
                    case OffMeshLinkType.LinkTypeManual:
                        OffMeshlinkType.Value = "manual";
                        break;
                    case OffMeshLinkType.LinkTypeDropDown:
                        OffMeshlinkType.Value = "dropDown";
                        break;
                    case OffMeshLinkType.LinkTypeJumpAcross:
                        OffMeshlinkType.Value = "jumpAcross";
                        break;
                }
            }

            if(!costOverride.IsNone)
            {
                costOverride.Value = link.offMeshLink.costOverride;
            }

            if(!occupied.IsNone)
            {
                occupied.Value = link.offMeshLink.occupied;
            }

            if(!autoUpdatePositions.IsNone)
            {
                autoUpdatePositions.Value = link.offMeshLink.autoUpdatePositions;
            }

            if(!navmeshArea.IsNone)
            {
                navmeshArea.Value = link.offMeshLink.area;
            }

            if(!startGameObject.IsNone)
            {
                startGameObject.Value = link.offMeshLink.startTransform.gameObject;
            }

            if(!endGameObject.IsNone)
            {
                endGameObject.Value = link.offMeshLink.endTransform.gameObject;
            }
        }
Esempio n. 15
0
 static public int get_linkType(IntPtr l)
 {
     UnityEngine.OffMeshLinkData o = (UnityEngine.OffMeshLinkData)checkSelf(l);
     pushEnum(l, (int)o.linkType);
     return(1);
 }
Esempio n. 16
0
 static public int get_offMeshLink(IntPtr l)
 {
     UnityEngine.OffMeshLinkData o = (UnityEngine.OffMeshLinkData)checkSelf(l);
     pushValue(l, o.offMeshLink);
     return(1);
 }
Esempio n. 17
0
    void Update()
    {
        if (Input.GetMouseButtonDown(1))
        {
            if (doubleClickTimer > 0)
            {
                doubleClicked = true;
            }
            doubleClickTimer = 1.5f;
        }

        if (select && set)
        {
            navAgent.destination = MoveD;
        }
        if (navAgent.pathStatus == NavMeshPathStatus.PathComplete)
        {
            set = false;
        }
        if (navAgent.pathPending == false) //Path created
        {
            if (navAgent.remainingDistance <= navAgent.stoppingDistance)
            {
                if (navAgent.hasPath || navAgent.velocity.sqrMagnitude == 0)
                {
                    if (currSpeed > 0.1f)
                    {
                        currSpeed -= 0.15f;
                    }
                    else if (currSpeed < 0.1f)
                    {
                        currSpeed = 0.1f;
                    }
                }
            }
            if (navAgent.remainingDistance <= 0)
            {
                isMoving = false;
            }
        }

        if (navAgent.isOnOffMeshLink && navAgent.currentOffMeshLinkData.endPos != currentLink.endPos)
        {
            if (jumped == false)
            {
                transform.gameObject.GetComponent<Animator>().SetBool("Jumped", true);
                jumpTimer = 0.6f;
                currentLink = navAgent.currentOffMeshLinkData;
                jumped = true;
            }
        }

        //Jumping
        if (jumpTimer > 0 && jumped)
        {
            jumpTimer -= Time.deltaTime;
            jumpItr += Time.deltaTime;

            fracJourney = jumpItr / 0.6f;

            if (fracJourney <= 1)
            {
                transform.position = Vector3.Lerp(currentLink.startPos, currentLink.endPos, fracJourney);
                transform.position = new Vector3(transform.position.x, transform.position.y+(Mathf.Sin(Mathf.PI * fracJourney)/2), transform.position.z) ;
            }
        }

        if (jumpTimer <= 0 && jumped)
        {
            jumpItr = 0;
            currSpeed = 0.1f;
            transform.gameObject.GetComponent<Animator>().SetBool("Jumped", false);
            transform.position = currentLink.endPos;
            jumped = false;
            navAgent.CompleteOffMeshLink();
            navAgent.Resume();
            currentLink = emptyLink;
        }
    }
Esempio n. 18
0
        private void AlertState()
        {
            if (!CanSeePlayer())
            {
                GetComponent<Animator>().SetBool("IsMoving", true);

                GetComponent<NavMeshAgent>().destination = _lastKnownLocation;

                if (Vector3.Distance(transform.position, _lastKnownLocation) < .1f)
                {
                    State = EnemyState.Searching;
                    GetComponent<Animator>().SetBool("IsMoving", false);
                }
            }
            else
            {
                if (Vector3.Distance(transform.position, _player.transform.position) < MinDistance)
                {
                    GetComponent<Animator>().SetBool("IsMoving", false);
                    GetComponent<Animator>().SetBool("IsAttacking", true);
                    _lastKnownLocation = _player.transform.position;
                    GetComponent<NavMeshAgent>().destination = transform.position;
                }
                else
                {
                    if (_navAgent.isOnOffMeshLink)
                    {
                        if (!_traversingLink)
                        {
                            _currLink = _navAgent.currentOffMeshLinkData;
                            _traversingLink = true;
                        }

                        var tlerp = .1f;
                        var newPos = Vector3.Lerp(_currLink.startPos, _currLink.endPos, tlerp);
                        newPos.y += 2f * Mathf.Sin(Mathf.PI * tlerp);
                        transform.position = newPos;

                        if (_currLink.startPos == _currLink.endPos)
                        {
                            transform.position = _currLink.endPos;
                            _traversingLink = false;
                            _navAgent.CompleteOffMeshLink();
                            _navAgent.Resume();
                        }
                    }
                    else
                    {
                        GetComponent<Animator>().SetBool("IsMoving", true);

                        _lastKnownLocation = _player.transform.position;
                        GetComponent<NavMeshAgent>().destination = _player.transform.position;

                        var targetRotation = Quaternion.LookRotation(_player.transform.position - transform.position);
                        transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, TurnSpeed * Time.deltaTime);
                    }
                }
            }
        }
 static int _CreateOffMeshLinkData(IntPtr L)
 {
     LuaScriptMgr.CheckArgsCount(L, 0);
     OffMeshLinkData obj = new OffMeshLinkData();
     LuaScriptMgr.PushValue(L, obj);
     return 1;
 }