调整了模板
This commit is contained in:
33
addons/BITPlugins/InspectorPlugins.cs
Normal file
33
addons/BITPlugins/InspectorPlugins.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
namespace BITKit;
|
||||
#if TOOLS
|
||||
using Godot;
|
||||
[Tool]
|
||||
public partial class InspectorPlugins : EditorInspectorPlugin
|
||||
{
|
||||
public override bool _CanHandle(GodotObject @object)
|
||||
{
|
||||
return @object is Node;
|
||||
}
|
||||
|
||||
public override bool _ParseProperty(
|
||||
GodotObject @object,
|
||||
Variant.Type type,
|
||||
string name,
|
||||
PropertyHint hintType,
|
||||
string hintString,
|
||||
PropertyUsageFlags usageFlags, bool wide)
|
||||
{
|
||||
// We handle properties of type integer.
|
||||
if (type != Variant.Type.Int) return false;
|
||||
// Create an instance of the custom property editor and register
|
||||
// it to a specific property path.
|
||||
AddPropertyEditor(name, new RandomIntEditor());
|
||||
// Inform the editor to remove the default property editor for
|
||||
// this property type.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
63
addons/BITPlugins/Plugins/RandomIntEditor.cs
Normal file
63
addons/BITPlugins/Plugins/RandomIntEditor.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
namespace BITKit;
|
||||
#if TOOLS
|
||||
using Godot;
|
||||
|
||||
[Tool]
|
||||
public partial class RandomIntEditor : EditorProperty
|
||||
{
|
||||
// The main control for editing the property.
|
||||
private Button _propertyControl = new Button();
|
||||
// An internal value of the property.
|
||||
private int _currentValue = 0;
|
||||
// A guard against internal changes when the property is updated.
|
||||
private bool _updating = false;
|
||||
|
||||
public RandomIntEditor()
|
||||
{
|
||||
// Add the control as a direct child of EditorProperty node.
|
||||
AddChild(_propertyControl);
|
||||
// Make sure the control is able to retain the focus.
|
||||
AddFocusable(_propertyControl);
|
||||
// Setup the initial state and connect to the signal to track changes.
|
||||
RefreshControlText();
|
||||
//_propertyControl.Connect("pressed", this, nameof(OnButtonPressed));
|
||||
}
|
||||
|
||||
private void OnButtonPressed()
|
||||
{
|
||||
// Ignore the signal if the property is currently being updated.
|
||||
if (_updating)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Generate a new random integer between 0 and 99.
|
||||
_currentValue = (int)GD.Randi() % 100;
|
||||
RefreshControlText();
|
||||
EmitChanged(GetEditedProperty(), _currentValue);
|
||||
}
|
||||
public override void _UpdateProperty()
|
||||
{
|
||||
// Read the current value from the property.
|
||||
var newValue = (int)GetEditedObject().Get(GetEditedProperty());
|
||||
if (newValue == _currentValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the control with the new value.
|
||||
_updating = true;
|
||||
_currentValue = newValue;
|
||||
RefreshControlText();
|
||||
_updating = false;
|
||||
}
|
||||
|
||||
private void RefreshControlText()
|
||||
{
|
||||
_propertyControl.Text = $"Value: {_currentValue}";
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -1,18 +0,0 @@
|
||||
#if TOOLS
|
||||
using Godot;
|
||||
|
||||
namespace BITKit;
|
||||
[Tool]
|
||||
public partial class RefencePlugin : EditorPlugin
|
||||
{
|
||||
public override void _EnterTree()
|
||||
{
|
||||
// Initialization of the plugin goes here.
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
// Clean-up of the plugin goes here.
|
||||
}
|
||||
}
|
||||
#endif
|
24
addons/BITPlugins/ReferenceContainer.tscn
Normal file
24
addons/BITPlugins/ReferenceContainer.tscn
Normal file
@@ -0,0 +1,24 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://r7xpryghff3b"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/BITPlugins/ReferenceExamples.cs" id="1_h7isd"]
|
||||
|
||||
[node name="ReferenceContainer" type="PanelContainer"]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_h7isd")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "引用插件"
|
||||
|
||||
[node name="Node" type="Node" parent="."]
|
||||
script = ExtResource("1_h7isd")
|
8
addons/BITPlugins/ReferenceExamples.cs
Normal file
8
addons/BITPlugins/ReferenceExamples.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
namespace BITKit;
|
||||
public partial class ReferenceExamples : Node
|
||||
{
|
||||
|
||||
}
|
23
addons/BITPlugins/ReferencePlugins.cs
Normal file
23
addons/BITPlugins/ReferencePlugins.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
#if TOOLS
|
||||
namespace BITKit;
|
||||
[Tool]
|
||||
public partial class ReferencePlugins : EditorPlugin
|
||||
{
|
||||
private InspectorPlugins _plugin;
|
||||
private PackedScene _containerTemplate = GD.Load<PackedScene>("res://addons/BITPlugins/ReferenceContainer.tscn");
|
||||
public override void _EnterTree()
|
||||
{
|
||||
_plugin = new InspectorPlugins();
|
||||
AddInspectorPlugin(_plugin);
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
RemoveInspectorPlugin(_plugin);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -1,18 +0,0 @@
|
||||
using Godot;
|
||||
|
||||
namespace BITKit;
|
||||
|
||||
#if TOOLS
|
||||
[Tool]
|
||||
public partial class RegistryPlugin : EditorPlugin
|
||||
{
|
||||
public override void _EnterTree()
|
||||
{
|
||||
// var type = typeof(StringResource);
|
||||
// const string classPath = "res://Artists/Scripts/Resource/StringResource.cs";
|
||||
// var script = GD.Load<Script>(classPath);
|
||||
// GD.Print($"已加载{script.ResourceName??script.ToString()}");
|
||||
// AddCustomType(type.Name, "Resource", script, null);
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -4,4 +4,4 @@ name="BITPlugins"
|
||||
description="BITKit为Godot支持的插件 "
|
||||
author="军火商小火柴"
|
||||
version=""
|
||||
script="RegistryPlugin.cs"
|
||||
script="ReferencePlugins.cs"
|
||||
|
Reference in New Issue
Block a user