using System; using Unity.VisualScripting; using UnityEngine; [UnitCategory("Custom")] public class UpdateDoorStencilNode : Unit { [DoNotSerialize] public ControlInput enter { get; private set; } [DoNotSerialize] public ControlOutput exit { get; private set; } protected override void Definition() { enter = ControlInput("enter", (flow) => { // Check if the variable exists in the flow variables if (flow.variables.IsDefined("CurrentDoor") && flow.variables.IsDefined("PreMaskVal")) { // Get the current game object var gameObject = flow.stack.gameObject; // Get the Current Door and PreMaskVal variables from the flow variables var currentDoor = flow.variables.Get("CurrentDoor"); var preMaskVal = flow.variables.Get("PreMaskVal"); // Get the material from the current door game object if (currentDoor != null) { var renderer = currentDoor.GetComponent(); if (renderer != null) { var material = renderer.material; if (material != null) { // Update the stencil mask to PreMaskVal material.SetInt("_StencilMask", preMaskVal); } } } // Update the Current Door and PreMaskVal variables flow.variables.Set("CurrentDoor", gameObject); // Get the new material and store its current Stencil Mask value to PreMaskVal var newRenderer = gameObject.GetComponent(); if (newRenderer != null) { var newMaterial = newRenderer.material; if (newMaterial != null) { flow.variables.Set("PreMaskVal", newMaterial.GetInt("_StencilMask")); // Set the current game object's stencil mask to 0 newMaterial.SetInt("_StencilMask", 0); } } } else { Debug.LogWarning("CurrentDoor and/or PreMaskVal variables are not set in the Visual Scripting flow."); } return exit; // Continue execution }); exit = ControlOutput("exit"); Succession(enter, exit); } }