您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

75 行
2.6 KiB

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<GameObject>("CurrentDoor");
var preMaskVal = flow.variables.Get<int>("PreMaskVal");
// Get the material from the current door game object
if (currentDoor != null)
{
var renderer = currentDoor.GetComponent<Renderer>();
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<Renderer>();
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);
}
}