Ejemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            if (Application.isPlaying)
            {
                return;
            }

            Event            e        = Event.current;
            PrefabCollection myTarget = (PrefabCollection)target;

            PrefabCollectionUtility.UpdatePrefabCollection(myTarget);

            if (myTarget.prefabs == null || myTarget.prefabs.Count == 0)
            {
                EditorGUILayout.LabelField("Please add some prefab collections", EditorStyles.boldLabel);
                return;
            }

            if (e.type == EventType.ScrollWheel)
            {
                myTarget.Step(PrefabCollectionUtility.GetScrollStep(e));
            }
        }
Ejemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            if (Application.isPlaying)
            {
                return;
            }

            CollectionGroup myTarget = (CollectionGroup)target;

            DrawChildren(myTarget);

            EditorGUILayout.Space();

            //Children
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("All Children");

            if (GUILayout.Button("<-", GUILayout.ExpandWidth(false)))
            {
                myTarget.Step(-1);
            }

            if (GUILayout.Button("->", GUILayout.ExpandWidth(false)))
            {
                myTarget.Step(1);
            }

            if (GUILayout.Button("?", GUILayout.ExpandWidth(false)))
            {
                myTarget.Randomize();
            }

            EditorGUILayout.EndHorizontal();

            //Scrolling
            if (Event.current.type == EventType.ScrollWheel)
            {
                myTarget.Step(PrefabCollectionUtility.GetScrollStep(Event.current));
            }
        }
Ejemplo n.º 3
0
        public static void UpdatePrefabCollection(PrefabCollection collection)
        {
            if (Application.isPlaying)
            {
                return;
            }

            //Reset index if prefab mode
            if (!PrefabCollectionUtility.IsPrefabMode() && collection.isPrefab)
            {
                collection.isPrefab      = false;
                collection.selectedIndex = -1;

                if (collection.spawnedObject != null)
                {
                    GameObject.DestroyImmediate(collection.spawnedObject);
                }
            }

            //Auto Selection
            if (collection.spawnedObject == null && collection.prefabs != null && collection.prefabs.Count > 0)
            {
                if (collection.selectedIndex == -1)
                {
                    PrefabCollectionUtility.SelectInitial(collection);
                }
                else
                {
                    PrefabCollectionUtility.Select(collection.selectedIndex, collection);
                }
            }

            //Detect no prefabs
            if (collection.spawnedObject == null && (collection.prefabs == null || collection.prefabs.Count == 0))
            {
                GameObject.DestroyImmediate(collection.spawnedObject);
                collection.spawnedObject = null;
                collection.selectedIndex = -1;
                EditorUtility.SetDirty(collection);
            }

            //Out of range
            if (collection.selectedIndex != -1 && collection.selectedIndex >= collection.prefabs.Count)
            {
                PrefabCollectionUtility.Select(collection.prefabs.Count - 1, collection);
            }

            else
            {
                //Detect change in current prefab
                bool isSamePrefab = true;

                if (collection.spawnedObject != null)
                {
                    isSamePrefab = PrefabUtility.GetCorrespondingObjectFromSource(collection.spawnedObject) == collection.prefabs[collection.selectedIndex];
                }

                if (collection.selectedIndex != -1 && !isSamePrefab)
                {
                    PrefabCollectionUtility.Select(collection.selectedIndex, collection);
                }
            }
        }
 public override void Step(int step)
 {
     PrefabCollectionUtility.Select(selectedIndex + step, this);
 }
 public override void Randomize()
 {
     PrefabCollectionUtility.SelectRandom(this);
 }
 public void Awake()
 {
     PrefabCollectionUtility.UpdatePrefabCollection(this);
 }