コード例 #1
0
 private void ReadActivities(Activities processTypeActivities, PoolElement poolElement)
 {
     if (processTypeActivities != null && processTypeActivities.Activity != null)
     {
         foreach (Activity activity in processTypeActivities.Activity)
         {
             object activityItem = activity.Item;
             if (activityItem != null)
             {
                 IActivityMapper mapper = ActivityMapperAttribute.GetMapper(activityItem.GetType());
                 if (mapper != null)
                 {
                     IBaseElement element = mapper.CreateElement(activityItem, activity.NodeGraphicsInfos);
                     element.Name = activity.Name;
                     element.Guid = Guid.Parse(activity.Id);
                     _elements.Add(element.Guid, element);
                     poolElement.Elements.Add(element);
                 }
                 else
                 {
                     throw new MapperNotFoundException(activityItem.GetType());
                 }
             }
         }
     }
 }
コード例 #2
0
    public void CreatePool(GameObject poolAbleObject, int poolSize = 50)
    {
        #region Protectors

        IPoolable objInterface = poolAbleObject.GetComponent <IPoolable>();
        if (objInterface == null)
        {
            Debug.LogWarningFormat("Can't create objectPool to object: {0}. There is no 'IPoolable' interface", poolAbleObject.name); return;
        }

        if (poolSize < 0)
        {
            poolSize = 20;
        }
        #endregion

        if (pools.Find(x => x.Key.Equals(poolAbleObject.name)) == null)
        {
            GameObject tempParrent = Instantiate(poolContainer, gameObject.transform);
            tempParrent.name = string.Format("{0}_Pool", poolAbleObject.name);
            PoolElement tmpPoolScript = tempParrent.GetComponent <PoolElement>();
            if (tmpPoolScript != null)
            {
                tmpPoolScript.CreatePool(poolAbleObject.gameObject, poolSize, tempParrent.transform);
                pools.Add(tmpPoolScript);
            }
        }
    }
コード例 #3
0
    /////////////////////////////////////////////
    public ObjectPool(int numElements, GameObject go)
    {
        if (numElements < 1)
        {
            Debug.LogError("Failed to init the Object Pool");
            return;
        }

#if DEBUG
        mMinimumAvailableElements = numElements;
#endif

        mActiveObjects    = new List <PoolElement>();
        mAvailableObjects = new Queue <PoolElement>();

        GameObject root = new GameObject("Pool_" + go.name);
        for (int i = 0; i < numElements; i++)
        {
            GameObject newOb = Object.Instantiate(go);
            newOb.transform.parent = root.transform;
            PoolElement component = newOb.GetComponent <PoolElement>();
            if (component == null)
            {
                Debug.LogError("ObjectPool: the GameObject " + go + " doesn't have a PoolElement component.");
            }
            component.SetProprietaryPool(this);
            component.Deactivate();
            mAvailableObjects.Enqueue(component);
        }
    }
コード例 #4
0
        private Transitions GetTransitions(PoolElement poolElement)
        {
            Transitions transitions = new Transitions();

            transitions.Transition = new Transition[poolElement.Connections.Count];
            HashSet <Guid> guids = new HashSet <Guid>(poolElement.Elements.Select(item => item.Guid));

            for (int i = 0; i < poolElement.Connections.Count; i++)
            {
                ConnectionElement connectionElement = poolElement.Connections[i];
                bool containsFirst = guids.Contains(connectionElement.SourceElement.Guid);
                if (!containsFirst)
                {
                    _errorList.Add(string.Format("Cannot create transition. Pool does not contains source element: {0}", connectionElement.SourceElement.Guid));
                }
                bool containsSecond = guids.Contains(connectionElement.TargetElement.Guid);
                if (!containsSecond)
                {
                    _errorList.Add(string.Format("Cannot create transition. Pool does not contains target element: {0}", connectionElement.TargetElement.Guid));
                }
                if (containsSecond && containsFirst)
                {
                    Transition transition = new Transition();
                    transition.Id                     = connectionElement.GetId();
                    transition.From                   = connectionElement.SourceElement.GetId();
                    transition.To                     = connectionElement.TargetElement.GetId();
                    transitions.Transition[i]         = transition;
                    transition.ConnectorGraphicsInfos = CreateConnectorGraphicsInfos(connectionElement);
                }
            }
            return(transitions);
        }
