Example #1
0
        private HumanTemplate OpenHumanTemplate()
        {
            string text  = "Assets/";
            string text2 = EditorUtility.OpenFilePanel("Open Human Template", text, "ht");

            if (text2 == string.Empty)
            {
                return(null);
            }
            string        projectRelativePath = FileUtil.GetProjectRelativePath(text2);
            HumanTemplate humanTemplate       = AssetDatabase.LoadMainAssetAtPath(projectRelativePath) as HumanTemplate;

            if (humanTemplate == null && EditorUtility.DisplayDialog("Human Template not found in project", "Import asset '" + text2 + "' into project", "Yes", "No"))
            {
                string text3 = text + FileUtil.GetLastPathNameComponent(text2);
                text3 = AssetDatabase.GenerateUniqueAssetPath(text3);
                FileUtil.CopyFileOrDirectory(text2, text3);
                AssetDatabase.Refresh();
                humanTemplate = (AssetDatabase.LoadMainAssetAtPath(text3) as HumanTemplate);
                if (humanTemplate == null)
                {
                    Debug.Log(string.Concat(new string[]
                    {
                        "Failed importing file '",
                        text2,
                        "' to '",
                        text3,
                        "'"
                    }));
                }
            }
            return(humanTemplate);
        }
        void GenericGUI()
        {
            AvatarSourceGUI();

            if (!m_CopyAvatar.hasMultipleDifferentValues)
            {
                if (!m_CopyAvatar.boolValue)
                {
                    // Do not allow multi edit of root node if all rigs doesn't match
                    EditorGUI.BeginChangeCheck();
                    using (new EditorGUI.DisabledScope(!m_CanMultiEditTransformList))
                    {
                        rootIndex = EditorGUILayout.Popup(styles.RootNode, rootIndex, m_RootMotionBoneList);
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (rootIndex > 0 && rootIndex < m_RootMotionBoneList.Length)
                        {
                            m_RootMotionBoneName.stringValue =
                                FileUtil.GetLastPathNameComponent(m_RootMotionBoneList[rootIndex].text);
                        }
                        else
                        {
                            m_RootMotionBoneName.stringValue = "";
                        }
                    }
                }
                else
                {
                    CopyAvatarGUI();
                }
            }
        }
Example #3
0
        void GenericGUI()
        {
            using (var horizontal = new EditorGUILayout.HorizontalScope())
            {
                using (var propertyField = new EditorGUI.PropertyScope(horizontal.rect, Styles.AvatarDefinition, m_AvatarSetup))
                {
                    EditorGUI.showMixedValue = m_AvatarSetup.hasMultipleDifferentValues;
                    using (var change = new EditorGUI.ChangeCheckScope())
                    {
                        var value = (ModelImporterAvatarSetup)EditorGUILayout.EnumPopup(propertyField.content, (ModelImporterAvatarSetup)m_AvatarSetup.intValue);
                        if (change.changed)
                        {
                            m_AvatarSetup.intValue = (int)value;
                        }
                    }

                    EditorGUI.showMixedValue = false;
                }
            }

            if (!m_AvatarSetup.hasMultipleDifferentValues)
            {
                if (m_AvatarSetup.intValue == (int)ModelImporterAvatarSetup.CreateFromThisModel)
                {
                    // Do not allow multi edit of root node if all rigs doesn't match
                    EditorGUI.BeginChangeCheck();
                    using (new EditorGUI.DisabledScope(!m_CanMultiEditTransformList))
                    {
                        if (assetTarget == null)
                        {
                            m_RootMotionBoneName.stringValue =
                                EditorGUILayout.TextField(Styles.RootNode, m_RootMotionBoneName.stringValue);
                        }
                        else
                        {
                            rootIndex = EditorGUILayout.Popup(Styles.RootNode, rootIndex, m_RootMotionBoneList);
                        }
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (assetTarget != null)
                        {
                            if (rootIndex > 0 && rootIndex < m_RootMotionBoneList.Length)
                            {
                                m_RootMotionBoneName.stringValue =
                                    FileUtil.GetLastPathNameComponent(m_RootMotionBoneList[rootIndex].text);
                            }
                            else
                            {
                                m_RootMotionBoneName.stringValue = "";
                            }
                        }
                    }
                }
                else if (m_AvatarSetup.intValue == (int)ModelImporterAvatarSetup.CopyFromOther)
                {
                    CopyAvatarGUI();
                }
            }
        }
