public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            if (!EditorApplication.isPlaying)
            {
                EditorGUILayout.HelpBox("Available during runtime only.", MessageType.Info);
                return;
            }

            ObjectPoolComponent t = (ObjectPoolComponent)target;

            if (IsPrefabInHierarchy(t.gameObject))
            {
                EditorGUILayout.LabelField("Object Pool Count", t.Count.ToString());

                ObjectPoolBase[] objectPools = t.GetAllObjectPools(true);
                foreach (ObjectPoolBase objectPool in objectPools)
                {
                    DrawObjectPool(objectPool);
                }
            }

            Repaint();
        }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            if (!EditorApplication.isPlaying)
            {
                EditorGUILayout.HelpBox("Available during runtime only.", MessageType.Info);
                return;
            }

            ObjectPoolComponent t = (ObjectPoolComponent)target;

            if (PrefabUtility.GetPrefabType(t.gameObject) != PrefabType.Prefab)
            {
                EditorGUILayout.LabelField("Object Pool Count", t.Count.ToString());

                BaseObjectPool[] objectPools = t.GetAllObjectPools(true);
                if (null != objectPools)
                {
                    foreach (BaseObjectPool objectPool in objectPools)
                    {
                        DrawObjectPool(objectPool);
                    }
                }
            }

            Repaint();
        }
        /// <summary>
        /// 设置对象池管理器。
        /// </summary>
        public void SetObjectPool()
        {
            m_ResourceComponent = CentorPivot.This.GetComponent <ResourceComponent>();

            if (m_ResourceComponent == null)
            {
                throw new Exception("Resource component is invalid.");
            }

            //更新模式下 才有对象池,编辑器模式下不适应对象池
            if (m_ResourceComponent.ResourceMode == ResourceMode.Updatable)
            {
                ObjectPoolComponent objectPool = CentorPivot.This.GetComponent <ObjectPoolComponent>();

                if (objectPool == null)
                {
                    throw new Exception("Object pool manager is invalid.");
                }

                ObjectGroup[] objectGroups = objectPool.ObjectGroup;

                foreach (ObjectGroup item in objectGroups)
                {
                    switch (item.AssetBundleCategory)
                    {
                    case AssetBundleCategory.Asset:

                        m_AssetPools[item.AssetCategory] = objectPool.CreateMultiSpawnObjectPool <AssetObject>(Utility.Text.Format("Asset Pool-{0}", item.AssetCategory.ToString()));
                        m_AssetPools[item.AssetCategory].AutoReleaseInterval = item.AutoReleaseInterval;
                        m_AssetPools[item.AssetCategory].Capacity            = item.Capacity;
                        m_AssetPools[item.AssetCategory].ExpireTime          = item.ExpireTime;
                        m_AssetPools[item.AssetCategory].Priority            = item.Priority;

                        break;

                    case AssetBundleCategory.Resource:

                        if (m_ResourcePool != null)
                        {
                            throw new Exception("资源包池请勿添加多个");
                        }

                        m_ResourcePool = objectPool.CreateMultiSpawnObjectPool <ResourceObject>("Resource Pool");
                        m_ResourcePool.AutoReleaseInterval = item.AutoReleaseInterval;
                        m_ResourcePool.Capacity            = item.Capacity;
                        m_ResourcePool.ExpireTime          = item.ExpireTime;
                        m_ResourcePool.Priority            = item.Priority;

                        break;

                    default:
                        break;
                    }
                }
            }
        }
예제 #4
0
    // Use this for initialization
    void Start()
    {
        //根据绝对路径设置与获取数据
        ObjectPoolComponent poolComponent = GameEntry.GetComponent <ObjectPoolComponent>();

        m_HPBarItemObjectPool =
            poolComponent.CreateSingleSpawnObjectPool <HPBarItemObject>("HPBarItem", 10);

        //HPBarItem hpBarItem = Instantiate(m_HPBarItemTemplate);
        //Transform transform = hpBarItem.GetComponent<Transform>();
        //transform.SetParent(m_HPBarInstanceRoot);
        //transform.localScale = Vector3.one;
        //m_HPBarItemObjectPool.Register(HPBarItemObject.Create(null), true);
    }
예제 #5
0
        public void SetTimeActionPool(string objectName, float autoReleaseInterval, float expireTime, int capacity)
        {
            ObjectPoolComponent m_ObjectPoolManager = CentorPivot.This.GetComponent <ObjectPoolComponent>();

            if (m_ObjectPoolManager == null)
            {
                throw new Exception("ObjectPool Component is invalid.");
            }

            m_TimeActionObjectPool = m_ObjectPoolManager.CreateSingleSpawnObjectPool <TimeActionObject>(objectName);
            m_TimeActionObjectPool.AutoReleaseInterval = autoReleaseInterval;
            m_TimeActionObjectPool.ExpireTime          = expireTime;
            m_TimeActionObjectPool.Capacity            = capacity;
        }
예제 #6
0
        private void Start()
        {
            m_ObjectPoolComponent = GameBox.GetComponent <ObjectPoolComponent>();
            m_IObjectPoo01        = m_ObjectPoolComponent.CreateSingleSpawnObjectPool <OPDemo>("对象池01");
            m_IObjectPoo02        = m_ObjectPoolComponent.CreateSingleSpawnObjectPool <OPDemo>("对象池02", 10, 1);

            m_IObjectPoo01.Register(new OPDemo("对象池01_对象1", GameObject.CreatePrimitive(PrimitiveType.Cube)), false);
            m_IObjectPoo01.Register(new OPDemo("对象池01_对象1", GameObject.CreatePrimitive(PrimitiveType.Cube)), false);
            m_IObjectPoo01.Register(new OPDemo("对象池01_对象1", GameObject.CreatePrimitive(PrimitiveType.Cube)), false);
            m_IObjectPoo01.Register(new OPDemo("对象池01_对象1", GameObject.CreatePrimitive(PrimitiveType.Cube)), false);
            m_IObjectPoo01.Register(new OPDemo("对象池01_对象1", GameObject.CreatePrimitive(PrimitiveType.Cube)), false);
            m_IObjectPoo01.Register(new OPDemo("对象池01_对象1", GameObject.CreatePrimitive(PrimitiveType.Cube)), false);


            m_IObjectPoo02.Register(new OPDemo("对象池02_对象2", m_Target), false);

            m_Target = GameObject.Instantiate(m_Target);
            m_Target.Register <OPDemo>("对象池03_对象1", "对象1");
            m_Target = GameObject.Instantiate(m_Target);
            m_Target.Register <OPDemo>("对象池03_对象1", "对象1");

            gameObject.Register <OPDemo>("对象池04_对象1", "对象1");
        }