示例#1
0
    private AnimatorMotion ReadNodeFromSerializedNodes(AnimatorState state, int index)
    {
        SerializableMotion    serialisedBo = state.serialisedMotions[index];
        List <AnimatorMotion> children     = new List <AnimatorMotion>();

        for (int i = 0; i < serialisedBo.childCount; i++)
        {
            children.Add(ReadNodeFromSerializedNodes(state, serialisedBo.indexOfFirstChild + i));
        }

        if (serialisedBo.isAnimation)
        {
            AnimatorClip anim = new AnimatorClip();
            anim.name      = serialisedBo.name;
            anim.data      = serialisedBo.animatorData;
            anim.treeIndex = index;
            return(anim);
        }
        else
        {
            AnimatorBlendTree blend = new AnimatorBlendTree();
            blend.name                 = serialisedBo.name;
            blend.positions            = serialisedBo.positions;
            blend.blendParameterIndex  = serialisedBo.blendParameterIndex;
            blend.blendParameterIndexY = serialisedBo.blendParameterIndexY;
            blend.resolution           = serialisedBo.resolution;
            blend.weightTable          = DeserializeWeightTable(serialisedBo.weightTable);
            blend.motions              = children.ToArray();
            blend.motionCount          = children.Count;
            blend.weights              = new FP[blend.motionCount];
            blend.treeIndex            = index;
            return(blend);
        }
    }
示例#2
0
 public void Toggle()
 {
     if (isOpen)
     {
         isOpen = false;
         AnimatorClip.CrossFade(animator, closeDoor);
     }
     else
     {
         isOpen = true;
         AnimatorClip.CrossFade(animator, openDoor);
     }
 }
示例#3
0
    public void SerialiseObject(AnimatorState state, AnimatorMotion mo = null)
    {
        SerializableMotion serialisedBo = new SerializableMotion();

        if (mo == null)//initial blend object will be patched in on first call
        {
            mo = state.motion;
        }

        if (mo is AnimatorClip)
        {
            AnimatorClip anim = mo as AnimatorClip;
            serialisedBo.isAnimation       = true;
            serialisedBo.name              = anim.data.clipName;
            serialisedBo.animatorData      = anim.data;
            serialisedBo.childCount        = 0;
            serialisedBo.indexOfFirstChild = state.serialisedMotions.Count + 1;

            state.serialisedMotions.Add(serialisedBo);
        }

        if (mo is AnimatorBlendTree)
        {
            AnimatorBlendTree blend = mo as AnimatorBlendTree;
            serialisedBo.isAnimation          = false;
            serialisedBo.name                 = blend.name;//string.Format("Tree of {0}", blend.motionCount);
            serialisedBo.positions            = blend.positions;
            serialisedBo.blendParameterIndex  = blend.blendParameterIndex;
            serialisedBo.blendParameterIndexY = blend.blendParameterIndexY;
            serialisedBo.weightTable          = SerializeWeightTable(blend.weightTable);
            serialisedBo.resolution           = blend.resolution;

            serialisedBo.childCount        = blend.motionCount;
            serialisedBo.indexOfFirstChild = state.serialisedMotions.Count + 1;

            state.serialisedMotions.Add(serialisedBo);
            foreach (var child in blend.motions)
            {
                SerialiseObject(state, child);
            }
        }
    }
示例#4
0
    //保存是更新值
    protected override void OnSave()
    {
        if (Target == null)
        {
            return;
        }
        var animatorListClips = Target.animator.listClips;

        animatorListClips.Clear();

        foreach (var clip in this.ListClip)
        {
            AnimatorClip aclip = new AnimatorClip();
            aclip.name       = clip.name;
            aclip.clipName   = clip.GetParam("clipName");
            aclip.param      = clip.GetParam("param");
            aclip.length     = clip.GetParamFloat("length");
            aclip.speed      = clip.GetParamFloat("speed");
            aclip.fadeFactor = clip.GetParamFloat("fadeFactor");

            aclip.UF_SetWrapMode(clip.GetParam("wrapMode", WrapMode.Once.ToString()));
            aclip.UF_SetCrossMode(clip.GetParam("crossMode", AnimatorClip.CrossMode.Direct.ToString()));

            foreach (var clipevent in clip.ListClipEvent)
            {
                ClipEvent ace = new ClipEvent();
                ace.name    = string.IsNullOrEmpty(clipevent.name) ? AvatarClipEventType.Null.ToString() : clipevent.name;
                ace.param   = clipevent.GetParam("param");
                ace.trigger = clipevent.triggerTime;
                aclip.clipEvents.Add(ace);
            }
            // 必须按照trigger 时间进行列表排序
            aclip.clipEvents.Sort((a, b) => { return(a.trigger < b.trigger ? -1:1); });

            animatorListClips.Add(aclip);
        }

        // 保存Avatar
        EditorTools.SetDirty(Target);
        EditorTools.RegisterUndo("AvatarController Action Change", Target);
    }