Example #4
0
 private void GenericGUI()
 {
     this.AvatarSourceGUI();
     if (!this.m_CopyAvatar.hasMultipleDifferentValues)
     {
         if (!this.m_CopyAvatar.boolValue)
         {
             EditorGUI.BeginDisabledGroup(!this.m_CanMultiEditTransformList);
             EditorGUI.BeginChangeCheck();
             this.rootIndex = EditorGUILayout.Popup(styles.RootNode, this.rootIndex, this.m_RootMotionBoneList, new GUILayoutOption[0]);
             EditorGUI.EndDisabledGroup();
             if (EditorGUI.EndChangeCheck())
             {
                 if ((this.rootIndex > 0) && (this.rootIndex < this.m_RootMotionBoneList.Length))
                 {
                     this.m_RootMotionBoneName.stringValue = FileUtil.GetLastPathNameComponent(this.m_RootMotionBoneList[this.rootIndex].text);
                 }
                 else
                 {
                     this.m_RootMotionBoneName.stringValue = string.Empty;
                 }
             }
         }
         else
         {
             this.CopyAvatarGUI();
         }
     }
 }
 private void GenericGUI()
 {
     this.AvatarSourceGUI();
     if (!this.m_CopyAvatar.hasMultipleDifferentValues)
     {
         if (!this.m_CopyAvatar.boolValue)
         {
             EditorGUI.BeginChangeCheck();
             using (new EditorGUI.DisabledScope(!this.m_CanMultiEditTransformList))
             {
                 this.rootIndex = EditorGUILayout.Popup(ModelImporterRigEditor.styles.RootNode, this.rootIndex, this.m_RootMotionBoneList, new GUILayoutOption[0]);
             }
             if (EditorGUI.EndChangeCheck())
             {
                 if (this.rootIndex > 0 && this.rootIndex < this.m_RootMotionBoneList.Length)
                 {
                     this.m_RootMotionBoneName.stringValue = FileUtil.GetLastPathNameComponent(this.m_RootMotionBoneList[this.rootIndex].text);
                 }
                 else
                 {
                     this.m_RootMotionBoneName.stringValue = "";
                 }
             }
         }
         else
         {
             this.CopyAvatarGUI();
         }
     }
 }
        private HumanTemplate OpenHumanTemplate()
        {
            string assetsDirectory = "Assets/";

            // Go forward with presenting user a save clip dialog
            string templatePath = EditorUtility.OpenFilePanel("Open Human Template", assetsDirectory, "ht");

            // If user canceled or save path is invalid, we can't create a template
            if (templatePath == "")
            {
                return(null);
            }

            // At this point we know that we can create a template
            string        relativeTemplatePath = FileUtil.GetProjectRelativePath(templatePath);
            HumanTemplate template             = AssetDatabase.LoadMainAssetAtPath(relativeTemplatePath) as HumanTemplate;

            // Asset not found in project, try to import it into the project
            if (template == null)
            {
                if (EditorUtility.DisplayDialog("Human Template not found in project", "Import asset \'" + templatePath + "\' into project", "Yes", "No"))
                {
                    string newFileName = assetsDirectory + FileUtil.GetLastPathNameComponent(templatePath);

                    newFileName = AssetDatabase.GenerateUniqueAssetPath(newFileName);

                    // Copy file
                    FileUtil.CopyFileOrDirectory(templatePath, newFileName);

                    AssetDatabase.Refresh();

                    template = AssetDatabase.LoadMainAssetAtPath(newFileName) as HumanTemplate;

                    if (template == null)
                    {
                        Debug.Log("Failed importing file \'" + templatePath + "\' to \'" + newFileName + "\'");
                    }
                }
            }
            return(template);
        }
Example #7
0
        private static Sprite HandleExternalDrag(bool perform)
        {
            if (DragAndDrop.paths.Length == 0)
            {
                return(null);
            }
            string text = DragAndDrop.paths[0];

            if (!SpriteUtility.ValidPathForTextureAsset(text))
            {
                return(null);
            }
            DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
            if (!perform)
            {
                return(null);
            }
            string text2 = AssetDatabase.GenerateUniqueAssetPath(Path.Combine("Assets", FileUtil.GetLastPathNameComponent(text)));

            if (text2.Length <= 0)
            {
                return(null);
            }
            FileUtil.CopyFileOrDirectory(text, text2);
            SpriteUtility.ForcedImportFor(text2);
            return(SpriteUtility.GenerateDefaultSprite(AssetDatabase.LoadMainAssetAtPath(text2) as Texture2D));
        }
Example #8
0
        private static void HandleExternalDrag(string[] paths, bool perform, ref List <Sprite> result)
        {
            foreach (var path in paths)
            {
                if (!ValidPathForTextureAsset(path))
                {
                    continue;
                }

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                if (!perform)
                {
                    continue;
                }

                var newPath = AssetDatabase.GenerateUniqueAssetPath(Path.Combine("Assets", FileUtil.GetLastPathNameComponent(path)));
                if (newPath.Length <= 0)
                {
                    continue;
                }

                FileUtil.CopyFileOrDirectory(path, newPath);
                ForcedImportFor(newPath);

                Sprite defaultSprite = GenerateDefaultSprite(AssetDatabase.LoadMainAssetAtPath(newPath) as UnityTexture2D);
                if (defaultSprite != null)
                {
                    result.Add(defaultSprite);
                }
            }
        }
