Advertisement
whiteflare

GenerateAvatarMaskFromHierarchy.cs

Aug 19th, 2022
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1. /*
  2.  *  The MIT License
  3.  *
  4.  *  Copyright 2022 whiteflare.
  5.  *
  6.  *  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
  7.  *  to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8.  *  and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  9.  *
  10.  *  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  11.  *
  12.  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13.  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  14.  *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  15.  *  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16.  */
  17.  
  18. using UnityEngine;
  19. using UnityEditor;
  20.  
  21. namespace WF.Utillty
  22. {
  23.     public class GenerateAvatarMaskFromHierarchy
  24.     {
  25.         [MenuItem("GameObject/Generate AvatarMask", validate = true)]
  26.         public static bool IsValid()
  27.         {
  28.             return Selection.GetFiltered<Transform>(SelectionMode.TopLevel).Length != 0;
  29.         }
  30.  
  31.         [MenuItem("GameObject/Generate AvatarMask", priority = 10)]
  32.         public static void Execute()
  33.         {
  34.             var path = EditorUtility.SaveFilePanelInProject("Save AvatarMask", "New Avatar Mask", "mask", "");
  35.             if (string.IsNullOrWhiteSpace(path))
  36.             {
  37.                 return;
  38.             }
  39.  
  40.             var result = new AvatarMask();
  41.             foreach (var t in Selection.GetFiltered<Transform>(SelectionMode.TopLevel))
  42.             {
  43.                 result.AddTransformPath(t, true);
  44.             }
  45.             AssetDatabase.CreateAsset(result, path);
  46.         }
  47.     }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement