Пример #1
0
        public override void OnGUI(Rect pos, SerializedProperty property, GUIContent label)
        {
            pos = EditorDrawer.Box(pos);

            EditorGUI.LabelField(EditorDrawer.WithHeight(pos, EditorGUIUtility.singleLineHeight),
                                 property.displayName,
                                 EditorStyles.boldLabel);
            pos = EditorDrawer.FromHeight(pos, EditorGUIUtility.singleLineHeight);

            pos = EditorDrawer.FromWidth(pos, 10);
            var rect = new Rect(pos.x + pos.width - 50, pos.y, 50, pos.height);

            pos = new Rect(pos.x, pos.y, pos.width - 50, pos.height);

            pos = EditorDrawer.PropertyField(pos, property, "parent");
            var spawnable = (property.GetObject() as VariedSpawnableList <T, U>);

            var prefabs = property.FindPropertyRelative("prefabs");
            var counts  = property.FindPropertyRelative("counts");

            var countRect = new Rect(pos.x, pos.y, 30, pos.height);

            pos = new Rect(pos.x + 30, pos.y, pos.width - 50, pos.height);
            var rmRect = new Rect(pos.x + pos.width, pos.y, 20, pos.height);

            for (int i = 0; i != prefabs.arraySize; ++i)
            {
                countRect = EditorDrawer.PropertyField(countRect, counts.GetArrayElementAtIndex(i),
                                                       GUIContent.none);

                var prefabProp = prefabs.GetArrayElementAtIndex(i);
                pos    = EditorDrawer.PropertyField(pos, prefabProp, GUIContent.none);
                rmRect = EditorDrawer.DefaultButton(rmRect, "-", Color.red, () => {
                    prefabs.DeleteArrayElementAtIndex(i);
                    counts.DeleteArrayElementAtIndex(i);
                    i -= 1;
                });
            }

            pos = EditorDrawer.Button(pos, "+", Color.green, () => {
                prefabs.arraySize++;
                counts.arraySize++;
            });

            if (GUI.Button(rect, "Build"))
            {
                var spawned = spawnable.EditorSpawn();
                spawned.gameObject.hideFlags = HideFlags.DontSaveInBuild;
            }
            GUI.enabled = true;
        }
Пример #2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var target = property.serializedObject.targetObject;
            var go     = (target as Component).gameObject;

            if (PrefabUtility.FindPrefabRoot(go) != go)
            {
                return;
            }

            EditorDrawer.Button(position, "Save Prefab", new Color(0.5f, 0.5f, 1),
                                () =>
            {
                var mono = property.serializedObject.targetObject as MonoBehaviour;

                var toSave = mono.GetComponentsInChildren <IPrefabSaveable>(true).ToList().ConvertAll(
                    (a) => (a as Component).gameObject
                    );
                toSave.Add(mono.gameObject);

                toSave.RemoveAll((g) => PrefabUtility.FindPrefabRoot(g) != g);

                var oldHideFlags = new Dictionary <GameObject, HideFlags>();
                foreach (var go1 in toSave)
                {
                    oldHideFlags[go1] = go1.hideFlags;
                    go1.hideFlags     = HideFlags.DontSave;
                }

//                foreach (var go2 in toSave)
//                {
                var go2       = mono.gameObject;
                go2.hideFlags = HideFlags.None;
                if (PrefabUtility.GetPrefabType(go2) == PrefabType.DisconnectedPrefabInstance)
                {
                    PrefabUtility.ReconnectToLastPrefab(go2);
                }
                PrefabUtility.ReplacePrefab(go2, PrefabUtility.GetPrefabParent(go2), ReplacePrefabOptions.ConnectToPrefab);
                go2.hideFlags = HideFlags.DontSave;
//                }

                foreach (var go3 in toSave)
                {
                    go3.hideFlags = oldHideFlags[go3];
                }
            });
        }