/// <summary>
        /// Creates and saves the Scriptable Object as an asset in the Editor. Adapted from Unity3D wiki:
        /// http://wiki.unity3d.com/index.php?title=CreateScriptableObjectAsset
        /// </summary>
        /// <returns>"Reference to the created asset instance</returns>
        /// <typeparam name="T">The type of the Scriptable Object to create.</typeparam>
        public static T CreateAsset <T>() where T : ScriptableObject
        {
            T scriptableObjectInstance = ScriptableObject.CreateInstance <T>();

            string currentPath          = SelectionUtility.GetDirectoryOfSelection();
            string path                 = currentPath;
            string typeName             = typeof(T).ToString();
            string typeWithoutNamespace = typeName.Split('.').Last();
            string uniqueAssetPath      = AssetDatabase.GenerateUniqueAssetPath(path + "New " + typeWithoutNamespace + ".asset");

            AssetDatabaseUtility.SaveAndSelectObject(scriptableObjectInstance, currentPath, Path.GetFileName(uniqueAssetPath));

            return(scriptableObjectInstance);
        }
Exemplo n.º 2
0
        public static void FillInClips()
        {
            string directory = SelectionUtility.GetDirectoryOfSelection();

            // Get all animation clips in the current directory
            List <AnimationClip> clipsForAnimator = new List <AnimationClip>();

            string[] clipGUIDs = AssetDatabase.FindAssets("t:animationClip");
            foreach (string clipGUID in clipGUIDs)
            {
                string guidPath = AssetDatabase.GUIDToAssetPath(clipGUID);
                if (guidPath.Contains(directory))
                {
                    clipsForAnimator.Add(AssetDatabase.LoadAssetAtPath <AnimationClip>(guidPath));
                }
            }

            AnimatorOverrideController overrideController = (AnimatorOverrideController)Selection.activeObject;

            // Replace clips if they match
            foreach (AnimationClip clip in clipsForAnimator)
            {
                // Get just the clip name
                string clipAnimName = ExtractAnimNameFromClipName(clip.name);
                Debug.Log("Searching for matches for clip: " + clipAnimName);

                // Find the corresponding clip to replace
                List <KeyValuePair <AnimationClip, AnimationClip> > overrides = new List <KeyValuePair <AnimationClip, AnimationClip> >(overrideController.overridesCount);
                overrideController.GetOverrides(overrides);
                for (int i = 0; i < overrides.Count; i++)
                {
                    //string originalClipName = overrideController.clips[i].originalClip.name;
                    string originalClipName = overrides[i].Key.name;
                    string animName         = ExtractAnimNameFromClipName(originalClipName);
                    if (clipAnimName == animName)
                    {
                        Debug.Log("Replacing clip: " + originalClipName + " With: " + clip.name);
                        overrideController[originalClipName] = clip;
                        break;
                    }
                }

                overrideController.ApplyOverrides(overrides);
            }
        }
 private static bool IsFillInClipsValid()
 {
     return(SelectionUtility.IsActiveObjectOfType <AnimatorOverrideController>());
 }
Exemplo n.º 4
0
 /// <summary>
 /// Create and Save an object in the AssetDatabase and then select it.
 /// </summary>
 /// <param name="objectToSave">Object to save.</param>
 /// <param name="path">Path for new file, not including filename</param>
 /// <param name="filename">Filename including file extension.</param>
 public static void SaveAndSelectObject(UnityEngine.Object objectToSave, string path, string filename)
 {
     SaveObject(objectToSave, path, filename);
     SelectionUtility.SelectObject(objectToSave);
 }
 private static bool IsCreateEightDirBlendValid()
 {
     return(SelectionUtility.IsActiveObjectOfType <AnimatorController>());
 }