Ejemplo n.º 1
0
        protected override void OnGUI_Internal(Rect rect, SerializedProperty property, GUIContent label)
        {
            AnimatorParamAttribute animatorParamAttribute = PropertyUtility.GetAttribute <AnimatorParamAttribute>(property);

            AnimatorController animatorController = GetAnimatorController(property, animatorParamAttribute.AnimatorName);

            if (animatorController == null)
            {
                DrawDefaultPropertyAndHelpBox(rect, property, InvalidAnimatorControllerWarningMessage, MessageType.Warning);
                return;
            }

            int parametersCount = animatorController.parameters.Length;
            List <AnimatorControllerParameter> animatorParameters = new List <AnimatorControllerParameter>(parametersCount);

            for (int i = 0; i < parametersCount; i++)
            {
                AnimatorControllerParameter parameter = animatorController.parameters[i];
                if (animatorParamAttribute.AnimatorParamType == null || parameter.type == animatorParamAttribute.AnimatorParamType)
                {
                    animatorParameters.Add(parameter);
                }
            }

            switch (property.propertyType)
            {
            case SerializedPropertyType.Integer:
                DrawPropertyForInt(rect, property, label, animatorParameters);
                break;

            case SerializedPropertyType.String:
                DrawPropertyForString(rect, property, label, animatorParameters);
                break;

            default:
                DrawDefaultPropertyAndHelpBox(rect, property, string.Format(InvalidTypeWarningMessage, property.name), MessageType.Warning);
                break;
            }
        }
Ejemplo n.º 2
0
                public AnimatorParameterSaveData(Animator animator, AnimatorControllerParameter parameter)
                {
                    id            = parameter.nameHash;
                    parameterType = parameter.type;
                    switch (parameterType)
                    {
                    case AnimatorControllerParameterType.Bool:
                        boolValue = animator.GetBool(id);
                        break;

                    case AnimatorControllerParameterType.Float:
                        floatValue = animator.GetFloat(id);
                        break;

                    case AnimatorControllerParameterType.Int:
                        intValuie = animator.GetInteger(id);
                        break;

                    case AnimatorControllerParameterType.Trigger:
                        break;
                    }
                }
Ejemplo n.º 3
0
        void ReadParameters(NetworkReader reader)
        {
            // need to read values from NetworkReader even if animator is disabled

            ulong dirtyBits = reader.ReadPackedUInt64();

            for (int i = 0; i < parameters.Length; i++)
            {
                if ((dirtyBits & (1ul << i)) == 0)
                {
                    continue;
                }

                AnimatorControllerParameter par = parameters[i];
                switch (par.type)
                {
                case AnimatorControllerParameterType.Int:
                {
                    int newIntValue = reader.ReadPackedInt32();
                    SetInteger(par, newIntValue);
                    break;
                }

                case AnimatorControllerParameterType.Float:
                {
                    float newFloatValue = reader.ReadSingle();
                    SetFloat(par, newFloatValue);
                    break;
                }

                case AnimatorControllerParameterType.Bool:
                {
                    bool newBoolValue = reader.ReadBoolean();
                    SetBool(par, newBoolValue);
                    break;
                }
                }
            }
        }
Ejemplo n.º 4
0
        public static void ResetParameters(this Animator animator)
        {
            AnimatorControllerParameter[] parameters = animator.parameters;
            for (int i = 0; i < parameters.Length; i++)
            {
                AnimatorControllerParameter parameter = parameters[i];
                switch (parameter.type)
                {
                case AnimatorControllerParameterType.Int:
                    animator.SetInteger(parameter.name, parameter.defaultInt);
                    break;

                case AnimatorControllerParameterType.Float:
                    animator.SetFloat(parameter.name, parameter.defaultFloat);
                    break;

                case AnimatorControllerParameterType.Bool:
                    animator.SetBool(parameter.name, parameter.defaultBool);
                    break;
                }
            }
        }