Example #9
0
 private static void HandleExternalDrag(string[] paths, bool perform, ref List <Sprite> result)
 {
     for (int i = 0; i < paths.Length; i++)
     {
         string text = paths[i];
         if (SpriteUtility.ValidPathForTextureAsset(text))
         {
             DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
             if (perform)
             {
                 string text2 = AssetDatabase.GenerateUniqueAssetPath(Path.Combine("Assets", FileUtil.GetLastPathNameComponent(text)));
                 if (text2.Length > 0)
                 {
                     FileUtil.CopyFileOrDirectory(text, text2);
                     SpriteUtility.ForcedImportFor(text2);
                     Sprite sprite = SpriteUtility.GenerateDefaultSprite(AssetDatabase.LoadMainAssetAtPath(text2) as UnityEngine.Texture2D);
                     if (sprite != null)
                     {
                         result.Add(sprite);
                     }
                 }
             }
         }
     }
 }
        internal static void ShaderErrorListUI(UnityEngine.Object shader, ShaderError[] errors, ref Vector2 scrollPosition)
        {
            // ISSUE: object of a compiler-generated type is created
            // ISSUE: variable of a compiler-generated type
            ShaderInspector.\u003CShaderErrorListUI\u003Ec__AnonStorey9A listUiCAnonStorey9A = new ShaderInspector.\u003CShaderErrorListUI\u003Ec__AnonStorey9A();
            // ISSUE: reference to a compiler-generated field
            listUiCAnonStorey9A.errors = errors;
            // ISSUE: reference to a compiler-generated field
            int length = listUiCAnonStorey9A.errors.Length;

            GUILayout.Space(5f);
            GUILayout.Label(string.Format("Errors ({0}):", (object)length), EditorStyles.boldLabel, new GUILayoutOption[0]);
            int   controlId = GUIUtility.GetControlID(ShaderInspector.kErrorViewHash, FocusType.Native);
            float minHeight = Mathf.Min((float)((double)length * 20.0 + 40.0), 150f);

            scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUISkin.current.box, GUILayout.MinHeight(minHeight));
            EditorGUIUtility.SetIconSize(new Vector2(16f, 16f));
            float height  = ShaderInspector.Styles.messageStyle.CalcHeight(EditorGUIUtility.TempContent((Texture)ShaderInspector.Styles.errorIcon), 100f);
            Event current = Event.current;

            for (int index = 0; index < length; ++index)
            {
                Rect controlRect = EditorGUILayout.GetControlRect(false, height, new GUILayoutOption[0]);
                // ISSUE: reference to a compiler-generated field
                string message = listUiCAnonStorey9A.errors[index].message;
                // ISSUE: reference to a compiler-generated field
                string platform = listUiCAnonStorey9A.errors[index].platform;
                // ISSUE: reference to a compiler-generated field
                bool flag = listUiCAnonStorey9A.errors[index].warning != 0;
                // ISSUE: reference to a compiler-generated field
                string pathNameComponent = FileUtil.GetLastPathNameComponent(listUiCAnonStorey9A.errors[index].file);
                // ISSUE: reference to a compiler-generated field
                int line = listUiCAnonStorey9A.errors[index].line;
                if (current.type == EventType.MouseDown && current.button == 0 && controlRect.Contains(current.mousePosition))
                {
                    GUIUtility.keyboardControl = controlId;
                    if (current.clickCount == 2)
                    {
                        // ISSUE: reference to a compiler-generated field
                        string             file   = listUiCAnonStorey9A.errors[index].file;
                        UnityEngine.Object target = !string.IsNullOrEmpty(file) ? AssetDatabase.LoadMainAssetAtPath(file) : (UnityEngine.Object)null;
                        if ((object)target == null)
                        {
                            target = shader;
                        }
                        int lineNumber = line;
                        AssetDatabase.OpenAsset(target, lineNumber);
                        GUIUtility.ExitGUI();
                    }
                    current.Use();
                }
                if (current.type == EventType.ContextClick && controlRect.Contains(current.mousePosition))
                {
                    // ISSUE: object of a compiler-generated type is created
                    // ISSUE: variable of a compiler-generated type
                    ShaderInspector.\u003CShaderErrorListUI\u003Ec__AnonStorey9B listUiCAnonStorey9B = new ShaderInspector.\u003CShaderErrorListUI\u003Ec__AnonStorey9B();
                    // ISSUE: reference to a compiler-generated field
                    listUiCAnonStorey9B.\u003C\u003Ef__ref\u0024154 = listUiCAnonStorey9A;
                    current.Use();
                    GenericMenu genericMenu = new GenericMenu();
                    // ISSUE: reference to a compiler-generated field
                    listUiCAnonStorey9B.errorIndex = index;
                    // ISSUE: reference to a compiler-generated method
                    genericMenu.AddItem(new GUIContent("Copy error text"), false, new GenericMenu.MenuFunction(listUiCAnonStorey9B.\u003C\u003Em__1B2));
                    genericMenu.ShowAsContext();
                }
                if (current.type == EventType.Repaint && (index & 1) == 0)
                {
                    ShaderInspector.Styles.evenBackground.Draw(controlRect, false, false, false, false);
                }
                Rect position1 = controlRect;
                position1.xMin = position1.xMax;
                if (line > 0)
                {
                    GUIContent content = !string.IsNullOrEmpty(pathNameComponent) ? EditorGUIUtility.TempContent(pathNameComponent + ":" + line.ToString((IFormatProvider)CultureInfo.InvariantCulture)) : EditorGUIUtility.TempContent(line.ToString((IFormatProvider)CultureInfo.InvariantCulture));
                    Vector2    vector2 = EditorStyles.miniLabel.CalcSize(content);
                    position1.xMin -= vector2.x;
                    GUI.Label(position1, content, EditorStyles.miniLabel);
                    position1.xMin -= 2f;
                    if ((double)position1.width < 30.0)
                    {
                        position1.xMin = position1.xMax - 30f;
                    }
                }
                Rect position2 = position1;
                position2.width = 0.0f;
                if (platform.Length > 0)
                {
                    GUIContent content = EditorGUIUtility.TempContent(platform);
                    Vector2    vector2 = EditorStyles.miniLabel.CalcSize(content);
                    position2.xMin -= vector2.x;
                    Color contentColor = GUI.contentColor;
                    GUI.contentColor = new Color(1f, 1f, 1f, 0.5f);
                    GUI.Label(position2, content, EditorStyles.miniLabel);
                    GUI.contentColor = contentColor;
                    position2.xMin  -= 2f;
                }
                Rect position3 = controlRect;
                position3.xMax = position2.xMin;
                GUI.Label(position3, EditorGUIUtility.TempContent(message, !flag ? (Texture)ShaderInspector.Styles.errorIcon : (Texture)ShaderInspector.Styles.warningIcon), ShaderInspector.Styles.messageStyle);
            }
            EditorGUIUtility.SetIconSize(Vector2.zero);
            GUILayout.EndScrollView();
        }
