Example #1
0
    void Start()
    {
        cookieMask    = new RenderTexture(TextureResolution, TextureResolution, 0);
        cookieBlurred = new RenderTexture(TextureResolution, TextureResolution, 0);
        cookieMask_i  = new RenderTexture(TextureResolution, TextureResolution, 0);
        //PastTexCount = CookieBlur.GetInt("_PastTexCount");
        pastMasks = new RenderTexture[PastTexCount];
        for (int i = 0; i < PastTexCount; i++)
        {
            pastMasks[i] = new RenderTexture(TextureResolution / 2, TextureResolution / 2, 0);
            CookieBlur.SetTexture("_PastTex" + i.ToString(), pastMasks[i]);
        }
        if (SRP)
        {
            decal = GetComponent <DecalProjectorComponent>();
            decal.m_Material.SetTexture("_BaseColorMap", cookieBlurred);
            projectorSize = decal.m_Size.x;
        }
        else
        {
            projector = GetComponent <Projector>();
            projector.material.SetTexture("_ShadowTex", cookieBlurred);
            projectorSize = projector.orthographicSize * 2;
        }
        CookieCreator.SetTexture("_RecurringCookie", cookieMask_i);
        CookieCreator.SetInt("_KeepUnfoged", (KeepUnfoged) ? (1) : (0));

        data    = new float[CastResolution * 2 + 3];
        data[0] = CastResolution;
        d_angle = 360 * Mathf.Deg2Rad / CastResolution;
    }
Example #2
0
 public void Start()
 {
     spellIndicator = Instantiate(spellIndicatorRef);
     spellIndicator.m_Material.enableInstancing = true;
     spellIndicator.transform.position          = transform.position;
     spellIndicator.m_Size = new Vector3(radius, radius, 1);
     charge = 0f;
 }
Example #3
0
 private void OnEnable()
 {
     // Create an instance of the MaterialEditor
     m_DecalProjectorComponent = (DecalProjectorComponent)target;
     m_MaterialEditor          = (MaterialEditor)CreateEditor(m_DecalProjectorComponent.Mat);
     m_DecalProjectorComponent.OnMaterialChange += OnMaterialChange;
     m_MaterialProperty     = serializedObject.FindProperty("m_Material");
     m_DrawDistanceProperty = serializedObject.FindProperty("m_DrawDistance");
     m_FadeScaleProperty    = serializedObject.FindProperty("m_FadeScale");
 }
Example #4
0
 private void OnEnable()
 {
     // Create an instance of the MaterialEditor
     m_DecalProjectorComponent = (DecalProjectorComponent)target;
     m_MaterialEditor          = (MaterialEditor)CreateEditor(m_DecalProjectorComponent.Mat);
     m_DecalProjectorComponent.OnMaterialChange += OnMaterialChange;
     m_MaterialProperty            = serializedObject.FindProperty("m_Material");
     m_DrawDistanceProperty        = serializedObject.FindProperty("m_DrawDistance");
     m_FadeScaleProperty           = serializedObject.FindProperty("m_FadeScale");
     m_UVScaleProperty             = serializedObject.FindProperty("m_UVScale");
     m_UVBiasProperty              = serializedObject.FindProperty("m_UVBias");
     m_AffectsTransparencyProperty = serializedObject.FindProperty("m_AffectsTransparency");
     m_Center = serializedObject.FindProperty("m_Offset");
     m_Size   = serializedObject.FindProperty("m_Size");
 }
Example #5
0
    // Start is called before the first frame update
    void Start()
    {
        Map           = WorldController.GetWorldController.GetComponent <TileMap3D>();
        Decal         = FOW.GetComponentInChildren <DecalProjectorComponent>();
        Directions    = new Vector2Int[8];
        Directions[0] = new Vector2Int(0, 1);
        Directions[1] = new Vector2Int(1, 0);
        Directions[2] = new Vector2Int(0, -1);
        Directions[3] = new Vector2Int(-1, 0);

        Directions[4] = new Vector2Int(1, 1);
        Directions[5] = new Vector2Int(1, -1);
        Directions[6] = new Vector2Int(-1, 1);
        Directions[7] = new Vector2Int(-1, -1);
    }