Ejemplo n.º 5
0
        void ReadParameters(NetworkReader reader)
        {
            ulong dirtyBits = reader.ReadUInt64();

            for (int i = 0; i < parameters.Length; i++)
            {
                if ((dirtyBits & (1ul << i)) == 0)
                {
                    continue;
                }

                AnimatorControllerParameter par = parameters[i];
                if (par.type == AnimatorControllerParameterType.Int)
                {
                    int newIntValue = reader.ReadInt32();
                    _animator.SetInteger(par.nameHash, newIntValue);
                }
                else if (par.type == AnimatorControllerParameterType.Float)
                {
                    float newFloatValue = reader.ReadSingle();
                    if (_smoothFloats)
                    {
                        float currentValue = _animator.GetFloat(par.nameHash);
                        float past         = base.syncInterval + _interpolationFallbehind;
                        float rate         = Mathf.Abs(currentValue - newFloatValue) / past;
                        _floatTargets[par.nameHash] = new LerpingFloat(rate, newFloatValue);
                    }
                    else
                    {
                        _animator.SetFloat(par.nameHash, newFloatValue);
                    }
                }
                else if (par.type == AnimatorControllerParameterType.Bool)
                {
                    bool newBoolValue = reader.ReadBoolean();
                    _animator.SetBool(par.nameHash, newBoolValue);
                }
            }
        }
Ejemplo n.º 6
0
        void ReadParameters(NetworkReader reader, bool autoSend)
        {
            // store the animator parameters in a variable - the "Animator.parameters" getter allocates
            // a new parameter array every time it is accessed so we should avoid doing it in a loop
            AnimatorControllerParameter[] parameters = m_Animator.parameters;

            for (int i = 0; i < parameters.Length; i++)
            {
                if (autoSend && !GetParameterAutoSend(i))
                {
                    continue;
                }

                AnimatorControllerParameter par = parameters[i];
                if (par.type == AnimatorControllerParameterType.Int)
                {
                    int newValue = (int)reader.ReadPackedUInt32();
                    m_Animator.SetInteger(par.nameHash, newValue);

                    SetRecvTrackingParam(par.name + ":" + newValue, i);
                }

                if (par.type == AnimatorControllerParameterType.Float)
                {
                    float newFloatValue = reader.ReadSingle();
                    m_Animator.SetFloat(par.nameHash, newFloatValue);

                    SetRecvTrackingParam(par.name + ":" + newFloatValue, i);
                }

                if (par.type == AnimatorControllerParameterType.Bool)
                {
                    bool newBoolValue = reader.ReadBoolean();
                    m_Animator.SetBool(par.nameHash, newBoolValue);

                    SetRecvTrackingParam(par.name + ":" + newBoolValue, i);
                }
            }
        }
Ejemplo n.º 7
0
        /*************************************************
        *
        * Animatior Enhancement
        *
        *************************************************/

        /// <summary>
        /// 复制 Animator ,注意 trigger 是不能复制的(一般而言也不用复制)
        /// </summary>
        public static void CopyTo(this Animator from, Animator to)
        {
            if (from == to || from == null || to == null)
            {
                return;
            }

            // Copy Parameter
            AnimatorControllerParameter [] parameters = from.parameters;
            for (int i = 0; i < parameters.Length; i++)
            {
                AnimatorControllerParameter param = parameters[i];
                switch (param.type)
                {
                case AnimatorControllerParameterType.Bool:
                    to.SetBool(param.nameHash, from.GetBool(param.nameHash));
                    break;

                case AnimatorControllerParameterType.Float:
                    to.SetFloat(param.nameHash, from.GetFloat(param.nameHash));
                    break;

                case AnimatorControllerParameterType.Int:
                    to.SetInteger(param.nameHash, from.GetInteger(param.nameHash));
                    break;
                }
            }

            // Copy Current State
            for (int i = 0; i < from.layerCount; i++)
            {
                AnimatorStateInfo info = from.GetCurrentAnimatorStateInfo(i);
                to.Play(info.fullPathHash, i, info.normalizedTime);
            }

            // Copy Transform
            from.transform.CopyTo(to.transform, true);
        }
