Esempio n. 1
0
 public UpdateObject(MonoBehaviour tar, System.Action <float> pDelgate, AnimatorUpdateMode pType = AnimatorUpdateMode.Normal)
 {
     target     = tar;
     Key        = target.gameObject.ToString();
     delgate    = pDelgate;
     updateType = pType;
 }
Esempio n. 2
0
        // Switching to ragdoll
        private void RagdollEnabler()
        {
            // Remember the last animated pose
            StoreLocalState();


            // Switch Animator update mode to AnimatePhysics, so IK is updated in the fixed time step
            animatorUpdateMode  = animator.updateMode;
            animator.updateMode = AnimatorUpdateMode.AnimatePhysics;

            // Disable the Animator so it won't overwrite physics
            animator.enabled = false;

            for (int i = 0; i < rigidbones.Length; i++)
            {
                rigidbones[i].WakeUp(applyVelocity, applyAngularVelocity);
            }



            ragdollWeight  = 1f;
            ragdollWeightV = 0f;

            enableRagdollFlag = false;
        }
Esempio n. 3
0
    static int IntToEnum(IntPtr L)
    {
        int arg0             = (int)LuaDLL.lua_tonumber(L, 1);
        AnimatorUpdateMode o = (AnimatorUpdateMode)arg0;

        LuaScriptMgr.PushEnum(L, o);
        return(1);
    }
Esempio n. 4
0
 public static void SetUpdateMode(AnimatorUpdateMode updateMode)
 {
     mode = updateMode;
     if (mode == AnimatorUpdateMode.UnscaledTime && mInstance != null)
     {
         mInstance.StartCoroutine(mInstance.UnscaledUpdate());
     }
 }
Esempio n. 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="binaryReader"></param>
 public override void Deserialize(BinaryReader binaryReader)
 {
     base.Deserialize(binaryReader);
     mRuntimeAnimatorController = binaryReader.ReadString();
     mAvatar          = binaryReader.ReadString();
     mApplyRootMotion = binaryReader.ReadBoolean();
     mUpdateMode      = (AnimatorUpdateMode)binaryReader.ReadInt32();
     mCullingMode     = (AnimatorCullingMode)binaryReader.ReadInt32();
 }
 void SetAnimatorUpdateMode(AnimatorUpdateMode mode)
 {
     // for changing the time scale to/from unscaled
     foreach (var part in CharacterParts)
     {
         if (part.animator != null)
         {
             part.animator.updateMode = mode;
         }
     }
 }
Esempio n. 7
0
 void Start()
 {
     IsOnHorse = Mounted = false;                                    //initialize in false
     if (Anim)
     {
         Initial_UpdateMode = Anim.updateMode;                 //Gets the Update Mode of the Animator to restore later when dismounted.
     }
     if (StartMounted)
     {
         AlreadyMounted();                                           //Set All if Started Mounted is Active
     }
 }
Esempio n. 8
0
        public virtual void UpdateAvatar(UMAData umaData)
        {
            if (umaData)
            {
                AnimationState[] snapshot = null;
                if (umaData.animationController)
                {
                    var animator = umaData.animator;

                    bool animating                  = false;
                    bool applyRootMotion            = false;
                    AnimatorUpdateMode  updateMode  = AnimatorUpdateMode.Normal;
                    AnimatorCullingMode cullingMode = AnimatorCullingMode.AlwaysAnimate;

                    if (animator)
                    {
                        animating       = animator.enabled;
                        applyRootMotion = animator.applyRootMotion;
                        updateMode      = animator.updateMode;
                        cullingMode     = animator.cullingMode;

                        if (umaData.animationController == animator.runtimeAnimatorController)
                        {
                            snapshot = new AnimationState[animator.layerCount];
                            for (int i = 0; i < animator.layerCount; i++)
                            {
                                var state = animator.GetCurrentAnimatorStateInfo(i);
                                snapshot[i].stateHash = state.nameHash;
                                snapshot[i].stateTime = Mathf.Max(0, state.normalizedTime - Time.deltaTime / state.length);
                            }
                        }

                        Object.DestroyImmediate(animator);
                    }
                    var oldParent = umaData.umaRoot.transform.parent;
                    umaData.umaRoot.transform.parent = null;
                    animator         = CreateAnimator(umaData, umaData.umaRecipe.raceData.TPose, umaData.animationController, applyRootMotion, updateMode, cullingMode);
                    umaData.animator = animator;
                    umaData.umaRoot.transform.parent = oldParent;
                    if (snapshot != null)
                    {
                        for (int i = 0; i < animator.layerCount; i++)
                        {
                            animator.Play(snapshot[i].stateHash, i, snapshot[i].stateTime);
                        }

                        animator.Update(0);
                        animator.enabled = animating;
                    }
                }
            }
        }
