다이얼로그 작업중
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2145001d8b7b79d4d90138544650514d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using Unity.GraphToolkit.Editor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.GraphToolkit.Samples.TextureMaker.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the result node in a Texture Maker Graph.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The result node serves as the end node in the texture graph, where the final texture is evaluated.
|
||||
/// </remarks>
|
||||
[Serializable]
|
||||
[UsedImplicitly]
|
||||
internal class CreateTextureNode : Node
|
||||
{
|
||||
/// Using constants for port ids provides type safety and ensures consistent references across the implementation
|
||||
internal const string TextureInputName = "InTexture";
|
||||
/// <summary>
|
||||
/// The width of the output texture.
|
||||
/// </summary>
|
||||
public const int OutputWidth = 16;
|
||||
|
||||
/// <summary>
|
||||
/// The height of the output texture.
|
||||
/// </summary>
|
||||
public const int OutputHeight = 16;
|
||||
|
||||
/// <summary>
|
||||
/// Defines the input for the node.
|
||||
/// </summary>
|
||||
protected override void OnDefinePorts(IPortDefinitionContext context)
|
||||
{
|
||||
context.AddInputPort<Texture2D>(TextureInputName).Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5bbd857d07214e2b97256039bbd713f7
|
||||
timeCreated: 1740675943
|
||||
@@ -0,0 +1,22 @@
|
||||
using Unity.GraphToolkit.Editor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.GraphToolkit.Samples.TextureMaker.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines an interface for evaluating Texture ports.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This interface is defined by nodes with the ability to output a Texture2D.
|
||||
/// Implementations of this interface should provide the logic to evaluate a given port model and return the resulting Texture.
|
||||
/// </remarks>
|
||||
internal interface ITextureEvaluatorNode
|
||||
{
|
||||
/// <summary>
|
||||
/// Evaluates the specified port and returns the resulting Texture.
|
||||
/// </summary>
|
||||
/// <param name="port">The port to evaluate.</param>
|
||||
/// <returns>The result of the evaluation.</returns>
|
||||
public Texture2D EvaluateTexturePort(IPort port);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 184980cc4753403d96db0011e12a78b2
|
||||
timeCreated: 1742204057
|
||||
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using Unity.GraphToolkit.Editor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.GraphToolkit.Samples.TextureMaker.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a node that combines two input textures and produces an output texture where pixel values are the mean
|
||||
/// of the two input values at the same position.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[UsedImplicitly]
|
||||
internal class MeanColorNode : Node, ITextureEvaluatorNode
|
||||
{
|
||||
/// Using constants for port ids provides type safety and ensures consistent references across the implementation
|
||||
internal const string Texture1InputName = "InTexture1";
|
||||
internal const string Texture2InputName = "InTexture2";
|
||||
internal const string TextureOutputName = "OutTexture";
|
||||
|
||||
/// <summary>
|
||||
/// Defines the input and output port for the Mean node.
|
||||
/// This node takes two textures as input and outputs a Texture2D.
|
||||
/// </summary>
|
||||
protected override void OnDefinePorts(IPortDefinitionContext context)
|
||||
{
|
||||
context.AddInputPort<Texture2D>(Texture1InputName).Build();
|
||||
context.AddInputPort<Texture2D>(Texture2InputName).Build();
|
||||
context.AddOutputPort<Texture2D>(TextureOutputName).Build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Evaluates the specified port and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="port">The port model to evaluate.</param>
|
||||
/// <returns>The result of the evaluation.</returns>
|
||||
public Texture2D EvaluateTexturePort(IPort port)
|
||||
{
|
||||
// Only the output port can be evaluated for this node.
|
||||
if (port != GetOutputPortByName(TextureOutputName))
|
||||
return null;
|
||||
|
||||
// Get the textures from the ports or the embedded value
|
||||
Texture2D firstTexture = TextureMakerGraph.ResolvePortValue<Texture2D>(GetInputPortByName(Texture1InputName));
|
||||
Texture2D secondTexture = TextureMakerGraph.ResolvePortValue<Texture2D>(GetInputPortByName(Texture2InputName));
|
||||
|
||||
if (firstTexture != null && secondTexture != null)
|
||||
{
|
||||
// Using min dimensions to prevent out-of-bounds access; simplified for learning (production code would handle varying texture sizes)
|
||||
int width = Math.Min(firstTexture.width, secondTexture.width);
|
||||
int height = Math.Min(firstTexture.height, secondTexture.height);
|
||||
|
||||
Texture2D resultTexture = new Texture2D(width, height);
|
||||
|
||||
for (var j = 0; j < height; j++)
|
||||
{
|
||||
for (var i = 0; i < width; i++)
|
||||
{
|
||||
// Set the color of each pixel in the texture
|
||||
Color firstColor = firstTexture.GetPixel(i, j);
|
||||
Color secondColor = secondTexture.GetPixel(i, j);
|
||||
Color color = (firstColor + secondColor) / 2;
|
||||
resultTexture.SetPixel(i, j, color);
|
||||
}
|
||||
}
|
||||
return resultTexture;
|
||||
}
|
||||
|
||||
// If one of the input ports have no resolved value, return a default texture
|
||||
return new Texture2D(CreateTextureNode.OutputWidth, CreateTextureNode.OutputHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2866fff3cefe46638f8fe6860cb86b5e
|
||||
timeCreated: 1742380071
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using Unity.GraphToolkit.Editor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.GraphToolkit.Samples.TextureMaker.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a node that generates a uniform texture from a specified color.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[UsedImplicitly]
|
||||
internal class UniformNode : Node, ITextureEvaluatorNode
|
||||
{
|
||||
/// Using constants for port ids provides type safety and ensures consistent references across the implementation
|
||||
internal const string ColorInputName = "InColor";
|
||||
internal const string TextureOutputName = "OutTexture";
|
||||
/// <summary>
|
||||
/// Defines the input and output port for the Uniform node.
|
||||
/// This nodes takes a color as input and outputs a Texture2D.
|
||||
/// </summary>
|
||||
protected override void OnDefinePorts(IPortDefinitionContext context)
|
||||
{
|
||||
context.AddInputPort<Color>(ColorInputName).Build();
|
||||
context.AddOutputPort<Texture2D>(TextureOutputName).Build();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Evaluates the specified port and returns the result.
|
||||
/// </summary>
|
||||
/// <param name="port">The port model to evaluate.</param>
|
||||
/// <returns>The result of the evaluation.</returns>
|
||||
public Texture2D EvaluateTexturePort(IPort port)
|
||||
{
|
||||
// Only the Texture output port can be evaluated for this node.
|
||||
if (port != GetOutputPortByName(TextureOutputName))
|
||||
return null;
|
||||
|
||||
// Gets the color port.
|
||||
var colorPort = GetInputPortByName(ColorInputName);
|
||||
|
||||
// Get the color from the connected port or the embedded value
|
||||
var color = TextureMakerGraph.ResolvePortValue<Color>(colorPort);
|
||||
|
||||
var texture = new Texture2D(CreateTextureNode.OutputWidth, CreateTextureNode.OutputHeight);
|
||||
// Set the color of each pixel in the texture
|
||||
for (var j = 0; j < CreateTextureNode.OutputHeight; j++)
|
||||
{
|
||||
for (var i = 0; i < CreateTextureNode.OutputWidth; i++)
|
||||
{
|
||||
texture.SetPixel(i, j, color);
|
||||
}
|
||||
}
|
||||
return texture;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b8ad780581240939565c81dd3d40ce5
|
||||
timeCreated: 1740675943
|
||||
Reference in New Issue
Block a user