Ejemplo n.º 8
0
        public static void Awake(this AnimatorComponent self)
        {
            Animator animator = self.Parent.GetComponent <GameObjectComponent>().GameObject.GetComponent(typeof(Animator)) as Animator;

            if (animator == null)
            {
                return;
            }

            if (animator.runtimeAnimatorController == null)
            {
                return;
            }

            if (animator.runtimeAnimatorController.animationClips == null)
            {
                return;
            }
            self.Animator = animator;

            int   count = animator.GetanimationClipsLength();
            Array animationClipArray = animator.runtimeAnimatorController.animationClips;               // animator.runtimeAnimatorController.animationClips;

            for (int i = 0; i < count; ++i)
            {
                AnimationClip animationClip = (AnimationClip)animationClipArray.GetValue(i);
                self.animationClips[animationClip.name] = animationClip;
            }

            count = animator.GetAnimatorControllerParameterLength();
            Array parametersArray = animator.parameters;

            for (int i = 0; i < count; ++i)
            {
                AnimatorControllerParameter animatorControllerParameter = (AnimatorControllerParameter)parametersArray.GetValue(i);
                self.Parameter.Add(animatorControllerParameter.name);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Load the previous state of an animation parameter
        /// </summary>
        /// <param name="param">The animation parameter to load.</param>
        private void RetrieveParameter(AnimatorControllerParameter param)
        {
            string key    = guid.ToString() + "_" + param.name;
            string folder = StaticFolders.ANIMATION;

            // Set the value based on the parameter type.
            switch (param.type)
            {
            case AnimatorControllerParameterType.Int: {
                key += Keys.ANIM_INT;
                if (VSave.Get(folder, key, out int value))
                {
                    anim.SetInteger(param.name, value);
                }
                break;
            }

            case AnimatorControllerParameterType.Bool: {
                key += Keys.ANIM_BOOL;
                if (VSave.Get(folder, key, out bool value))
                {
                    anim.SetBool(param.name, value);
                }
                break;
            }

            case AnimatorControllerParameterType.Float: {
                key += Keys.ANIM_FLOAT;
                if (VSave.Get(folder, key, out float value))
                {
                    anim.SetFloat(param.name, value);
                }
                break;
            }

            default: return; // Triggers fire one off. They don't need to be stored.
            }
        }
        public void DoTransitionPreview()
        {
            if (m_Controller == null)
            {
                return;
            }

            if (Event.current.type == EventType.Repaint)
            {
                m_AvatarPreview.timeControl.Update();
            }

            DoTimeline();

            // Draw the blend values

            AnimatorControllerParameter[] parameters = m_Controller.parameters;
            if (parameters.Length > 0)
            {
                m_ShowBlendValue = EditorGUILayout.Foldout(m_ShowBlendValue, "BlendTree Parameters", true);

                if (m_ShowBlendValue)
                {
                    for (int i = 0; i < parameters.Length; i++)
                    {
                        AnimatorControllerParameter parameter = m_Controller.parameters[i];
                        float value    = m_ParameterInfoList[i].m_Value;
                        float newValue = EditorGUILayout.Slider(parameter.name, value, m_ParameterMinMax[i][0], m_ParameterMinMax[i][1]);
                        if (newValue != value)
                        {
                            m_ParameterInfoList[i].m_Value = newValue;
                            mustResample        = true;
                            m_MustSampleMotions = true;
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
    /// <summary>
    /// Will set the Animation with the supplied parameter
    /// </summary>
    /// <param name="animation">The Animation to set</param>
    /// <param name="animator">The animator to get the Animations</param>
    /// <param name="parameter">The value for the Animation</param>
    public static void setAnimationTypeAndValue(Animation animation, Animator animator, object value)
    {
        if (value == null)
        {
            return;
        }

        //Grab what Type of parameter
        AnimatorControllerParameter param = getAnimatorControllerParameter(animation, animator);

        //If param doesn't exist, just get out
        if (param == null)
        {
            return;
        }

        switch (param.type)
        {
        case AnimatorControllerParameterType.Bool:
            animator.SetBool(animation.ToString(), (bool)value);
            break;

        case AnimatorControllerParameterType.Float:
            animator.SetFloat(animation.ToString(), (float)value);
            break;

        case AnimatorControllerParameterType.Int:
            animator.SetInteger(animation.ToString(), (int)value);
            break;

        case AnimatorControllerParameterType.Trigger:
            animator.SetTrigger(animation.ToString());
            break;

        default:
            break;
        }
    }
Ejemplo n.º 12
0
    /// <summary>
    /// Idle状態にする。
    /// </summary>
    public void PlayIdle()
    {
        int count = CacheAnimator.parameters.Length;

        for (int i = 0; i < count; i++)
        {
            AnimatorControllerParameter param = CacheAnimator.parameters[i];
            if (param.type == AnimatorControllerParameterType.Bool)
            {
                CacheAnimator.SetBool(param.name, param.defaultBool);
            }
            else if (param.type == AnimatorControllerParameterType.Int)
            {
                CacheAnimator.SetInteger(param.name, param.defaultInt);
            }
            else if (param.type == AnimatorControllerParameterType.Float)
            {
                CacheAnimator.SetFloat(param.name, param.defaultFloat);
            }
        }

        //PlayMotion();
    }
Ejemplo n.º 13
0
    private List <AnimatorControllerParameter> GetAnimatorControllerParameter()
    {
        if (_combo == null)
        {
            Debug.LogError("Combo is null.");
            return(null);
        }
        if (_CharacterAnimatorNamingList == null)
        {
            Debug.LogError("CharacterAnimatorNamingList is null.");
            return(null);
        }
        List <AnimatorControllerParameter> AnimatorControllerParameters = new List <AnimatorControllerParameter>();

        AnimatorControllerParameter _normalizedParam = ParameterCreator.CreateParameter(_CharacterAnimatorNamingList.NormalizedTimeParameterName, AnimatorControllerParameterType.Float);
        AnimatorControllerParameter _speedParam      = ParameterCreator.CreateParameter(_CharacterAnimatorNamingList.SpeedParameterName, AnimatorControllerParameterType.Float);


        AnimatorControllerParameters.Add(_combo.AnimatorControllerParameter);
        AnimatorControllerParameters.Add(_normalizedParam);
        AnimatorControllerParameters.Add(_speedParam);
        return(AnimatorControllerParameters);
    }
Ejemplo n.º 14
0
            public static bool AnimeParamFindSet(
                UnityEngine.Animator animator,
                Tuple <string, object>[] nameValues,
                AnimatorControllerParameter[] animParams)
            {
                bool flag = false;

                using (IEnumerator <\u003C\u003E__AnonType33 <AnimatorControllerParameterType, Tuple <string, object> > > enumerator = ((IEnumerable <Tuple <string, object> >)nameValues).Select <Tuple <string, object>, \u003C\u003E__AnonType33 <AnimatorControllerParameterType, Tuple <string, object> > >((Func <Tuple <string, object>, \u003C\u003E__AnonType33 <AnimatorControllerParameterType, Tuple <string, object> > >)(v =>
                {
                    AnimatorControllerParameter controllerParameter = ((IEnumerable <AnimatorControllerParameter>)animParams).FirstOrDefault <AnimatorControllerParameter>((Func <AnimatorControllerParameter, bool>)(p => p.get_name() == v.Item1));
                    // ISSUE: object of a compiler-generated type is created
                    return(controllerParameter == null ? (\u003C\u003E__AnonType33 <AnimatorControllerParameterType, Tuple <string, object> >)null : new \u003C\u003E__AnonType33 <AnimatorControllerParameterType, Tuple <string, object> >(controllerParameter.get_type(), v));
                })).GetEnumerator())
                {
                    while (((IEnumerator)enumerator).MoveNext())
                    {
                        // ISSUE: variable of a compiler-generated type
                        \u003C\u003E__AnonType33 <AnimatorControllerParameterType, Tuple <string, object> > current = enumerator.Current;
                        flag |= Utils.Animator.AnimeParamSet(animator, current.value, current.type);
                    }
                }
                return(flag);
            }
Ejemplo n.º 15
0
    private void SetAnimatorParameterData(AnimatorControllerParameter param, object data)
    {
        AnimatorControllerParameterType type = param.type;

        if (type != AnimatorControllerParameterType.Int)
        {
            if (type != AnimatorControllerParameterType.Float)
            {
                if (type == AnimatorControllerParameterType.Bool)
                {
                    this.m_Animator.SetBool(param.nameHash, (bool)data);
                }
            }
            else
            {
                this.m_Animator.SetFloat(param.nameHash, (float)data);
            }
        }
        else
        {
            this.m_Animator.SetInteger(param.nameHash, (int)data);
        }
    }
Ejemplo n.º 16
0
 void Sync(NeutronReader streamReader)
 {
     using (streamReader)
     {
         object[] parameters = streamReader.ReadBytes(8192).DeserializeObject <object[]>();
         for (int i = 0; i < parameters.Length; i++)
         {
             AnimatorControllerParameter parameter = GetAnimator.GetParameter(i);
             if (parameter.type == AnimatorControllerParameterType.Bool)
             {
                 GetAnimator.SetBool(parameter.name, (bool)parameters[i]);
             }
             else if (parameter.type == AnimatorControllerParameterType.Float)
             {
                 GetAnimator.SetFloat(parameter.name, (float)parameters[i]);
             }
             else if (parameter.type == AnimatorControllerParameterType.Int)
             {
                 GetAnimator.SetInteger(parameter.name, (int)parameters[i]);
             }
         }
     }
 }
Ejemplo n.º 17
0
    private void SetAnimatorParameterData(AnimatorControllerParameter param, object data)
    {
        switch (param.type)
        {
        case AnimatorControllerParameterType.Float:
            this.m_Animator.SetFloat(param.nameHash, (float)data);
            return;

        case (AnimatorControllerParameterType)2:
            break;

        case AnimatorControllerParameterType.Int:
            this.m_Animator.SetInteger(param.nameHash, (int)data);
            return;

        case AnimatorControllerParameterType.Bool:
            this.m_Animator.SetBool(param.nameHash, (bool)data);
            break;

        default:
            return;
        }
    }
Ejemplo n.º 18
0
        private void Update()
        {
            if (isInterpolating)
            {
                // If we weren't previously interpolating, we need to cache the current float values from the animator before we start to interpolate.
                // Otherwise, there might be a noticeable jump as the parameters settle in.
                if (!wasInterpolating)
                {
                    CacheFloatTargets();
                }

                for (int i = 0; i < parameters.Length; i++)
                {
                    AnimatorControllerParameter par = parameters[i];
                    if (par.type == AnimatorControllerParameterType.Float)
                    {
                        float newFloatValue = Mathf.Lerp(floatParametersTargets[i], animator.GetFloat(par.nameHash), interpolationFactor);
                        animator.SetFloat(par.nameHash, newFloatValue);
                    }
                }
            }
            wasInterpolating = isInterpolating;
        }
Ejemplo n.º 19
0
        public static List <NetworkAnimatorParameter> GetAnimatorParams(Animator animator)
        {
            List <NetworkAnimatorParameter> dumppedparamList = new List <NetworkAnimatorParameter>();

            AnimatorControllerParameter[] paramList = animator.parameters;
            //Logger.InfoFormat("Parameters Count; {0}", paramList.Length);

            for (int i = 0; i < paramList.Length; i++)
            {
                AnimatorControllerParameter param       = paramList[i];
                NetworkAnimatorParameter    copyedParam = null;
                switch (param.type)
                {
                case AnimatorControllerParameterType.Bool:
                    bool boolVal = animator.GetBool(param.nameHash);
                    copyedParam = new NetworkAnimatorParameter(param.type, boolVal, param.nameHash);
                    break;

                case AnimatorControllerParameterType.Float:
                    float floatVal = animator.GetFloat(param.nameHash);
                    copyedParam = new NetworkAnimatorParameter(param.type, floatVal, param.nameHash);
                    break;

                case AnimatorControllerParameterType.Int:
                    int intVal = animator.GetInteger(param.nameHash);
                    copyedParam = new NetworkAnimatorParameter(param.type, intVal, param.nameHash);
                    break;

                case AnimatorControllerParameterType.Trigger:
                    throw new Exception("not supported");
                }

                dumppedparamList.Add(copyedParam);
            }

            return(dumppedparamList);
        }
Ejemplo n.º 20
0
        private void WriteParameters(BinaryWriter writer, bool autoSend)
        {
            if (animatorParameters == null)
            {
                animatorParameters = animator.parameters;
            }

            for (int i = 0; i < animatorParameters.Length; i++)
            {
                if (autoSend && !GetParameterAutoSend(i))
                {
                    continue;
                }

                AnimatorControllerParameter par = animatorParameters[i];
                if (par.type == AnimatorControllerParameterType.Int)
                {
                    writer.Write((uint)animator.GetInteger(par.nameHash));

                    SetSendTrackingParam(par.name + ":" + animator.GetInteger(par.nameHash), i);
                }

                if (par.type == AnimatorControllerParameterType.Float)
                {
                    writer.Write(animator.GetFloat(par.nameHash));

                    SetSendTrackingParam(par.name + ":" + animator.GetFloat(par.nameHash), i);
                }

                if (par.type == AnimatorControllerParameterType.Bool)
                {
                    writer.Write(animator.GetBool(par.nameHash));

                    SetSendTrackingParam(par.name + ":" + animator.GetBool(par.nameHash), i);
                }
            }
        }
Ejemplo n.º 21
0
        void ReadParameters(NetworkReader reader)
        {
            ulong dirtyBits = reader.ReadPackedUInt64();

            for (int i = 0; i < parameters.Length; i++)
            {
                if ((dirtyBits & (1ul << i)) == 0)
                {
                    continue;
                }

                AnimatorControllerParameter par = parameters[i];
                if (par.type == AnimatorControllerParameterType.Int)
                {
                    int newIntValue = reader.ReadPackedInt32();
                    animator.SetInteger(par.nameHash, newIntValue);
                }
                else if (par.type == AnimatorControllerParameterType.Float)
                {
                    float newFloatValue = reader.ReadSingle();
                    // If interpolating, set the target. Otherwise, set the value immediately.
                    if (interpolateFloatParameters)
                    {
                        floatParametersTargets[i] = newFloatValue;
                    }
                    else
                    {
                        animator.SetFloat(par.nameHash, newFloatValue);
                    }
                }
                else if (par.type == AnimatorControllerParameterType.Bool)
                {
                    bool newBoolValue = reader.ReadBoolean();
                    animator.SetBool(par.nameHash, newBoolValue);
                }
            }
        }
    public static bool HasParameter(this Animator i_Animator, int i_ParamNameHash)
    {
        if (i_Animator == null)
        {
            return(false);
        }

        for (int index = 0; index < i_Animator.parameterCount; ++index)
        {
            AnimatorControllerParameter parameter = i_Animator.GetParameter(index);

            if (parameter == null)
            {
                continue;
            }

            if (parameter.nameHash == i_ParamNameHash)
            {
                return(true);
            }
        }

        return(false);
    }
Ejemplo n.º 23
0
    bool GetParameters(out object[] mParams)
    {
        object[] parametersToSend = new object[GetAnimator.parameterCount];

        for (int i = 0; i < parametersToSend.Length; i++)
        {
            AnimatorControllerParameter parameter = GetAnimator.GetParameter(i);
            if (parameter.type == AnimatorControllerParameterType.Bool)
            {
                parametersToSend[i] = GetAnimator.GetBool(parameter.name);
            }
            else if (parameter.type == AnimatorControllerParameterType.Float)
            {
                parametersToSend[i] = GetAnimator.GetFloat(parameter.name);
            }
            else if (parameter.type == AnimatorControllerParameterType.Int)
            {
                parametersToSend[i] = GetAnimator.GetInteger(parameter.name);
            }
        }
        mParams = parametersToSend;
        //===========================//
        return(true);
    }
Ejemplo n.º 24
0
        void WriteParameters(NetworkWriter writer, bool autoSend)
        {
            // store the animator parameters in a variable - the "Animator.parameters" getter allocates
            // a new parameter array every time it is accessed so we should avoid doing it in a loop
            AnimatorControllerParameter[] parameters = m_Animator.parameters;

            for (int i = 0; i < parameters.Length; i++)
            {
                if (autoSend && !GetParameterAutoSend(i))
                {
                    continue;
                }

                AnimatorControllerParameter par = parameters[i];
                if (par.type == AnimatorControllerParameterType.Int)
                {
                    writer.WritePackedUInt32((uint)m_Animator.GetInteger(par.nameHash));

                    SetSendTrackingParam(par.name + ":" + m_Animator.GetInteger(par.nameHash), i);
                }

                if (par.type == AnimatorControllerParameterType.Float)
                {
                    writer.Write(m_Animator.GetFloat(par.nameHash));

                    SetSendTrackingParam(par.name + ":" + m_Animator.GetFloat(par.nameHash), i);
                }

                if (par.type == AnimatorControllerParameterType.Bool)
                {
                    writer.Write(m_Animator.GetBool(par.nameHash));

                    SetSendTrackingParam(par.name + ":" + m_Animator.GetBool(par.nameHash), i);
                }
            }
        }
Ejemplo n.º 25
0
        // ####################### save ######################### //

        public void Save()
        {
            //Save Data into Animator

            // parameters
            List <AnimatorControllerParameter> newParameters = new List <AnimatorControllerParameter>();

            foreach (var input in inputs)
            {
                AnimatorControllerParameter controllerParameter = new AnimatorControllerParameter();
                controllerParameter.name        = input.parameterName;
                controllerParameter.type        = input.type;
                controllerParameter.defaultBool = input.defaultBool;
                if (input.options.Count > input.defaultOptionIndex)
                {
                    controllerParameter.defaultFloat = input.options[input.defaultOptionIndex].floatValue;
                    controllerParameter.defaultInt   = input.options[input.defaultOptionIndex].intValue;
                }
                newParameters.Add(controllerParameter);
            }

            // layers
            List <AnimatorControllerLayer> newLayers = new List <AnimatorControllerLayer>();

            foreach (var layer in layers)
            {
                AnimatorControllerLayer controllerLayer = new AnimatorControllerLayer();
                controllerLayer.name          = layer.Name;
                controllerLayer.stateMachine  = AddStateMachine(layer.stateMachine);
                controllerLayer.defaultWeight = 1;
                newLayers.Add(controllerLayer);
            }

            referenceAnimator.parameters = newParameters.ToArray();
            referenceAnimator.layers     = newLayers.ToArray();
        }
Ejemplo n.º 26
0
    public static void ResetParameter(Animator animator, AnimatorControllerParameter parameter)
    {
        switch (parameter.type)
        {
        case AnimatorControllerParameterType.Float:
            animator.SetFloat(parameter.name, parameter.defaultFloat);
            break;

        case AnimatorControllerParameterType.Int:
            animator.SetInteger(parameter.name, parameter.defaultInt);
            break;

        case AnimatorControllerParameterType.Bool:
            animator.SetBool(parameter.name, parameter.defaultBool);
            break;

        case AnimatorControllerParameterType.Trigger:
            animator.SetTrigger(parameter.name);
            break;

        default:
            break;
        }
    }
Ejemplo n.º 27
0
        public static void SetAnimation(this Animator animator, AnimatorControllerParameter animationToSet, object parameter = null)
        {
            switch (animationToSet.type)
            {
            case AnimatorControllerParameterType.Int:
                animator.SetInteger(animationToSet.name, (int)parameter);
                break;

            case AnimatorControllerParameterType.Float:
                animator.SetFloat(animationToSet.name, (float)parameter);
                break;

            case AnimatorControllerParameterType.Bool:
                animator.SetBool(animationToSet.name, (bool)parameter);
                break;

            case AnimatorControllerParameterType.Trigger:
                animator.SetTrigger(animationToSet.name);
                break;

            default:
                throw new System.Exception("Cannot find animation type.");
            }
        }
Ejemplo n.º 28
0
        private void DrawParameter(FireFxTreeDebuger d, Insp_TextInput insp)
        {
            if (d == null || insp == null || actionType == AnimatorActionType.Play)
            {
                return;
            }
            if (animTarget != AnimatorTarget.Host)
            {
                paramName = EditorGUILayout.TextField(insp.label, paramName);
                return;
            }
            EditorGUI.BeginChangeCheck();
            string st = AnimatorGUI.ParameterField(d.hero, insp.label, paramName);

            if (EditorGUI.EndChangeCheck())
            {
                insp.SetValueString(st);
                AnimatorControllerParameter p = EditAnimatorUtils.GetAnimParameter(d.hero, st);
                if (p != null)
                {
                    paramType = p.type;
                }
            }
        }
Ejemplo n.º 29
0
        protected void SetFlag(AnimatorControllerParameter param, bool flag)
        {
            switch (param.type)
            {
            case AnimatorControllerParameterType.Trigger:
                if (flag)
                {
                    Animator.SetTrigger(param.name);
                }
                else
                {
                    Animator.ResetTrigger(param.name);
                }
                break;

            case AnimatorControllerParameterType.Bool:
                Animator.SetBool(param.name, flag);
                break;

            case AnimatorControllerParameterType.Int:
                Animator.SetInteger(param.name, flag ? 1 : 0);
                break;
            }
        }
Ejemplo n.º 30
0
        void ReadParameters(NetworkReader reader, bool autoSend)
        {
            m_AnimatorControllerParameters = m_Animator.parameters;
            for (int i = 0; i < m_AnimatorControllerParameters.Length; i++)
            {
                if (autoSend && !GetParameterAutoSend(i))
                {
                    continue;
                }

                m_AnimatorControllerParameter = m_AnimatorControllerParameters[i];
                if (m_AnimatorControllerParameter.type == AnimatorControllerParameterType.Int)
                {
                    int newValue = (int)reader.ReadPackedUInt32();
                    m_Animator.SetInteger(m_AnimatorControllerParameter.nameHash, newValue);

                    SetRecvTrackingParam(m_AnimatorControllerParameter.name + ":" + newValue, i);
                }

                if (m_AnimatorControllerParameter.type == AnimatorControllerParameterType.Float)
                {
                    float newFloatValue = reader.ReadSingle();
                    m_Animator.SetFloat(m_AnimatorControllerParameter.nameHash, newFloatValue);

                    SetRecvTrackingParam(m_AnimatorControllerParameter.name + ":" + newFloatValue, i);
                }

                if (m_AnimatorControllerParameter.type == AnimatorControllerParameterType.Bool)
                {
                    bool newBoolValue = reader.ReadBoolean();
                    m_Animator.SetBool(m_AnimatorControllerParameter.nameHash, newBoolValue);

                    SetRecvTrackingParam(m_AnimatorControllerParameter.name + ":" + newBoolValue, i);
                }
            }
        }