Пример #1
0
        public static void ShowWindow(string title, SerializedProperty elements)
        {
            AssetWindow[] objArray = Resources.FindObjectsOfTypeAll <AssetWindow>();
            AssetWindow   window   = (objArray.Length <= 0 ? ScriptableObject.CreateInstance <AssetWindow>() : objArray[0]);

            window.hideFlags             = HideFlags.HideAndDontSave;
            window.minSize               = new Vector2(260f, 200f);
            window.titleContent          = new GUIContent(title);
            window.m_ElementPropertyPath = elements.propertyPath;
            window.m_Target              = elements.serializedObject.targetObject;
            window.m_Targets             = new UnityEngine.Object[elements.arraySize];
            for (int i = 0; i < elements.arraySize; i++)
            {
                window.m_Targets[i] = elements.GetArrayElementAtIndex(i).objectReferenceValue;
            }
            window.m_HasPrefab = PrefabUtility.GetNearestPrefabInstanceRoot(window.m_Target) != null;
            window.m_Editors   = new List <Editor>();
            window.elementType = TypeUtility.GetType(elements.arrayElementType.Replace("PPtr<$", "").Replace(">", ""));
            for (int i = 0; i < window.m_Targets.Length; i++)
            {
                Editor editor = Editor.CreateEditor(window.m_Targets[i]);
                window.m_Editors.Add(editor);
            }
            window.FixMissingAssets();
            EditorApplication.playModeStateChanged += OnPlaymodeStateChange;
            window.ShowUtility();
        }
Пример #2
0
        protected static void OnScriptsReloaded()
        {
            string scriptName = EditorPrefs.GetString("NewScriptToCreate");
            int    windowID   = EditorPrefs.GetInt("AssetWindowID");

            if (string.IsNullOrEmpty(scriptName))
            {
                EditorPrefs.DeleteKey("NewScriptToCreate");
                EditorPrefs.DeleteKey("AssetWindowID");
                return;
            }

            Type type = Utility.GetType(scriptName);

            if (!EditorApplication.isPlayingOrWillChangePlaymode && !string.IsNullOrEmpty(scriptName) && type != null)
            {
                AssetWindow[] windows = Resources.FindObjectsOfTypeAll <AssetWindow>();
                AssetWindow   window  = windows.Where(x => x.GetInstanceID() == windowID).FirstOrDefault();
                if (window != null)
                {
                    window.AddAsset(type);
                }
            }
            EditorPrefs.DeleteKey("NewScriptToCreate");
            EditorPrefs.DeleteKey("AssetWindowID");
        }