Esempio n. 1
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            if (target != null)
            {
                meshCreator = (AICreateMeshFromSkinnedMesh)target;
            }

            GUILayout.Label("Save Directory: " + meshCreator.saveDirectory);
            if (GUILayout.Button("Set Save Directory"))
            {
                string saveDir = EditorUtility.OpenFolderPanel("Set Save Directory", System.Environment.CurrentDirectory, "");
                if (saveDir != string.Empty)
                {
                    meshCreator.saveDirectory = saveDir;
                }
            }

            GUILayout.Space(5);

            if (GUILayout.Button("Transform"))
            {
                GameObject copy = GameObject.Instantiate(meshCreator.gameObject);
                copy.name = meshCreator.gameObject.name + " AI";

                copy.AddComponent <AIAnimator>();

                AICreateMeshFromSkinnedMesh meshCopyComp = copy.GetComponent <AICreateMeshFromSkinnedMesh>();

                Mesh[] newMeshes = meshCopyComp.Transform();

                DestroyImmediate(meshCopyComp);
                DestroyImmediate(copy.GetComponent <AICreateAnimations>());
                DestroyImmediate(copy.GetComponent <Animator>());

                AICreateAnimations createAnimations = meshCreator.GetComponent <AICreateAnimations>();
                if (createAnimations != null)
                {
                    createAnimations.meshesCreated = newMeshes;
                }
            }
        }
    public override void OnInspectorGUI()
    {
        AICreateAnimations createAnimations = (AICreateAnimations)target;


        SerializedObject   so           = new SerializedObject(target);
        SerializedProperty meshProperty = so.FindProperty("meshesCreated");

        EditorGUILayout.PropertyField(meshProperty, true);
        so.ApplyModifiedProperties();

        GUILayout.Space(10);

        GUILayout.Label("Save Directory: " + createAnimations.saveDirectory);
        if (GUILayout.Button("Set Save Directory"))
        {
            string saveDir = EditorUtility.OpenFolderPanel("Set Save Directory", System.Environment.CurrentDirectory, "");
            if (saveDir != string.Empty)
            {
                createAnimations.saveDirectory = saveDir;
            }
        }
        GUILayout.Space(5);

        createAnimations.saveMode = (AICreateAnimations.SaveMode)EditorGUILayout.EnumPopup("Save Mode:", createAnimations.saveMode);


        switch (createAnimations.saveMode)
        {
        case AICreateAnimations.SaveMode.SingleAnimation:
            createAnimations.animationForSave[0] = EditorGUILayout.TextField("Animation Name: ", createAnimations.animationForSave[0]);
            createAnimations.clipLenght          = EditorGUILayout.FloatField("clipLenght: ", createAnimations.clipLenght);
            break;

        case AICreateAnimations.SaveMode.Multiple:
            SerializedProperty stringsProperty = so.FindProperty("animationForSave");
            EditorGUILayout.PropertyField(stringsProperty, true); // True means show children

            if (createAnimations.animationForSave.Length <= 0)
            {
                createAnimations.animationForSave = new string[1];
            }

            so.ApplyModifiedProperties(); // Remember to apply modified properties
            break;
        }

        GUILayout.Space(20);


        EditorGUI.BeginDisabledGroup(!createAnimations.canCreate);
        if (!createAnimations.canCreate)
        {
            GUILayout.Label("Can only bake in playmode");
        }
        if (GUILayout.Button("Create"))
        {
            if (createAnimations.saveMode == AICreateAnimations.SaveMode.All)
            {
                createAnimations.SetAllAnimations();
            }
            createAnimations.GenerateAnimations();
        }
        EditorGUI.EndDisabledGroup();
    }