示例#1
0
    private static void ImportAnimatorState(GameObject modelAsset, GameObject prefab)
    {
        if (Directory.Exists(ANIMATOR_DESTINATION_DIRECTORY) == false)
        {
            Directory.CreateDirectory(ANIMATOR_DESTINATION_DIRECTORY);
        }

        if (prefab.GetComponent <AnimationController>() == null)
        {
            prefab.AddComponent <AnimationController>();
        }

        AnimatorController controller;

        Animator animator = prefab.GetComponent <Animator>();

        if (animator == null)
        {
            animator = prefab.gameObject.AddComponent <Animator>();
            //animator.avatar = modelImporter.sourceAvatar;
        }

        if (animator.runtimeAnimatorController == null)
        {
            controller = CreateAnimationController(prefab);
            animator.runtimeAnimatorController = (RuntimeAnimatorController)controller;
        }
        else
        {
            controller = (AnimatorController)animator.runtimeAnimatorController;
        }

        AnimatorStateImporter importer = new AnimatorStateImporter();

        importer.isClearOnStartUp = true;
        importer.controller       = controller;
        importer.fbxFiles         = new GameObject[1] {
            modelAsset
        };
        importer.Import();
        importer.Alignment();
    }
示例#2
0
    private void OnGUI()
    {
        if (style == null)
        {
            style = new GUIStyle();
        }

        if (stateImporter == null)
        {
            stateImporter = new AnimatorStateImporter();
        }

        using (new GUILayout.VerticalScope())
        {
            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("Animator", GUILayout.Width(180));
                stateImporter.controller = (AnimatorController)EditorGUILayout.ObjectField(stateImporter.controller, typeof(AnimatorController), false, GUILayout.Width(200));
                GUILayout.ExpandWidth(true);
            }

            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("Animation FBX Files Directory", GUILayout.Width(180));
                stateImporter.directory = (DefaultAsset)EditorGUILayout.ObjectField(stateImporter.directory, typeof(DefaultAsset), false, GUILayout.Width(200));
                GUILayout.ExpandWidth(true);
            }

            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("Animation FBX File Count", GUILayout.Width(180));
                capacityStr = EditorGUILayout.TextField(capacityStr, GUILayout.Width(180));
                GUILayout.ExpandWidth(true);
            }

            if (stateImporter.fbxFiles == null || (stateImporter.fbxFiles != null && stateImporter.fbxFiles.Length != capacity))
            {
                stateImporter.fbxFiles = new GameObject[capacity];
            }

            for (int i = 0; i < stateImporter.fbxFiles.Length; i++)
            {
                using (new GUILayout.HorizontalScope())
                {
                    EditorGUILayout.LabelField(string.Format("FBX File ({0})", i + 1), GUILayout.Width(150));
                    stateImporter.fbxFiles[i] = (GameObject)EditorGUILayout.ObjectField(stateImporter.fbxFiles[i], typeof(GameObject), false, GUILayout.Width(200));
                    GUILayout.ExpandWidth(true);
                }
            }

            stateImporter.isClearOnStartUp = EditorGUILayout.ToggleLeft("ClearOnStartup", stateImporter.isClearOnStartUp, GUILayout.Width(120));
            stateImporter.isOverwrite      = EditorGUILayout.ToggleLeft("Overwrite", stateImporter.isOverwrite, GUILayout.Width(120));

            if (GUILayout.Button("Import", GUILayout.Width(100)))
            {
                importResult = stateImporter.Import();
                stateImporter.Alignment();
            }

            style.fontStyle        = FontStyle.Bold;
            style.normal.textColor = Color.white;
            style.fontSize         = 30;
            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.BeginVertical();
            GUILayout.Label(importResult == true ? "SUCCESS..!!" : "", style);
            GUILayout.Label(successTime);
            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.FlexibleSpace();
        }
    }