Idle









How do I use Idle
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: PickupController.cs Copy
73     // Are we jumping? (Initiated with jump button and not grounded yet)
77     // Are we moving backwards (This locks the camera to not do a 180 degree spin)
81     // When did the user start walking (Used for going into trot after a while)
87     // the height we jumped from (Used to determine for how long to apply extra jump power after jumping.)
101     void Awake()
102     {
103         // PUN: automatically determine isControllable, if this GO has a PhotonView
104         PhotonView pv = this.gameObject.GetComponent();
105         if (pv != null)
106         {
107             isControllable = pv.isMine;
108
109             // The pickup demo assigns this GameObject as the PhotonPlayer.TagObject. This way, we can access this character (controller, position, etc) easily
110             if (this.AssignAsTagObject)
111             {
112                 pv.owner.TagObject = this.gameObject;
113             }
114
115             // please note: we change this setting on ANY PickupController if "DoRotate" is off. not only locally when it's "our" GameObject!
116             if (pv.observed is Transform && !DoRotate)
117             {
118                 pv.onSerializeTransformOption = OnSerializeTransform.OnlyPosition;
119             }
120         }
121
122
123         moveDirection = transform.TransformDirection(Vector3.forward);
124
125         _animation = GetComponent();
126         if (!_animation)
127             Debug.Log("The character you would like to control doesn't have animations. Moving her might look weird.");
128
129         if (!idleAnimation)
130         {
131             _animation = null;
132             Debug.Log("No idle animation found. Turning off animations.");
133         }
134         if (!walkAnimation)
135         {
136             _animation = null;
137             Debug.Log("No walk animation found. Turning off animations.");
138         }
139         if (!runAnimation)
140         {
141             _animation = null;
142             Debug.Log("No run animation found. Turning off animations.");
143         }
144         if (!jumpPoseAnimation && canJump)
145         {
146             _animation = null;
147             Debug.Log("No jump animation found and the character has canJump enabled. Turning off animations.");
148         }
149     }
File name: PickupController.cs Copy
151     void Update()
152     {
153         if (isControllable)
154         {
155             if (Input.GetButtonDown("Jump"))
156             {
157                 lastJumpButtonTime = Time.time;
158             }
159
160             UpdateSmoothedMovementDirection();
161
162             // Apply gravity
163             // - extra power jump modifies gravity
164             // - controlledDescent mode modifies gravity
165             ApplyGravity();
166
167             // Apply jumping logic
168             ApplyJumping();
169
170
171             // Calculate actual motion
172             Vector3 movement = moveDirection * moveSpeed + new Vector3(0, verticalSpeed, 0) + inAirVelocity;
173             movement *= Time.deltaTime;
174
175             //Debug.Log(movement.x.ToString("0.000") + ":" + movement.z.ToString("0.000"));
176
177             // Move the controller
178             CharacterController controller = GetComponent();
179             collisionFlags = controller.Move(movement);
180
181         }
182
183         // PUN: if a remote position is known, we smooth-move to it (being late(r) but smoother)
184         if (this.remotePosition != Vector3.zero)
185         {
186             transform.position = Vector3.Lerp(transform.position, this.remotePosition, Time.deltaTime * this.RemoteSmoothing);
187         }
188
189         velocity = (transform.position - lastPos)*25;
190
191         // ANIMATION sector
192         if (_animation)
193         {
194             if (_characterState == PickupCharacterState.Jumping)
195             {
196                 if (!jumpingReachedApex)
197                 {
198                     _animation[jumpPoseAnimation.name].speed = jumpAnimationSpeed;
199                     _animation[jumpPoseAnimation.name].wrapMode = WrapMode.ClampForever;
200                     _animation.CrossFade(jumpPoseAnimation.name);
201                 }
202                 else
203                 {
204                     _animation[jumpPoseAnimation.name].speed = -landAnimationSpeed;
205                     _animation[jumpPoseAnimation.name].wrapMode = WrapMode.ClampForever;
206                     _animation.CrossFade(jumpPoseAnimation.name);
207                 }
208             }
209             else
210             {
211                 if (_characterState == PickupCharacterState.Idle)
212                 {
213                     _animation.CrossFade(idleAnimation.name);
214                 }
215                 else if (_characterState == PickupCharacterState.Running)
216                 {
217                     _animation[runAnimation.name].speed = runMaxAnimationSpeed;
218                     if (this.isControllable)
219                     {
220                         _animation[runAnimation.name].speed = Mathf.Clamp(velocity.magnitude, 0.0f, runMaxAnimationSpeed);
221                     }
222                     _animation.CrossFade(runAnimation.name);
223                 }
224                 else if (_characterState == PickupCharacterState.Trotting)
225                 {
226                     _animation[walkAnimation.name].speed = trotMaxAnimationSpeed;
227                     if (this.isControllable)
228                     {
229                         _animation[walkAnimation.name].speed = Mathf.Clamp(velocity.magnitude, 0.0f, trotMaxAnimationSpeed);
230                     }
231                     _animation.CrossFade(walkAnimation.name);
232                 }
233                 else if (_characterState == PickupCharacterState.Walking)
234                 {
235                     _animation[walkAnimation.name].speed = walkMaxAnimationSpeed;
236                     if (this.isControllable)
237                     {
238                         _animation[walkAnimation.name].speed = Mathf.Clamp(velocity.magnitude, 0.0f, walkMaxAnimationSpeed);
239                     }
240                     _animation.CrossFade(walkAnimation.name);
241                 }
242
243                 if (_characterState != PickupCharacterState.Running)
244                 {
245                     _animation[runAnimation.name].time = 0.0f;
246                 }
247             }
248         }
249         // ANIMATION sector
250
251         // Set rotation to the move direction
252         if (IsGrounded())
253         {
254             // a specialty of this controller: you can disable rotation!
255             if (DoRotate)
256             {
257                 transform.rotation = Quaternion.LookRotation(moveDirection);
258             }
259         }
260         else
261         {
262             /* This causes choppy behaviour when colliding with SIDES
263              * Vector3 xzMove = velocity;
264             xzMove.y = 0;
265             if (xzMove.sqrMagnitude > 0.001f)
266             {
267                 transform.rotation = Quaternion.LookRotation(xzMove);
268             }*/
269         }
270
271         // We are in jump mode but just became grounded
272         if (IsGrounded())
273         {
274             lastGroundedTime = Time.time;
275             inAirVelocity = Vector3.zero;
276             if (jumping)
277             {
278                 jumping = false;
279                 SendMessage("DidLand", SendMessageOptions.DontRequireReceiver);
280             }
281         }
282
283         lastPos = transform.position;
284     }
File name: ThirdPersonController.cs Copy
71     // Are we jumping? (Initiated with jump button and not grounded yet)
75     // Are we moving backwards (This locks the camera to not do a 180 degree spin)
79     // When did the user start walking (Used for going into trot after a while)
85     // the height we jumped from (Used to determine for how long to apply extra jump power after jumping.)
92     void Awake()
93     {
94         moveDirection = transform.TransformDirection(Vector3.forward);
95
96         _animation = GetComponent();
97         if (!_animation)
98             Debug.Log("The character you would like to control doesn't have animations. Moving her might look weird.");
99
100         /*
101     public AnimationClip idleAnimation;
102     public AnimationClip walkAnimation;
103     public AnimationClip runAnimation;
104     public AnimationClip jumpPoseAnimation;
105         */
106         if (!idleAnimation)
107         {
108             _animation = null;
109             Debug.Log("No idle animation found. Turning off animations.");
110         }
111         if (!walkAnimation)
112         {
113             _animation = null;
114             Debug.Log("No walk animation found. Turning off animations.");
115         }
116         if (!runAnimation)
117         {
118             _animation = null;
119             Debug.Log("No run animation found. Turning off animations.");
120         }
121         if (!jumpPoseAnimation && canJump)
122         {
123             _animation = null;
124             Debug.Log("No jump animation found and the character has canJump enabled. Turning off animations.");
125         }
126
127     }
File name: GameplayController.cs Copy
198  void DistanceBetweenCannonAndBullet(){
199   GameObject[] bullet = GameObject.FindGameObjectsWithTag ("Player Bullet");
200   foreach (GameObject distanceToBullet in bullet) {
201    if (!distanceToBullet.transform.GetComponent ().isIdle) {
202     if (distanceToBullet.transform.position.x - player.position.x > distance) {
203      camera.isFollowing = true;
204      checkGameStatus = true;
205      timeSinceStartedShot = Time.time;
206      TimeSinceShot ();
207      camera.target = distanceToBullet.transform;
208     } else {
209      if(PlayerBullet() == 0){
210       camera.isFollowing = true;
211       checkGameStatus = true;
212       timeSinceStartedShot = Time.time;
213       TimeSinceShot ();
214       camera.target = distanceToBullet.transform;
215      }
216     }
217    }
218   }
219   /*if (GameObject.FindGameObjectWithTag ("Player Bullet") != null) {
220    if (!GameObject.FindGameObjectWithTag ("Player Bullet").transform.GetComponent ().isIdle) {
221     Transform distanceToBullet = GameObject.FindGameObjectWithTag ("Player Bullet").transform;
222     if (distanceToBullet.position.x - player.position.x > distance) {
223      camera.isFollowing = true;
224      checkGameStatus = true;
225      TimeSinceShot ();
226      camera.target = distanceToBullet;
227     }
228    }
229
230   }*/
231  }
File name: GameplayController.cs Copy
233  void TimeSinceShot(){
234   time += Time.deltaTime;
235   if (time > 3f) {
236    time = 0f;
237    GameObject.FindGameObjectWithTag ("Player Bullet").transform.GetComponent ().isIdle = true;
238   }
239
240  }
File name: Filters.cs Copy
15   public void SetAll(int nVal)
16   {
17    TopLeft = TopMid = TopRight = MidLeft = Pixel = MidRight = BottomLeft = BottomMid = BottomRight = nVal;
18   }
File name: Filters.cs Copy
114   public static bool Conv3x3(Bitmap b, ConvMatrix m)
115   {
116    // Avoid divide by zero errors
117    if (0 == m.Factor) return false;
118
119    Bitmap bSrc = (Bitmap)b.Clone();
120
121    // GDI+ still lies to us - the return format is BGR, NOT RGB.
122    BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
123    BitmapData bmSrc = bSrc.LockBits(new Rectangle(0, 0, bSrc.Width, bSrc.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
124
125    int stride = bmData.Stride;
126    int stride2 = stride * 2;
127    System.IntPtr Scan0 = bmData.Scan0;
128    System.IntPtr SrcScan0 = bmSrc.Scan0;
129
130    unsafe
131    {
132     byte * p = (byte *)(void *)Scan0;
133     byte * pSrc = (byte *)(void *)SrcScan0;
134
135     int nOffset = stride + 6 - b.Width*3;
136     int nWidth = b.Width - 2;
137     int nHeight = b.Height - 2;
138
139     int nPixel;
140
141     for(int y=0;y < nHeight;++y)
142     {
143      for(int x=0; x < nWidth; ++x )
144      {
145       nPixel = ( ( ( (pSrc[2] * m.TopLeft) + (pSrc[5] * m.TopMid) + (pSrc[8] * m.TopRight) +
146        (pSrc[2 + stride] * m.MidLeft) + (pSrc[5 + stride] * m.Pixel) + (pSrc[8 + stride] * m.MidRight) +
147        (pSrc[2 + stride2] * m.BottomLeft) + (pSrc[5 + stride2] * m.BottomMid) + (pSrc[8 + stride2] * m.BottomRight)) / m.Factor) + m.Offset);
148
149       if (nPixel < 0) nPixel = 0;
150       if (nPixel > 255) nPixel = 255;
151
152       p[5 + stride]= (byte)nPixel;
153
154       nPixel = ( ( ( (pSrc[1] * m.TopLeft) + (pSrc[4] * m.TopMid) + (pSrc[7] * m.TopRight) +
155        (pSrc[1 + stride] * m.MidLeft) + (pSrc[4 + stride] * m.Pixel) + (pSrc[7 + stride] * m.MidRight) +
156        (pSrc[1 + stride2] * m.BottomLeft) + (pSrc[4 + stride2] * m.BottomMid) + (pSrc[7 + stride2] * m.BottomRight)) / m.Factor) + m.Offset);
157
158       if (nPixel < 0) nPixel = 0;
159       if (nPixel > 255) nPixel = 255;
160
161       p[4 + stride] = (byte)nPixel;
162
163       nPixel = ( ( ( (pSrc[0] * m.TopLeft) + (pSrc[3] * m.TopMid) + (pSrc[6] * m.TopRight) +
164        (pSrc[0 + stride] * m.MidLeft) + (pSrc[3 + stride] * m.Pixel) + (pSrc[6 + stride] * m.MidRight) +
165        (pSrc[0 + stride2] * m.BottomLeft) + (pSrc[3 + stride2] * m.BottomMid) + (pSrc[6 + stride2] * m.BottomRight)) / m.Factor) + m.Offset);
166
167       if (nPixel < 0) nPixel = 0;
168       if (nPixel > 255) nPixel = 255;
169
170       p[3 + stride] = (byte)nPixel;
171
172       p += 3;
173       pSrc += 3;
174      }
175
176      p += nOffset;
177      pSrc += nOffset;
178     }
179    }
180
181    b.UnlockBits(bmData);
182    bSrc.UnlockBits(bmSrc);
183
184    return true;
185   }
File name: Filters.cs Copy
186   public static bool EmbossLaplacian(Bitmap b)
187   {
188    ConvMatrix m = new ConvMatrix();
189    m.SetAll(-1);
190    m.TopMid = m.MidLeft = m.MidRight = m.BottomMid = 0;
191    m.Pixel = 4;
192    m.Offset = 127;
193
194    return BitmapFilter.Conv3x3(b, m);
195   }
File name: Filters.cs Copy
196   public static bool EdgeDetectQuick(Bitmap b)
197   {
198    ConvMatrix m = new ConvMatrix();
199    m.TopLeft = m.TopMid = m.TopRight = -1;
200    m.MidLeft = m.Pixel = m.MidRight = 0;
201    m.BottomLeft = m.BottomMid = m.BottomRight = 1;
202
203    m.Offset = 127;
204
205    return BitmapFilter.Conv3x3(b, m);
206   }
File name: frmEnrollment.cs Copy
125   void FrmEnrollmentLoad(object sender, EventArgs e)
126   {
127    grabber = new Capture();
128             grabber.QueryFrame();
129             Application.Idle += new EventHandler(FrameGrabber);
130   }

Download file with original file name:Idle

Idle 106 lượt xem

Gõ tìm kiếm nhanh...