コード例 #5
0
 private void ReadTransitions(ProcessType processType)
 {
     if (processType.Transitions?.Transition == null)
     {
         return;
     }
     foreach (var transition in processType.Transitions.Transition)
     {
         var         from        = transition.From;
         var         to          = transition.To;
         PoolElement poolElement = null;
         var         guid        = Guid.Parse(processType.Id);
         if (_poolByProcessDictionary.TryGetValue(guid, out poolElement))
         {
             try
             {
                 IBaseElement      fromElement = _elements[Guid.Parse(from)];
                 IBaseElement      toElement   = _elements[Guid.Parse(to)];
                 ConnectionElement connection  = new ConnectionElement(fromElement, toElement);
                 connection.Guid = Guid.Parse(transition.Id);
                 List <Point> points = GetPoints(transition.ConnectorGraphicsInfos);
                 connection.Points = points;
                 poolElement.Connections.Add(connection);
             }
             catch (KeyNotFoundException ex)
             {
                 throw new BaseElementNotFoundException(ex);
             }
         }
     }
 }
コード例 #6
0
 private void ReadPools(Pools packagePools)
 {
     foreach (Pool pool in packagePools.Pool)
     {
         Guid        guid        = Guid.Parse(pool.Id);
         Guid        processGuid = Guid.Parse(pool.Process);
         PoolElement poolElement = new PoolElement(guid)
         {
             Name        = pool.Name,
             Guid        = guid,
             ProcessGuid = processGuid
         };
         _poolByProcessDictionary.Add(processGuid, poolElement);
         if (poolElement.Name != XpdlInfo.MainPoolName)
         {
             SetVisualElementInfo(pool.NodeGraphicsInfos, poolElement);
             Document.Pools.Add(poolElement);
         }
         else
         {
             Document.MainPoolElement = poolElement;
         }
         SetLanes(poolElement, pool);
     }
 }
コード例 #7
0
    private void AddNewPoolElement()
    {
        GameObject  go          = GameObject.Instantiate(_prefab);
        PoolElement poolElement = go.AddComponent <PoolElement>();

        poolElement.Pool = this;

        _pool.Push(go);
    }
コード例 #8
0
    private void OnTriggerEnter(Collider other)
    {
        PoolElement e = other.GetComponent <PoolElement>();

        if (e.Spawner != this && other.tag.CompareTo(this.tag) == 0)
        {
            e.release();
        }
    }
コード例 #9
0
    public void PopBlossom(Vector2 position)
    {
        StartCoroutine(m_scriptSoundManager.Pop());
        PoolElement leaf = m_blossomleafPool.Pop();

        leaf.gameObject.transform.position = position;
        leaf.GetComponent <BlossomLeaf>().Fall();
        m_nPopCount++;
    }
コード例 #10
0
 private void ReadHeader(ProcessHeader processHeader, PoolElement poolElement)
 {
     if (processHeader?.Created != null)
     {
         DateTime dateTime;
         if (DateTime.TryParse(processHeader.Created.Value, out dateTime))
         {
             poolElement.CreatedOn = dateTime;
         }
     }
 }
コード例 #11
0
 //Set an object to disabled
 /////////////////////////////////////////////
 public void Destroy(PoolElement element)
 {
     if (!mActiveObjects.Contains(element))
     {
         Debug.LogWarning("ObjectPool: object is not active " + element + ".");
         return;
     }
     Debug.Log("ObjectPool: deactivating object " + element.gameObject);
     element.Deactivate();
     mActiveObjects.Remove(element);
     mAvailableObjects.Enqueue(element);
 }