Esempio n. 9
0
        IEnumerator CoPlay(float duration, AnimatorUpdateMode updateMode = AnimatorUpdateMode.Normal)
        {
            float time = 0;

            while (time < duration)
            {
                location = time / duration;
                time    += updateMode == AnimatorUpdateMode.UnscaledTime
                    ? Time.unscaledDeltaTime
                    : Time.deltaTime;
                yield return(null);
            }
        }
Esempio n. 10
0
        // Switching to ragdoll
        private void RagdollEnabler()
        {
            // Remember the last animated pose
            StoreLocalState();

            // Disable IK components if necessary
            for (int i = 0; i < allIKComponents.Length; i++)
            {
                disabledIKComponents[i] = false;
            }

            if (!applyIkOnRagdoll)
            {
                for (int i = 0; i < allIKComponents.Length; i++)
                {
                    if (allIKComponents[i].enabled)
                    {
                        allIKComponents[i].Disable();
                        disabledIKComponents[i] = true;
                    }
                }
            }

            // Disable the Animator so it won't overwrite physics
            animator.enabled = false;

            for (int i = 0; i < rigidbones.Length; i++)
            {
                rigidbones[i].WakeUp(applyVelocity, applyAngularVelocity);
            }

            // Remember some variables so we can revert to them when coming back from ragdoll
            for (int i = 0; i < fixTransforms.Length; i++)
            {
                fixTransforms[i] = allIKComponents[i].fixTransforms;
                allIKComponents[i].fixTransforms = false;
            }

            // Switch Animator update mode to AnimatePhysics, so IK is updated in the fixed time step
            animatorUpdateMode  = animator.updateMode;
            animator.updateMode = AnimatorUpdateMode.AnimatePhysics;

            ragdollWeight  = 1f;
            ragdollWeightV = 0f;

            enableRagdollFlag = false;
        }
Esempio n. 11
0
        void Start()
        {
            inputSystem = DefaultInput.GetInputSystem(PlayerID);        //Set the Correct Input System

            MountInput.InputSystem              =
                DismountInput.InputSystem       =
                    CallAnimalInput.InputSystem = inputSystem;

            IsOnHorse = Mounted = false;                                    //initialize in false
            if (Anim)
            {
                Initial_UpdateMode = Anim.updateMode;                 //Gets the Update Mode of the Animator to restore later when dismounted.
            }
            if (StartMounted)
            {
                AlreadyMounted();                                           //Set All if Started Mounted is Active
            }
        }
Esempio n. 12
0
    public void OpenMenu(SubMenu sub)
    {
        // === Saving old stats to restore them later === //

        // Saving and updating animator update mode
        oldAnimatorUpdateMode = controller.shadowAnimator.updateMode;
        controller.SetShadowAnimatorNormalMode(AnimatorUpdateMode.Normal);

        // Saving and updating time scale
        oldTimeScale   = Time.timeScale;
        Time.timeScale = 0f;

        // Disabling inputs
        controller.enabled   = false;
        inputManager.enabled = false;

        subMenus[0].EnableMenu();
    }
        protected override void ReadFromImpl(object obj)
        {
            base.ReadFromImpl(obj);
            Animator uo = (Animator)obj;

            rootPosition                         = uo.rootPosition;
            rootRotation                         = uo.rootRotation;
            applyRootMotion                      = uo.applyRootMotion;
            updateMode                           = uo.updateMode;
            stabilizeFeet                        = uo.stabilizeFeet;
            feetPivotActive                      = uo.feetPivotActive;
            speed                                = uo.speed;
            cullingMode                          = uo.cullingMode;
            recorderStartTime                    = uo.recorderStartTime;
            recorderStopTime                     = uo.recorderStopTime;
            runtimeAnimatorController            = ToID(uo.runtimeAnimatorController);
            layersAffectMassCenter               = uo.layersAffectMassCenter;
            logWarnings                          = uo.logWarnings;
            fireEvents                           = uo.fireEvents;
            keepAnimatorControllerStateOnDisable = uo.keepAnimatorControllerStateOnDisable;
        }