Example #11
0
        // shared by compute shader inspector too
        internal static void ShaderErrorListUI(Object shader, ShaderMessage[] messages, ref Vector2 scrollPosition)
        {
            int n = messages.Length;

            GUILayout.Space(kSpace);
            GUILayout.Label(string.Format("Errors ({0}):", n), EditorStyles.boldLabel);
            int   errorListID = GUIUtility.GetControlID(kErrorViewHash, FocusType.Passive);
            float height      = Mathf.Min(n * 20f + 40f, 150f);

            scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUISkin.current.box, GUILayout.MinHeight(height));

            EditorGUIUtility.SetIconSize(new Vector2(16.0f, 16.0f));
            float lineHeight = Styles.messageStyle.CalcHeight(EditorGUIUtility.TempContent(Styles.errorIcon), 100);

            Event e = Event.current;

            for (int i = 0; i < n; ++i)
            {
                Rect r = EditorGUILayout.GetControlRect(false, lineHeight);

                string err      = messages[i].message;
                string plat     = messages[i].platform.ToString();
                bool   warn     = messages[i].severity != ShaderCompilerMessageSeverity.Error;
                string fileName = FileUtil.GetLastPathNameComponent(messages[i].file);
                int    line     = messages[i].line;

                // Double click opens shader file at error line
                if (e.type == EventType.MouseDown && e.button == 0 && r.Contains(e.mousePosition))
                {
                    GUIUtility.keyboardControl = errorListID;
                    if (e.clickCount == 2)
                    {
                        string filePath = messages[i].file;
                        Object asset    = string.IsNullOrEmpty(filePath) ? null : AssetDatabase.LoadMainAssetAtPath(filePath);

                        // if we don't have an asset and the filePath is an absolute path, it's an error in a system
                        // cginc - open that instead
                        if (asset == null && System.IO.Path.IsPathRooted(filePath))
                        {
                            ShaderUtil.OpenSystemShaderIncludeError(filePath, line);
                        }
                        else
                        {
                            AssetDatabase.OpenAsset(asset ?? shader, line);
                        }
                        GUIUtility.ExitGUI();
                    }
                    e.Use();
                }

                // Context menu, "Copy"
                if (e.type == EventType.ContextClick && r.Contains(e.mousePosition))
                {
                    e.Use();
                    var menu = new GenericMenu();
                    // need to copy current value to be used in delegate
                    // (C# closures close over variables, not their values)
                    var errorIndex = i;
                    menu.AddItem(EditorGUIUtility.TrTextContent("Copy error text"), false, delegate {
                        string errMsg = messages[errorIndex].message;
                        if (!string.IsNullOrEmpty(messages[errorIndex].messageDetails))
                        {
                            errMsg += '\n';
                            errMsg += messages[errorIndex].messageDetails;
                        }
                        EditorGUIUtility.systemCopyBuffer = errMsg;
                    });
                    menu.ShowAsContext();
                }

                // background
                if (e.type == EventType.Repaint)
                {
                    if ((i & 1) == 0)
                    {
                        GUIStyle st = Styles.evenBackground;
                        st.Draw(r, false, false, false, false);
                    }
                }

                // error location on the right side
                Rect locRect = r;
                locRect.xMin = locRect.xMax;
                if (line > 0)
                {
                    GUIContent gc;
                    if (string.IsNullOrEmpty(fileName))
                    {
                        gc = EditorGUIUtility.TempContent(line.ToString(CultureInfo.InvariantCulture));
                    }
                    else
                    {
                        gc = EditorGUIUtility.TempContent(fileName + ":" + line.ToString(CultureInfo.InvariantCulture));
                    }

                    // calculate size so we can right-align it
                    Vector2 size = EditorStyles.miniLabel.CalcSize(gc);
                    locRect.xMin -= size.x;
                    GUI.Label(locRect, gc, EditorStyles.miniLabel);
                    locRect.xMin -= 2;
                    // ensure some minimum width so that platform field next will line up
                    if (locRect.width < 30)
                    {
                        locRect.xMin = locRect.xMax - 30;
                    }
                }

                // platform to the left of it
                Rect platRect = locRect;
                platRect.width = 0;
                if (plat.Length > 0)
                {
                    GUIContent gc = EditorGUIUtility.TempContent(plat);
                    // calculate size so we can right-align it
                    Vector2 size = EditorStyles.miniLabel.CalcSize(gc);
                    platRect.xMin -= size.x;

                    // draw platform in dimmer color; it's often not very important information
                    Color oldColor = GUI.contentColor;
                    GUI.contentColor = new Color(1, 1, 1, 0.5f);
                    GUI.Label(platRect, gc, EditorStyles.miniLabel);
                    GUI.contentColor = oldColor;
                    platRect.xMin   -= 2;
                }

                // error message
                Rect msgRect = r;
                msgRect.xMax = platRect.xMin;
                GUI.Label(msgRect, EditorGUIUtility.TempContent(err, warn ? Styles.warningIcon : Styles.errorIcon), Styles.messageStyle);
            }
            EditorGUIUtility.SetIconSize(Vector2.zero);
            GUILayout.EndScrollView();
        }
        internal override void OnEnable()
        {
            m_AnimationType       = serializedObject.FindProperty("m_AnimationType");
            m_AvatarSource        = serializedObject.FindProperty("m_LastHumanDescriptionAvatarSource");
            m_OptimizeGameObjects = serializedObject.FindProperty("m_OptimizeGameObjects");

            // Generic bone setup
            m_RootMotionBoneName     = serializedObject.FindProperty("m_HumanDescription.m_RootMotionBoneName");
            m_RootMotionBoneRotation = serializedObject.FindProperty("m_HumanDescription.m_RootMotionBoneRotation");

            m_ExposeTransformEditor = new ExposeTransformEditor();

            string[] transformPaths = singleImporter.transformPaths;
            m_RootMotionBoneList = new GUIContent[transformPaths.Length];
            for (int i = 0; i < transformPaths.Length; i++)
            {
                m_RootMotionBoneList[i] = new GUIContent(transformPaths[i]);
            }

            if (m_RootMotionBoneList.Length > 0)
            {
                m_RootMotionBoneList[0] = EditorGUIUtility.TrTextContent("None");
            }

            rootIndex = ArrayUtility.FindIndex(m_RootMotionBoneList, delegate(GUIContent content) { return(FileUtil.GetLastPathNameComponent(content.text) == m_RootMotionBoneName.stringValue); });
            rootIndex = rootIndex < 1 ? 0 : rootIndex;

            m_SrcHasExtraRoot = serializedObject.FindProperty("m_HasExtraRoot");
            m_DstHasExtraRoot = serializedObject.FindProperty("m_HumanDescription.m_HasExtraRoot");

            // Animation
            m_CopyAvatar = serializedObject.FindProperty("m_CopyAvatar");
            m_LegacyGenerateAnimations = serializedObject.FindProperty("m_LegacyGenerateAnimations");
            m_AnimationCompression     = serializedObject.FindProperty("m_AnimationCompression");

            m_RigImportErrors   = serializedObject.FindProperty("m_RigImportErrors");
            m_RigImportWarnings = serializedObject.FindProperty("m_RigImportWarnings");

            m_ExposeTransformEditor.OnEnable(singleImporter.transformPaths, serializedObject);

            m_CanMultiEditTransformList = CanMultiEditTransformList();

            // Check if avatar definition is same as the one it's copied from
            CheckIfAvatarCopyIsUpToDate();

            m_IsBiped            = false;
            m_BipedMappingReport = new List <string>();

            if (m_AnimationType.intValue == (int)ModelImporterAnimationType.Human)
            {
                GameObject go = assetTarget as GameObject;
                if (go != null)
                {
                    m_IsBiped = AvatarBipedMapper.IsBiped(go.transform, m_BipedMappingReport);
                }

                if (m_Avatar == null)
                {
                    ResetAvatar();
                }
            }
        }
        static private string[] TokeniseHumanTransformsPath(string[] refTransformsPath, string[] humanTransforms)
        {
            if (humanTransforms == null)
            {
                return(null);
            }

            // all list must always include the string "" which is the root game object
            string[] tokeniseTransformsPath = new string[] { "" };

            for (int i = 0; i < humanTransforms.Length; i++)
            {
                int index1 = ArrayUtility.FindIndex(refTransformsPath, s => humanTransforms[i] == FileUtil.GetLastPathNameComponent(s));
                if (index1 != -1)
                {
                    int insertIndex = tokeniseTransformsPath.Length;

                    string path = refTransformsPath[index1];
                    while (path.Length > 0)
                    {
                        int index2 = ArrayUtility.FindIndex(tokeniseTransformsPath, s => path == s);
                        if (index2 == -1)
                        {
                            ArrayUtility.Insert(ref tokeniseTransformsPath, insertIndex, path);
                        }

                        int lastIndex = path.LastIndexOf('/');
                        path = path.Substring(0, lastIndex != -1 ? lastIndex : 0);
                    }
                }
            }

            return(tokeniseTransformsPath);
        }
