public void SetColor(Color col) { if (this.rends == null) { this.rends = base.GetComponentsInChildren <MeshRenderer>(); } MeshRenderer[] array = this.rends; for (int i = 0; i < array.Length; i++) { MeshRenderer meshRenderer = array[i]; Color color = meshRenderer.material.GetColor("_TintColor"); AnimationCurve curve = AnimationCurve.Linear(0f, color.r, 1f, col.r); AnimationCurve curve2 = AnimationCurve.Linear(0f, color.g, 1f, col.g); AnimationCurve curve3 = AnimationCurve.Linear(0f, color.b, 1f, col.b); AnimationClip animationClip = new AnimationClip(); animationClip.legacy = true; animationClip.SetCurve(string.Empty, typeof(Material), "_TintColor.r", curve); animationClip.SetCurve(string.Empty, typeof(Material), "_TintColor.g", curve2); animationClip.SetCurve(string.Empty, typeof(Material), "_TintColor.b", curve3); Animation animation = meshRenderer.gameObject.GetComponent <Animation>(); if (animation == null) { animation = meshRenderer.gameObject.AddComponent <Animation>(); } animationClip.wrapMode = WrapMode.Once; animation.AddClip(animationClip, "ColorAnim"); animation.Play("ColorAnim"); } }
public override void OnActivate() { if (Object.op_Inequality((Object)this.m_CameraAnime, (Object)null)) { Animation animation = (Animation)((Component)Camera.get_main()).get_gameObject().GetComponent <Animation>(); if (Object.op_Equality((Object)animation, (Object)null)) { animation = (Animation)((Component)Camera.get_main()).get_gameObject().AddComponent <Animation>(); } if (Object.op_Inequality((Object)animation, (Object)null)) { animation.AddClip(this.m_CameraAnime, ((Object)this.m_CameraAnime).ToString()); animation.Play(((Object)this.m_CameraAnime).ToString()); } Camera.get_main().set_nearClipPlane(this.Near); Camera.get_main().set_farClipPlane(this.Far); if (!this.m_Async) { return; } this.ActivateNext(true); } else { this.ActivateNext(); } }
/// <summary> /// animtionCurveからClip作成処理 /// </summary> /// <param name="animation"></param> /// <param name="animDic"></param> /// <returns></returns> public IEnumerator moduleAddClip(Animation animation, Dictionary <string, AnimationCurve> animDic) { //AnimationClip AnimationClip anim = new AnimationClip(); anim.legacy = true; anim.name = "AnimClip"; foreach (var dic in animDic) { string _path = dic.Key.Split('_')[0]; string _property = dic.Key.Replace(_path + "_", ""); Type type = typeof(Transform); if (_property.IndexOf("AddRotate") >= 0) { type = typeof(PartsControll); anim.SetCurve(_path, type, _property, dic.Value); } if (_property.IndexOf("m_Angle") >= 0) { type = typeof(PartsControll); anim.SetCurve(_path, type, _property, dic.Value); } if (_property.IndexOf("EnagyValue") >= 0) { type = typeof(Parts); anim.SetCurve(_path, type, _property, dic.Value); } } animation.AddClip(anim, anim.name); animation.GetComponent <Animation>().clip = anim; }
protected void Initialize(Animation animation, Transform transform, string newName = null) { if (clip == null) { Debug.LogError("clip is null. Cannot initialize animation " + (name == null ? "NULL" : name)); return; } animation.RemoveClip(Name); if (newName != null) { name = newName; } animation.AddClip(clip, Name); animation [Name].layer = Layer; foreach (var mt in MixingTransforms) { if (AnimationNames.ContainsKey(mt) && transform.Find(AnimationNames [mt]) != null && transform != null) { animation [Name].AddMixingTransform(transform.Find(AnimationNames [mt])); } else { Debug.LogError("[assembly: " + Assembly.GetExecutingAssembly().GetName().Name + "]: animation mixing transform " + mt + " from animation " + Name + " does not exist, or could not be found."); } } }
// creates/returns a dynamic Audio object to position and plays in the world with loop public static GameObject CreateGetFadeAudioObject(AudioClip aClip, bool dLoop, AnimationClip fadeClip, string objName) { // instance a new gameobject GameObject apObject = new GameObject(objName); // position the object in the world apObject.transform.position = Vector3.zero; // add our DontDestroyOnLoad DontDestroyOnLoad(apObject); // add an AudioSource component apObject.AddComponent <AudioSource>(); // return this script for use AudioSource apAudio = apObject.GetComponent <AudioSource>(); // initialize some AudioSource fields apAudio.playOnAwake = false; apAudio.rolloffMode = AudioRolloffMode.Linear; apAudio.loop = dLoop; apAudio.clip = aClip; apAudio.volume = 1.0f; // default if (fadeClip != null) { Animation apAnim = apObject.AddComponent <Animation>(); apAnim.AddClip(fadeClip, fadeClip.name); apAnim.clip = fadeClip; apAnim.playAutomatically = false; } // return our AudioObject return(apObject); }
private void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Activador")) { //Abrimos puertas animI.AddClip(clipI, clipI.name); animD.AddClip(clipD, clipD.name); animI.Play(clipI.name); animD.Play(clipD.name); //Guardamos el primer Terreno en t1 t1 = Terreno.gameObject; //Creamos el siguiente terreno Terreno = Instantiate(Terreno); cuentaTerrenos = cuentaTerrenos + 1; Terreno.name = "TerrenoNuevo"; //Asignamos las puertas del nuevo Terreno a las variables puertas y los obstaculos asignarTerreno(); //instancia de forma aleatoria obstaculos en los empty objects asignarObstaculos(); //Asignamos las animaciones de las puertas a las nuevas puertas asignarAnimacion(); //Cogemos el transform del siguiente terreno tr = Terreno.transform; //Posicionamos el siguiente terreno despues del anterior tr.SetPositionAndRotation(new Vector3(0f, 0, moveTerreno), new Quaternion(0f, 0f, 0f, 0f)); moveTerreno = moveTerreno + 191.1f; } if (other.gameObject.CompareTag("Destruir")) { //Destruimos el terreno que ya hemos pasado Destroy(t1); } }
protected override List <Matrix4x4[, ]> SampleAnimationClips(float frameRate, List <Clip> clips, out int numberOfKeyFrames, out int numberOfBones) { foreach (var i in clips) { _animationComponent.AddClip(i.clip, i.name); } List <AnimationClip> animationClips = _animationComponent.GetAllAnimationClips(); foreach (var clip in animationClips) { _animationComponent[clip.name].enabled = false; _animationComponent[clip.name].weight = 0f; } numberOfKeyFrames = 0; var sampledBoneMatrices = new List <Matrix4x4[, ]>(); foreach (var animationClip in animationClips) { var sampledMatrix = SampleAnimationClip(animationClip, _originalRenderer, _animationComponent, frameRate); sampledBoneMatrices.Add(sampledMatrix); numberOfKeyFrames += sampledMatrix.GetLength(0); } numberOfBones = sampledBoneMatrices[0].GetLength(1); return(sampledBoneMatrices); }
public void SetColor(Color col) { if (rends == null) { rends = GetComponentsInChildren <MeshRenderer>(); } foreach (MeshRenderer rend in rends) { Color current = rend.material.GetColor("_TintColor"); AnimationCurve curveR = AnimationCurve.Linear(0, current.r, 1, col.r); AnimationCurve curveG = AnimationCurve.Linear(0, current.g, 1, col.g); AnimationCurve curveB = AnimationCurve.Linear(0, current.b, 1, col.b); AnimationClip clip = new AnimationClip(); clip.SetCurve("", typeof(Material), "_TintColor.r", curveR); clip.SetCurve("", typeof(Material), "_TintColor.g", curveG); clip.SetCurve("", typeof(Material), "_TintColor.b", curveB); Animation anim = rend.gameObject.GetComponent <Animation>(); if (anim == null) { anim = rend.gameObject.AddComponent <Animation>(); } clip.wrapMode = WrapMode.Once; anim.AddClip(clip, "ColorAnim"); anim.Play("ColorAnim"); } }
public static void MoveTo(GameObject obj, Vector2 startpos, Vector2 NewPos, float duration, float z) { Animation anim = obj.GetComponent <Animation>(); //if (anim.GetClipCount() > 1) //{ // anim.RemoveClip("Moveto"); //} anim.enabled = true; AnimationClip animclip = new AnimationClip(); #if UNITY_5 animclip.legacy = true; #endif AnimationCurve curvex = AnimationCurve.Linear(0, startpos.x, duration, NewPos.x); AnimationCurve curvey = AnimationCurve.Linear(0, startpos.y, duration, NewPos.y); AnimationCurve curvez = AnimationCurve.Linear(0, z, duration, z); AnimationCurve curvenable = AnimationCurve.Linear(0, 1, duration, 0); animclip.SetCurve("", typeof(Transform), "localPosition.x", curvex); animclip.SetCurve("", typeof(Transform), "localPosition.y", curvey); animclip.SetCurve("", typeof(Transform), "localPosition.z", curvez); animclip.SetCurve("", typeof(Animation), "m_Enabled", curvenable); anim.AddClip(animclip, "Moveto"); anim.Play("Moveto"); Destroy(animclip, duration); }
private void OnDataLoaded() { foreach (GameObject gameObject in WPFMonoBehaviour.gameData.m_parts) { BasePart component = gameObject.GetComponent <BasePart>(); if (component.m_partType == this.partType) { if (this.partSpriteParent == null) { this.partSpriteParent = new GameObject(string.Format("PartVisualisation_{0}", this.partType)); } GameObject gameObject2 = UnityEngine.Object.Instantiate <GameObject>(component.m_constructionIconSprite.gameObject); gameObject2.layer = base.gameObject.layer; this.partSprite = gameObject2.transform; this.partSprite.name = "PartVisualisation"; this.partSprite.parent = this.partSpriteParent.transform; this.partSprite.localPosition = Vector3.zero; this.partSprite.localRotation = Quaternion.identity; this.partSprite.GetComponent <Renderer>().enabled = false; if (this.collectAnimation != null) { Animation animation = this.partSprite.gameObject.AddComponent <Animation>(); animation.playAutomatically = false; animation.AddClip(this.collectAnimation, this.collectAnimation.name); } } } if (GameProgress.HasKey(string.Format("{0}_star_{1}", Singleton <GameManager> .Instance.CurrentSceneName, base.NameKey), GameProgress.Location.Local, null) && !GameProgress.HasKey(string.Format("{0}_part_{1}", Singleton <GameManager> .Instance.CurrentSceneName, base.NameKey), GameProgress.Location.Local, null)) { GameProgress.AddPartBox(Singleton <GameManager> .Instance.CurrentSceneName, base.NameKey); GameProgress.AddSandboxParts(Singleton <GameManager> .Instance.CurrentSceneName, this.partType, this.count, true); } }
/// <summary> /// アニメーション作成メソッド /// </summary> private void CreateAnimationClips(int startIndex, int endIndex) { int srcIndex = startIndex; int nxtIndex; // すでにアニメーションがある場合,全削除 foreach (AnimationClip clip in animationClipList) { thisAnimation.RemoveClip(clip); } animationClipList.Clear(); /*-- ここからフレーム作成 --*/ for (int i = 0; i < Mathf.Abs(startIndex - endIndex); i++) { if (startIndex < endIndex) { nxtIndex = srcIndex + 1; } else { nxtIndex = srcIndex - 1; } // アニメーションクリップ作成.初期設定. int clipIndex = animationClipList.Count; animationClipList.Add(new AnimationClip()); animationClipList [clipIndex].legacy = true; // SetCurveを使用するにはlegacyをtrueにする必要あり animationClipList [clipIndex].name = clipIndex.ToString(); // 全関節に対してアニメーションを作成 for (int j = 0; j < objects.MotionData.ModelJointList.Count; j++) { // 変数初期化 (今のフレームと一つ先のフレームの回転量と遷移時間) var angleOld = Quaternion.Euler(objects.MotionData.FrameList [srcIndex].JointAngles [j].EulerAngle); var angleNew = Quaternion.Euler(objects.MotionData.FrameList [nxtIndex].JointAngles[j].EulerAngle); var time = (float)objects.MotionData.FrameList [nxtIndex].TransitionTime / 1000; // Rotationプロパティのx,y,z,wに対して一つずつアニメーションを設定 AnimationCurve curveX = AnimationCurve.EaseInOut(0f, angleOld.x, time, angleNew.x); AnimationCurve curveY = AnimationCurve.EaseInOut(0f, angleOld.y, time, angleNew.y); AnimationCurve curveZ = AnimationCurve.EaseInOut(0f, angleOld.z, time, angleNew.z); AnimationCurve curveW = AnimationCurve.EaseInOut(0f, angleOld.w, time, angleNew.w); animationClipList [i].SetCurve(relativePathes [j], typeof(Transform), "localRotation.x", curveX); animationClipList [i].SetCurve(relativePathes [j], typeof(Transform), "localRotation.y", curveY); animationClipList [i].SetCurve(relativePathes [j], typeof(Transform), "localRotation.z", curveZ); animationClipList [i].SetCurve(relativePathes [j], typeof(Transform), "localRotation.w", curveW); } // 作成したアニメーションクリップをAnimationに加える thisAnimation.AddClip(animationClipList [clipIndex], animationClipList [clipIndex].name); if (startIndex < endIndex) { srcIndex++; } else { srcIndex--; } } }
public void Play(AnimationClip anim, PlayMode mode = PlayMode.StopSameLayer, Action <bool> onAnimationFinished = null) { if (m_animations.GetClip(anim.name) == null) { m_animations.AddClip(anim, anim.name); } Play(anim.name, mode, onAnimationFinished); }
private void OnEnable() { string name = "Name"; animator.AddClip(anim, name); animator.Play(name); Debug.Log("I'm awake"); }
protected virtual void Start() { if (modelParent != null) { if (moveAnimation == null || idleAnimation == null || attackAnimation == null || deathAnimation == null) { Debug.LogWarning("Warning: " + CreatureName + " has insufficient animations set to assign an animation controller!"); } else { moveAnimation.legacy = true; idleAnimation.legacy = true; attackAnimation.legacy = true; deathAnimation.legacy = true; animationController = modelParent.AddComponent <Animation>(); animationController.cullingType = AnimationCullingType.BasedOnRenderers; animationController.AddClip(moveAnimation, moveAnimation.name); animationController.AddClip(idleAnimation, idleAnimation.name); animationController.AddClip(attackAnimation, attackAnimation.name); animationController.AddClip(deathAnimation, deathAnimation.name); } if (GetComponent <Animator>() != null) { // Whilst I know that Animator is technically newer, the Animation component allows more generic code Debug.LogError("This class doesn't support the Animator - Please drag the animation clips into the appropriate slots and delete the Animator"); } } if (model == null) { Debug.LogWarning("Please assign the model to this creature script!"); } else { modelOutline = model.AddComponent <ModelOutline>(); modelOutline.color = 0; modelOutline.enabled = false; } // Server only reads if (!Application.isEditor) { InvokeRepeating("NetCode", 0f, 0.1f); } }
// Use this for initialization void Start() { or = speed; anim.AddClip(Socc, "Socc"); tra = anim["Socc"]; bal.GetComponent <Animation>()["Socc"].wrapMode = WrapMode.Loop; bal.GetComponent <Animation>().Play("Socc"); }
public static void Play(this Animation animationComponent, AnimationClip animationClip) { if (animationComponent.GetClip(animationClip.name) == null) { animationComponent.AddClip(animationClip, animationClip.name); } animationComponent.Play(animationClip.name); }
void JumpAnimation(Vector3 JumpDirection) { clip1 = new AnimationClip(); clip1.legacy = true; clip2 = new AnimationClip(); clip2.legacy = true; clip1.SetCurve("", typeof(Transform), "localPosition.z", AnimationCurve.Linear(0, transform.position.z, JumpDuration / 2, transform.position.z + (JumpDirection.z / 2))); clip1.SetCurve("", typeof(Transform), "localPosition.y", AnimationCurve.EaseInOut(0, 0.8f, JumpDuration / 2, 5f)); clip1.SetCurve("", typeof(Transform), "localPosition.x", AnimationCurve.Linear(0, transform.position.x, JumpDuration / 2, transform.position.x + (JumpDirection.x / 2))); clip2.SetCurve("", typeof(Transform), "localPosition.z", AnimationCurve.Linear(0, transform.position.z + (JumpDirection.z / 2), JumpDuration / 2, transform.position.z + JumpDirection.z)); clip2.SetCurve("", typeof(Transform), "localPosition.y", AnimationCurve.EaseInOut(0, 5f, JumpDuration / 2, 0.8f)); clip2.SetCurve("", typeof(Transform), "localPosition.x", AnimationCurve.Linear(0, transform.position.x + (JumpDirection.x / 2), JumpDuration / 2, transform.position.x + JumpDirection.x)); Anim.AddClip(clip1, "jumppart1"); Anim.AddClip(clip2, "jumppart2"); Anim.Play("jumppart1"); Anim.PlayQueued("jumppart2", QueueMode.CompleteOthers); }
private void OnEnable() { _image = GetComponent <Image>(); _animation = GetComponent <Animation>(); _image.enabled = false; _animation.AddClip(LevelCompleteClip, LevelCompleteClip.name); }
// Use this for initialization void Start() { ball = FindObjectOfType <SoccerBall>(); anim.AddClip(Socc, "Socc"); tra = anim["Socc"]; bal.GetComponent <Animation>()["Socc"].wrapMode = WrapMode.Loop; bal.GetComponent <Animation>().Play("Socc"); }
public void Play() { CreateClip(); anim = GetComponent <Animation>(); anim.AddClip(myClip, myClip.name); anim.Play(myClip.name); }
public void AddAndPlayAnimation(GameObject go) { Animation animation = go.GetComponent <Animation>(); animation.clip = applyAnimation; animation.AddClip(applyAnimation, applyAnimation.name); animation.Play(); }
public override void Action() { if (bPlayed) { bPlayed = false; anim.AddClip(offClip, offClip.name); anim.clip = offClip; anim.Play(); } else { bPlayed = true; anim.AddClip(onClip, onClip.name); anim.clip = onClip; anim.Play(); } }
public void AddAnimationClip(AnimationClip clip) { if (clip == null) { return; } mAnimation.AddClip(clip, clip.name); }
public virtual AnimState Clone(State _parent) { string cloneName = name + "_clone"; anim.AddClip(anim[name].clip, cloneName); return(new AnimState(cloneName, anim, _parent)); }
void OnEnable() { AnimationClip animacaoSorteada = animacoesPossiveis[Random.Range(0, animacoesPossiveis.Length)]; alvo.AddClip(animacaoSorteada, animacaoSorteada.name); alvo.clip = animacaoSorteada; alvo.Play(); }
public override void Initialize(Animation animObj = null, GameObject weaponPov = null) { base.Initialize(animObj); animObj?.AddClip(this.Anim_ADS, "ADS"); this.MuzzleObj = weaponPov; this._originalFOV = Camera.main.fieldOfView; }
public void MoveCard(Vector3 newPosition, bool isEndFlipped, float playTime, bool isSloppy) { float _zRotEndValue = 0; if (isSloppy) { RandomTransform _addSlop = GetRandomTransform(40.0f, 0.4f); newPosition = newPosition + _addSlop.position; _zRotEndValue = _addSlop.rotation.z; } Animation _anim = GetComponent <Animation>(); AnimationCurve _xCurve = AnimationCurve.Linear(0, transform.localPosition.x, //start time, startValue, playTime, newPosition.x); //endTime, endValue AnimationCurve _yCurve = AnimationCurve.Linear(0, transform.localPosition.y, playTime, newPosition.y); AnimationCurve _zCurve = AnimationCurve.Linear(0, newPosition.z, playTime, newPosition.z); AnimationCurve _xRot = AnimationCurve.Linear(0, transform.localRotation.x, playTime, 0); AnimationCurve _yRot; if (IsFlipped == isEndFlipped) { _yRot = AnimationCurve.Linear(0, transform.localRotation.y, playTime, 0); } else { _yRot = AnimationCurve.Linear(0, 3.14f, playTime, 0.0f); Invoke("Flip", playTime / 2); } AnimationCurve _zRot = AnimationCurve.Linear(0, transform.localRotation.z, playTime, _zRotEndValue); AnimationCurve _wRot = AnimationCurve.Linear(0, transform.localRotation.w, playTime, transform.localRotation.w); AnimationClip _clip = new AnimationClip(); _clip.SetCurve("", typeof(Transform), "localPosition.x", _xCurve); _clip.SetCurve("", typeof(Transform), "localPosition.y", _yCurve); _clip.SetCurve("", typeof(Transform), "localPosition.z", _zCurve); _clip.SetCurve("", typeof(Transform), "localRotation.x", _xRot); _clip.SetCurve("", typeof(Transform), "localRotation.y", _yRot); _clip.SetCurve("", typeof(Transform), "localRotation.z", _zRot); _clip.SetCurve("", typeof(Transform), "localRotation.w", _wRot); _anim.AddClip(_clip, "moveCard" + Name.ToString()); _anim.Play("moveCard" + Name.ToString()); }
public static bool IsSPEElementLegal(SpecialEffectElement element, out string errorMsg) { bool bRet = true; errorMsg = string.Empty; if (null == element) { errorMsg = "特效元素为Null"; return(false); } Type elemType = element.GetType(); if (elemType == typeof(SpecialEffectAnimation)) { Animation anim = element.gameObject.GetComponent <Animation>(); if ( (null == anim) || (null == anim.clip) ) { errorMsg = element.gameObject.name + "中的animation脚本没有clip动画或者此动画是animator的动画,animation的动画必须是Legacy的属性"; bRet = false; return(bRet); } #if UNITY_5_0 || UNITY_5_1 if (!anim.clip.legacy) { bRet = false; return(bRet); } #else SerializedObject serializedClip = new SerializedObject(anim.clip); SerializedProperty animationType = serializedClip.FindProperty("m_AnimationType"); if (animationType == null) { bRet = false; return(bRet); } if (animationType.intValue != (int)ModelImporterAnimationType.Legacy) { errorMsg = element.gameObject.name + "中的animation脚本没有clip动画或者此动画是animator的动画,animation的动画必须是Legacy的属性"; bRet = false; return(bRet); } #endif if (null == anim.GetComponent <Animation>()[anim.GetComponent <Animation>().clip.name]) { anim.AddClip(anim.clip, anim.GetComponent <Animation>().clip.name); } } return(bRet); }
// Start is called before the first frame update void Start() { animator = GetComponent <Animation>(); animator.playAutomatically = false; openAnimation.legacy = true; closeAnimation.legacy = true; animator.AddClip(openAnimation, GateState.Open.ToString()); animator.AddClip(closeAnimation, GateState.Closed.ToString()); currentState = initialState; var clip = GetCurrentAnimation(); animator[clip].speed = 9999; animator.Play(clip); SetCollider(); }
// Use this for initialization void Start() { cheerframe = gameObject.GetComponent <Cheer>().Frame; anim = GetComponent <Animation> (); animationCounter = Random.Range(0, 600); animNames.Add("HeadIdle"); //animNames.Add("HeadSpin"); animNames.Add("IdleSway"); animNames.Add("IdleYawn"); animNames.Add("LegsIdle"); //animNames.Add("IdleRobot"); anim.AddClip(headIdle, "HeadIdle"); //anim.AddClip (headSpin, "HeadSpin"); anim.AddClip(idleSway, "IdleSway"); anim.AddClip(idleYawn, "IdleYawn"); anim.AddClip(legsIdle, "LegsIdle"); //anim.AddClip (idleRobot, "IdleRobot"); }