mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 01:54:35 +08:00
add edit script button
This commit is contained in:
parent
5492c8a956
commit
22b77485c5
@ -1,7 +1,6 @@
|
||||
#if UNITY_EDITOR
|
||||
using DCFApixels.DragonECS.Unity.Editors;
|
||||
using DCFApixels.DragonECS.Unity.Internal;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
|
@ -4,6 +4,7 @@ using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using static PlasticGui.WebApi.Responses.CloudOrganizationHelpActionsResponse;
|
||||
|
||||
namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
@ -187,14 +188,14 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
Rect paddingPosition = RectUtility.AddPadding(position, Padding * 2f);
|
||||
|
||||
#region Draw Component Block
|
||||
Rect removeButtonRect = position;
|
||||
removeButtonRect.center -= new Vector2(0, removeButtonRect.height);
|
||||
removeButtonRect.yMin = removeButtonRect.yMax;
|
||||
removeButtonRect.yMax += HeadIconsRect.height;
|
||||
removeButtonRect.xMin = removeButtonRect.xMax - HeadIconsRect.width;
|
||||
removeButtonRect.center += Vector2.up * Padding * 1f;
|
||||
Rect optionButton = position;
|
||||
optionButton.center -= new Vector2(0, optionButton.height);
|
||||
optionButton.yMin = optionButton.yMax;
|
||||
optionButton.yMax += HeadIconsRect.height;
|
||||
optionButton.xMin = optionButton.xMax - HeadIconsRect.width;
|
||||
optionButton.center += Vector2.up * Padding * 1f;
|
||||
|
||||
bool isRemoveComponent = EcsGUI.CloseButton(removeButtonRect);
|
||||
bool isRemoveComponent = EcsGUI.CloseButton(optionButton);
|
||||
|
||||
if (propCount <= 0)
|
||||
{
|
||||
@ -228,12 +229,16 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
componentRefProp.managedReferenceValue = null;
|
||||
}
|
||||
|
||||
if (UnityEditorUtility.TryGetScriptAsset(componentType, out MonoScript script))
|
||||
{
|
||||
optionButton = HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
|
||||
EcsGUI.ScriptAssetButton(optionButton, script);
|
||||
}
|
||||
if (string.IsNullOrEmpty(description) == false)
|
||||
{
|
||||
Rect tooltipIconRect = HeadIconsRect;
|
||||
tooltipIconRect.center = removeButtonRect.center;
|
||||
tooltipIconRect.center -= Vector2.right * tooltipIconRect.width;
|
||||
EcsGUI.DescriptionIcon(tooltipIconRect, description);
|
||||
optionButton = HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
|
||||
EcsGUI.DescriptionIcon(optionButton, description);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -46,10 +46,6 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
name = group.Name + name;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(description) == false)
|
||||
{
|
||||
name = $"{name} [i]";
|
||||
}
|
||||
_genericMenu.AddItem(new GUIContent(name, description), false, OnAddComponent, dummy);
|
||||
}
|
||||
|
||||
@ -179,18 +175,18 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
Color alphaPanelColor = panelColor;
|
||||
alphaPanelColor.a = EscEditorConsts.COMPONENT_DRAWER_ALPHA;
|
||||
|
||||
Rect removeButtonRect = GUILayoutUtility.GetLastRect();
|
||||
Rect optionButton = GUILayoutUtility.GetLastRect();
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
GUILayout.BeginVertical(UnityEditorUtility.GetStyle(alphaPanelColor));
|
||||
|
||||
#region Draw Component Block
|
||||
removeButtonRect.yMin = removeButtonRect.yMax;
|
||||
removeButtonRect.yMax += HeadIconsRect.height;
|
||||
removeButtonRect.xMin = removeButtonRect.xMax - HeadIconsRect.width;
|
||||
removeButtonRect.center += Vector2.up * padding * 2f;
|
||||
optionButton.yMin = optionButton.yMax;
|
||||
optionButton.yMax += HeadIconsRect.height;
|
||||
optionButton.xMin = optionButton.xMax - HeadIconsRect.width;
|
||||
optionButton.center += Vector2.up * padding * 2f;
|
||||
|
||||
bool isRemoveComponent = EcsGUI.CloseButton(removeButtonRect);
|
||||
bool isRemoveComponent = EcsGUI.CloseButton(optionButton);
|
||||
|
||||
if (propCount <= 0)
|
||||
{
|
||||
@ -213,12 +209,16 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
OnRemoveComponentAt(index);
|
||||
}
|
||||
|
||||
if (UnityEditorUtility.TryGetScriptAsset(componentType, out MonoScript script))
|
||||
{
|
||||
optionButton = HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
|
||||
EcsGUI.ScriptAssetButton(optionButton, script);
|
||||
}
|
||||
if (string.IsNullOrEmpty(description) == false)
|
||||
{
|
||||
Rect tooltipIconRect = HeadIconsRect;
|
||||
tooltipIconRect.center = removeButtonRect.center;
|
||||
tooltipIconRect.center -= Vector2.right * tooltipIconRect.width;
|
||||
EcsGUI.DescriptionIcon(tooltipIconRect, description);
|
||||
optionButton = HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
|
||||
EcsGUI.DescriptionIcon(optionButton, description);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
BIN
src/Icons/FileIcon.png
Normal file
BIN
src/Icons/FileIcon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 299 B |
122
src/Icons/FileIcon.png.meta
Normal file
122
src/Icons/FileIcon.png.meta
Normal file
@ -0,0 +1,122 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f1ca6aa9d407844485856184c785946
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
ignoreMasterTextureLimit: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: 1
|
||||
aniso: 1
|
||||
mipBias: 0
|
||||
wrapU: 0
|
||||
wrapV: 0
|
||||
wrapW: 0
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 0
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Server
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
nameFileIdTable: {}
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -28,6 +28,8 @@ namespace DCFApixels.DragonECS.Unity.Internal
|
||||
private Texture _labelIconType;
|
||||
[SerializeField]
|
||||
private Texture _labelIconMeta;
|
||||
[SerializeField]
|
||||
private Texture _fileIcon;
|
||||
|
||||
internal Texture HelpIcon { get { return _helpIcon; } }
|
||||
internal Texture CloseIcon { get { return _closeIcon; } }
|
||||
@ -40,6 +42,7 @@ namespace DCFApixels.DragonECS.Unity.Internal
|
||||
internal Texture VisibilityIconOff { get { return _visibilityIconOff; } }
|
||||
internal Texture LabelIconType { get { return _labelIconType; } }
|
||||
internal Texture LabelIconMeta { get { return _labelIconMeta; } }
|
||||
internal Texture FileIcon { get { return _fileIcon; } }
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ MonoImporter:
|
||||
- _visibilityIconOff: {fileID: 2800000, guid: 1f25a5ca611092642a8ee4e08fafcd43, type: 3}
|
||||
- _labelIconType: {fileID: 2800000, guid: 5476d6e1435981e4cbc915a080f93ee6, type: 3}
|
||||
- _labelIconMeta: {fileID: 2800000, guid: ebb82b09315bde749a10dfa45e64067c, type: 3}
|
||||
- _fileIcon: {fileID: 2800000, guid: 4f1ca6aa9d407844485856184c785946, type: 3}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
|
@ -23,3 +23,4 @@ MonoBehaviour:
|
||||
_visibilityIconOff: {fileID: 2800000, guid: 1f25a5ca611092642a8ee4e08fafcd43, type: 3}
|
||||
_labelIconType: {fileID: 2800000, guid: 5476d6e1435981e4cbc915a080f93ee6, type: 3}
|
||||
_labelIconMeta: {fileID: 2800000, guid: ebb82b09315bde749a10dfa45e64067c, type: 3}
|
||||
_fileIcon: {fileID: 2800000, guid: 4f1ca6aa9d407844485856184c785946, type: 3}
|
@ -4,8 +4,9 @@ using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityObject = UnityEngine.Object;
|
||||
using static PlasticGui.WebApi.Responses.CloudOrganizationHelpActionsResponse;
|
||||
using UnityComponent = UnityEngine.Component;
|
||||
using UnityObject = UnityEngine.Object;
|
||||
|
||||
namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
@ -118,8 +119,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
internal readonly static Color GreenColor = new Color32(75, 255, 0, 255);
|
||||
internal readonly static Color RedColor = new Color32(255, 0, 75, 255);
|
||||
|
||||
private static readonly Rect RemoveButtonRect = new Rect(0f, 0f, 19f, 19f);
|
||||
private static readonly Rect TooltipIconRect = new Rect(0f, 0f, 19f, 19f);
|
||||
private static readonly Rect HeadIconsRect = new Rect(0f, 0f, 19f, 19f);
|
||||
|
||||
public static float EntityBarHeight => EditorGUIUtility.singleLineHeight + 3f;
|
||||
|
||||
@ -180,7 +180,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
#region small elems
|
||||
public static void DrawIcon(Rect position, Texture icon, float iconPadding, string description)
|
||||
{
|
||||
if(position.width != position.height)
|
||||
if (position.width != position.height)
|
||||
{
|
||||
Vector2 center = position.center;
|
||||
float size = Mathf.Min(position.width, position.height);
|
||||
@ -196,13 +196,20 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
}
|
||||
public static (bool, bool) IconButtonGeneric(Rect position)
|
||||
{
|
||||
Color dc = GUI.color;
|
||||
GUI.color = Color.clear; //Хак чтобы сделать реакцию от курсора мыши без лага
|
||||
bool result = GUI.Button(position, "", EditorStyles.miniButtonMid);
|
||||
GUI.color = dc;
|
||||
|
||||
var current = Event.current;
|
||||
return (GUI.enabled && HitTest(position, current), result);
|
||||
using (SetAlpha(0))
|
||||
{
|
||||
bool result = GUI.Button(position, string.Empty, EditorStyles.miniButtonMid);
|
||||
var current = Event.current;
|
||||
return (GUI.enabled && HitTest(position, current), result);
|
||||
}
|
||||
}
|
||||
public static bool IconHoverScan(Rect position, Event current)
|
||||
{
|
||||
using (Disable) using (SetAlpha(0))
|
||||
{
|
||||
GUI.Button(position, string.Empty, EditorStyles.miniButtonMid);
|
||||
return HitTest(position, current);
|
||||
}
|
||||
}
|
||||
public static bool IconButton(Rect position, Texture icon, float iconPadding, string description)
|
||||
{
|
||||
@ -217,18 +224,41 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
DrawIcon(position, Icons.Instance.HelpIcon, 0, description);
|
||||
}
|
||||
}
|
||||
public static bool CloseButton(Rect position)
|
||||
public static void ScriptAssetButton(Rect position, MonoScript script)
|
||||
{
|
||||
var current = Event.current;
|
||||
|
||||
var hover = IconHoverScan(position, current);
|
||||
|
||||
using (new ColorScope(new Color(1f, 1f, 1f, hover ? 1f : 0.8f)))
|
||||
{
|
||||
DrawIcon(position, Icons.Instance.FileIcon, hover ? 1f : 2f, "One click - Ping File. Double click - Edit Script");
|
||||
}
|
||||
|
||||
if (hover)
|
||||
{
|
||||
if (current.type == EventType.MouseUp)
|
||||
{
|
||||
EditorGUIUtility.PingObject(script);
|
||||
}
|
||||
else if (current.type == EventType.MouseDown && current.clickCount >= 2)
|
||||
{
|
||||
AssetDatabase.OpenAsset(script);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static bool CloseButton(Rect position, string description = null)
|
||||
{
|
||||
using (new ColorScope(new Color(1f, 1f, 1f, 0.8f)))
|
||||
{
|
||||
var (hover, click) = IconButtonGeneric(position);
|
||||
if (hover)
|
||||
{
|
||||
DrawIcon(position, Icons.Instance.CloseIconOn, -4f, null);
|
||||
DrawIcon(position, Icons.Instance.CloseIconOn, -4f, description);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawIcon(position, Icons.Instance.CloseIcon, 0, null);
|
||||
DrawIcon(position, Icons.Instance.CloseIcon, 0, description);
|
||||
}
|
||||
return click;
|
||||
}
|
||||
@ -560,17 +590,17 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
Color panelColor = SelectPanelColor(meta, index, total).Desaturate(EscEditorConsts.COMPONENT_DRAWER_DESATURATE);
|
||||
|
||||
float padding = EditorGUIUtility.standardVerticalSpacing;
|
||||
Rect removeButtonRect = GUILayoutUtility.GetLastRect();
|
||||
Rect optionButton = GUILayoutUtility.GetLastRect();
|
||||
|
||||
GUILayout.BeginVertical(UnityEditorUtility.GetStyle(panelColor, EscEditorConsts.COMPONENT_DRAWER_ALPHA));
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
bool isRemoveComponent = false;
|
||||
removeButtonRect.yMin = removeButtonRect.yMax;
|
||||
removeButtonRect.yMax += RemoveButtonRect.height;
|
||||
removeButtonRect.xMin = removeButtonRect.xMax - RemoveButtonRect.width;
|
||||
removeButtonRect.center += Vector2.up * padding * 2f;
|
||||
if (CloseButton(removeButtonRect))
|
||||
optionButton.yMin = optionButton.yMax;
|
||||
optionButton.yMax += HeadIconsRect.height;
|
||||
optionButton.xMin = optionButton.xMax - HeadIconsRect.width;
|
||||
optionButton.center += Vector2.up * padding * 2f;
|
||||
if (CloseButton(optionButton))
|
||||
{
|
||||
isRemoveComponent = true;
|
||||
}
|
||||
@ -590,12 +620,16 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (UnityEditorUtility.TryGetScriptAsset(componentType, out MonoScript script))
|
||||
{
|
||||
optionButton = HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
|
||||
EcsGUI.ScriptAssetButton(optionButton, script);
|
||||
}
|
||||
if (string.IsNullOrEmpty(meta.Description.Text) == false)
|
||||
{
|
||||
Rect tooltipIconRect = TooltipIconRect;
|
||||
tooltipIconRect.center = removeButtonRect.center;
|
||||
tooltipIconRect.center -= Vector2.right * tooltipIconRect.width;
|
||||
DescriptionIcon(tooltipIconRect, meta.Description.Text);
|
||||
optionButton = HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
|
||||
DescriptionIcon(optionButton, meta.Description.Text);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
@ -94,7 +94,6 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
return b.ToString();
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,6 +113,28 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
private static GUIContent _singletonContent = null;
|
||||
private static GUIStyle _inputFieldCenterAnhor = null;
|
||||
|
||||
private static Dictionary<Type, MonoScript> scriptsAssets = new Dictionary<Type, MonoScript>(256);
|
||||
|
||||
internal static bool TryGetScriptAsset(Type type, out MonoScript script)
|
||||
{
|
||||
if (scriptsAssets.TryGetValue(type, out script) == false)
|
||||
{
|
||||
script = null;
|
||||
var guids = AssetDatabase.FindAssets($"{type.Name} t:MonoScript");
|
||||
for (var i = 0; i < guids.Length; i++)
|
||||
{
|
||||
MonoScript textAsset = AssetDatabase.LoadAssetAtPath<MonoScript>(AssetDatabase.GUIDToAssetPath(guids[i]));
|
||||
if (textAsset != null && textAsset.name == type.Name)
|
||||
{
|
||||
script = textAsset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
scriptsAssets.Add(type, script);
|
||||
}
|
||||
return script != null;
|
||||
}
|
||||
|
||||
#region Label
|
||||
public static GUIStyle GetInputFieldCenterAnhor()
|
||||
{
|
||||
|
@ -69,6 +69,12 @@ namespace DCFApixels.DragonECS.Unity.Internal
|
||||
result.center += addVector;
|
||||
return result;
|
||||
}
|
||||
public static Rect MoveTo(in this Rect rect, Vector2 center)
|
||||
{
|
||||
Rect result = rect;
|
||||
result.center = center;
|
||||
return result;
|
||||
}
|
||||
public static Rect Move(in this Rect rect, float addX, float addY)
|
||||
{
|
||||
return Move(rect, new Vector2(addX, addY));
|
||||
|
Loading…
Reference in New Issue
Block a user