/// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(InspectorProperty property, SuffixLabelAttribute attribute, GUIContent label)
        {
            PropertyContext <StringMemberHelper> context;

            if (property.Context.Get(this, "SuffixContext", out context))
            {
                context.Value = new StringMemberHelper(property.FindParent(PropertyValueCategory.Member, true).ParentType, attribute.Label);
            }

            if (attribute.Overlay)
            {
                this.CallNextDrawer(property, label);
                GUIHelper.PushGUIEnabled(true);
                GUI.Label(GUILayoutUtility.GetLastRect().HorizontalPadding(0, 8), context.Value.GetString(property), SirenixGUIStyles.RightAlignedGreyMiniLabel);
                GUIHelper.PopGUIEnabled();
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.BeginVertical();
                this.CallNextDrawer(property, label);
                GUILayout.EndVertical();
                GUIHelper.PushGUIEnabled(true);
                GUILayout.Label(context.Value.GetString(property), SirenixGUIStyles.RightAlignedGreyMiniLabel, GUILayoutOptions.ExpandWidth(false));
                GUIHelper.PopGUIEnabled();
                GUILayout.EndHorizontal();
            }
        }
Esempio n. 2
0
        void IDefinesGenericMenuItems.PopulateGenericMenu(InspectorProperty property, GenericMenu genericMenu)
        {
            var parentProperty = property.FindParent(PropertyValueCategory.Member, true);
            IPropertyValueEntry <string> entry = (IPropertyValueEntry <string>)property.ValueEntry;
            string parent = entry.Context.Get <FilePathContext>(this, "FilePathContext", (FilePathContext)null).Value.Parent.GetString(parentProperty);

            if (genericMenu.GetItemCount() > 0)
            {
                genericMenu.AddSeparator("");
            }

            string path = entry.SmartValue;

            // Create an absolute path from the current value.
            if (path.IsNullOrWhitespace() == false)
            {
                if (Path.IsPathRooted(path) == false)
                {
                    if (parent.IsNullOrWhitespace() == false)
                    {
                        path = Path.Combine(parent, path);
                    }

                    path = Path.GetFullPath(path);
                }
            }
            else if (parent.IsNullOrWhitespace() == false)
            {
                // Use the parent path instead.
                path = Path.GetFullPath(parent);
            }
            else
            {
                // Default to Unity project.
                path = Path.GetDirectoryName(Application.dataPath);
            }

            // Find first existing directory.
            if (path.IsNullOrWhitespace() == false)
            {
                while (path.IsNullOrWhitespace() == false && Directory.Exists(path) == false)
                {
                    path = Path.GetDirectoryName(path);
                }
            }

            // Show in explorer
            if (path.IsNullOrWhitespace() == false)
            {
                genericMenu.AddItem(new GUIContent("Show in explorer"), false, () => System.Diagnostics.Process.Start(path));
            }
            else
            {
                genericMenu.AddDisabledItem(new GUIContent("Show in explorer"));
            }
        }
        protected override void Initialize()
        {
            isListElement = Property.Parent != null && Property.Parent.ChildResolver is IOrderedCollectionResolver;
            bool isList = !isListElement;
            InspectorProperty listProperty = isList ? Property : Property.Parent;

            baseMemberProperty     = listProperty.FindParent(x => x.Info.PropertyType == PropertyType.Value, true);
            globalSelectedProperty = baseMemberProperty.Context.GetGlobal
                                         ("selectedIndex" + baseMemberProperty.GetHashCode(), (InspectorProperty)null);

            if (isList)
            {
                Type parentType = baseMemberProperty.ParentValues[0].GetType();
                selectedIndexSetter = EmitUtilities.CreateWeakInstanceMethodCaller <int>
                                          (parentType.GetMethod(Attribute.SetSelectedMethod, Flags.AllMembers));
            }
        }
        //private bool PathExists(string path, string parent)
        //{
        //    if (string.IsNullOrEmpty(path))
        //    {
        //        return false;
        //    }
        //    else if (parent.IsNullOrWhitespace() == false)
        //    {
        //        path = Path.Combine(parent, path);
        //    }

        //    return Directory.Exists(path);
        //}

        /// <summary>
        /// Adds customs generic menu options.
        /// </summary>
        public void PopulateGenericMenu(InspectorProperty property, GenericMenu genericMenu)
        {
            var parentProperty = property.FindParent(p => p.Info.HasSingleBackingMember, true);
            IPropertyValueEntry <string> entry = (IPropertyValueEntry <string>)property.ValueEntry;
            string parent = this.parentPath.GetString(parentProperty);

            if (genericMenu.GetItemCount() > 0)
            {
                genericMenu.AddSeparator("");
            }

            bool   exists = false;
            string createDirectoryPath = entry.SmartValue;

            if (createDirectoryPath.IsNullOrWhitespace() == false)
            {
                // Get the absolute path.
                if (Path.IsPathRooted(createDirectoryPath) == false)
                {
                    if (parent.IsNullOrWhitespace() == false)
                    {
                        createDirectoryPath = Path.Combine(parent, createDirectoryPath);
                    }

                    createDirectoryPath = Path.GetFullPath(createDirectoryPath);
                }

                exists = Directory.Exists(createDirectoryPath);
            }

            string showInExplorerPath = createDirectoryPath;

            if (showInExplorerPath.IsNullOrWhitespace())
            {
                if (parent.IsNullOrWhitespace() == false)
                {
                    // Use parent path instead.
                    showInExplorerPath = Path.GetFullPath(parent);
                }
                else
                {
                    // Default to Unity project path.
                    showInExplorerPath = Path.GetDirectoryName(Application.dataPath);
                }
            }

            // Find first existing path to open.
            while (showInExplorerPath.IsNullOrWhitespace() == false && Directory.Exists(showInExplorerPath) == false)
            {
                showInExplorerPath = Path.GetDirectoryName(showInExplorerPath);
            }

            // Show in explorer
            if (showInExplorerPath.IsNullOrWhitespace() == false)
            {
                genericMenu.AddItem(new GUIContent("Show in explorer"), false, () => Application.OpenURL(showInExplorerPath));
            }
            else
            {
                genericMenu.AddDisabledItem(new GUIContent("Show in explorer"));
            }

            // Create path
            if (exists || createDirectoryPath.IsNullOrWhitespace()) // Disable the create path option, if the directory already exists, or the path is invalid.
            {
                genericMenu.AddDisabledItem(new GUIContent("Create directory"));
            }
            else
            {
                genericMenu.AddItem(new GUIContent("Create directory"), false, () =>
                {
                    Directory.CreateDirectory(createDirectoryPath);
                    AssetDatabase.Refresh();
                });
            }
        }