Ejemplo n.º 1
0
        public Instance GetPermutation(int[] permutations)
        {
            if (instances == null)
            {
                instances = new InstanceCollection();
            }
            else
            {
                instances.Clear();
            }

            for (int i = 0; i < gbxmodelValues.Regions.Count; i++)
            {
                switch (lod)
                {
                case LevelOfDetail.SuperLow:
                    for (int j = 0; j < superLow[i][permutations[i]].Count; j++)
                    {
                        instances.Add(superLow[i][permutations[i]][j]);
                    }
                    break;

                case LevelOfDetail.Low:
                    for (int j = 0; j < low[i][permutations[i]].Count; j++)
                    {
                        instances.Add(low[i][permutations[i]][j]);
                    }
                    break;

                case LevelOfDetail.Medium:
                    for (int j = 0; j < medium[i][permutations[i]].Count; j++)
                    {
                        instances.Add(medium[i][permutations[i]][j]);
                    }
                    break;

                case LevelOfDetail.High:
                    for (int j = 0; j < high[i][permutations[i]].Count; j++)
                    {
                        instances.Add(high[i][permutations[i]][j]);
                    }
                    break;

                case LevelOfDetail.SuperHigh:
                    for (int j = 0; j < superHigh[i][permutations[i]].Count; j++)
                    {
                        instances.Add(superHigh[i][permutations[i]][j]);
                    }
                    break;
                }
            }

            return(instances);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 预创建Instance
        /// </summary>
        /// <param name="collection"></param>
        /// <returns></returns>
        private IEnumerator PreCreateInstance(InstanceCollection collection)
        {
            if (collection == null)
            {
                yield break;
            }

            if (m_EditorLog)
            {
                Debug.LogFormat(
                    "{0} -> {1} -> Start pre-load instances. Count('{2}').",
                    poolName,
                    collection.prefabName,
                    collection.preCount
                    );
            }

            yield return(null);

            while (collection.Count < collection.preCount)
            {
                int count = Mathf.Min(collection.preCount - collection.Count, collection.preCountPerFrame);
                for (int i = 0; i < count; i++)
                {
                    GameObject     go       = GameObject.Instantiate(collection.prefab);
                    ReusableObject reusable = GetOrAddReusableObject(go);
                    reusable.Despawn(false);
                    collection.Add(go);
                }
                yield return(null);
            }
        }
Ejemplo n.º 3
0
 internal void AddToScope(IRegistration registration, object instance)
 {
     if (!_scopeInstances.Contains(registration.RegisteredType))
     {
         _scopeInstances.Add(registration.RegisteredType, instance);
     }
 }
Ejemplo n.º 4
0
        public InstanceCollection UpdateFrustumSelection(InstanceCollection InstanceList)
        {
            InstanceCollection selected_items = new InstanceCollection();
            WorldInstance      wi;

            Plane[] fplanes;
            MdxRender.Camera.GetFrustumPlanes(selectionBoxStartX, selectionBoxStartY,
                                              selectionBoxEndX, selectionBoxEndY, out fplanes);

            float test;

            //there seems to be a little bit of a plane calculation bug, objects within the bounding box are
            //not always selected perfectly
            bool bInsideFrustum = false;
            int  sel_count      = 0;

            for (int i = 0; i < InstanceList.Count; i++)
            {
                wi             = (WorldInstance)InstanceList[i];
                bInsideFrustum = true;
                for (int p = 0; p < fplanes.Length; p++)
                {
                    test = wi.ObjectTransform.X * fplanes[p].A +
                           wi.ObjectTransform.Y * fplanes[p].B +
                           wi.ObjectTransform.Z * fplanes[p].C +
                           fplanes[p].D;

                    if (test < 0) //test for behind plane (outside of frustum) (normals point to inside of frustum)
                    {
                        bInsideFrustum = false;
                        break;
                    }
                }

                wi.Selected = bInsideFrustum;
                if (bInsideFrustum)
                {
                    selected_items.Add(wi);
                    sel_count++;
                }
                else
                {
                }
            }
            //Trace.WriteLine("---------------------------------");
            //Trace.WriteLine(string.Format("selected:  {0}/{1}", sel_count, this.Count));
            //Trace.WriteLine(string.Format("near   Nx={0:N3}   Ny={1:N3}   Nz={2:N3}   D={3:N3}", fplanes[0].A, fplanes[0].B, fplanes[0].C, fplanes[0].D));
            //Trace.WriteLine(string.Format("far    Nx={0:N3}   Ny={1:N3}   Nz={2:N3}   D={3:N3}", fplanes[1].A, fplanes[1].B, fplanes[1].C, fplanes[1].D));
            //Trace.WriteLine(string.Format("right  Nx={0:N3}   Ny={1:N3}   Nz={2:N3}   D={3:N3}", fplanes[2].A, fplanes[2].B, fplanes[2].C, fplanes[2].D));
            //Trace.WriteLine(string.Format("left   Nx={0:N3}   Ny={1:N3}   Nz={2:N3}   D={3:N3}", fplanes[3].A, fplanes[3].B, fplanes[3].C, fplanes[3].D));
            //Trace.WriteLine(string.Format("top    Nx={0:N3}   Ny={1:N3}   Nz={2:N3}   D={3:N3}", fplanes[4].A, fplanes[4].B, fplanes[4].C, fplanes[4].D));
            //Trace.WriteLine(string.Format("Bottom Nx={0:N3}   Ny={1:N3}   Nz={2:N3}   D={3:N3}", fplanes[5].A, fplanes[5].B, fplanes[5].C, fplanes[5].D));
            return(selected_items);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 加入外部Instance,由RuntimePrePoolObject组件调用
        /// </summary>
        /// <param name="runtime"></param>
        /// <returns></returns>
        internal bool AddUnpooledObject(RuntimePrePoolObject runtime)
        {
            if (!m_PrefabDict.ContainsKey(runtime.m_PrefabName))
            {
                Debug.LogErrorFormat(
                    "{0} -> Add unpooled object '{1}' The prefab is not found.",
                    poolName,
                    runtime.gameObject.name
                    );
                return(false);
            }

            InstanceCollection collection = m_InstanceCollections.Find(c => c.prefabName == runtime.m_PrefabName);

            if (collection == null)
            {
                Debug.LogErrorFormat("{0} -> UNEXPECTED ERROR! May be the pool name was changed at runtime.", poolName);
                return(false);
            }

            collection.Add(runtime.gameObject);
            return(true);
        }