1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 09:16:01 +08:00

Update NodePort.cs

Fixed always returns default value for casted types.
This commit is contained in:
Raistlin Wolfe 2022-09-17 00:20:50 -06:00 committed by GitHub
parent cfbbbc8432
commit 07c334aed0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using UnityEngine; using UnityEngine;
@ -147,9 +147,18 @@ namespace XNode {
/// <summary> Return the output value of the first connected port. Returns null if none found or invalid. </summary> /// <summary> Return the output value of the first connected port. Returns null if none found or invalid. </summary>
/// <returns> <see cref="NodePort.GetOutputValue"/> </returns> /// <returns> <see cref="NodePort.GetOutputValue"/> </returns>
public T GetInputValue<T>() { public T GetInputValue<T> ()
object obj = GetInputValue(); {
return obj is T ? (T) obj : default(T); object obj = GetInputValue ();
if ( obj.GetType () == typeof ( T ) )
return (T) obj;
if ( typeof ( T ).IsCastableFrom ( obj.GetType () ) && obj.TryCast<T> ( out object t ) )
return (T) t;
return default;
} }
/// <summary> Return the output values of all connected ports. </summary> /// <summary> Return the output values of all connected ports. </summary>