コード例 #1
0
        void AddItem(GameObject go, int index)
        {
            string guid = UIEditorHelper.ObjectToGUID(go);

            if (string.IsNullOrEmpty(guid))
            {
                string path = EditorUtility.SaveFilePanelInProject("Save a prefab",
                                                                   go.name + ".prefab", "prefab", "Save prefab as...", "");

                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

                go = PrefabUtility.CreatePrefab(path, go);
                if (go == null)
                {
                    return;
                }

                guid = UIEditorHelper.ObjectToGUID(go);
                if (string.IsNullOrEmpty(guid))
                {
                    return;
                }
            }

            PreviewItem ent = new PreviewItem();

            ent.prefab = go;
            ent.guid   = guid;
            GeneratePreview(ent);
            RectivateLights();

            if (index < mItems.size)
            {
                mItems.Insert(index, ent);
            }
            else
            {
                mItems.Add(ent);
            }
            Save();
        }