Esempio n. 14
0
			public void SaveAnimatorState(Animator animator)
			{
				animating = animator.enabled;
				applyRootMotion = animator.applyRootMotion;
				updateMode = animator.updateMode;
				cullingMode = animator.cullingMode;

				int layerCount = animator.layerCount;
				stateHashes = new int[layerCount];
				stateTimes = new float[layerCount];
				for (int i = 0; i < layerCount; i++)
				{
					var state = animator.GetCurrentAnimatorStateInfo(i);
#if UNITY_4_6
					stateHashes[i] = state.nameHash;
#else
					stateHashes[i] = state.fullPathHash;
#endif
					stateTimes[i] = Mathf.Max(0, state.normalizedTime - Time.deltaTime / state.length);
				}
			}
Esempio n. 15
0
            public void SaveAnimatorState(Animator animator)
            {
                animating       = animator.enabled;
                applyRootMotion = animator.applyRootMotion;
                updateMode      = animator.updateMode;
                cullingMode     = animator.cullingMode;

                int layerCount = animator.layerCount;

                stateHashes = new int[layerCount];
                stateTimes  = new float[layerCount];
                for (int i = 0; i < layerCount; i++)
                {
                    var state = animator.GetCurrentAnimatorStateInfo(i);
#if UNITY_4_6
                    stateHashes[i] = state.nameHash;
#else
                    stateHashes[i] = state.fullPathHash;
#endif
                    stateTimes[i] = Mathf.Max(0, state.normalizedTime - Time.deltaTime / state.length);
                }
            }
Esempio n. 16
0
        protected CapsuleCollider mountedCollider;  //For creating a collider when is mounted for Hit Porpouse
        #endregion

        #endregion

        void Awake()
        {
            t         = transform;
            Anim      = GetComponentInChildren <Animator>();
            RB        = GetComponentInChildren <Rigidbody>();
            colliders = GetComponentsInChildren <Collider>().ToList();

            var CleanCol = new List <Collider>();

            foreach (var col in colliders)
            {
                if (col.enabled && !col.isTrigger)
                {
                    CleanCol.Add(col);
                }
            }
            colliders = new List <Collider>(CleanCol);


            Anim = GetComponentInParent <Animator>();
            RB   = GetComponentInParent <Rigidbody>();

            if (Anim)
            {
                MountLayerIndex = Anim.GetLayerIndex(MountLayer);

                Spine = Anim.GetBoneTransform(HumanBodyBones.Spine);   //Get the Rider Spine transform
                //Hips = Anim.GetBoneTransform(HumanBodyBones.Hips);                   //Get the Rider Hips transform
                Chest = Anim.GetBoneTransform(HumanBodyBones.Chest);   //Get the Rider Chest transform

                Default_Anim_UpdateMode = Anim.updateMode;             //Gets the Update Mode of the Animator to restore later when dismounted.
            }


            SpeedMultiplier       = 1f;
            TargetSpeedMultiplier = 1f;
        }
Esempio n. 17
0
 /// <summary>
 /// Play effect.
 /// </summary>
 public void Play(float duration, AnimatorUpdateMode updateMode)
 {
     StopAllCoroutines();
     StartCoroutine(CoPlay(duration, updateMode));
 }
Esempio n. 18
0
 // Prevents the animator to be fully accessible by making it public ;
 // We don't want to change the animation in another script,
 // just wether it is affected by the timescale or not.
 internal void SetShadowAnimatorNormalMode(AnimatorUpdateMode mode)
 {
     shadowAnimator.updateMode = mode;
 }
Esempio n. 19
0
        public static Animator CreateAnimator(UMAData umaData, UmaTPose umaTPose, RuntimeAnimatorController controller, bool applyRootMotion, AnimatorUpdateMode updateMode, AnimatorCullingMode cullingMode)
        {
            var animator = umaData.umaRoot.AddComponent <Animator>();

            switch (umaData.umaRecipe.raceData.umaTarget)
            {
            case RaceData.UMATarget.Humanoid:
                umaTPose.DeSerialize();
                animator.avatar = CreateAvatar(umaData, umaTPose);
                break;

            case RaceData.UMATarget.Generic:
                animator.avatar = CreateGenericAvatar(umaData);
                break;
            }
            animator.runtimeAnimatorController = controller;
            animator.applyRootMotion           = applyRootMotion;
            animator.updateMode  = updateMode;
            animator.cullingMode = cullingMode;
            return(animator);
        }
