void DrawCam(Color col, float sang, float eng, MOVETYPE dtype) { GL.PushMatrix(); rotationMatrix = locklocalToWorldMatrix; GL.MultMatrix(rotationMatrix); lineMaterial.SetPass(0); GL.Begin(GL.TRIANGLES); GL.Color(col); float ang; switch (dtype) { case MOVETYPE.X: for (int i = 0; i < 20; i++) { ang = sang + (eng) * i / 20; GL.Vertex3(0, 0, 0); GL.Vertex3(0, Mathf.Sin(ang) * SetSpread, Mathf.Cos(ang) * SetSpread); ang = sang + (eng) * (i + 1) / 20; GL.Vertex3(0, Mathf.Sin(ang) * SetSpread, Mathf.Cos(ang) * SetSpread); } break; case MOVETYPE.Y: for (int i = 0; i < 20; i++) { ang = sang + (eng) * i / 20; GL.Vertex3(0, 0, 0); GL.Vertex3(Mathf.Cos(ang) * SetSpread, 0, Mathf.Sin(ang) * SetSpread); ang = sang + (eng) * (i + 1) / 20; GL.Vertex3(Mathf.Cos(ang) * SetSpread, 0, Mathf.Sin(ang) * SetSpread); } break; case MOVETYPE.Z: for (int i = 0; i < 20; i++) { ang = sang + (eng) * i / 20; GL.Vertex3(0, 0, 0); GL.Vertex3(Mathf.Sin(ang) * SetSpread, Mathf.Cos(ang) * SetSpread, 0); ang = sang + (eng) * (i + 1) / 20; GL.Vertex3(Mathf.Sin(ang) * SetSpread, Mathf.Cos(ang) * SetSpread, 0); } break; } GL.End(); GL.PopMatrix(); }
public void Spawn(Vector3 spawnPoint) { if (MoveType == MOVETYPE.DEAD) { PlayerController pc = _game.Network.PlayerController; pc.Translation = new Vector3(pc.Translation.x, 0, pc.Translation.z); } if (Team == 0) { MoveType = MOVETYPE.SPECTATOR; } else { MoveType = MOVETYPE.NORMAL; } SetupClass(); SetDefaultValues(); this.Translation = spawnPoint; this.SetServerState(this.GlobalTransform.origin, this._playerVelocity, this._mesh.Rotation, _maxHealth , _maxArmour, (_activeWeapon == null) ? WEAPONTYPE.NONE : _activeWeapon.WeaponType); _predictedState = _serverState; _game.Network.SendPlayerInfo(this); }
private void NormalProcess(PlayerCmd pCmd, float delta) { if (IsNetworkMaster()) { int diff = _game.World.LocalSnapNum - pCmd.snapshot; if (diff < 0) { return; } _game.World.RewindPlayers(diff, delta); } this.ProcessDebuffs(delta); this.ProcessImpulses(pCmd); if (_settingDetpack) { _setDetpackTime += delta; if (_setDetpackTime >= _detpackTimeRequired) { Projectile proj = _game.World.ProjectileManager.AddProjectile(this, this.GlobalTransform.origin, "Detpack", WEAPONTYPE.DETPACK); Detpack dp = (Detpack)proj; if (_detpackTimeSetting <= 5) { dp.WarnSound.Play(); dp.WarnSoundPlayed = true; } else { dp.SetSound.Play(); } _settingDetpack = false; dp.MaxLifeTime = _detpackTimeSetting; MoveType = MOVETYPE.NORMAL; ActiveWeapon.WeaponMesh.Visible = true; } } this.ProcessAttack(pCmd, delta); if (IsNetworkMaster()) { _game.World.FastForwardPlayers(); } if (MoveType == MOVETYPE.NORMAL) { this.ProcessMovementCmd(_predictedState, pCmd, delta); } }
public void Die() { SetDefaultValues(); _currentHealth = 0; _currentArmour = 0; MoveType = MOVETYPE.DEAD; if (PlayerControlled) { // orientation change // TODO - pc should be on player if available PlayerController pc = _game.Network.PlayerController; pc.Translation = new Vector3(pc.Translation.x, _feet.Translation.y, pc.Translation.z); } pCmdQueue.Clear(); _dieSound.Play(); }
public IEnumerator HandleInput() { while (true) { while (Mathf.CeilToInt(Input.GetAxis("Vertical")) > 0) { PlayerState = MOVETYPE.WALK; yield return(StartCoroutine(Move(MoveDistance))); } PlayerState = MOVETYPE.IDLE; yield return(null); } }
virtual public void Init(Player shooter, Vector3 vel, WEAPONTYPE weapon, Game game) { _game = game; this.AddCollisionExceptionWith(shooter); Transform t = this.GlobalTransform; t.origin = shooter.Head.GlobalTransform.origin; this.GlobalTransform = t; Velocity = vel; this.LookAt(vel * 1000, _game.World.Up); _playerOwner = shooter; _moveType = MOVETYPE.FLY; Weapon = weapon; _damage = shooter.ActiveWeapon.Damage; _speed = shooter.ActiveWeapon.Speed; _particleScene = (PackedScene)ResourceLoader.Load(_particleResource); }
void OnRenderObject() { if (lines < 1) { lines = 1; } if (ScaleOption && ShowColOutlineDuringScale) { TurnOnOutline(); } if (RotationOption && ShowColOutlineDuringRotate) { TurnOnOutline(); } if (TransformationOption && ShowColOutlineDurtingTransform) { TurnOnOutline(); } if(SelectedType==MOVETYPE.NONE){ NothingSelected(); } if(!Input.GetMouseButton(0)){ SelectedType=MOVETYPE.NONE; if( SelectedType==MOVETYPE.NONE){ RenderGizmos(); } } planeXZ.SetNormalAndPosition(Item.transform.up,Item.transform.position); planeXY.SetNormalAndPosition(Item.transform.forward,Item.transform.position); planeYZ.SetNormalAndPosition(Item.transform.right,Item.transform.position); Ray ray=Camera.main.ScreenPointToRay(Input.mousePosition); float enter=0.0f; float rlens=0.0f; planeXZ.Raycast(ray,out enter); Vector3 hit=ray.GetPoint(enter); if (SelectedType == MOVETYPE.RY) { hit = locklocalToWorldMatrix.inverse.MultiplyPoint (hit); } else {hit = rotationMatrix.inverse.MultiplyPoint (hit);} if(TransformationOption ){ if(SelectedType==MOVETYPE.NONE&& hit.x>0f && hit.x<=0.3f*SetSpread && hit.z>0 && hit.z<=0.3f*SetSpread){ panY=SelectedColor; SelectedType=MOVETYPE.XZ; MouseDown=hit; } if(SelectedType==MOVETYPE.XZ && ( Input.GetAxis("Mouse X")!=0f || Input.GetAxis("Mouse Y")!=0f) ){ Drag=hit-MouseDown; Drag.y=0; Item.transform.position+=Item.transform.localRotation*Drag; } if(SelectedType==MOVETYPE.NONE && hit.x>0f && hit.x<=SetSpread && Mathf.Abs(hit.z)<SelectedSencsitivity ){ //case x selX=SelectedColor; SelectedType=MOVETYPE.X; MouseDown=hit; } if(SelectedType==MOVETYPE.X && ( Input.GetAxis("Mouse X")!=0f || Input.GetAxis("Mouse Y")!=0f)){ Drag=hit-MouseDown; Drag.y=0; Drag.z=0; Item.transform.position+=Item.transform.localRotation*Drag; } if(SelectedType==MOVETYPE.NONE && hit.z>0f && hit.z<=SetSpread && Mathf.Abs(hit.x)<SelectedSencsitivity ){//case z selZ=SelectedColor; SelectedType=MOVETYPE.Z; MouseDown=hit; } if(SelectedType==MOVETYPE.Z && ( Input.GetAxis("Mouse X")!=0f || Input.GetAxis("Mouse Y")!=0f)){ Drag=hit-MouseDown; Drag.y=0; Drag.x=0; Item.transform.position+=Item.transform.localRotation*Drag; } } //TransformationOption end if(ScaleOption){ if(SelectedType==MOVETYPE.NONE&& hit.x>0f && hit.x<=0.3f*SetSpread && hit.z>0 && hit.z<=0.3f*SetSpread && hit.x+hit.z-0.3f*SetSpread<=0f){ panY=SelectedColor; SelectedType=MOVETYPE.TXZ; MouseDown=hit; } if(SelectedType==MOVETYPE.TXZ && ( Input.GetAxis("Mouse X")!=0f || Input.GetAxis("Mouse Y")!=0f) ){ Drag=hit-MouseDown; Drag.y=0; float dm = Drag.x+Drag.z; float dchg= (int)((dm)*10)/10f; Item.transform.localScale=CurrentScale+ new Vector3(dchg,0,dchg); } if(SelectedType==MOVETYPE.NONE && hit.x>0f && hit.x<=SetSpread && Mathf.Abs(hit.z)<SelectedSencsitivity ){ //case x selX=SelectedColor; SelectedType=MOVETYPE.TX; MouseDown=hit; } if(SelectedType==MOVETYPE.TX && ( Input.GetAxis("Mouse X")!=0f || Input.GetAxis("Mouse Y")!=0f)){ Drag=hit-MouseDown; Drag.y=0; Drag.z=0; float dm = Drag.x; float dchg= (int)((dm)*10)/10f; Item.transform.localScale=CurrentScale+ new Vector3(dchg,0,0); } if(SelectedType==MOVETYPE.NONE && hit.z>0f && hit.z<=SetSpread && Mathf.Abs(hit.x)<SelectedSencsitivity ){//case z selZ=SelectedColor; SelectedType=MOVETYPE.TZ; MouseDown=hit; } if(SelectedType==MOVETYPE.TZ && ( Input.GetAxis("Mouse X")!=0f || Input.GetAxis("Mouse Y")!=0f)){ Drag=hit-MouseDown; Drag.y=0; Drag.x=0; float dm = Drag.z; float dchg= (int)((dm)*10)/10f; Item.transform.localScale=CurrentScale+ new Vector3(0,0,dchg); }//ScaleOption end } rlens=(Mathf.Sqrt(hit.x*hit.x+hit.z*hit.z)/3) * distanceMovement; if(RotationOption){ if( Vector3.Dot(hit,uForward)>=.2f) if(SelectedType==MOVETYPE.NONE&& rlens>(1-(Sencsitivity*100) ) && rlens<((4+(Sencsitivity) )) ){ circleX=Color.red; circleY=Color.green; circleZ=Color.blue; circleY=SelectedColor; SelectedType=MOVETYPE.RY; MouseDown=hit; locklocalToWorldMatrix=rotationMatrix; rotaCal=0.0f; } if(SelectedType==MOVETYPE.RY ){ //rotate y Drag= hit; float angledown =Vector3.Dot(MouseDown.normalized, Vector3.right); float anglemove =Vector3.Dot(Drag.normalized, Vector3.right); float angledeta =Vector3.Dot(MouseDown.normalized,Drag.normalized); angledown= SnapDot(angledown,MouseDown.x,MouseDown.z); anglemove= SnapDot(anglemove,Drag.x,Drag.z); angledeta=Mathf.Acos(angledeta); if(angledown==anglemove){ RenderGizmos(); return;} float judge=angledown+Mathf.PI; if(judge>2*Mathf.PI){ if(anglemove>=0f && anglemove<=judge-2*Mathf.PI || anglemove>angledown){ } else angledeta=-angledeta; }else{ if(anglemove>=angledown && anglemove<=judge){ } else angledeta=-angledeta; } rotaCal=angledeta-rotaCal; DrawCam(Color.white,angledown,angledeta,MOVETYPE.Y); if(NeedContactToTurn == true){ Item.transform.Rotate(new Vector3(0,-rotaCal,0)*RotationSpeed); }else{ Item.transform.Rotate(Vector3.up*(-Input.GetAxis("Mouse X")+Input.GetAxis("Mouse Y"))*(RotationSpeed/2)); } rotaCal=angledeta; } }//RotationOption end enter=0.0f; planeXY.Raycast(ray,out enter); hit=ray.GetPoint(enter); if(SelectedType==MOVETYPE.RZ){ hit=locklocalToWorldMatrix.inverse.MultiplyPoint(hit); } else hit=rotationMatrix.inverse.MultiplyPoint(hit); if(TransformationOption){ if(SelectedType==MOVETYPE.NONE&&hit.x>0f && hit.x<=0.3f*SetSpread && hit.y>0 && hit.y<=0.3f*SetSpread){ panZ=SelectedColor; SelectedType=MOVETYPE.XY; MouseDown=hit; } if(SelectedType==MOVETYPE.XY ){ Drag=hit-MouseDown; Drag.z=0; Item.transform.position+=Item.transform.localRotation*Drag; } if(SelectedType==MOVETYPE.NONE && hit.x>0f && hit.x<=SetSpread && Mathf.Abs(hit.y)<SelectedSencsitivity ){ //case x selX=SelectedColor; SelectedType=MOVETYPE.X2; MouseDown=hit; } if(SelectedType==MOVETYPE.X2 && ( Input.GetAxis("Mouse X")!=0f || Input.GetAxis("Mouse Y")!=0f)){ Drag=hit-MouseDown; Drag.y=0; Drag.z=0; Item.transform.position+=Item.transform.localRotation*Drag; } if(SelectedType==MOVETYPE.NONE && hit.y>0f && hit.y<=SetSpread && Mathf.Abs(hit.x)<SelectedSencsitivity){ //case y selY=SelectedColor; SelectedType=MOVETYPE.Y; MouseDown=hit; } if(SelectedType==MOVETYPE.Y && ( Input.GetAxis("Mouse X")!=0f || Input.GetAxis("Mouse Y")!=0f)){ Drag=hit-MouseDown; Drag.z=0; Drag.x=0; Item.transform.position+=Item.transform.localRotation*Drag; } }//TransformationOption end if(ScaleOption){ if(SelectedType==MOVETYPE.NONE&&hit.x>0f && hit.x<=0.3f*SetSpread && hit.y>0 && hit.y<=0.3f*SetSpread&& hit.x+hit.y-0.3f*SetSpread<=0f){ panZ=SelectedColor; SelectedType=MOVETYPE.TXY; MouseDown=hit; } if(SelectedType==MOVETYPE.TXY ){ Drag=hit-MouseDown; Drag.z=0; float dm = Drag.x+Drag.y; float dchg= (int)((dm)*10)/10f; Item.transform.localScale=CurrentScale+ new Vector3(dchg,dchg,0f); } if(SelectedType==MOVETYPE.NONE && hit.x>0f && hit.x<=SetSpread && Mathf.Abs(hit.y)<SelectedSencsitivity){ //case x selX=SelectedColor; SelectedType=MOVETYPE.TX2; MouseDown=hit; } if(SelectedType==MOVETYPE.TX2 && ( Input.GetAxis("Mouse X")!=0f || Input.GetAxis("Mouse Y")!=0f)){ Drag=hit-MouseDown; Drag.y=0; Drag.z=0; float dm = Drag.x; float dchg= (int)((dm)*10)/10f; Item.transform.localScale=CurrentScale+ new Vector3(dchg,0,0); } if(SelectedType==MOVETYPE.NONE && hit.y>0f && hit.y<=SetSpread && Mathf.Abs(hit.x)<SelectedSencsitivity){ //case y selY=SelectedColor; SelectedType=MOVETYPE.TY; MouseDown=hit; } if(SelectedType==MOVETYPE.TY && ( Input.GetAxis("Mouse X")!=0f || Input.GetAxis("Mouse Y")!=0f)){ Drag=hit-MouseDown; Drag.z=0; Drag.x=0; float dm = Drag.y; float dchg= (int)((dm)*10)/10f; Item.transform.localScale=CurrentScale+ new Vector3(0,dchg,0); } }//ScaleOption end rlens=(Mathf.Sqrt(hit.x*hit.x+hit.y*hit.y)/3) * distanceMovement; if(RotationOption){ if( Vector3.Dot(hit,fForward)>=.2f) if(SelectedType==MOVETYPE.NONE&& rlens>(1-(Sencsitivity*100) )&& rlens<((4+Sencsitivity )) ){ circleX=Color.red; circleY=Color.green; circleZ=Color.blue; circleZ=SelectedColor; SelectedType=MOVETYPE.RZ; MouseDown=hit; locklocalToWorldMatrix=rotationMatrix; rotaCal=0.0f; } if(SelectedType==MOVETYPE.RZ ){ Drag= hit; float angledown =Vector3.Dot(MouseDown.normalized, Vector3.up); float anglemove =Vector3.Dot(Drag.normalized, Vector3.up); float angledeta =Vector3.Dot(MouseDown.normalized,Drag.normalized); angledown= SnapDot(angledown,MouseDown.y,MouseDown.x); anglemove= SnapDot(anglemove,Drag.y,Drag.x); angledeta=Mathf.Acos(angledeta); if(angledown==anglemove){ RenderGizmos(); return;} float judge=angledown+Mathf.PI; if(judge>2*Mathf.PI){ if(anglemove>=0f && anglemove<=judge-2*Mathf.PI || anglemove>angledown){ } else angledeta=-angledeta; }else{ if(anglemove>=angledown && anglemove<=judge){ } else angledeta=-angledeta; } rotaCal=angledeta-rotaCal; DrawCam(Color.white,angledown,angledeta,MOVETYPE.Z); if(NeedContactToTurn == true){ Item.transform.Rotate(new Vector3(0,0,-rotaCal)*RotationSpeed); }else{ Item.transform.Rotate(Vector3.forward*(-Input.GetAxis("Mouse X")+Input.GetAxis("Mouse Y"))*RotationSpeed); } rotaCal=angledeta; } }//RotationOption end enter=0.0f; planeYZ.Raycast(ray,out enter); hit=ray.GetPoint(enter); if(SelectedType==MOVETYPE.RX){ hit=locklocalToWorldMatrix.inverse.MultiplyPoint(hit); } else hit=rotationMatrix.inverse.MultiplyPoint(hit); if(TransformationOption){ if(SelectedType==MOVETYPE.NONE&& hit.z>0 && hit.z<=0.3f*SetSpread && hit.y>0 && hit.y<=0.3f*SetSpread ){ panX=SelectedColor; SelectedType=MOVETYPE.YZ; MouseDown=hit; } if(SelectedType==MOVETYPE.YZ){ Drag=hit-MouseDown; Drag.x=0; Item.transform.position+=Item.transform.localRotation*Drag; } if(SelectedType==MOVETYPE.NONE && hit.z>0f && hit.z<=SetSpread && Mathf.Abs(hit.y)<SelectedSencsitivity*SetSpread){//case z selZ=SelectedColor; SelectedType=MOVETYPE.Z2; MouseDown=hit; } if(SelectedType==MOVETYPE.Z2 && ( Input.GetAxis("Mouse X")!=0f || Input.GetAxis("Mouse Y")!=0f)){ Drag=hit-MouseDown; Drag.y=0; Drag.x=0; Item.transform.position+=Item.transform.localRotation*Drag; } if(SelectedType==MOVETYPE.NONE && hit.y>0f && hit.y<=SetSpread && Mathf.Abs(hit.z)<SelectedSencsitivity*SetSpread ){ //case y selY=SelectedColor; SelectedType=MOVETYPE.Y2; MouseDown=hit; } if(SelectedType==MOVETYPE.Y2 && ( Input.GetAxis("Mouse X")!=0f || Input.GetAxis("Mouse Y")!=0f)){ Drag=hit-MouseDown; Drag.z=0; Drag.x=0; Item.transform.position+=Item.transform.localRotation*Drag; } }//TransformationOption end if(ScaleOption){ if(SelectedType==MOVETYPE.NONE&& hit.z>0 && hit.z<=0.3f*SetSpread && hit.y>0 && hit.y<=0.3f*SetSpread && hit.y+hit.z-0.3f*SetSpread<=0f){ panX=SelectedColor; SelectedType=MOVETYPE.TYZ; MouseDown=hit; } if(SelectedType==MOVETYPE.TYZ){ Drag=hit-MouseDown; Drag.x=0; float dm = Drag.z+Drag.y; float dchg= (int)((dm)*10)/10f; Item.transform.localScale=CurrentScale+ new Vector3(0,dchg,dchg); } if(SelectedType==MOVETYPE.NONE && hit.z>0f && hit.z<=SetSpread && Mathf.Abs(hit.y)<SelectedSencsitivity*SetSpread){//case z selZ=SelectedColor; SelectedType=MOVETYPE.TZ2; MouseDown=hit; } if(SelectedType==MOVETYPE.TZ2 && ( Input.GetAxis("Mouse X")!=0f || Input.GetAxis("Mouse Y")!=0f)){ Drag=hit-MouseDown; Drag.y=0; Drag.x=0; float dm = Drag.z; float dchg= (int)((dm)*10)/10f; Item.transform.localScale=CurrentScale+ new Vector3(0,0,dchg); } if(SelectedType==MOVETYPE.NONE && hit.y>0f && hit.y<=SetSpread && Mathf.Abs(hit.z)<SelectedSencsitivity*SetSpread ){ //case y selY=SelectedColor; SelectedType=MOVETYPE.TY2; MouseDown=hit; } if(SelectedType==MOVETYPE.TY2 && ( Input.GetAxis("Mouse X")!=0f || Input.GetAxis("Mouse Y")!=0f)){ Drag=hit-MouseDown; Drag.z=0; Drag.x=0; float dm = Drag.y; float dchg= (int)((dm)*10)/10f; Item.transform.localScale=CurrentScale+ new Vector3(0,dchg,0); } }//ScaleOption end rlens=(Mathf.Sqrt(hit.z*hit.z+hit.y*hit.y)/3) * distanceMovement; if(RotationOption){ if( Vector3.Dot(hit,rForward)>=.2f) if(SelectedType==MOVETYPE.NONE&& rlens>(1-(Sencsitivity*100) )&& (rlens<((4+Sencsitivity ))) ){ circleX=Color.red; circleY=Color.green; circleZ=Color.blue; circleX=SelectedColor; SelectedType=MOVETYPE.RX; MouseDown=hit; locklocalToWorldMatrix=rotationMatrix; rotaCal=0.0f; } if(SelectedType==MOVETYPE.RX ){ Drag= hit; float angledown =Vector3.Dot(MouseDown.normalized, Vector3.forward); float anglemove =Vector3.Dot(Drag.normalized, Vector3.forward); float angledeta =Vector3.Dot(MouseDown.normalized,Drag.normalized); angledown= SnapDot(angledown,MouseDown.z,MouseDown.y); anglemove= SnapDot(anglemove,Drag.z,Drag.y); angledeta=Mathf.Acos(angledeta); if(angledown==anglemove){ RenderGizmos();} else{ float judge=angledown+Mathf.PI; if(judge>2*Mathf.PI){ if(anglemove>=0f && anglemove<=judge-2*Mathf.PI || anglemove>angledown){ } else angledeta=-angledeta; }else{ if(anglemove>=angledown && anglemove<=judge){ } else angledeta=-angledeta; } rotaCal=angledeta-rotaCal; DrawCam(Color.white,angledown,angledeta,MOVETYPE.X); if(NeedContactToTurn == true){ Item.transform.Rotate( new Vector3(-rotaCal,0,0)*RotationSpeed); }else{ Item.transform.Rotate(Vector3.right*(Input.GetAxis("Mouse X")+Input.GetAxis("Mouse Y"))*RotationSpeed); } rotaCal=angledeta; } } }//RotationOption end RenderGizmos(); }
void DrawCam(Color col, float sang,float eng ,MOVETYPE dtype) { GL.PushMatrix(); rotationMatrix = locklocalToWorldMatrix; GL.MultMatrix(rotationMatrix); lineMaterial.SetPass(0); GL.Begin(GL.TRIANGLES); GL.Color(col); float ang; switch(dtype){ case MOVETYPE.X: for(int i=0;i<20;i++){ ang=sang+(eng)*i/20; GL.Vertex3(0,0,0); GL.Vertex3( 0,Mathf.Sin(ang)*SetSpread,Mathf.Cos(ang)*SetSpread); ang=sang+(eng)*(i+1)/20; GL.Vertex3( 0,Mathf.Sin(ang)*SetSpread,Mathf.Cos(ang)*SetSpread); } break; case MOVETYPE.Y: for(int i=0;i<20;i++){ ang=sang+(eng)*i/20; GL.Vertex3(0,0,0); GL.Vertex3( Mathf.Cos(ang)*SetSpread,0,Mathf.Sin(ang)*SetSpread); ang=sang+(eng)*(i+1)/20; GL.Vertex3( Mathf.Cos(ang)*SetSpread,0,Mathf.Sin(ang)*SetSpread); } break; case MOVETYPE.Z: for(int i=0;i<20;i++){ ang=sang+(eng)*i/20; GL.Vertex3(0,0,0); GL.Vertex3( Mathf.Sin(ang)*SetSpread,Mathf.Cos(ang)*SetSpread,0); ang=sang+(eng)*(i+1)/20; GL.Vertex3( Mathf.Sin(ang)*SetSpread,Mathf.Cos(ang)*SetSpread,0); } break; } GL.End(); GL.PopMatrix(); }
void OnRenderObject() { if (lines < 1) { lines = 1; } if (ScaleOption && ShowColOutlineDuringScale) { TurnOnOutline(); } if (RotationOption && ShowColOutlineDuringRotate) { TurnOnOutline(); } if (TransformationOption && ShowColOutlineDurtingTransform) { TurnOnOutline(); } if (SelectedType == MOVETYPE.NONE) { NothingSelected(); } if (!Input.GetMouseButton(0)) { SelectedType = MOVETYPE.NONE; if (SelectedType == MOVETYPE.NONE) { RenderGizmos(); } } planeXZ.SetNormalAndPosition(transform.up, transform.position); planeXY.SetNormalAndPosition(transform.forward, transform.position); planeYZ.SetNormalAndPosition(transform.right, transform.position); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); float enter = 0.0f; float rlens = 0.0f; planeXZ.Raycast(ray, out enter); Vector3 hit = ray.GetPoint(enter); if (SelectedType == MOVETYPE.RY) { hit = locklocalToWorldMatrix.inverse.MultiplyPoint(hit); } else { hit = rotationMatrix.inverse.MultiplyPoint(hit); } if (TransformationOption) { if (SelectedType == MOVETYPE.NONE && hit.x > 0f && hit.x <= 0.3f * SetSpread && hit.z > 0 && hit.z <= 0.3f * SetSpread) { panY = SelectedColor; SelectedType = MOVETYPE.XZ; MouseDown = hit; } if (SelectedType == MOVETYPE.XZ && (Input.GetAxis("Mouse X") != 0f || Input.GetAxis("Mouse Y") != 0f)) { Drag = hit - MouseDown; Drag.y = 0; transform.position += transform.localRotation * Drag; } if (SelectedType == MOVETYPE.NONE && hit.x > 0f && hit.x <= SetSpread && Mathf.Abs(hit.z) < SelectedSencsitivity) //case x { selX = SelectedColor; SelectedType = MOVETYPE.X; MouseDown = hit; } if (SelectedType == MOVETYPE.X && (Input.GetAxis("Mouse X") != 0f || Input.GetAxis("Mouse Y") != 0f)) { Drag = hit - MouseDown; Drag.y = 0; Drag.z = 0; transform.position += transform.localRotation * Drag; } if (SelectedType == MOVETYPE.NONE && hit.z > 0f && hit.z <= SetSpread && Mathf.Abs(hit.x) < SelectedSencsitivity)//case z { selZ = SelectedColor; SelectedType = MOVETYPE.Z; MouseDown = hit; } if (SelectedType == MOVETYPE.Z && (Input.GetAxis("Mouse X") != 0f || Input.GetAxis("Mouse Y") != 0f)) { Drag = hit - MouseDown; Drag.y = 0; Drag.x = 0; transform.position += transform.localRotation * Drag; } } //TransformationOption end if (ScaleOption) { if (SelectedType == MOVETYPE.NONE && hit.x > 0f && hit.x <= 0.3f * SetSpread && hit.z > 0 && hit.z <= 0.3f * SetSpread && hit.x + hit.z - 0.3f * SetSpread <= 0f) { panY = SelectedColor; SelectedType = MOVETYPE.TXZ; MouseDown = hit; } if (SelectedType == MOVETYPE.TXZ && (Input.GetAxis("Mouse X") != 0f || Input.GetAxis("Mouse Y") != 0f)) { Drag = hit - MouseDown; Drag.y = 0; float dm = Drag.x + Drag.z; float dchg = (int)((dm) * 10) / 10f; transform.localScale = CurrentScale + new Vector3(dchg, 0, dchg); } if (SelectedType == MOVETYPE.NONE && hit.x > 0f && hit.x <= SetSpread && Mathf.Abs(hit.z) < SelectedSencsitivity) //case x { selX = SelectedColor; SelectedType = MOVETYPE.TX; MouseDown = hit; } if (SelectedType == MOVETYPE.TX && (Input.GetAxis("Mouse X") != 0f || Input.GetAxis("Mouse Y") != 0f)) { Drag = hit - MouseDown; Drag.y = 0; Drag.z = 0; float dm = Drag.x; float dchg = (int)((dm) * 10) / 10f; transform.localScale = CurrentScale + new Vector3(dchg, 0, 0); } if (SelectedType == MOVETYPE.NONE && hit.z > 0f && hit.z <= SetSpread && Mathf.Abs(hit.x) < SelectedSencsitivity)//case z { selZ = SelectedColor; SelectedType = MOVETYPE.TZ; MouseDown = hit; } if (SelectedType == MOVETYPE.TZ && (Input.GetAxis("Mouse X") != 0f || Input.GetAxis("Mouse Y") != 0f)) { Drag = hit - MouseDown; Drag.y = 0; Drag.x = 0; float dm = Drag.z; float dchg = (int)((dm) * 10) / 10f; transform.localScale = CurrentScale + new Vector3(0, 0, dchg); } //ScaleOption end } rlens = (Mathf.Sqrt(hit.x * hit.x + hit.z * hit.z) / 3) * distanceMovement; if (RotationOption) { if (Vector3.Dot(hit, uForward) >= .2f) { if (SelectedType == MOVETYPE.NONE && rlens > (1 - (Sencsitivity * 100)) && rlens < ((4 + (Sencsitivity)))) { circleX = Color.red; circleY = Color.green; circleZ = Color.blue; circleY = SelectedColor; SelectedType = MOVETYPE.RY; MouseDown = hit; locklocalToWorldMatrix = rotationMatrix; rotaCal = 0.0f; } } if (SelectedType == MOVETYPE.RY) //rotate y { Drag = hit; float angledown = Vector3.Dot(MouseDown.normalized, Vector3.right); float anglemove = Vector3.Dot(Drag.normalized, Vector3.right); float angledeta = Vector3.Dot(MouseDown.normalized, Drag.normalized); angledown = SnapDot(angledown, MouseDown.x, MouseDown.z); anglemove = SnapDot(anglemove, Drag.x, Drag.z); angledeta = Mathf.Acos(angledeta); if (angledown == anglemove) { RenderGizmos(); return; } float judge = angledown + Mathf.PI; if (judge > 2 * Mathf.PI) { if (anglemove >= 0f && anglemove <= judge - 2 * Mathf.PI || anglemove > angledown) { } else { angledeta = -angledeta; } } else { if (anglemove >= angledown && anglemove <= judge) { } else { angledeta = -angledeta; } } rotaCal = angledeta - rotaCal; DrawCam(Color.white, angledown, angledeta, MOVETYPE.Y); if (NeedContactToTurn == true) { transform.Rotate(new Vector3(0, -rotaCal, 0) * RotationSpeed); } else { transform.Rotate(Vector3.up * (-Input.GetAxis("Mouse X") + Input.GetAxis("Mouse Y")) * (RotationSpeed / 2)); } rotaCal = angledeta; } } //RotationOption end enter = 0.0f; planeXY.Raycast(ray, out enter); hit = ray.GetPoint(enter); if (SelectedType == MOVETYPE.RZ) { hit = locklocalToWorldMatrix.inverse.MultiplyPoint(hit); } else { hit = rotationMatrix.inverse.MultiplyPoint(hit); } if (TransformationOption) { if (SelectedType == MOVETYPE.NONE && hit.x > 0f && hit.x <= 0.3f * SetSpread && hit.y > 0 && hit.y <= 0.3f * SetSpread) { panZ = SelectedColor; SelectedType = MOVETYPE.XY; MouseDown = hit; } if (SelectedType == MOVETYPE.XY) { Drag = hit - MouseDown; Drag.z = 0; transform.position += transform.localRotation * Drag; } if (SelectedType == MOVETYPE.NONE && hit.x > 0f && hit.x <= SetSpread && Mathf.Abs(hit.y) < SelectedSencsitivity) //case x { selX = SelectedColor; SelectedType = MOVETYPE.X2; MouseDown = hit; } if (SelectedType == MOVETYPE.X2 && (Input.GetAxis("Mouse X") != 0f || Input.GetAxis("Mouse Y") != 0f)) { Drag = hit - MouseDown; Drag.y = 0; Drag.z = 0; transform.position += transform.localRotation * Drag; } if (SelectedType == MOVETYPE.NONE && hit.y > 0f && hit.y <= SetSpread && Mathf.Abs(hit.x) < SelectedSencsitivity) //case y { selY = SelectedColor; SelectedType = MOVETYPE.Y; MouseDown = hit; } if (SelectedType == MOVETYPE.Y && (Input.GetAxis("Mouse X") != 0f || Input.GetAxis("Mouse Y") != 0f)) { Drag = hit - MouseDown; Drag.z = 0; Drag.x = 0; transform.position += transform.localRotation * Drag; } } //TransformationOption end if (ScaleOption) { if (SelectedType == MOVETYPE.NONE && hit.x > 0f && hit.x <= 0.3f * SetSpread && hit.y > 0 && hit.y <= 0.3f * SetSpread && hit.x + hit.y - 0.3f * SetSpread <= 0f) { panZ = SelectedColor; SelectedType = MOVETYPE.TXY; MouseDown = hit; } if (SelectedType == MOVETYPE.TXY) { Drag = hit - MouseDown; Drag.z = 0; float dm = Drag.x + Drag.y; float dchg = (int)((dm) * 10) / 10f; transform.localScale = CurrentScale + new Vector3(dchg, dchg, 0f); } if (SelectedType == MOVETYPE.NONE && hit.x > 0f && hit.x <= SetSpread && Mathf.Abs(hit.y) < SelectedSencsitivity) //case x { selX = SelectedColor; SelectedType = MOVETYPE.TX2; MouseDown = hit; } if (SelectedType == MOVETYPE.TX2 && (Input.GetAxis("Mouse X") != 0f || Input.GetAxis("Mouse Y") != 0f)) { Drag = hit - MouseDown; Drag.y = 0; Drag.z = 0; float dm = Drag.x; float dchg = (int)((dm) * 10) / 10f; transform.localScale = CurrentScale + new Vector3(dchg, 0, 0); } if (SelectedType == MOVETYPE.NONE && hit.y > 0f && hit.y <= SetSpread && Mathf.Abs(hit.x) < SelectedSencsitivity) //case y { selY = SelectedColor; SelectedType = MOVETYPE.TY; MouseDown = hit; } if (SelectedType == MOVETYPE.TY && (Input.GetAxis("Mouse X") != 0f || Input.GetAxis("Mouse Y") != 0f)) { Drag = hit - MouseDown; Drag.z = 0; Drag.x = 0; float dm = Drag.y; float dchg = (int)((dm) * 10) / 10f; transform.localScale = CurrentScale + new Vector3(0, dchg, 0); } } //ScaleOption end rlens = (Mathf.Sqrt(hit.x * hit.x + hit.y * hit.y) / 3) * distanceMovement; if (RotationOption) { if (Vector3.Dot(hit, fForward) >= .2f) { if (SelectedType == MOVETYPE.NONE && rlens > (1 - (Sencsitivity * 100)) && rlens < ((4 + Sencsitivity))) { circleX = Color.red; circleY = Color.green; circleZ = Color.blue; circleZ = SelectedColor; SelectedType = MOVETYPE.RZ; MouseDown = hit; locklocalToWorldMatrix = rotationMatrix; rotaCal = 0.0f; } } if (SelectedType == MOVETYPE.RZ) { Drag = hit; float angledown = Vector3.Dot(MouseDown.normalized, Vector3.up); float anglemove = Vector3.Dot(Drag.normalized, Vector3.up); float angledeta = Vector3.Dot(MouseDown.normalized, Drag.normalized); angledown = SnapDot(angledown, MouseDown.y, MouseDown.x); anglemove = SnapDot(anglemove, Drag.y, Drag.x); angledeta = Mathf.Acos(angledeta); if (angledown == anglemove) { RenderGizmos(); return; } float judge = angledown + Mathf.PI; if (judge > 2 * Mathf.PI) { if (anglemove >= 0f && anglemove <= judge - 2 * Mathf.PI || anglemove > angledown) { } else { angledeta = -angledeta; } } else { if (anglemove >= angledown && anglemove <= judge) { } else { angledeta = -angledeta; } } rotaCal = angledeta - rotaCal; DrawCam(Color.white, angledown, angledeta, MOVETYPE.Z); if (NeedContactToTurn == true) { transform.Rotate(new Vector3(0, 0, -rotaCal) * RotationSpeed); } else { transform.Rotate(Vector3.forward * (-Input.GetAxis("Mouse X") + Input.GetAxis("Mouse Y")) * RotationSpeed); } rotaCal = angledeta; } } //RotationOption end enter = 0.0f; planeYZ.Raycast(ray, out enter); hit = ray.GetPoint(enter); if (SelectedType == MOVETYPE.RX) { hit = locklocalToWorldMatrix.inverse.MultiplyPoint(hit); } else { hit = rotationMatrix.inverse.MultiplyPoint(hit); } if (TransformationOption) { if (SelectedType == MOVETYPE.NONE && hit.z > 0 && hit.z <= 0.3f * SetSpread && hit.y > 0 && hit.y <= 0.3f * SetSpread) { panX = SelectedColor; SelectedType = MOVETYPE.YZ; MouseDown = hit; } if (SelectedType == MOVETYPE.YZ) { Drag = hit - MouseDown; Drag.x = 0; transform.position += transform.localRotation * Drag; } if (SelectedType == MOVETYPE.NONE && hit.z > 0f && hit.z <= SetSpread && Mathf.Abs(hit.y) < SelectedSencsitivity * SetSpread)//case z { selZ = SelectedColor; SelectedType = MOVETYPE.Z2; MouseDown = hit; } if (SelectedType == MOVETYPE.Z2 && (Input.GetAxis("Mouse X") != 0f || Input.GetAxis("Mouse Y") != 0f)) { Drag = hit - MouseDown; Drag.y = 0; Drag.x = 0; transform.position += transform.localRotation * Drag; } if (SelectedType == MOVETYPE.NONE && hit.y > 0f && hit.y <= SetSpread && Mathf.Abs(hit.z) < SelectedSencsitivity * SetSpread) //case y { selY = SelectedColor; SelectedType = MOVETYPE.Y2; MouseDown = hit; } if (SelectedType == MOVETYPE.Y2 && (Input.GetAxis("Mouse X") != 0f || Input.GetAxis("Mouse Y") != 0f)) { Drag = hit - MouseDown; Drag.z = 0; Drag.x = 0; transform.position += transform.localRotation * Drag; } } //TransformationOption end if (ScaleOption) { if (SelectedType == MOVETYPE.NONE && hit.z > 0 && hit.z <= 0.3f * SetSpread && hit.y > 0 && hit.y <= 0.3f * SetSpread && hit.y + hit.z - 0.3f * SetSpread <= 0f) { panX = SelectedColor; SelectedType = MOVETYPE.TYZ; MouseDown = hit; } if (SelectedType == MOVETYPE.TYZ) { Drag = hit - MouseDown; Drag.x = 0; float dm = Drag.z + Drag.y; float dchg = (int)((dm) * 10) / 10f; transform.localScale = CurrentScale + new Vector3(0, dchg, dchg); } if (SelectedType == MOVETYPE.NONE && hit.z > 0f && hit.z <= SetSpread && Mathf.Abs(hit.y) < SelectedSencsitivity * SetSpread)//case z { selZ = SelectedColor; SelectedType = MOVETYPE.TZ2; MouseDown = hit; } if (SelectedType == MOVETYPE.TZ2 && (Input.GetAxis("Mouse X") != 0f || Input.GetAxis("Mouse Y") != 0f)) { Drag = hit - MouseDown; Drag.y = 0; Drag.x = 0; float dm = Drag.z; float dchg = (int)((dm) * 10) / 10f; transform.localScale = CurrentScale + new Vector3(0, 0, dchg); } if (SelectedType == MOVETYPE.NONE && hit.y > 0f && hit.y <= SetSpread && Mathf.Abs(hit.z) < SelectedSencsitivity * SetSpread) //case y { selY = SelectedColor; SelectedType = MOVETYPE.TY2; MouseDown = hit; } if (SelectedType == MOVETYPE.TY2 && (Input.GetAxis("Mouse X") != 0f || Input.GetAxis("Mouse Y") != 0f)) { Drag = hit - MouseDown; Drag.z = 0; Drag.x = 0; float dm = Drag.y; float dchg = (int)((dm) * 10) / 10f; transform.localScale = CurrentScale + new Vector3(0, dchg, 0); } } //ScaleOption end rlens = (Mathf.Sqrt(hit.z * hit.z + hit.y * hit.y) / 3) * distanceMovement; if (RotationOption) { if (Vector3.Dot(hit, rForward) >= .2f) { if (SelectedType == MOVETYPE.NONE && rlens > (1 - (Sencsitivity * 100)) && (rlens < ((4 + Sencsitivity)))) { circleX = Color.red; circleY = Color.green; circleZ = Color.blue; circleX = SelectedColor; SelectedType = MOVETYPE.RX; MouseDown = hit; locklocalToWorldMatrix = rotationMatrix; rotaCal = 0.0f; } } if (SelectedType == MOVETYPE.RX) { Drag = hit; float angledown = Vector3.Dot(MouseDown.normalized, Vector3.forward); float anglemove = Vector3.Dot(Drag.normalized, Vector3.forward); float angledeta = Vector3.Dot(MouseDown.normalized, Drag.normalized); angledown = SnapDot(angledown, MouseDown.z, MouseDown.y); anglemove = SnapDot(anglemove, Drag.z, Drag.y); angledeta = Mathf.Acos(angledeta); if (angledown == anglemove) { RenderGizmos(); } else { float judge = angledown + Mathf.PI; if (judge > 2 * Mathf.PI) { if (anglemove >= 0f && anglemove <= judge - 2 * Mathf.PI || anglemove > angledown) { } else { angledeta = -angledeta; } } else { if (anglemove >= angledown && anglemove <= judge) { } else { angledeta = -angledeta; } } rotaCal = angledeta - rotaCal; DrawCam(Color.white, angledown, angledeta, MOVETYPE.X); if (NeedContactToTurn == true) { transform.Rotate(new Vector3(-rotaCal, 0, 0) * RotationSpeed); } else { transform.Rotate(Vector3.right * (Input.GetAxis("Mouse X") + Input.GetAxis("Mouse Y")) * RotationSpeed); } rotaCal = angledeta; } } } //RotationOption end RenderGizmos(); }