Fixes and improvements

This commit is contained in:
Wojciech Figat
2021-11-18 11:21:30 +01:00
parent 2a2b70f83f
commit cdcb2f8f7a
15 changed files with 46 additions and 48 deletions

View File

@@ -143,7 +143,7 @@ namespace FlaxEditor.CustomEditors
}
else
{
var type = new ScriptType(typeof(object));
var type = ScriptType.Object;
if (selection.HasDifferentTypes == false)
type = TypeUtils.GetObjectType(selection[0]);
Editor = CustomEditorsUtil.CreateEditor(type, false);

View File

@@ -47,7 +47,7 @@ namespace FlaxEditor.CustomEditors.Editors
{
if (_type == value)
return;
if (value == ScriptType.Null || (value.Type != typeof(Object) && !value.IsSubclassOf(new ScriptType(typeof(Object)))))
if (value == ScriptType.Null || (value.Type != typeof(Object) && !value.IsSubclassOf(ScriptType.Object)))
throw new ArgumentException(string.Format("Invalid type for FlaxObjectRefEditor. Input type: {0}", value != ScriptType.Null ? value.TypeName : "null"));
_type = value;
@@ -132,7 +132,7 @@ namespace FlaxEditor.CustomEditors.Editors
public FlaxObjectRefPickerControl()
: base(0, 0, 50, 16)
{
_type = new ScriptType(typeof(Object));
_type = ScriptType.Object;
}
private bool IsValid(Object obj)

View File

@@ -119,7 +119,7 @@ namespace FlaxEditor.CustomEditors.Editors
public TypePickerControl()
: base(0, 0, 50, 16)
{
_type = new ScriptType(typeof(object));
_type = ScriptType.Object;
}
private bool IsValid(ScriptType obj)
@@ -400,9 +400,9 @@ namespace FlaxEditor.CustomEditors.Editors
{
_element.CustomControl.ValueChanged += () => SetValue(_element.CustomControl.Value.Type);
if (_element.CustomControl.Type == new ScriptType(typeof(object)))
if (_element.CustomControl.Type == ScriptType.Object)
{
_element.CustomControl.Type = Values.Type.Type != typeof(object) || Values[0] == null ? new ScriptType(typeof(object)) : TypeUtils.GetObjectType(Values[0]);
_element.CustomControl.Type = Values.Type.Type != typeof(object) || Values[0] == null ? ScriptType.Object : TypeUtils.GetObjectType(Values[0]);
}
}
}

View File

@@ -17,7 +17,7 @@ namespace FlaxEditor.CustomEditors
/// </summary>
/// <param name="value">The initial value.</param>
public ReadOnlyValueContainer(object value)
: base(ScriptMemberInfo.Null, new ScriptType(typeof(object)))
: base(ScriptMemberInfo.Null, ScriptType.Object)
{
Add(value);
}

View File

@@ -8,7 +8,6 @@ using FlaxEditor.Options;
using FlaxEditor.Scripting;
using FlaxEngine;
using FlaxEngine.GUI;
using Object = System.Object;
namespace FlaxEditor.Modules.SourceCodeEditing
{
@@ -21,7 +20,7 @@ namespace FlaxEditor.Modules.SourceCodeEditing
private sealed class CachedVisualScriptPropertyTypesCollection : CachedTypesCollection
{
public CachedVisualScriptPropertyTypesCollection(int capacity, Func<Assembly, bool> checkAssembly)
: base(capacity, new ScriptType(typeof(Object)), CheckFunc, checkAssembly)
: base(capacity, ScriptType.Object, CheckFunc, checkAssembly)
{
}

View File

@@ -698,6 +698,11 @@ namespace FlaxEditor.Scripting
/// </summary>
public static readonly ScriptType Void = new ScriptType(typeof(void));
/// <summary>
/// A <see cref="ScriptType" /> that is System.Object.
/// </summary>
public static readonly ScriptType Object = new ScriptType(typeof(object));
/// <summary>
/// Gets the type of the script as <see cref="System.Type"/>.
/// </summary>

View File

@@ -64,7 +64,7 @@ namespace FlaxEditor.Scripting
Utilities.Utils.InitDefaultValues(value);
return value;
}
if (new ScriptType(typeof(object)).IsAssignableFrom(type))
if (ScriptType.Object.IsAssignableFrom(type))
return null;
if (type.CanCreateInstance)
{

View File

@@ -855,7 +855,7 @@ namespace FlaxEditor.Surface.Archetypes
{
_picker = new TypePickerControl
{
Type = new ScriptType(typeof(object)),
Type = ScriptType.Object,
Bounds = new Rectangle(FlaxEditor.Surface.Constants.NodeMarginX, FlaxEditor.Surface.Constants.NodeMarginY + FlaxEditor.Surface.Constants.NodeHeaderSize, 140, 16),
Parent = this,
};
@@ -1515,7 +1515,7 @@ namespace FlaxEditor.Surface.Archetypes
{
TypeID = 26,
Title = "Cast Value",
Create = (id, context, arch, groupArch) => new CastNode(id, context, arch, groupArch, new ScriptType(typeof(object))),
Create = (id, context, arch, groupArch) => new CastNode(id, context, arch, groupArch, ScriptType.Object),
Description = "Tries to cast the object to a given type. Returns null if fails.",
Flags = NodeFlags.VisualScriptGraph,
Size = new Vector2(200, 60),

View File

@@ -317,7 +317,7 @@ namespace FlaxEditor.Surface
public Box AddBox(bool isOut, int id, int yLevel, string text, ScriptType type, bool single, int valueIndex = -1)
{
if (type == ScriptType.Null)
type = new ScriptType(typeof(object));
type = ScriptType.Object;
// Try to reuse box
var box = GetBox(id);

View File

@@ -288,7 +288,7 @@ namespace FlaxEditor.Utilities
case VariantType.Matrix: return new ScriptType(typeof(Matrix));
case VariantType.Array: return new ScriptType(typeof(object[]));
case VariantType.Dictionary: return new ScriptType(typeof(Dictionary<object, object>));
case VariantType.ManagedObject: return new ScriptType(typeof(object));
case VariantType.ManagedObject: return ScriptType.Object;
case VariantType.Blob: return new ScriptType(typeof(byte[]));
default: throw new ArgumentOutOfRangeException($"Unknown Variant Type {variantType} without typename.");
}
@@ -541,6 +541,15 @@ namespace FlaxEditor.Utilities
stream.Write(int.MaxValue);
stream.WriteStrAnsi(type.FullName, 77);
break;
case VariantType.Array:
if (type != typeof(object[]))
{
stream.Write(int.MaxValue);
stream.WriteStrAnsi(type.FullName, 77);
}
else
stream.Write(0);
break;
default:
stream.Write(0);
break;

View File

@@ -587,13 +587,7 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu
{
// Animation Output
case 1:
{
if (box->HasConnection())
value = eatBox(nodeBase, box->FirstConnection());
else
value = Value::Null;
break;
}
value = tryGetValue(box, Value::Null);
// Animation
case 2:
{
@@ -1637,7 +1631,7 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu
// Evaluate the function output
context.GraphStack.Push((Graph*)data.Graph);
value = functionOutputBox && functionOutputBox->HasConnection() ? eatBox(nodeBase, functionOutputBox->FirstConnection()) : Value::Zero;
value = tryGetValue(functionOutputBox, Value::Zero);
context.GraphStack.Pop();
break;
}

View File

@@ -56,10 +56,8 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
}
// Screen Size
case 7:
{
value = Value(VariantType::Vector2, box->ID == 0 ? TEXT("ScreenSize.xy") : TEXT("ScreenSize.zw"));
break;
}
// Custom code
case 8:
{
@@ -331,7 +329,7 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
// Evaluate the function output
_graphStack.Push(graph);
value = functionOutputBox && functionOutputBox->HasConnection() ? eatBox(node, functionOutputBox->FirstConnection()) : Value::Zero;
value = tryGetValue(functionOutputBox, Value::Zero);
_graphStack.Pop();
break;
}
@@ -400,7 +398,6 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
case 30:
{
const auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
value = writeLocal(inValue.Type, String::Format(TEXT("ddx({0})"), inValue.Value), node);
break;
}
@@ -408,7 +405,6 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
case 31:
{
const auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
value = writeLocal(inValue.Type, String::Format(TEXT("ddy({0})"), inValue.Value), node);
break;
}
@@ -416,7 +412,6 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
case 32:
{
const auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
value = writeLocal(ValueType::Float, String::Format(TEXT("sign({0})"), inValue.Value), node);
break;
}
@@ -424,7 +419,6 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
case 33:
{
const auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
value = writeLocal(ValueType::Bool, String::Format(TEXT("any({0})"), inValue.Value), node);
break;
}
@@ -432,7 +426,6 @@ void MaterialGenerator::ProcessGroupMaterial(Box* box, Node* node, Value& value)
case 34:
{
const auto inValue = tryGetValue(node->GetBox(0), 0, Value::Zero);
value = writeLocal(ValueType::Bool, String::Format(TEXT("all({0})"), inValue.Value), node);
break;
}

View File

@@ -48,7 +48,7 @@ public:
public:
ShaderGraphBox* FirstConnection() const
FORCE_INLINE ShaderGraphBox* FirstConnection() const
{
return (ShaderGraphBox*)Connections[0];
}

View File

@@ -1323,18 +1323,3 @@ void VisjectExecutor::ProcessGroupCollections(Box* box, Node* node, Value& value
}
}
}
VisjectExecutor::Value VisjectExecutor::tryGetValue(Box* box, int32 defaultValueBoxIndex, const Value& defaultValue)
{
const auto parentNode = box->GetParent<Node>();
if (box->HasConnection())
return eatBox(parentNode, box->FirstConnection());
if (parentNode->Values.Count() > defaultValueBoxIndex)
return Value(parentNode->Values[defaultValueBoxIndex]);
return defaultValue;
}
VisjectExecutor::Value VisjectExecutor::tryGetValue(Box* box, const Value& defaultValue)
{
return box && box->HasConnection() ? eatBox(box->GetParent<Node>(), box->FirstConnection()) : defaultValue;
}

View File

@@ -262,6 +262,19 @@ protected:
virtual Value eatBox(Node* caller, Box* box) = 0;
virtual Graph* GetCurrentGraph() const = 0;
Value tryGetValue(Box* box, int32 defaultValueBoxIndex, const Value& defaultValue);
Value tryGetValue(Box* box, const Value& defaultValue);
FORCE_INLINE Value tryGetValue(Box* box, int32 defaultValueBoxIndex, const Value& defaultValue)
{
const auto parentNode = box->GetParent<Node>();
if (box->HasConnection())
return eatBox(parentNode, box->FirstConnection());
if (parentNode->Values.Count() > defaultValueBoxIndex)
return Value(parentNode->Values[defaultValueBoxIndex]);
return defaultValue;
}
FORCE_INLINE Value tryGetValue(Box* box, const Value& defaultValue)
{
return box && box->HasConnection() ? eatBox(box->GetParent<Node>(), box->FirstConnection()) : defaultValue;
}
};