Esempio n. 20
0
        public IEnumerator InitiateConversation(IConversationIntermediary intermediary)
        {
            mInitiatingConversation = true;
            if (intermediary == null && !worlditem.HasPlayerAttention)
            {
                                #if UNITY_EDITOR
                Debug.Log("We don't have player's attention");
                                #endif
                mInitiatingConversation = false;
                yield break;
            }
            Motile m = null;
            if (worlditem.Is <Motile> (out m) && !m.IsImmobilized)
            {
                //if the character isn't already immobile
                //make the character stand still
                Character character = null;
                if (worlditem.Is <Character> (out character))
                {
                    mTalkMotileAction = character.LookAtPlayer();
                }

                var waitToStart = mTalkMotileAction.WaitForActionToStart(0.01f);
                while (waitToStart.MoveNext())
                {
                                        #if UNITY_EDITOR
                    Debug.Log("Waiting for motile action to start");
                                        #endif
                    yield return(waitToStart.Current);
                }

                if (mTalkMotileAction.IsFinished)
                {
                                        #if UNITY_EDITOR
                    Debug.Log("Talk motile action got finished for some reason, quitting");
                                        #endif
                    mInitiatingConversation = false;
                    yield break;
                }
            }

            if (State.DefaultToDTS)
            {
                Speech speech = null;
                mInitiatingConversation = false;
                if (Mods.Get.Runtime.LoadMod(ref speech, "Speech", State.DTSSpeechName))
                {
                    SayDTS(speech);
                }
                                #if UNITY_EDITOR
                Debug.Log("Defaulting to DTS");
                                #endif
                mInitiatingConversation = false;
                yield break;
            }

            yield return(null);

            Conversation conversation = null;
            string       DTSOverride  = string.Empty;
            if (Conversations.Get.ConversationByName(State.ConversationName, worlditem.FileName, out conversation, out DTSOverride))
            {
                //wuhoo we got the conversation
                State.ConversationName = conversation.Props.Name;
                conversation.Initiate(character, this, intermediary);
                while (conversation.Initiating)
                {
                    yield return(null);
                }
                //this will load the conversation without hitches
                //now we may just have a dts - in which case the conversation won't be in progress
                if (!Conversation.ConversationInProgress)
                {
                                        #if UNITY_EDITOR
                    Debug.Log("Conversation not in progress, must have defaulted to DTS");
                                        #endif
                    mInitiatingConversation = false;
                    yield break;
                }
            }
            else if (!string.IsNullOrEmpty(DTSOverride))
            {
                                #if UNITY_EDITOR
                Debug.Log("We have a dts override: " + DTSOverride);
                                #endif
                //whoa we have a DTS override
                State.DTSSpeechName     = DTSOverride;
                mInitiatingConversation = false;
                Speech speech = null;
                if (Mods.Get.Runtime.LoadMod(ref speech, "Speech", State.DTSSpeechName))
                {
                    SayDTS(speech);
                }
                mInitiatingConversation = false;
                yield break;
            }
            else
            {
                                #if UNITY_EDITOR
                Debug.Log("Couldn't get the conversation, canceling");
                                #endif
                //aw shit we never got the conversation
                mInitiatingConversation = false;
                yield break;
            }

            Character          c          = worlditem.Get <Character> ();
            AnimatorUpdateMode updateMode = c.Body.Animator.animator.updateMode;
            if (c.Ghost)
            {
                c.Body.Animator.animator.updateMode = AnimatorUpdateMode.UnscaledTime;
            }

            yield return(null);

            while (conversation.IsActive)
            {
                //wait for the player to end the conversation
                yield return(null);
            }

            if (c.Ghost)
            {
                c.Body.Animator.animator.updateMode = updateMode;
            }

            mInitiatingConversation = false;
            yield break;
        }
Esempio n. 21
0
        public static Animator CreateAnimator(UMAData umaData, UmaTPose umaTPose, RuntimeAnimatorController controller, bool applyRootMotion, AnimatorUpdateMode updateMode, AnimatorCullingMode cullingMode)
        {
            var animator = CreateAnimator(umaData, umaTPose, controller);

            animator.applyRootMotion = applyRootMotion;
            animator.updateMode      = updateMode;
            animator.cullingMode     = cullingMode;
            return(animator);
        }
Esempio n. 22
0
		public static Animator CreateAnimator(UMAData umaData, UmaTPose umaTPose, RuntimeAnimatorController controller, bool applyRootMotion, AnimatorUpdateMode updateMode, AnimatorCullingMode cullingMode)
		{
			var animator = CreateAnimator(umaData, umaTPose, controller);
			animator.applyRootMotion = applyRootMotion;
			animator.updateMode = updateMode;
			animator.cullingMode = cullingMode;
			return animator;
		}
 public void SetUpdateMode(AnimatorUpdateMode updateMode)
 {
     animator.updateMode = updateMode;
 }