Example #6
0
    private void Awake()
    {
        projector         = GetComponent <DecalProjectorComponent>();
        projector.enabled = true;

        prevTexture = GenerateTexture();
        currTexture = GenerateTexture();

        // Projector materials aren't instanced, resulting in the material asset getting changed.
        // Instance it here to prevent us from having to check in or discard these changes manually.
        projector.m_Material = new Material(projectorMaterial);

        projector.m_Material.SetTexture("_PrevTexture", prevTexture);
        projector.m_Material.SetTexture("_CurrTexture", currTexture);

        StartNewBlend();
    }
Example #7
0
 private void Update()
 {
     if (spellIndicator != null)
     {
         charge += Time.deltaTime;
         if (charge >= timer)
         {
             Destroy(spellIndicator);
             spellIndicator = null;
             Effect();
         }
         else
         {
             spellIndicator.m_Material.SetFloat("_ChargingPercent", Mathf.Clamp01(charge / timer));
         }
     }
 }
 private void OnEnable()
 {
     // Create an instance of the MaterialEditor
     m_DecalProjectorComponent = (DecalProjectorComponent)target;
     m_LayerMask      = m_DecalProjectorComponent.gameObject.layer;
     m_MaterialEditor = (MaterialEditor)CreateEditor(m_DecalProjectorComponent.Mat);
     m_DecalProjectorComponent.OnMaterialChange += OnMaterialChange;
     m_MaterialProperty            = serializedObject.FindProperty("m_Material");
     m_DrawDistanceProperty        = serializedObject.FindProperty("m_DrawDistance");
     m_FadeScaleProperty           = serializedObject.FindProperty("m_FadeScale");
     m_UVScaleProperty             = serializedObject.FindProperty("m_UVScale");
     m_UVBiasProperty              = serializedObject.FindProperty("m_UVBias");
     m_AffectsTransparencyProperty = serializedObject.FindProperty("m_AffectsTransparency");
     m_Size = serializedObject.FindProperty("m_Size");
     m_IsCropModeEnabledProperty = serializedObject.FindProperty("m_IsCropModeEnabled");
     m_FadeFactor = serializedObject.FindProperty("m_FadeFactor");
 }
        public void HandleDragEnd(MapInteractionManager.DraggingEventArgs e)
        {
            for (int i = 0; i < zones.Count; i++)
            {
                for (int y = 0; y < zones[i].TilesInZone.Count; y++)
                {
                    if (zones[i].TilesInZone[y] == e.StartTile)
                    {
                        zones[i].TilesInZone.AddRange(e.TileSelectionData.Tiles);
                        zones[i].verts.AddRange(e.TileSelectionData.Vertices);

                        Rect rect = new Rect((int)e.StartTile.TilePosition.x, (int)e.StartTile.TilePosition.y,
                                             (int)(e.StartTile.TilePosition.x - MapInteractionManager.Instance.GetCurrentTile().TilePosition.x),
                                             (int)(e.StartTile.TilePosition.y -
                                                   MapInteractionManager.Instance.GetCurrentTile().TilePosition.y));

                        DecalProjectorComponent tempProjector = new DecalProjectorComponent();

                        zoneObject.GetComponent <DecalProjectorComponent>().m_Size = new Vector3(rect.width, 200, rect.height);
                        Instantiate(zoneObject, new Vector3(rect.x, 200, rect.y), Quaternion.identity);


                        Debug.Log($"Extended existing zone {zones[i].AssetId}");
                        return;
                    }
                }
            }

            Debug.Log(e.EndTile);
            Rect rect1 = new Rect(
                (int)e.EndTile.TilePosition.y,
                (int)e.EndTile.TilePosition.y,
                (int)(Math.Abs(e.StartTile.TilePosition.x - e.EndTile.TilePosition.x)),
                (int)(Math.Abs(e.StartTile.TilePosition.y - e.EndTile.TilePosition.y)));

            zoneObject.GetComponent <DecalProjectorComponent>().m_Size = new Vector3(rect1.width, 200, rect1.height);
            Instantiate(zoneObject, new Vector3(rect1.x, 50, rect1.y), Quaternion.identity);

            var tempZone = new TestZone(e.TileSelectionData.Tiles);

            tempZone.verts = e.TileSelectionData.Vertices;
            isDraggingZone = false;

            CalculateMesh();
        }
        static void DrawGizmosSelected(DecalProjectorComponent decalProjector, GizmoType gizmoType)
        {
            //draw them scale independent
            using (new Handles.DrawingScope(Color.white, Matrix4x4.TRS(decalProjector.transform.position, decalProjector.transform.rotation, Vector3.one)))
            {
                handle.center = decalProjector.offset;
                handle.size   = decalProjector.size;
                handle.DrawHull(editMode == k_EditShapePreservingUV || editMode == k_EditShapeWithoutPreservingUV);

                int        controlID      = GUIUtility.GetControlID(handle.GetHashCode(), FocusType.Passive);
                Quaternion arrowRotation  = Quaternion.LookRotation(Vector3.down, Vector3.right);
                float      arrowSize      = decalProjector.size.z * 0.25f;
                Vector3    pivot          = decalProjector.offset;
                Vector3    projectedPivot = pivot + decalProjector.size.z * 0.5f * Vector3.back;
                Handles.ArrowHandleCap(controlID, projectedPivot, Quaternion.identity, arrowSize, EventType.Repaint);

                //[TODO: add editable pivot. Uncomment this when ready]
                //draw pivot
                //Handles.SphereHandleCap(controlID, pivot, Quaternion.identity, 0.02f, EventType.Repaint);
                //Color c = Color.white;
                //c.a = 0.2f;
                //Handles.color = c;
                //Handles.DrawLine(projectedPivot, projectedPivot + decalProjector.m_Size.x * 0.5f * Vector3.right);
                //Handles.DrawLine(projectedPivot, projectedPivot + decalProjector.m_Size.y * 0.5f * Vector3.up);
                //Handles.DrawLine(projectedPivot, projectedPivot + decalProjector.m_Size.z * 0.5f * Vector3.forward);

                //draw UV
                Color face = Color.green;
                face.a = 0.1f;
                Vector2 size = new Vector2(
                    (decalProjector.uvScale.x > 100000 || decalProjector.uvScale.x < -100000 ? 0f : 1f / decalProjector.uvScale.x) * decalProjector.size.x,
                    (decalProjector.uvScale.x > 100000 || decalProjector.uvScale.x < -100000 ? 0f : 1f / decalProjector.uvScale.y) * decalProjector.size.y
                    );
                Vector2 start = (Vector2)projectedPivot - new Vector2(decalProjector.uvBias.x * size.x, decalProjector.uvBias.y * size.y);
                using (new Handles.DrawingScope(face, Matrix4x4.TRS(decalProjector.transform.position - decalProjector.transform.rotation * (decalProjector.size * 0.5f + decalProjector.offset.z * Vector3.back), decalProjector.transform.rotation, Vector3.one)))
                {
                    Handles.DrawSolidRectangleWithOutline(new Rect(start, size), face, Color.white);
                }
            }
        }
 private void OnEnable()
 {
     // Create an instance of the MaterialEditor
     m_DecalProjectorComponent = (DecalProjectorComponent)target;
     m_MaterialEditor          = (MaterialEditor)CreateEditor(m_DecalProjectorComponent.Mat);
 }
        void DrawHandles()
        {
            //Note: each target need to be handled individually to allow multi edition
            DecalProjectorComponent decalProjector = target as DecalProjectorComponent;

            if (editMode == k_EditShapePreservingUV || editMode == k_EditShapeWithoutPreservingUV)
            {
                using (new Handles.DrawingScope(Color.white, Matrix4x4.TRS(decalProjector.transform.position, decalProjector.transform.rotation, Vector3.one)))
                {
                    bool needToRefreshDecalProjector = false;

                    handle.center = decalProjector.offset;
                    handle.size   = decalProjector.size;

                    Vector3 boundsSizePreviousOS = handle.size;
                    Vector3 boundsMinPreviousOS  = handle.size * -0.5f + handle.center;

                    EditorGUI.BeginChangeCheck();
                    handle.DrawHandle();
                    if (EditorGUI.EndChangeCheck())
                    {
                        needToRefreshDecalProjector = true;

                        // Adjust decal transform if handle changed.
                        Undo.RecordObject(decalProjector, "Decal Projector Change");

                        decalProjector.size   = handle.size;
                        decalProjector.offset = handle.center;

                        Vector3 boundsSizeCurrentOS = handle.size;
                        Vector3 boundsMinCurrentOS  = handle.size * -0.5f + handle.center;

                        if (editMode == k_EditShapePreservingUV)
                        {
                            // Treat decal projector bounds as a crop tool, rather than a scale tool.
                            // Compute a new uv scale and bias terms to pin decal projection pixels in world space, irrespective of projector bounds.
                            Vector2 uvScale = decalProjector.uvScale;
                            uvScale.x *= Mathf.Max(1e-5f, boundsSizeCurrentOS.x) / Mathf.Max(1e-5f, boundsSizePreviousOS.x);
                            uvScale.y *= Mathf.Max(1e-5f, boundsSizeCurrentOS.y) / Mathf.Max(1e-5f, boundsSizePreviousOS.y);
                            decalProjector.uvScale = uvScale;

                            Vector2 uvBias = decalProjector.uvBias;
                            uvBias.x += (boundsMinCurrentOS.x - boundsMinPreviousOS.x) / Mathf.Max(1e-5f, boundsSizeCurrentOS.x) * decalProjector.uvScale.x;
                            uvBias.y += (boundsMinCurrentOS.y - boundsMinPreviousOS.y) / Mathf.Max(1e-5f, boundsSizeCurrentOS.y) * decalProjector.uvScale.y;
                            decalProjector.uvBias = uvBias;
                        }

                        if (PrefabUtility.IsPartOfNonAssetPrefabInstance(decalProjector))
                        {
                            PrefabUtility.RecordPrefabInstancePropertyModifications(decalProjector);
                        }
                    }

                    // [TODO: remove this part. As soon as you select component that are old enough to have Offset not reseted, it will change the position
                    // It is also incompatible with pivot management]
                    // Automatically recenter our transform component if necessary.
                    // In order to correctly handle world-space snapping, we only perform this recentering when the user is no longer interacting with the gizmo.
                    if ((GUIUtility.hotControl == 0) && (decalProjector.offset != Vector3.zero))
                    {
                        needToRefreshDecalProjector = true;

                        // Both the DecalProjectorComponent, and the transform will be modified.
                        // The undo system will automatically group all RecordObject() calls here into a single action.
                        Undo.RecordObject(decalProjector, "Decal Projector Change");

                        // Re-center the transform to the center of the decal projector bounds,
                        // while maintaining the world-space coordinates of the decal projector boundings vertices.
                        decalProjector.transform.Translate(decalProjector.offset, Space.Self);

                        decalProjector.offset = Vector3.zero;
                        if (PrefabUtility.IsPartOfNonAssetPrefabInstance(decalProjector))
                        {
                            PrefabUtility.RecordPrefabInstancePropertyModifications(decalProjector);
                        }
                    }

                    if (needToRefreshDecalProjector)
                    {
                        // Smoothly update the decal image projected
                        Matrix4x4 sizeOffset = Matrix4x4.Translate(decalProjector.decalOffset) * Matrix4x4.Scale(decalProjector.decalSize);
                        DecalSystem.instance.UpdateCachedData(decalProjector.position, decalProjector.rotation, sizeOffset, decalProjector.drawDistance, decalProjector.fadeScale, decalProjector.uvScaleBias, decalProjector.affectsTransparency, decalProjector.Handle, decalProjector.gameObject.layer, decalProjector.fadeFactor);
                    }
                }
            }

            //[TODO: add editable pivot. Uncomment this when ready]
            //else if (editMode == k_EditUV)
            //{
            //    //here should be handles code to manipulate the pivot without changing the UV
            //}
        }