示例#5
0
    public override void OnInspectorGUI()
    {
        var graph = asset.Settings;

        if (GUILayout.Button("Import Mecanim Controller"))
        {
            ExportAnimations.CreateAsset(asset, (UnityEditor.Animations.AnimatorController)asset.controller);

            EditorUtility.SetDirty(asset);
            AssetDatabase.Refresh();
        }

        if (graph != null && graph.layers != null)
        {
            int layerCount = graph.layers.Length;
            if (layerCount > 0)
            {
                string[] layerNames = new string[layerCount];
                for (int l = 0; l < layerCount; l++)
                {
                    layerNames[l] = graph.layers[l].name;
                }
                selectedLayer = GUILayout.Toolbar(selectedLayer, layerNames);
                AnimatorLayer layer = graph.layers[selectedLayer];

                if (layer != null)
                {
                    int stateCount = layer.states.Length;

                    if (stateCount > 0)
                    {
                        string[] stateNames = new string[stateCount];
                        for (int s = 0; s < stateCount; s++)
                        {
                            stateNames[s] = layer.states[s].name;
                        }
                        selectedState = GUILayout.Toolbar(selectedState, stateNames);
                        AnimatorState state = layer.states[selectedState];

                        if (state != null)
                        {
                            EditorGUILayout.BeginVertical("box");

                            EditorGUILayout.LabelField("State");
                            EditorGUILayout.LabelField(state.name);
                            EditorGUILayout.LabelField(string.Format("Is Default: {0}", state.isDefault));
                            if (state.motion != null)
                            {
                                EditorGUILayout.LabelField(string.Format("Is Blend Tree: {0}", state.motion.isTree));

                                if (!state.motion.isTree)
                                {
                                    AnimatorClip motion = state.motion as AnimatorClip;
                                    AnimationClipGui(motion);
                                }
                                else
                                {
                                    AnimatorBlendTree motion = state.motion as AnimatorBlendTree;
                                    string[]          blends = new string[motion.motionCount];
                                    for (int b = 0; b < motion.motionCount; b++)
                                    {
                                        blends[b] = motion.motions[b].name;
                                    }
                                    selectedBlend = SelectionField(blends, selectedBlend, 2);

                                    AnimatorClip clip = motion.motions[selectedBlend] as AnimatorClip;
                                    AnimationClipGui(clip);
                                }
                            }
                            else
                            {
                                EditorGUILayout.LabelField("No Motion Set");
                            }

                            EditorGUILayout.Space();
                            EditorGUILayout.LabelField("Transitions");
                            int transitionCount = state.transitions.Length;
                            for (int t = 0; t < transitionCount; t++)
                            {
                                EditorGUILayout.BeginVertical("Box");

                                AnimatorTransition transition = state.transitions[t];

                                EditorGUILayout.LabelField(string.Format("{0}. {1}", transition.index, transition.name));
                                EditorGUILayout.LabelField(string.Format("Duration: {0} sec", transition.duration.AsFloat));
                                EditorGUILayout.LabelField(string.Format("Has Exit Time: {0}", transition.hasExitTime));
                                EditorGUILayout.LabelField(string.Format("Exit Time: {0} sec", transition.exitTime.AsFloat));
                                EditorGUILayout.LabelField(string.Format("Destination State (Hash): {0} ({1})", transition.destinationStateName, transition.destinationStateId));
                                EditorGUILayout.LabelField(string.Format("Offset: {0} sec", transition.offset.AsFloat));

                                int conditionCount = transition.conditions.Length;
                                for (int c = 0; c < conditionCount; c++)
                                {
                                    EditorGUILayout.BeginVertical("Box");
                                    AnimatorCondition condition = transition.conditions[c];
                                    AnimatorVariable  variable  = graph.variables[graph.VariableIndex(condition.variableName)];

                                    string conditionMode = "";
                                    switch (condition.mode)
                                    {
                                    case AnimatorCondition.Modes.Equals:
                                        conditionMode = "==";
                                        break;

                                    case AnimatorCondition.Modes.Greater:
                                        conditionMode = ">";
                                        break;

                                    case AnimatorCondition.Modes.If:
                                        conditionMode = "is true";
                                        break;

                                    case AnimatorCondition.Modes.IfNot:
                                        conditionMode = "is false";
                                        break;

                                    case AnimatorCondition.Modes.Less:
                                        conditionMode = "<";
                                        break;

                                    case AnimatorCondition.Modes.NotEqual:
                                        conditionMode = "!=";
                                        break;
                                    }

                                    string threshold = "";
                                    switch (variable.type)
                                    {
                                    case AnimatorVariable.VariableType.FP:
                                        threshold = condition.thresholdFp.AsFloat.ToString();
                                        break;

                                    case AnimatorVariable.VariableType.Int:
                                        threshold = condition.thresholdInt.ToString();
                                        break;
                                    }

                                    EditorGUILayout.LabelField(string.Format("\"{0}\" - {1} - {2}", condition.variableName, conditionMode, threshold));

                                    EditorGUILayout.EndVertical();
                                }

                                EditorGUILayout.EndVertical();
                            }

                            EditorGUILayout.EndVertical();
                        }
                    }
                }
            }
        }

        base.OnInspectorGUI();
    }