Example #14
0
        internal static void ShaderErrorListUI(UnityEngine.Object shader, ShaderError[] errors, ref Vector2 scrollPosition)
        {
            int num = errors.Length;

            GUILayout.Space(5f);
            GUILayout.Label(string.Format("Errors ({0}):", num), EditorStyles.boldLabel, new GUILayoutOption[0]);
            int   controlID = GUIUtility.GetControlID(ShaderInspector.kErrorViewHash, FocusType.Passive);
            float minHeight = Mathf.Min((float)num * 20f + 40f, 150f);

            scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUISkin.current.box, new GUILayoutOption[]
            {
                GUILayout.MinHeight(minHeight)
            });
            EditorGUIUtility.SetIconSize(new Vector2(16f, 16f));
            float height  = ShaderInspector.Styles.messageStyle.CalcHeight(EditorGUIUtility.TempContent(ShaderInspector.Styles.errorIcon), 100f);
            Event current = Event.current;

            for (int i = 0; i < num; i++)
            {
                Rect   controlRect           = EditorGUILayout.GetControlRect(false, height, new GUILayoutOption[0]);
                string message               = errors[i].message;
                string platform              = errors[i].platform;
                bool   flag                  = errors[i].warning != 0;
                string lastPathNameComponent = FileUtil.GetLastPathNameComponent(errors[i].file);
                int    line                  = errors[i].line;
                if (current.type == EventType.MouseDown && current.button == 0 && controlRect.Contains(current.mousePosition))
                {
                    GUIUtility.keyboardControl = controlID;
                    if (current.clickCount == 2)
                    {
                        string             file    = errors[i].file;
                        UnityEngine.Object @object = (!string.IsNullOrEmpty(file)) ? AssetDatabase.LoadMainAssetAtPath(file) : null;
                        if (@object == null && Path.IsPathRooted(file))
                        {
                            ShaderUtil.OpenSystemShaderIncludeError(file, line);
                        }
                        else
                        {
                            AssetDatabase.OpenAsset(@object ?? shader, line);
                        }
                        GUIUtility.ExitGUI();
                    }
                    current.Use();
                }
                if (current.type == EventType.ContextClick && controlRect.Contains(current.mousePosition))
                {
                    current.Use();
                    GenericMenu genericMenu = new GenericMenu();
                    int         errorIndex  = i;
                    genericMenu.AddItem(EditorGUIUtility.TrTextContent("Copy error text", null, null), false, delegate
                    {
                        string text = errors[errorIndex].message;
                        if (!string.IsNullOrEmpty(errors[errorIndex].messageDetails))
                        {
                            text += '\n';
                            text += errors[errorIndex].messageDetails;
                        }
                        EditorGUIUtility.systemCopyBuffer = text;
                    });
                    genericMenu.ShowAsContext();
                }
                if (current.type == EventType.Repaint)
                {
                    if ((i & 1) == 0)
                    {
                        GUIStyle evenBackground = ShaderInspector.Styles.evenBackground;
                        evenBackground.Draw(controlRect, false, false, false, false);
                    }
                }
                Rect rect = controlRect;
                rect.xMin = rect.xMax;
                if (line > 0)
                {
                    GUIContent content;
                    if (string.IsNullOrEmpty(lastPathNameComponent))
                    {
                        content = EditorGUIUtility.TempContent(line.ToString(CultureInfo.InvariantCulture));
                    }
                    else
                    {
                        content = EditorGUIUtility.TempContent(lastPathNameComponent + ":" + line.ToString(CultureInfo.InvariantCulture));
                    }
                    Vector2 vector = EditorStyles.miniLabel.CalcSize(content);
                    rect.xMin -= vector.x;
                    GUI.Label(rect, content, EditorStyles.miniLabel);
                    rect.xMin -= 2f;
                    if (rect.width < 30f)
                    {
                        rect.xMin = rect.xMax - 30f;
                    }
                }
                Rect position = rect;
                position.width = 0f;
                if (platform.Length > 0)
                {
                    GUIContent content2 = EditorGUIUtility.TempContent(platform);
                    Vector2    vector2  = EditorStyles.miniLabel.CalcSize(content2);
                    position.xMin -= vector2.x;
                    Color contentColor = GUI.contentColor;
                    GUI.contentColor = new Color(1f, 1f, 1f, 0.5f);
                    GUI.Label(position, content2, EditorStyles.miniLabel);
                    GUI.contentColor = contentColor;
                    position.xMin   -= 2f;
                }
                Rect position2 = controlRect;
                position2.xMax = position.xMin;
                GUI.Label(position2, EditorGUIUtility.TempContent(message, (!flag) ? ShaderInspector.Styles.errorIcon : ShaderInspector.Styles.warningIcon), ShaderInspector.Styles.messageStyle);
            }
            EditorGUIUtility.SetIconSize(Vector2.zero);
            GUILayout.EndScrollView();
        }
        private void DoPrefabButtons(PrefabType prefabType, GameObject go)
        {
            // @TODO: If/when we support multi-editing of prefab/model instances,
            // handle it here. Only show prefab bar if all are same type?
            if (!m_HasInstance)
            {
                return;
            }

            using (new EditorGUI.DisabledScope(EditorApplication.isPlayingOrWillChangePlaymode))
            {
                EditorGUILayout.BeginHorizontal();

                // Prefab information
                GUIContent prefixLabel = targets.Length > 1 ? s_Styles.goTypeLabelMultiple : s_Styles.goTypeLabel[(int)prefabType];

                if (prefixLabel != null)
                {
                    EditorGUILayout.BeginHorizontal(GUILayout.Width(kIconSize + s_Styles.tagFieldWidth));
                    GUILayout.FlexibleSpace();
                    if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.MissingPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance)
                    {
                        GUI.contentColor = GUI.skin.GetStyle("CN StatusWarn").normal.textColor;
                        GUILayout.Label(prefixLabel, EditorStyles.whiteLabel, GUILayout.ExpandWidth(false));
                        GUI.contentColor = Color.white;
                    }
                    else
                    {
                        GUILayout.Label(prefixLabel, GUILayout.ExpandWidth(false));
                    }
                    EditorGUILayout.EndHorizontal();
                }

                if (targets.Length > 1)
                {
                    GUILayout.Label("Instance Management Disabled", s_Styles.instanceManagementInfo);
                }
                else
                {
                    // Select prefab
                    if (prefabType != PrefabType.MissingPrefabInstance)
                    {
                        if (GUILayout.Button("Select", "MiniButtonLeft"))
                        {
                            Selection.activeObject = PrefabUtility.GetCorrespondingObjectFromSource(target);
                            EditorGUIUtility.PingObject(Selection.activeObject);
                        }
                    }

                    using (new EditorGUI.DisabledScope(AnimationMode.InAnimationMode()))
                    {
                        if (prefabType != PrefabType.MissingPrefabInstance)
                        {
                            // Revert this gameobject and components to prefab
                            if (GUILayout.Button("Revert", "MiniButtonMid"))
                            {
                                PrefabUtility.RevertPrefabInstanceWithUndo(go);

                                // case931300 - The selected gameobject might get destroyed by RevertPrefabInstance
                                if (go != null)
                                {
                                    CalculatePrefabStatus();
                                }

                                // This is necessary because Revert can potentially destroy game objects and components
                                // In that case the Editor classes would be destroyed but still be invoked. (case 837113)
                                GUIUtility.ExitGUI();
                            }

                            // Apply to prefab
                            if (prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance)
                            {
                                GameObject rootUploadGameObject = PrefabUtility.FindValidUploadPrefabInstanceRoot(go);

                                GUI.enabled = rootUploadGameObject != null && !AnimationMode.InAnimationMode();

                                if (GUILayout.Button("Apply", "MiniButtonRight"))
                                {
                                    UnityObject correspondingAssetObject = PrefabUtility.GetCorrespondingObjectFromSource(rootUploadGameObject);
                                    string      prefabAssetPath = AssetDatabase.GetAssetPath(correspondingAssetObject);
                                    bool        isRootFolder, isReadonly;
                                    bool        validPath = AssetDatabase.GetAssetFolderInfo(prefabAssetPath, out isRootFolder, out isReadonly);

                                    if (validPath && isReadonly)
                                    {
                                        string prefabName = FileUtil.GetLastPathNameComponent(FileUtil.GetPathWithoutExtension(prefabAssetPath));
                                        EditorUtility.DisplayDialog("Cannot apply changes", string.Format("Original prefab \"{0}\" is immutable.", prefabName), "Close");
                                    }
                                    else
                                    {
                                        bool editablePrefab = Provider.PromptAndCheckoutIfNeeded(
                                            new string[] { prefabAssetPath },
                                            "The version control requires you to check out the prefab before applying changes.");

                                        if (editablePrefab)
                                        {
                                            PrefabUtility.ReplacePrefabWithUndo(rootUploadGameObject);

                                            CalculatePrefabStatus();

                                            // This is necessary because ReplacePrefab can potentially destroy game objects and components
                                            // In that case the Editor classes would be destroyed but still be invoked. (case 468434)
                                            GUIUtility.ExitGUI();
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // Edit model prefab
                    if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.ModelPrefabInstance)
                    {
                        if (GUILayout.Button("Open", "MiniButtonRight"))
                        {
                            AssetDatabase.OpenAsset(PrefabUtility.GetCorrespondingObjectFromSource(target));
                            GUIUtility.ExitGUI();
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
        }
Example #16
0
 public void OnEnable()
 {
     this.m_AnimationType         = base.serializedObject.FindProperty("m_AnimationType");
     this.m_AvatarSource          = base.serializedObject.FindProperty("m_LastHumanDescriptionAvatarSource");
     this.m_OptimizeGameObjects   = base.serializedObject.FindProperty("m_OptimizeGameObjects");
     this.m_RootMotionBoneName    = base.serializedObject.FindProperty("m_HumanDescription.m_RootMotionBoneName");
     this.m_ExposeTransformEditor = new ExposeTransformEditor();
     string[] transformPaths = this.singleImporter.transformPaths;
     this.m_RootMotionBoneList = new GUIContent[transformPaths.Length];
     for (int i = 0; i < transformPaths.Length; i++)
     {
         this.m_RootMotionBoneList[i] = new GUIContent(transformPaths[i]);
     }
     if (this.m_RootMotionBoneList.Length > 0)
     {
         this.m_RootMotionBoneList[0] = new GUIContent("None");
     }
     this.rootIndex    = ArrayUtility.FindIndex <GUIContent>(this.m_RootMotionBoneList, content => FileUtil.GetLastPathNameComponent(content.text) == this.m_RootMotionBoneName.stringValue);
     this.rootIndex    = (this.rootIndex >= 1) ? this.rootIndex : 0;
     this.m_CopyAvatar = base.serializedObject.FindProperty("m_CopyAvatar");
     this.m_LegacyGenerateAnimations = base.serializedObject.FindProperty("m_LegacyGenerateAnimations");
     this.m_AnimationCompression     = base.serializedObject.FindProperty("m_AnimationCompression");
     this.m_ExposeTransformEditor.OnEnable(this.singleImporter.transformPaths, base.serializedObject);
     this.m_CanMultiEditTransformList = this.CanMultiEditTransformList();
     this.CheckIfAvatarCopyIsUpToDate();
     this.m_IsBiped = false;
     if (this.m_AnimationType.intValue == 3)
     {
         GameObject obj2 = AssetDatabase.LoadMainAssetAtPath(this.singleImporter.assetPath) as GameObject;
         this.m_IsBiped = AvatarBipedMapper.IsBiped(obj2.transform);
     }
 }
 internal override void OnEnable()
 {
     this.m_AnimationType          = base.serializedObject.FindProperty("m_AnimationType");
     this.m_AvatarSource           = base.serializedObject.FindProperty("m_LastHumanDescriptionAvatarSource");
     this.m_OptimizeGameObjects    = base.serializedObject.FindProperty("m_OptimizeGameObjects");
     this.m_RootMotionBoneName     = base.serializedObject.FindProperty("m_HumanDescription.m_RootMotionBoneName");
     this.m_RootMotionBoneRotation = base.serializedObject.FindProperty("m_HumanDescription.m_RootMotionBoneRotation");
     this.m_ExposeTransformEditor  = new ExposeTransformEditor();
     string[] transformPaths = this.singleImporter.transformPaths;
     this.m_RootMotionBoneList = new GUIContent[transformPaths.Length];
     for (int i = 0; i < transformPaths.Length; i++)
     {
         this.m_RootMotionBoneList[i] = new GUIContent(transformPaths[i]);
     }
     if (this.m_RootMotionBoneList.Length > 0)
     {
         this.m_RootMotionBoneList[0] = new GUIContent("None");
     }
     this.rootIndex                  = ArrayUtility.FindIndex <GUIContent>(this.m_RootMotionBoneList, (GUIContent content) => FileUtil.GetLastPathNameComponent(content.text) == this.m_RootMotionBoneName.stringValue);
     this.rootIndex                  = ((this.rootIndex >= 1) ? this.rootIndex : 0);
     this.m_SrcHasExtraRoot          = base.serializedObject.FindProperty("m_HasExtraRoot");
     this.m_DstHasExtraRoot          = base.serializedObject.FindProperty("m_HumanDescription.m_HasExtraRoot");
     this.m_CopyAvatar               = base.serializedObject.FindProperty("m_CopyAvatar");
     this.m_LegacyGenerateAnimations = base.serializedObject.FindProperty("m_LegacyGenerateAnimations");
     this.m_AnimationCompression     = base.serializedObject.FindProperty("m_AnimationCompression");
     this.m_RigImportErrors          = base.serializedObject.FindProperty("m_RigImportErrors");
     this.m_RigImportWarnings        = base.serializedObject.FindProperty("m_RigImportWarnings");
     this.m_ExposeTransformEditor.OnEnable(this.singleImporter.transformPaths, base.serializedObject);
     this.m_CanMultiEditTransformList = this.CanMultiEditTransformList();
     this.CheckIfAvatarCopyIsUpToDate();
     this.m_IsBiped            = false;
     this.m_BipedMappingReport = new List <string>();
     if (this.m_AnimationType.intValue == 3)
     {
         GameObject gameObject = AssetDatabase.LoadMainAssetAtPath(this.singleImporter.assetPath) as GameObject;
         this.m_IsBiped = AvatarBipedMapper.IsBiped(gameObject.transform, this.m_BipedMappingReport);
         if (this.m_Avatar == null)
         {
             this.ResetAvatar();
         }
     }
 }
            private static bool PickBuildLocation(BuildTargetGroup targetGroup, BuildTarget target, BuildOptions options, out bool updateExistingBuild)
            {
                updateExistingBuild = false;
                var previousPath = EditorUserBuildSettings.GetBuildLocation(target);

                string defaultFolder;
                string defaultName;

                if (previousPath == String.Empty)
                {
                    defaultFolder = FileUtil.DeleteLastPathNameComponent(Application.dataPath);
                    defaultName   = "";
                }
                else
                {
                    defaultFolder = FileUtil.DeleteLastPathNameComponent(previousPath);
                    defaultName   = FileUtil.GetLastPathNameComponent(previousPath);
                }

                string extension = PostprocessBuildPlayer.GetExtensionForBuildTarget(targetGroup, target, options);

                // Invalidate default name, if extension mismatches the default file (for ex., when switching between folder type export to file type export, see Android)
                if (extension != Path.GetExtension(defaultName).Replace(".", ""))
                {
                    defaultName = string.Empty;
                }

                // Hack: For Windows Standalone, we want the BuildPanel to choose a folder,
                // but we don't want BuildPlayer to take a folder path because historically it took an .exe path
                // and we would be breaking tons of projects!
                bool   isWindowsStandalone = target == BuildTarget.StandaloneWindows || target == BuildTarget.StandaloneWindows64;
                string realExtension       = extension;

                if (isWindowsStandalone)
                {
                    extension = string.Empty;
                    // Remove the filename.exe part from the path
                    if (!string.IsNullOrEmpty(defaultName))
                    {
                        defaultName = Path.GetDirectoryName(defaultName);
                    }
                }

                string title = "Build " + BuildPlatforms.instance.GetBuildTargetDisplayName(targetGroup, target);
                string path  = EditorUtility.SaveBuildPanel(target, title, defaultFolder, defaultName, extension, out updateExistingBuild);

                if (path == string.Empty)
                {
                    return(false);
                }

                if (isWindowsStandalone)
                {
                    extension = realExtension;
                    path      = Path.Combine(path, Paths.MakeValidFileName(PlayerSettings.productName) + '.' + extension);
                }

                if (!IsBuildPathValid(path))
                {
                    return(false);
                }

                // Enforce extension if needed
                if (extension != string.Empty && FileUtil.GetPathExtension(path).ToLower() != extension)
                {
                    path += '.' + extension;
                }

                // A path may not be empty initially, but it could contain, e.g., a drive letter (as in Windows),
                // so even appending an extension will work fine, but in reality the name will be, for example,
                // G:/
                //Debug.Log(path);

                string currentlyChosenName = FileUtil.GetLastPathNameComponent(path);

                if (currentlyChosenName == string.Empty)
                {
                    return(false); // No nameless projects, please
                }
                // We don't want to re-create a directory that already exists, this may
                // result in access-denials that will make users unhappy.
                string check_dir = extension != string.Empty ? FileUtil.DeleteLastPathNameComponent(path) : path;

                if (!Directory.Exists(check_dir))
                {
                    Directory.CreateDirectory(check_dir);
                }

                // On OSX we've got replace/update dialog, for other platforms warn about deleting
                // files in target folder.
                if ((target == BuildTarget.iOS) && (Application.platform != RuntimePlatform.OSXEditor))
                {
                    if (!FolderIsEmpty(path) && !UserWantsToDeleteFiles(path))
                    {
                        return(false);
                    }
                }

                EditorUserBuildSettings.SetBuildLocation(target, path);
                return(true);
            }
Example #19
0
        private HumanTemplate OpenHumanTemplate()
        {
            string directory = "Assets/";
            string str       = EditorUtility.OpenFilePanel("Open Human Template", directory, "ht");

            if (str == string.Empty)
            {
                return((HumanTemplate)null);
            }
            HumanTemplate humanTemplate = AssetDatabase.LoadMainAssetAtPath(FileUtil.GetProjectRelativePath(str)) as HumanTemplate;

            if ((UnityEngine.Object)humanTemplate == (UnityEngine.Object)null && EditorUtility.DisplayDialog("Human Template not found in project", "Import asset '" + str + "' into project", "Yes", "No"))
            {
                string uniqueAssetPath = AssetDatabase.GenerateUniqueAssetPath(directory + FileUtil.GetLastPathNameComponent(str));
                FileUtil.CopyFileOrDirectory(str, uniqueAssetPath);
                AssetDatabase.Refresh();
                humanTemplate = AssetDatabase.LoadMainAssetAtPath(uniqueAssetPath) as HumanTemplate;
                if ((UnityEngine.Object)humanTemplate == (UnityEngine.Object)null)
                {
                    Debug.Log((object)("Failed importing file '" + str + "' to '" + uniqueAssetPath + "'"));
                }
            }
            return(humanTemplate);
        }