コード例 #12
0
    public void ReturtToPool(GameObject prefab)
    {
        PoolElement foundedPool = pools.Find(x => prefab.name.StartsWith(x.Key));

        if (foundedPool != null)
        {
            prefab.transform.SetParent(foundedPool.parrent);
        }
        else
        {
            Debug.LogError("Can't fond ObjectPool for this object: " + prefab.name);
        }
    }
コード例 #13
0
    public GameObject GetGameObjectFromPool(string nameOfPrefab, System.Action <GameObject> beforeActive = null)
    {
        PoolElement foundedPool = pools.Find(x => x.Key == nameOfPrefab);

        if (foundedPool != null)
        {
            return(foundedPool.GetFromPool(beforeActive));
        }
        else
        {
            Debug.LogError("Can't fond ObjectPool for this object: " + nameOfPrefab);
        }
        return(null);
    }
コード例 #14
0
 private void ReadProcesses(WorkflowProcesses workflowProcesses)
 {
     foreach (ProcessType processType in workflowProcesses.WorkflowProcess)
     {
         Guid        processGuid = Guid.Parse(processType.Id);
         PoolElement poolElement = null;
         if (_poolByProcessDictionary.TryGetValue(processGuid, out poolElement))
         {
             ReadHeader(processType.ProcessHeader, poolElement);
             ReadActivities(processType.Activities, poolElement);
         }
         ReadTransitions(processType);
     }
 }
コード例 #15
0
    public GameObject GetGameObjectFromPool(GameObject prefab, System.Action <GameObject> beforeActive = null)
    {
        PoolElement foundedPool = pools.Find(x => x.reference == prefab);

        if (foundedPool != null)
        {
            return(foundedPool.GetFromPool(beforeActive));
        }
        else
        {
            Debug.LogError("Can't fond ObjectPool for this object: " + prefab.name);
        }
        return(null);
    }
コード例 #16
0
        /// <summary>
        /// Creates xpdl pool based on program pool
        /// </summary>
        /// <param name="poolElement"></param>
        /// <param name="isVisible"></param>
        /// <returns></returns>
        private static Pool CreatePool(PoolElement poolElement, bool isVisible = true)
        {
            Pool result = new Pool();

            result.BoundaryVisible = isVisible;
            result.Id                = poolElement.GetId();
            result.Process           = poolElement.ProcessGuid.ToString();
            result.Lanes             = GetLanes(poolElement);
            result.Name              = poolElement.Name;
            result.NodeGraphicsInfos = new NodeGraphicsInfos();
            result.NodeGraphicsInfos.NodeGraphicsInfo    = new NodeGraphicsInfo[1];
            result.NodeGraphicsInfos.NodeGraphicsInfo[0] = CreateNodeGraphicsInfo(poolElement);
            return(result);
        }
コード例 #17
0
        private ProcessType GetProcess(PoolElement poolElement)
        {
            ProcessType processType = new ProcessType();

            processType.Id                    = poolElement.ProcessGuid.ToString();
            processType.ProcessHeader         = new ProcessHeader();
            processType.ProcessHeader.Created = new Created()
            {
                Value = XpdlInfo.GetUtcDateTime(poolElement.CreatedOn)
            };
            processType.Name        = poolElement.Name;
            processType.Activities  = GetActivities(poolElement.Elements);
            processType.Transitions = GetTransitions(poolElement);
            return(processType);
        }
