Пример #1
0
    /// <summary>
    /// Checks to see if the hit colldier has a valid tag override and return the SplatterDecal class related to that override. If not returns the first/blank element.
    /// </summary>
    /// <param name="hit">Raycast hit information.</param>
    /// <returns></returns>
    private SplatterDecals CheckSplatterOverrides(RaycastHit hit)
    {
        SplatterDecals defaultDecals = null;
        string         tag           = hit.collider.tag;

        for (int i = 0; i < splatterDecals.Length; i++)
        {
            if (splatterDecals[i].overrideTag == "")
            {
                defaultDecals = splatterDecals[i];
            }

            if (tag == splatterDecals[i].overrideTag)
            {
                return(splatterDecals[i]);
            }
        }

        if (splatterDecals.Length > 0)
        {
            defaultDecals = splatterDecals[0];
        }

        return(defaultDecals);
    }
Пример #2
0
    /// <summary>
    /// Get a projector from the pool and place it at the correct location and rotation. Activate the gameobject and adjust the size, material and parent transform.
    /// </summary>
    /// <param name="position">The position in the world where the projector will be placed.</param>
    /// <param name="rotation">The rotation in the world where the projector will be placed.</param>
    /// <param name="splatterParent">The parent transform to place the splatter projectors into.</param>
    /// <param name="hit">Details from the raycast hit.</param>
    private void DrawSplatterProjector(Vector3 position, Quaternion rotation, GameObject splatterParent, RaycastHit hit, SplatterDecals _splatterDecals)
    {
        for (int i = 0; i < _splatterDecals.numberOfDecals; i++)
        {
            GameObject projector = ObjectPooler.instance.GetPooledObject();
            if (projector != null)
            {
                projector.transform.position = position;
                projector.transform.rotation = Quaternion.FromToRotation(Vector3.forward, -hit.normal);
                projector.SetActive(true);

                SetParentObject(projector, splatterParent);

                projector.transform.localPosition = GenerateRandomSplatterSpread(_splatterDecals.horizontalSpread, _splatterDecals.verticalSpread);

                int      randIndex    = Random.Range(0, _splatterDecals.decals.Length);
                Material randMaterial = _splatterDecals.decals[randIndex];

                Projector _projector = projector.GetComponentInChildren <Projector>();
                _projector.material         = randMaterial;
                _projector.orthographicSize = _splatterDecals.decalSize;
                _projector.farClipPlane     = _splatterDecals.decalDepth;
            }
        }
    }