// Update is called once per frame void Update() { X2DTools.DrawPosMark(gameObject, transform.position, gameObject.layer); #if UNITY_EDITOR if (!Application.isPlaying) { EditorUpdateClipArray(); for (int i = 0; i < clipArray.Length; i++) { clipArray[i].transform.localPosition = Vector3.zero; //保持为(0, 0, 0),这样改变朝向时不会出错,见X2DAniamtion.isFacingRight } return; } #endif if (!isPlaying) { return; } timer += Time.deltaTime; for (int i = 0; i < clipArray.Length; i++) { X2DEffectClip clip = clipArray[i]; if (!clip.isPlaying) { if (timer > clip.startTime && timer < clip.endTime) { clip.gameObject.SetActive(true); clip.Play(); } } else if (clip.endTime > 0 && timer >= clip.endTime) { clip.Stop(); stoppedClipCount++; //循环播 if (loop && stoppedClipCount == clipArray.Length) { isPlaying = false; Play(); } } } if (stoppedClipCount == clipArray.Length && timer >= duration) { isPlaying = false; return; } }
public void EditorUpdateClipArray() { clipArray = GetComponentsInChildren <X2DEffectClip>(true); //剪辑名字排列 for (int i = 0; i < clipArray.Length - 1; i++) { for (int j = 0; j < clipArray.Length - 1 - i; j++) { if (clipArray[j].name.CompareTo(clipArray[j + 1].name) > 0) { X2DEffectClip t = clipArray[j]; clipArray[j] = clipArray[j + 1]; clipArray[j + 1] = t; } } } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); X2DEffectClip clip = target as X2DEffectClip; clip.x2dAnima.isFaceRight = EditorGUILayout.Toggle("isFaceRight", clip.x2dAnima.isFaceRight); //if(GUILayout.Button("AnimationTimeAsDuration", GUILayout.Width(180))) if (clip.autoDuration) { if (clip.x2dAnima == null) { Debug.Log("x2dAnima is null"); } else if (clip.x2dAnima.defaultClip == null) { Debug.Log("x2dAnima.defaultClip is null"); } else { clip.duration = clip.x2dAnima.defaultClip.duration; } } }