Beispiel #1
0
        IEnumerator TraverseSpecial(RichSpecial rs)
        {
            traversingSpecialPath = true;
            velocity = Vector3.zero;

            AnimationLink al = rs.nodeLink as AnimationLink;

            if (al == null)
            {
                Debug.LogError("Unhandled RichSpecial");
                yield break;
            }

            //Rotate character to face the correct direction
            while (!RotateTowards(rs.first.forward))
            {
                yield return(null);
            }

            //Reposition
            tr.parent.position = tr.position;

            tr.parent.rotation = tr.rotation;
            tr.localPosition   = Vector3.zero;
            tr.localRotation   = Quaternion.identity;

            //Set up animation speeds
            if (rs.reverse && al.reverseAnim)
            {
                anim[al.clip].speed          = -al.animSpeed;
                anim[al.clip].normalizedTime = 1;
                anim.Play(al.clip);
                anim.Sample();
            }
            else
            {
                anim[al.clip].speed = al.animSpeed;
                anim.Rewind(al.clip);
                anim.Play(al.clip);
            }

            //Fix required for animations in reverse direction
            tr.parent.position -= tr.position - tr.parent.position;

            //Wait for the animation to finish
            yield return(new WaitForSeconds(Mathf.Abs(anim[al.clip].length / al.animSpeed)));

            traversingSpecialPath = false;
            NextPart();

            //If a path completed during the time we traversed the special connection, we need to recalculate it
            if (delayUpdatePath)
            {
                delayUpdatePath = false;
                UpdatePath();
            }
        }
Beispiel #2
0
        protected virtual IEnumerator TraverseSpecial(RichSpecial rs)
        {
            this.traversingSpecialPath = true;
            this.velocity2D            = Vector3.zero;
            AnimationLink link = rs.nodeLink as AnimationLink;

            if (link == null)
            {
                Debug.LogError("Unhandled RichSpecial");
                yield break;
            }
            while (Vector2.Angle(this.movementPlane.ToPlane(this.rotationIn2D ? this.tr.up : this.tr.forward), this.movementPlane.ToPlane(rs.first.forward)) > 5f)
            {
                this.RotateTowards(this.movementPlane.ToPlane(rs.first.forward), this.rotationSpeed * Time.deltaTime);
                yield return(null);
            }
            this.tr.parent.position = this.tr.position;
            this.tr.parent.rotation = this.tr.rotation;
            this.tr.localPosition   = Vector3.zero;
            this.tr.localRotation   = Quaternion.identity;
            if (rs.reverse && link.reverseAnim)
            {
                this.anim[link.clip].speed          = -link.animSpeed;
                this.anim[link.clip].normalizedTime = 1f;
                this.anim.Play(link.clip);
                this.anim.Sample();
            }
            else
            {
                this.anim[link.clip].speed = link.animSpeed;
                this.anim.Rewind(link.clip);
                this.anim.Play(link.clip);
            }
            this.tr.parent.position -= this.tr.position - this.tr.parent.position;
            yield return(new WaitForSeconds(Mathf.Abs(this.anim[link.clip].length / link.animSpeed)));

            this.traversingSpecialPath = false;
            this.NextPart();
            if (this.delayUpdatePath)
            {
                this.delayUpdatePath = false;
                this.UpdatePath();
            }
            yield break;
            yield break;
        }
Beispiel #3
0
		private static Transform SearchRec(Transform tr, string name)
		{
			int childCount = tr.childCount;
			for (int i = 0; i < childCount; i++)
			{
				Transform child = tr.GetChild(i);
				if (child.name == name)
				{
					return child;
				}
				Transform transform = AnimationLink.SearchRec(child, name);
				if (transform != null)
				{
					return transform;
				}
			}
			return null;
		}