示例#6
0
    private void AnimationClipGui(AnimatorClip clip)
    {
        EditorGUILayout.BeginVertical("box", GUILayout.Width(EditorGUIUtility.currentViewWidth - 20));
        EditorGUILayout.LabelField("Animator Clip");
        EditorGUILayout.LabelField(string.Format("Name: {0}", clip.clipName));
        EditorGUILayout.LabelField(string.Format("Length: {0}", clip.data.length.AsFloat));
        EditorGUILayout.LabelField(string.Format("Frame Rate: {0}", clip.data.frameRate));
        EditorGUILayout.LabelField(string.Format("Frame Count: {0}", clip.data.frameCount));
        EditorGUILayout.LabelField(string.Format("Looped: {0}", clip.data.looped));
        EditorGUILayout.LabelField(string.Format("Mirrored: {0}", clip.data.mirror));

        int frameCount = clip.data.frameCount;

        Vector3[]    positions  = new Vector3[frameCount];
        Quaternion[] rotationsQ = new Quaternion[frameCount];
        Vector3[]    rotations  = new Vector3[frameCount];
        float[]      times      = new float[frameCount];
        for (int f = 0; f < frameCount; f++)
        {
            AnimatorFrame frame     = clip.data.frames[f];
            float         frameTime = frame.time.AsFloat;
            FPVector3     position  = frame.position;
            FPQuaternion  rotation  = frame.rotation;

            Vector3    pV3 = new Vector3(position.X.AsFloat, position.Y.AsFloat, position.Z.AsFloat);
            Quaternion rQ  = new Quaternion(rotation.X.AsFloat, rotation.Y.AsFloat, rotation.Z.AsFloat, rotation.W.AsFloat);
            Vector3    rV3 = rQ.eulerAngles;

            positions[f]  = pV3;
            rotationsQ[f] = rQ;
            rotations[f]  = rV3;
            times[f]      = frameTime;
        }

        EditorGUILayout.BeginVertical("box");

        EditorGUILayout.LabelField(string.Format("Delta Movement: {0}", (positions[frameCount - 1] - positions[0]).ToString("F3")));
        Quaternion deltaQ  = Quaternion.FromToRotation(rotationsQ[0] * Vector3.forward, rotationsQ[frameCount - 1] * Vector3.forward);
        Vector3    deltaQV = deltaQ.eulerAngles;

        if (deltaQV.x > 180)
        {
            deltaQV.x += -360;
        }
        if (deltaQV.y > 180)
        {
            deltaQV.y += -360;
        }
        if (deltaQV.z > 180)
        {
            deltaQV.z += -360;
        }
        EditorGUILayout.LabelField(string.Format("Delta Rotation: {0}", deltaQV.ToString("F3")));

        EditorGUILayout.EndVertical();


        EditorGUILayout.BeginVertical("box");
        if (showMovementData = EditorGUILayout.Foldout(showMovementData, "Movement Data"))
        {
            EditorGUILayout.BeginHorizontal();


            EditorGUILayout.BeginVertical();
            EditorGUILayout.LabelField("Times", GUILayout.Width(75));
            for (int f = 0; f < frameCount; f++)
            {
                EditorGUILayout.LabelField(times[f].ToString("F3"), GUILayout.Width(75));
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical();
            EditorGUILayout.LabelField("Positions", GUILayout.Width(160));
            for (int f = 0; f < frameCount; f++)
            {
                EditorGUILayout.LabelField(positions[f].ToString("F2"), GUILayout.Width(160));
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical();
            EditorGUILayout.LabelField("Rotations", GUILayout.Width(160));
            for (int f = 0; f < frameCount; f++)
            {
                EditorGUILayout.LabelField(rotations[f].ToString("F2"), GUILayout.Width(160));
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.EndVertical();

        EditorGUILayout.EndVertical();
    }
示例#7
0
    /*
     * [MenuItem("Assets/Export Mecanim Animation Controller", false, 301)]
     * private static void CreateAnimatorFile() {
     * var animatorController = Selection.activeObject as AnimatorController;
     * if (animatorController == null) {
     *  return;
     * }
     *
     * CreateAsset(animatorController);
     * }
     *
     * [MenuItem("Assets/Export Mecanim Animation Controller", true)]
     * private static bool CreateAnimatorController() {
     * return Selection.activeObject is AnimatorController;
     * }
     */

    //  public static AnimatorGraphAsset Fetch(string name) {
    //    AnimatorGraphAsset output = null;

    //#if UNITY_EDITOR
    //    string pathToAnimationResource = "Assets/Resources/DB/Animator/";
    //    string animationFilePath = pathToAnimationResource + name + ".asset";
    //    output = UnityEditor.AssetDatabase.LoadAssetAtPath(animationFilePath, typeof(AnimatorGraphAsset)) as AnimatorGraphAsset;

    //    if (output == null) {
    //      output = CreateInstance<AnimatorGraphAsset>();
    //      animationFilePath = UnityEditor.AssetDatabase.GenerateUniqueAssetPath(animationFilePath);
    //      UnityEditor.AssetDatabase.CreateAsset(output, animationFilePath);
    //      UnityEditor.AssetDatabase.SaveAssets();
    //      UnityEditor.AssetDatabase.Refresh();
    //    }
    //#endif

    //    if (output != null) {
    //      if (output.Settings == null)
    //        output.Settings = new AnimatorGraph();
    //    }

    //    return output;
    //  }

    public static void CreateAsset(AnimatorGraphAsset dataAsset, AnimatorController controller)
    {
        if (!controller)
        {
            return;
        }

        if (!dataAsset)
        {
            return;
        }

        QuantumRunner.Init();//make sure we can get debug calls from Quantum
        dataAsset.controller = controller;
        int weightTableResolution = (int)dataAsset.weight_table_resolution;
        int variableCount         = controller.parameters.Length;

        dataAsset.Settings.variables = new AnimatorVariable[variableCount];

        //Mecanim Parameters/Variables
        //make a dictionary of paramets by name for use when extracting conditions for transitions
        Dictionary <string, AnimatorControllerParameter> parameterDic = new Dictionary <string, AnimatorControllerParameter>();

        for (int v = 0; v < variableCount; v++)
        {
            AnimatorControllerParameter parameter = controller.parameters[v];
            parameterDic.Add(parameter.name, parameter);
            AnimatorVariable newVariable = new AnimatorVariable();

            newVariable.name  = parameter.name;
            newVariable.index = v;
            switch (parameter.type)
            {
            case AnimatorControllerParameterType.Bool:
                newVariable.type        = AnimatorVariable.VariableType.Bool;
                newVariable.defaultBool = parameter.defaultBool;
                break;

            case AnimatorControllerParameterType.Float:
                newVariable.type      = AnimatorVariable.VariableType.FP;
                newVariable.defaultFp = FP.FromFloat_UNSAFE(parameter.defaultFloat);
                break;

            case AnimatorControllerParameterType.Int:
                newVariable.type       = AnimatorVariable.VariableType.Int;
                newVariable.defaultInt = parameter.defaultInt;
                break;

            case AnimatorControllerParameterType.Trigger:
                newVariable.type = AnimatorVariable.VariableType.Trigger;
                break;
            }

            dataAsset.Settings.variables[v] = newVariable;
        }

        //Mecanim State Graph
        int layerCount = controller.layers.Length;

        dataAsset.clips.Clear();
        dataAsset.Settings.layers = new AnimatorLayer[layerCount];
        for (int l = 0; l < layerCount; l++)
        {
            AnimatorLayer newLayer = new AnimatorLayer();
            newLayer.name = controller.layers[l].name;
            newLayer.id   = l;

            int stateCount = controller.layers[l].stateMachine.states.Length;
            newLayer.states = new Quantum.AnimatorState[stateCount + 1];//additional element for the any state
            Dictionary <UnityEditor.Animations.AnimatorState, Quantum.AnimatorState> stateDictionary = new Dictionary <AnimatorState, Quantum.AnimatorState>();

            for (int s = 0; s < stateCount; s++)
            {
                UnityEditor.Animations.AnimatorState state = controller.layers[l].stateMachine.states[s].state;
                Quantum.AnimatorState newState             = new Quantum.AnimatorState();
                newState.name        = state.name;
                newState.id          = state.nameHash;
                newState.isDefault   = controller.layers[l].stateMachine.defaultState == state;
                newState.speed       = FP.FromFloat_UNSAFE(state.speed);
                newState.cycleOffset = FP.FromFloat_UNSAFE(state.cycleOffset);

                if (state.motion != null)
                {
                    AnimationClip clip = state.motion as AnimationClip;
                    if (clip != null)
                    {
                        dataAsset.clips.Add(clip);
                        AnimatorClip newClip = new AnimatorClip();
                        newClip.name    = state.motion.name;
                        newClip.data    = Extract(clip);
                        newState.motion = newClip;
                    }
                    else
                    {
                        BlendTree tree = state.motion as BlendTree;
                        if (tree != null)
                        {
                            int childCount = tree.children.Length;

                            AnimatorBlendTree newBlendTree = new AnimatorBlendTree();
                            newBlendTree.name        = state.motion.name;
                            newBlendTree.motionCount = childCount;
                            newBlendTree.motions     = new AnimatorMotion[childCount];
                            newBlendTree.positions   = new FPVector2[childCount];
                            newBlendTree.weights     = new FP[childCount];

                            string parameterXname = tree.blendParameter;
                            string parameterYname = tree.blendParameterY;
                            for (int v = 0; v < variableCount; v++)
                            {
                                if (controller.parameters[v].name == parameterXname)
                                {
                                    newBlendTree.blendParameterIndex = v;
                                }
                                if (controller.parameters[v].name == parameterYname)
                                {
                                    newBlendTree.blendParameterIndexY = v;
                                }
                            }

                            for (int c = 0; c < childCount; c++)
                            {
                                ChildMotion   cMotion = tree.children[c];
                                AnimationClip cClip   = cMotion.motion as AnimationClip;
                                newBlendTree.positions[c] = new FPVector2(FP.FromFloat_UNSAFE(cMotion.position.x), FP.FromFloat_UNSAFE(cMotion.position.y));

                                if (cClip != null)
                                {
                                    dataAsset.clips.Add(cClip);
                                    AnimatorClip newClip = new AnimatorClip();
                                    newClip.data            = Extract(cClip);
                                    newClip.name            = newClip.clipName;
                                    newBlendTree.motions[c] = newClip;
                                }
                            }


                            FP val = FP._0 / 21;
                            newBlendTree.CalculateWeightTable(weightTableResolution);

                            newState.motion = newBlendTree;
                        }
                    }
                }
                newLayer.states[s] = newState;

                stateDictionary.Add(state, newState);
            }

            //State Transistions
            //once the states have all been created
            //we'll hook up the transitions
            for (int s = 0; s < stateCount; s++)
            {
                UnityEditor.Animations.AnimatorState state = controller.layers[l].stateMachine.states[s].state;
                Quantum.AnimatorState newState             = newLayer.states[s];
                int transitionCount = state.transitions.Length;
                newState.transitions = new Quantum.AnimatorTransition[transitionCount];
                for (int t = 0; t < transitionCount; t++)
                {
                    AnimatorStateTransition transition = state.transitions[t];
                    if (!stateDictionary.ContainsKey(transition.destinationState))
                    {
                        continue;
                    }
                    Quantum.AnimatorTransition newTransition = new Quantum.AnimatorTransition();
                    newTransition.index                = t;
                    newTransition.name                 = string.Format("{0} to {1}", state.name, transition.destinationState.name);
                    newTransition.duration             = FP.FromFloat_UNSAFE(transition.duration * state.motion.averageDuration);
                    newTransition.hasExitTime          = transition.hasExitTime;
                    newTransition.exitTime             = FP.FromFloat_UNSAFE(transition.exitTime * state.motion.averageDuration);
                    newTransition.offset               = FP.FromFloat_UNSAFE(transition.offset * transition.destinationState.motion.averageDuration);
                    newTransition.destinationStateId   = stateDictionary[transition.destinationState].id;
                    newTransition.destinationStateName = stateDictionary[transition.destinationState].name;
                    newTransition.canTransitionToSelf  = transition.canTransitionToSelf;


                    int conditionCount = transition.conditions.Length;
                    newTransition.conditions = new Quantum.AnimatorCondition[conditionCount];
                    for (int c = 0; c < conditionCount; c++)
                    {
                        UnityEditor.Animations.AnimatorCondition condition = state.transitions[t].conditions[c];

                        if (!parameterDic.ContainsKey(condition.parameter))
                        {
                            continue;
                        }
                        AnimatorControllerParameter parameter    = parameterDic[condition.parameter];
                        Quantum.AnimatorCondition   newCondition = new Quantum.AnimatorCondition();

                        newCondition.variableName = condition.parameter;
                        newCondition.mode         = (Quantum.AnimatorCondition.Modes)condition.mode;

                        switch (parameter.type)
                        {
                        case AnimatorControllerParameterType.Float:
                            newCondition.thresholdFp = FP.FromFloat_UNSAFE(condition.threshold);
                            break;

                        case AnimatorControllerParameterType.Int:
                            newCondition.thresholdInt = Mathf.RoundToInt(condition.threshold);
                            break;
                        }

                        newTransition.conditions[c] = newCondition;
                    }

                    newState.transitions[t] = newTransition;
                }
            }

            //Create Any State
            Quantum.AnimatorState anyState = new Quantum.AnimatorState();
            anyState.name  = "Any State";
            anyState.id    = anyState.name.GetHashCode();
            anyState.isAny = true;//important for this one
            AnimatorStateTransition[] anyStateTransitions = controller.layers[l].stateMachine.anyStateTransitions;
            int anyStateTransitionCount = anyStateTransitions.Length;
            anyState.transitions = new Quantum.AnimatorTransition[anyStateTransitionCount];
            for (int t = 0; t < anyStateTransitionCount; t++)
            {
                AnimatorStateTransition transition = anyStateTransitions[t];
                if (!stateDictionary.ContainsKey(transition.destinationState))
                {
                    continue;
                }
                Quantum.AnimatorTransition newTransition = new Quantum.AnimatorTransition();
                newTransition.index                = t;
                newTransition.name                 = string.Format("Any State to {0}", transition.destinationState.name);
                newTransition.duration             = FP.FromFloat_UNSAFE(transition.duration);
                newTransition.hasExitTime          = transition.hasExitTime;
                newTransition.exitTime             = FP._1;
                newTransition.offset               = FP.FromFloat_UNSAFE(transition.offset * transition.destinationState.motion.averageDuration);
                newTransition.destinationStateId   = stateDictionary[transition.destinationState].id;
                newTransition.destinationStateName = stateDictionary[transition.destinationState].name;
                newTransition.canTransitionToSelf  = transition.canTransitionToSelf;

                int conditionCount = transition.conditions.Length;
                newTransition.conditions = new Quantum.AnimatorCondition[conditionCount];
                for (int c = 0; c < conditionCount; c++)
                {
                    UnityEditor.Animations.AnimatorCondition condition = anyStateTransitions[t].conditions[c];

                    if (!parameterDic.ContainsKey(condition.parameter))
                    {
                        continue;
                    }
                    AnimatorControllerParameter parameter    = parameterDic[condition.parameter];
                    Quantum.AnimatorCondition   newCondition = new Quantum.AnimatorCondition();

                    newCondition.variableName = condition.parameter;
                    newCondition.mode         = (Quantum.AnimatorCondition.Modes)condition.mode;

                    switch (parameter.type)
                    {
                    case AnimatorControllerParameterType.Float:
                        newCondition.thresholdFp = FP.FromFloat_UNSAFE(condition.threshold);
                        break;

                    case AnimatorControllerParameterType.Int:
                        newCondition.thresholdInt = Mathf.RoundToInt(condition.threshold);
                        break;
                    }

                    newTransition.conditions[c] = newCondition;
                }

                anyState.transitions[t] = newTransition;
            }
            newLayer.states[stateCount] = anyState;

            dataAsset.Settings.layers[l] = newLayer;
        }

        EditorUtility.SetDirty(dataAsset);
    }
示例#8
0
文件: Door.cs 项目: SamCaves/Escapism
 public void Close()
 {
     AnimatorClip.CrossFade(animator, closeDoor);
 }
示例#9
0
文件: Door.cs 项目: SamCaves/Escapism
 public void Open()
 {
     AnimatorClip.CrossFade(animator, openDoor);
 }
示例#10
0
    static AvatarController MakeAvatar(string name, GameObject target, Texture texture, AnimatorController animatorController)
    {
        GameObject       controllerGO = new GameObject(name);
        AvatarController controller   = controllerGO.AddComponent <AvatarController> ();

        GameObject model = Object.Instantiate <GameObject>(target);

        model.name = "model";
        model.transform.localPosition    = Vector3.zero;
        model.transform.localEulerAngles = Vector3.zero;
        model.transform.localScale       = Vector3.one;
        model.transform.SetParent(controller.transform);
        EditorAvatarController.AddToMarkPoint(controller);

        string targetPath = AssetDatabase.GetAssetPath(target);
        string dataPath   = Application.dataPath.Replace("\\", "/");

        System.IO.FileInfo fi     = new System.IO.FileInfo(dataPath + targetPath);
        string             folder = fi.Directory.FullName.Replace("\\", "/").Replace(dataPath, "");

        string matPath = folder + "/Materials/" + target.name + ".mat";

        //render

        Material mt = AssetDatabase.LoadAssetAtPath <Material>(matPath);

        if (mt == null)
        {
            mt             = new Material(Shader.Find("Game/Character/Diffuse"));
            mt.name        = target.name;
            mt.mainTexture = texture;
            if (!AssetDatabase.IsValidFolder(folder + "/Materials"))
            {
                AssetDatabase.CreateFolder(folder, "Materials");
            }

            AssetDatabase.CreateAsset(mt, matPath);
        }


        SkinnedMeshRenderer[] renders = model.GetComponentsInChildren <SkinnedMeshRenderer>(true);
        foreach (SkinnedMeshRenderer meshrender in renders)
        {
            meshrender.sharedMaterial = AssetDatabase.LoadAssetAtPath <Material>(matPath);
        }

        //capsule
        controller.capsule.height = 2;
        controller.capsule.radius = 0.5f;
        controller.capsule.center = new Vector3(0, 1, 0);

        //加入左右挂点
        GenMarkPointRL(model);


        //animation
        Animator animator = model.GetComponent <Animator>();

        if (animator == null)
        {
            animator = model.AddComponent <Animator>();
        }
        animator.runtimeAnimatorController = animatorController;
        var listClips = controller.animator.listClips;

        listClips.Clear();
        foreach (string value in DEAFULT_ACTION_TRACK)
        {
            var new_ActionClip = new AnimatorClip(value);
            new_ActionClip.length   = 1;
            new_ActionClip.clipName = value;
            if (CheckKeyword(value, "idle"))
            {
                new_ActionClip.crossMode = AnimatorClip.CrossMode.CrossFabe;
            }
            if (CheckKeyword(value, "idle") || CheckKeyword(value, "run"))
            {
                new_ActionClip.wrapMode = WrapMode.Loop;
            }
            if (CheckKeyword(value, "die"))
            {
                new_ActionClip.wrapMode = WrapMode.ClampForever;
            }
            listClips.Add(new_ActionClip);
        }


        EditorTools.SetDirty(controller);
        AssetDatabase.SaveAssets();

        return(controller);
    }
示例#11
0
 public void Display(string text)
 {
     AnimatorClip.Play(_animator, animatorClip);
     _textMesh.text = text;
 }