Exemplo n.º 1
0
        //Constructor
        public PoolItem(ProjectionPool Pool)
        {
            //Set Pool
            pool = Pool;

            //Generate GameObject
            GameObject go = new GameObject("Projection");

            go.transform.SetParent(pool.Parent);

            //Disable
            go.SetActive(false);

            //Attach Renderer
            renderer          = go.AddComponent <ProjectionRenderer>();
            renderer.PoolItem = this;
        }
Exemplo n.º 2
0
        internal ProjectionPool PoolFromInstance(PoolInstance Instance)
        {
            //Make sure we are initialized
            if (Pools == null)
            {
                Pools = new Dictionary <int, ProjectionPool>();
            }

            ProjectionPool pool;

            if (!Pools.TryGetValue(Instance.id, out pool))
            {
                pool = new ProjectionPool(Instance);
                Pools.Add(Instance.id, pool);
            }
            return(pool);
        }
Exemplo n.º 3
0
        /**
         * The simplest method of printing available. Use this when you know exactly where you want to print.
         * Printing is still subject to frequency & interection checks, and any fading or culling specified will still be applied.
         * @param Position The position to print the projection at, in world space.
         * @param Rotation The orientation of the printed projection, in world space.
         * @param Surface The transform the projection will be childed to. Will be ignored unless printer has Print Parent set to surface (Not default).
         */
        public void Print(Vector3 Position, Quaternion Rotation, Transform Surface, int Layer = 0)
        {
            //Projection Check
            if (prints == null || prints.Length < 1)
            {
                Debug.LogError("No Projections to print. Please set at least one projection to print.");
                return;
            }

            //Frequency Check
            if (timeSincePrint >= frequencyTime && Vector3.Distance(Position, lastPrintPos) >= frequencyDistance)
            {
                //Intersection Check
                if (overlaps.Length > 0)
                {
                    for (int i = 0; i < overlaps.Length; i++)
                    {
                        //Get the pool being refered to
                        ProjectionPool pool = DynamicDecals.System.GetPool(overlaps[i].poolId);

                        //Validity & Intersection Check
                        if (pool.ID == overlaps[i].poolId && pool.CheckIntersecting(Position, overlaps[i].intersectionStrength))
                        {
                            //Destroy on print
                            if (destroyOnPrint)
                            {
                                Destroy(gameObject);
                            }
                            return;
                        }
                    }
                }

                //Print using print method
                switch (printMethod)
                {
                case PrintSelection.Layer:
                    if (printLayers == null || printLayers.Length == 0)
                    {
                        PrintProjection(prints[0], Position, Rotation, Surface);
                    }
                    else
                    {
                        //If the layer mask contains the hit layer, print the decal associated with it.
                        for (int i = 0; i < printLayers.Length; i++)
                        {
                            if (printLayers[i] == (printLayers[i] | (1 << Layer)))
                            {
                                PrintProjection(prints[i], Position, Rotation, Surface);
                            }
                        }
                    }
                    break;

                case PrintSelection.Tag:
                    if (printLayers == null || printLayers.Length == 0)
                    {
                        PrintProjection(prints[0], Position, Rotation, Surface);
                    }
                    else
                    {
                        bool printed = false;
                        //If the surface is of the tag, print the decal associated with it.
                        for (int i = 1; i < printTags.Length; i++)
                        {
                            if (printTags[i] == Surface.tag)
                            {
                                PrintProjection(prints[i], Position, Rotation, Surface);
                                printed = true;
                            }
                        }

                        //If the surface has no relevant tag, print the default print.
                        if (!printed)
                        {
                            PrintProjection(prints[0], Position, Rotation, Surface);
                        }
                    }
                    break;

                case PrintSelection.Random:
                    //Generate an int between one and the prints length
                    int index = Random.Range(0, prints.Length);
                    //Print the projection at that index
                    PrintProjection(prints[index], Position, Rotation, Surface);
                    break;

                case PrintSelection.All:
                    //Print each projection once
                    foreach (ProjectionRenderer projection in prints)
                    {
                        PrintProjection(projection, Position, Rotation, Surface);
                    }
                    break;
                }

                //Destroy on print
                if (destroyOnPrint)
                {
                    Destroy(gameObject);
                }

                //Cache frequency data
                timeSincePrint = 0;
                lastPrintPos   = Position;
            }
        }