Beispiel #4
0
        private IEnumerator TraverseSpecial(RichSpecial rs)
        {
            this.traversingSpecialPath = true;
            this.velocity = Vector3.zero;
            AnimationLink al = rs.nodeLink as AnimationLink;

            if (al == null)
            {
                Debug.LogError("Unhandled RichSpecial");
                yield break;
            }
            while (!this.RotateTowards(rs.first.forward))
            {
                yield return(null);
            }
            this.tr.parent.position = this.tr.position;
            this.tr.parent.rotation = this.tr.rotation;
            this.tr.localPosition   = Vector3.zero;
            this.tr.localRotation   = Quaternion.identity;
            if (rs.reverse && al.reverseAnim)
            {
                this.anim[al.clip].speed          = -al.animSpeed;
                this.anim[al.clip].normalizedTime = 1f;
                this.anim.Play(al.clip);
                this.anim.Sample();
            }
            else
            {
                this.anim[al.clip].speed = al.animSpeed;
                this.anim.Rewind(al.clip);
                this.anim.Play(al.clip);
            }
            this.tr.parent.position -= this.tr.position - this.tr.parent.position;
            yield return(new WaitForSeconds(Mathf.Abs(this.anim[al.clip].length / al.animSpeed)));

            this.traversingSpecialPath = false;
            this.NextPart();
            if (this.delayUpdatePath)
            {
                this.delayUpdatePath = false;
                this.UpdatePath();
            }
            yield break;
        }
Beispiel #5
0
        public override void OnInspectorGUI()
        {
        #if UNITY_LE_4_3
            EditorGUIUtility.LookLikeInspector();
        #endif
            DrawDefaultInspector();

            AnimationLink script = target as AnimationLink;

            EditorGUI.BeginDisabledGroup(script.EndTransform == null);
            if (GUILayout.Button("Autoposition Endpoint"))
            {
                List <Vector3> buffer = Pathfinding.Util.ListPool <Vector3> .Claim();

                Vector3 endpos;
                script.CalculateOffsets(buffer, out endpos);
                script.EndTransform.position = endpos;
                Pathfinding.Util.ListPool <Vector3> .Release(buffer);
            }
            EditorGUI.EndDisabledGroup();
        }
Beispiel #6
0
        public void CalculateOffsets(List <Vector3> trace, out Vector3 endPosition)
        {
            endPosition = base.transform.position;
            if (this.referenceMesh == null)
            {
                return;
            }
            GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(this.referenceMesh, base.transform.position, base.transform.rotation);

            gameObject.hideFlags = HideFlags.HideAndDontSave;
            Transform transform = AnimationLink.SearchRec(gameObject.transform, this.boneRoot);

            if (transform == null)
            {
                throw new Exception("Could not find root transform");
            }
            Animation animation = gameObject.GetComponent <Animation>();

            if (animation == null)
            {
                animation = gameObject.AddComponent <Animation>();
            }
            for (int i = 0; i < this.sequence.Length; i++)
            {
                animation.AddClip(this.sequence[i].clip, this.sequence[i].clip.name);
            }
            Vector3 a      = Vector3.zero;
            Vector3 vector = base.transform.position;
            Vector3 b      = Vector3.zero;

            for (int j = 0; j < this.sequence.Length; j++)
            {
                AnimationLink.LinkClip linkClip = this.sequence[j];
                if (linkClip == null)
                {
                    endPosition = vector;
                    return;
                }
                animation[linkClip.clip.name].enabled = true;
                animation[linkClip.clip.name].weight  = 1f;
                for (int k = 0; k < linkClip.loopCount; k++)
                {
                    animation[linkClip.clip.name].normalizedTime = 0f;
                    animation.Sample();
                    Vector3 vector2 = transform.position - base.transform.position;
                    if (j > 0)
                    {
                        vector += a - vector2;
                    }
                    else
                    {
                        b = vector2;
                    }
                    for (int l = 0; l <= 20; l++)
                    {
                        float num = (float)l / 20f;
                        animation[linkClip.clip.name].normalizedTime = num;
                        animation.Sample();
                        Vector3 item = vector + (transform.position - base.transform.position) + linkClip.velocity * num * linkClip.clip.length;
                        trace.Add(item);
                    }
                    vector += linkClip.velocity * 1f * linkClip.clip.length;
                    animation[linkClip.clip.name].normalizedTime = 1f;
                    animation.Sample();
                    Vector3 vector3 = transform.position - base.transform.position;
                    a = vector3;
                }
                animation[linkClip.clip.name].enabled = false;
                animation[linkClip.clip.name].weight  = 0f;
            }
            vector += a - b;
            UnityEngine.Object.DestroyImmediate(gameObject);
            endPosition = vector;
        }