コード例 #18
0
ファイル: Util_PoolManager.cs プロジェクト: young1048/Pooling
    public void Resize(int size)
    {
        int oldSize = _pooledList.Length;
        int newSize = size;

        PoolElement[] newArr = new PoolElement[size];

        try {
            System.Array.Copy(_pooledList, newArr, _pooledList.Length);
        }
        catch (System.ArgumentException e) {
            Debug.Log(e.Message);

            for (int i = 0; i < _pooledList.Length; ++i)
            {
                newArr[i] = _pooledList[i];
            }
        }

        _pooledAmount = newSize;

        _pooledList = newArr;

        for (int i = oldSize; i < size; i++)
        {
            GameObject o = GameObject.Instantiate(_prefabsObject) as GameObject;
            o.transform.parent = _parent;
            if (_parent == null)
            {
                if (_poolingContainer == null)
                {
                    _poolingContainer = GameObject.FindWithTag("PoolingContainer");
                }

                if (_poolingContainer != null)
                {
                    o.transform.parent = _poolingContainer.transform;
                }
            }
            _pooledList[i]           = new PoolElement();
            _pooledList[i]._element  = o;
            _pooledList[i]._reserved = false;
        }

        Debug.Log("Resize pool manager " + _tag + " from " + oldSize.ToString() + " to " + newSize.ToString());

        _loaded = true;
    }
コード例 #19
0
    /// <summary>
    /// Instanciamos los objetos del pull
    /// </summary>
    void Start()
    {
        poolList = new List <GameObject>();

        foreach (GameObject objeto in objectPrefabs)
        {
            for (int i = 0; i < objectCount; i++)
            {
                GameObject  aux  = Instantiate(objeto, poolPosition, Quaternion.Euler(0, 0, 0));
                PoolElement elem = aux.GetComponent <PoolElement>();
                elem.SetPositionPool(aux.transform);
                elem.SetInactive();
                poolList.Add(aux);
            }
        }
    }
コード例 #20
0
        private void SetLanes(PoolElement poolElement, Pool pool)
        {
            List <Lane> orderedLanes = OrderLanes(pool.Lanes);

            foreach (Lane lane in orderedLanes)
            {
                LaneElement laneElement = new LaneElement();
                laneElement.Name = lane.Name;
                laneElement.Guid = Guid.Parse(lane.Id);
                NodeGraphicsInfo graphicsInfo = GetNodeGraphicsInfo(lane.NodeGraphicsInfos);
                if (graphicsInfo != null)
                {
                    laneElement.Height = graphicsInfo.Height;
                }
                poolElement.Lanes.Add(laneElement);
            }
        }
コード例 #21
0
ファイル: Weapon.cs プロジェクト: andxet/evil-cubes
        /////////////////////////////////////////////
        Bullet CreateBullet()
        {
            Bullet bullet = null;

            {
                PoolElement bulletEl = mBulletPool.Create();
                if (bulletEl != null)
                {
                    bullet = bulletEl.gameObject.GetComponent <Bullet>();
                }
            }
            if (bullet == null)
            {
                Debug.LogWarning("Failed to shoot the projectile. Maybe the bullet frefab is wrong?");
            }
            return(bullet);
        }
コード例 #22
0
 public PoolViewModel(DocumentViewModel documentViewModel, PoolElement poolElement) : this(documentViewModel)
 {
     _poolElement = poolElement;
     BaseElement  = _poolElement;
     int count = 0;
     foreach (LaneElement lane in poolElement.Lanes)
     {
         LaneViewModel laneViewModel = new LaneViewModel(count, this, lane);
         if (count == poolElement.Lanes.Count - 1)
         {
             PropertyChanged += laneViewModel.PoolPropertyChanged;
         }
         Lanes.Add(laneViewModel);
         count++;
     }
     MinHeight = CalculateMinHeight();
 }
コード例 #23
0
        /// <summary>
        /// Creates Xpdl Lanes based on LaneElements inside pool
        /// </summary>
        /// <param name="poolElement"></param>
        /// <returns></returns>
        private static Lanes GetLanes(PoolElement poolElement)
        {
            Lanes lanes = new Lanes();

            lanes.Lane = new Lane[poolElement.Lanes.Count];
            for (int i = 0; i < poolElement.Lanes.Count; i++)
            {
                lanes.Lane[i] = new Lane();
                var laneElement = poolElement.Lanes[i];
                lanes.Lane[i].Id                = laneElement.GetId();
                lanes.Lane[i].Name              = laneElement.Name;
                lanes.Lane[i].ParentPool        = poolElement.GetId();
                lanes.Lane[i].NodeGraphicsInfos = new NodeGraphicsInfos();
                lanes.Lane[i].NodeGraphicsInfos.NodeGraphicsInfo    = new NodeGraphicsInfo[1];
                lanes.Lane[i].NodeGraphicsInfos.NodeGraphicsInfo[0] = CreateNodeGraphicsInfo(laneElement, i);
            }
            return(lanes);
        }
