Пример #1
0
        PoolDataController _Spawn(string type, string name, Transform toParent, Vector3?position, Quaternion?rot, GenericParams parms)
        {
            PoolDataController entityRet = null;

            FactoryData dat = null;

            if (string.IsNullOrEmpty(type))
            {
                //this should only be used if there's just one type
                if (factory != null && factory.Length > 0)
                {
                    dat = mFactory[factory[0].template.name];
                }
                else if (mFactory.Count > 0)
                {
                    foreach (var pair in mFactory)
                    {
                        dat = pair.Value;
                        break;
                    }
                }
            }
            else
            {
                mFactory.TryGetValue(type, out dat);
            }

            if (dat != null)
            {
                var pdc = dat.Allocate(group, name, toParent == null ? dat.defaultParent == null ? transform : null : toParent);

                if (pdc != null)
                {
                    entityRet = pdc;

                    var t = entityRet.transform;

                    if (position.HasValue)
                    {
                        t.position = position.Value;
                    }
                    if (rot.HasValue)
                    {
                        t.rotation = rot.Value;
                    }

                    pdc.Spawn(parms);

                    if (spawnCallback != null)
                    {
                        spawnCallback(pdc);
                    }
                }
                else
                {
                    Debug.LogWarning("Failed to allocate type: " + type + " for: " + name);
                }
            }
            else
            {
                Debug.LogWarning("No such type: " + type + " attempt to allocate: " + name);
            }

            return(entityRet);
        }