Esempio n. 24
0
        private void Change(bool change)
        {
            var t             = gameObject.transform;
            var localPosition = t.localPosition;
            var localRotation = t.localRotation;
            var localScale    = t.localScale;

            Undo.RecordObject(this, "Change Animator Controller");
            Undo.RecordObject(animatorCache, "Change Animator Controller");
            if (change)
            {
                Assert.IsFalse(changed);
                animatorCache.hideFlags |= HideFlags.NotEditable;

                originalAnimatorApplyRootMotion = animatorCache.applyRootMotion;
                originalAnimatorUpdateMode      = animatorCache.updateMode;
                originalAnimatorCullingMode     = animatorCache.cullingMode;

                animatorCache.applyRootMotion = false;
                animatorCache.updateMode      = AnimatorUpdateMode.Normal;
                animatorCache.cullingMode     = AnimatorCullingMode.AlwaysAnimate;

                #region AnimatorController
                {
                    originalRuntimeAnimatorController = animatorCache.runtimeAnimatorController;
                    tmpAnimatorController             = new UnityEditor.Animations.AnimatorController();
                    tmpAnimatorController.name        = "Very Animation Temporary Controller";
                    tmpAnimatorController.hideFlags  |= HideFlags.HideAndDontSave;
                    {
                        tmpAnimatorController.AddLayer("Very Animation Layer");
                        layers = tmpAnimatorController.layers;
                        foreach (var layer in layers)
                        {
                            layer.iKPass = true;
                            var stateMachine = layer.stateMachine;
                            stateMachine.hideFlags |= HideFlags.HideAndDontSave;
                            {
                                state            = stateMachine.AddState("Animation");
                                state.hideFlags |= HideFlags.HideAndDontSave;
                                stateNameHash    = state.nameHash;
                            }
                            layer.stateMachine = stateMachine;
                        }
                        tmpAnimatorController.layers = layers;
                    }
                    UnityEditor.Animations.AnimatorController.SetAnimatorController(animatorCache, tmpAnimatorController);
                }
                #endregion
                changed = true;
            }
            else
            {
                Assert.IsTrue(changed);
                animatorCache.hideFlags &= ~HideFlags.NotEditable;

                animatorCache.applyRootMotion = originalAnimatorApplyRootMotion;
                animatorCache.updateMode      = originalAnimatorUpdateMode;
                animatorCache.cullingMode     = originalAnimatorCullingMode;

                #region AnimatorController
                {
                    {
                        var layerCount = tmpAnimatorController.layers.Length;
                        for (int i = 0; i < layerCount; i++)
                        {
                            tmpAnimatorController.RemoveLayer(0);
                        }
                    }
                    DestroyImmediate(tmpAnimatorController);
                    tmpAnimatorController = null;
                    animatorCache.runtimeAnimatorController = originalRuntimeAnimatorController;
                }
                #endregion

                originalRuntimeAnimatorController = null;

                changed = false;
            }

            //Cause unknown. It does not allow initialization.
            {
                t.localPosition = localPosition;
                t.localRotation = localRotation;
                t.localScale    = localScale;
            }
        }
Esempio n. 25
0
		// Switching to ragdoll
		private void RagdollEnabler() {
			// Remember the last animated pose
			StoreLocalState();

			// Disable IK components if necessary
			for (int i = 0; i < allIKComponents.Length; i++) disabledIKComponents[i] = false;

			if (!applyIkOnRagdoll) {
				for (int i = 0; i < allIKComponents.Length; i++) {
					if (allIKComponents[i].enabled) {
						allIKComponents[i].Disable();
						disabledIKComponents[i] = true;
					}
				}
			}

			// Disable the Animator so it won't overwrite physics
			animator.enabled = false;
			
			for (int i = 0; i < rigidbones.Length; i++) rigidbones[i].WakeUp(applyVelocity, applyAngularVelocity);

			// Remember some variables so we can revert to them when coming back from ragdoll
			for (int i = 0; i < fixTransforms.Length; i++) {
				fixTransforms[i] = allIKComponents[i].fixTransforms;
				allIKComponents[i].fixTransforms = false;
			}

			// Switch Animator update mode to AnimatePhysics, so IK is updated in the fixed time step
			animatorUpdateMode = animator.updateMode;
			animator.updateMode = AnimatorUpdateMode.AnimatePhysics;
			
			ragdollWeight = 1f;
			ragdollWeightV = 0f;

			enableRagdollFlag = false;
		}