コード例 #24
0
    private void DestroyElement(PoolElement element)
    {
        if (element.IsActive)
        {
            Debug.Log("Something went wrong because an active pool element should not be destroyed from the pool. Think again about destroying pool element as well.");
            return;
        }

        if (poolElementSet.Contains(element))
        {
            poolElementList.Remove(element);

            poolElementSet.Remove(element);

            availableElements.Remove(element);

            Destroy(element.gameObject);
        }
    }
コード例 #25
0
    private void SpawnElement()
    {
        GameObject newClone = Instantiate(clonedPrefab, transform);

        PoolElement element = newClone.GetComponent <PoolElement>();

        if (element == null)
        {
            element = newClone.AddComponent <PoolElement>();
        }

        totalSpawnedCount += 1;

        element.Initialize(totalSpawnedCount, this);

        poolElementList.Add(element);

        poolElementSet.Add(element);

        availableElements.Add(element);
    }
コード例 #26
0
    public GameObject InstantiateElement(Vector3 position, Quaternion rotation)
    {
        perUpdateUsageCount += 1;

        if (availableElements.Count == 0)
        {
            ExtendPool(1);
        }

        PoolElement selectedElement = availableElements[0];

        availableElements.Remove(selectedElement);

        selectedElement.OnSelectedForInstantiate(position, rotation);

        //Select an appropriate pooled object from the list.

        //When get activated fire off OnInstantiate event on element's PoolElement script.

        return(selectedElement.gameObject);
    }
コード例 #27
0
    /////////////////////////////////////////////
    public PoolElement Create()
    {
        if (mAvailableObjects.Count == 0)
        {
            Debug.LogWarning("ObjectPool: no available objects.");
            return(null);
        }
        PoolElement element = mAvailableObjects.Dequeue();

        mActiveObjects.Add(element);
        element.Reset();
        Debug.Log("ObjectPool: resuming object " + element.gameObject);
#if DEBUG
        if (mMinimumAvailableElements > mAvailableObjects.Count)
        {
            mMinimumAvailableElements = mAvailableObjects.Count;
            Debug.Log("ObjectPool: Minimum available elements reached: " + mMinimumAvailableElements);
        }
#endif
        return(element);
    }
コード例 #28
0
ファイル: ModelHelper.cs プロジェクト: jablko359/BpmnEditor
 public static void AddModelConnection(ElementsConnectionViewModel connection)
 {
     try
     {
         PoolElementViewModel startElementViewModel = connection.From as PoolElementViewModel;
         PoolViewModel        poolElementViewModel  = startElementViewModel.Pool;
         PoolElement          pool = null;
         if (poolElementViewModel != null)
         {
             pool = startElementViewModel.Pool.BaseElement as PoolElement;
         }
         else
         {
             pool = startElementViewModel.Document.Document.MainPoolElement;
         }
         pool.Connections.Add(connection.Model);
     }
     catch (NullReferenceException exception)
     {
         throw new ArgumentException("Error while creating connection. Model not found", exception);
     }
 }
コード例 #29
0
        /////////////////////////////////////////////
        void SpawnPowerup(Vector3 position)
        {
            PoolElement powerup = m_powerups.Create();

            powerup.transform.position = position;
        }
コード例 #30
0
 protected override VisualElement CreateElement()
 {
     _poolElement = new PoolElement();
     Name         = "Pool";
     return(_poolElement);
 }