#region Author/* Jones St. Lewis Cropper (caLLow) Another caLLowCreation Visit us on Google+ and other social media outlets @caLLowCreation Thanks for using our product. Send questions/comments/concerns/requests to e-mail: caLLowCreation@gmail.com subject: PoolEverything*/#endregion#region Author/* Jones St. Lewis Cropper (caLLow) Another caLLowCreation Visit us on Google+ and other social media outlets @caLLowCreation Thanks for using our product. Send questions/comments/concerns/requests to e-mail: caLLowCreation@gmail.com subject: PoolEverything*/#endregionusingUnityEngine;usingSystem.Collections.Generic;namespacePoolEverything.Helpers{publicclassMultiObjectPool:MonoBehaviour{ [SerializeField, PoolManagerPicker]PoolManagerm_PoolManager=null; [SerializeField, MultiObjectPoolPicker("m_PoolManager", "Object Id")]List<int>m_ObjectIds=null; [SerializeField, MultiObjectPoolPicker("m_PoolManager", "Id")]intm_ObjectId=-1;}}
#region Author/* Jones St. Lewis Cropper (caLLow) Another caLLowCreation Visit us on Google+ and other social media outlets @caLLowCreation Thanks for using our product. Send questions/comments/concerns/requests to e-mail: caLLowCreation@gmail.com subject: PoolEverything*/#endregionusingUnityEngine;namespacePoolEverything.Helpers{/// <summary>/// Attribute to draw a Pool Manager and index popup to replace the integer field allows for multiple object selections/// </summary>publicclassMultiObjectPoolPickerAttribute:PropertyAttribute{/// <summary>/// Name of PoolManager field/// </summary>publicreadonlystringpoolManagerName;/// <summary>/// Label to replace the default field name/// </summary>publicreadonlystringlabel;/// <summary>/// Constructor/// </summary>publicMultiObjectPoolPickerAttribute(stringpoolManagerName="m_PoolManager",stringlabel="Pool Object"){this.poolManagerName=poolManagerName;this.label=label;}}}
#region Author/* Jones St. Lewis Cropper (caLLow) Another caLLowCreation Visit us on Google+ and other social media outlets @caLLowCreation Thanks for using our product. Send questions/comments/concerns/requests to e-mail: caLLowCreation@gmail.com subject: PoolEverything*/#endregionusingUnityEditor;usingUnityEngine;usingSystem.Linq;usingPoolEverything.Helpers;usingPoolEverything;namespacePoolEverythingEditor{/// <summary>/// Custom editor to draw popup to pick a pool manager and pooled object/// </summary> [CustomPropertyDrawer(typeof(MultiObjectPoolPickerAttribute), true)] [CanEditMultipleObjects]publicclassMultiObjectPoolPickerDrawer:PropertyDrawer{intm_PoolKey=-1;/// <summary>/// Called to draw the proeprty/// </summary>/// <param name="position">Rectangle position to draw property</param>/// <param name="property">Peoperty passed in by the calss field</param>/// <param name="label">Name and toolip of field property</param>publicoverridevoidOnGUI(Rectposition,SerializedPropertyproperty,GUIContentlabel){MultiObjectPoolPickerAttributeattr=attributeasMultiObjectPoolPickerAttribute;SerializedPropertypoolManagerProperty=property.serializedObject.FindProperty(attr.poolManagerName);PoolManagerpoolManager=poolManagerProperty.objectReferenceValueasPoolManager;intpoolIndex=property.intValue;for(inti=0;poolManager&&poolManager.poolReferences!=null&&i<poolManager.poolReferences.Length;i++){if(poolIndex==i){m_PoolKey=i;break;}}if(poolManager){varprefabs=poolManager.poolReferences;if(prefabs==null||poolManager.poolReferences.Where(x=>x.reference).Count()==0){varhelpRect=position;helpRect.x=100;helpRect.width-=86;EditorGUI.HelpBox(helpRect,"No pools in manager.",MessageType.Info);varbtnRect=position;btnRect.x+=10;btnRect.width=74;if(GUI.Button(btnRect,"Add Now")){Selection.activeObject=poolManager;}}else{varguiContents=prefabs.Select(x=>newGUIContent(x!=null&&x.reference?x.reference.name:"")).ToArray();m_PoolKey=EditorGUI.Popup(position,newGUIContent(attr.label),m_PoolKey,guiContents);}if(GUI.changed){property.intValue=m_PoolKey;}}else{EditorGUI.HelpBox(position,"Select a Pool Manager",MessageType.Info);m_PoolKey=-1;}}}}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.