Skip to content

Commit

Permalink
- add inspector and refactor folder
Browse files Browse the repository at this point in the history
  • Loading branch information
DucNV2000 committed Jul 3, 2024
1 parent 216f0e3 commit 64464de
Show file tree
Hide file tree
Showing 486 changed files with 14,521 additions and 4 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions Core/UnityCommon.Core.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "UnityCommon.Core"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Inspector.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

708 changes: 708 additions & 0 deletions Inspector/.editorconfig

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions Inspector/.github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

**Describe the bug**
<!-- A clear and concise description of what the bug is. -->

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->

**Code Sample**
<!-- If applicable, add code sample to help explain your problem. -->
```csharp
//
```

**Screenshots**
<!-- If applicable, add screenshots to help explain your problem. -->

**Desktop:** <!-- e.g. Windows 10 -->
**Unity version:** <!-- e.g. 2020.3.35f1 -->
**Tri Inspector version:** <!-- e.g. 1.6.1 -->
8 changes: 8 additions & 0 deletions Inspector/.github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
blank_issues_enabled: false
contact_links:
- name: Feature request or Idea
url: https://github.com/codewriter-packages/Tri-Inspector/discussions/categories/ideas
about: Suggest an idea for this project.
- name: Question
url: https://github.com/codewriter-packages/Tri-Inspector/discussions/categories/q-a
about: Please ask and answer questions here.
16 changes: 16 additions & 0 deletions Inspector/.github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# .github/release.yml

changelog:
categories:
- title: Breaking Changes
labels:
- breaking-change
- title: Features
labels:
- enhancement
- title: Fixes
labels:
- bug
- title: Changes
labels:
- "*"
26 changes: 26 additions & 0 deletions Inspector/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
*.*~
*.db
*.sln
*.userprefs
*.csproj
*.pidb
*.unityproj
*.apk
*.stackdump
/Library
/obj
/Temp
/Build*
/Logs/
/AssetBundles
/Logs/
.vs
.vscode
.idea
.gradle
*_LEGACY
*.DotSettings.user
/Assets/Plugins/Editor/JetBrains*
/Assets/LEGACY*
/Assets/TextMesh Pro*
/Assets/Plugins/Sirenix*
8 changes: 8 additions & 0 deletions Inspector/Editor.Extras.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Inspector/Editor.Extras/Drawers.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions Inspector/Editor.Extras/Drawers/BuiltinDrawerBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using UnityEditor;
using UnityEngine;

namespace VirtueSky.Inspector.Drawers
{
public abstract class BuiltinDrawerBase<T> : TriValueDrawer<T>
{
public sealed override TriElement CreateElement(TriValue<T> propertyValue, TriElement next)
{
if (propertyValue.Property.TryGetSerializedProperty(out _))
{
return next;
}

return base.CreateElement(propertyValue, next);
}

public virtual int CompactModeLines => 1;
public virtual int WideModeLines => 1;

public sealed override float GetHeight(float width, TriValue<T> propertyValue, TriElement next)
{
var lineHeight = EditorGUIUtility.singleLineHeight;
var spacing = EditorGUIUtility.standardVerticalSpacing;
var lines = EditorGUIUtility.wideMode ? WideModeLines : CompactModeLines;
return lineHeight * lines + spacing * (lines - 1);
}

public sealed override void OnGUI(Rect position, TriValue<T> propertyValue, TriElement next)
{
var value = propertyValue.SmartValue;

EditorGUI.BeginChangeCheck();

value = OnValueGUI(position, propertyValue.Property.DisplayNameContent, value);

if (EditorGUI.EndChangeCheck())
{
propertyValue.SetValue(value);
}
}

protected abstract T OnValueGUI(Rect position, GUIContent label, T value);
}
}
3 changes: 3 additions & 0 deletions Inspector/Editor.Extras/Drawers/BuiltinDrawerBase.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

224 changes: 224 additions & 0 deletions Inspector/Editor.Extras/Drawers/BuiltinDrawers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
using System;
using VirtueSky.Inspector;
using VirtueSky.Inspector.Drawers;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;

[assembly: RegisterTriValueDrawer(typeof(IntegerDrawer), TriDrawerOrder.Fallback)]
[assembly: RegisterTriValueDrawer(typeof(LongDrawer), TriDrawerOrder.Fallback)]
[assembly: RegisterTriValueDrawer(typeof(BooleanDrawer), TriDrawerOrder.Fallback)]
[assembly: RegisterTriValueDrawer(typeof(FloatDrawer), TriDrawerOrder.Fallback)]
[assembly: RegisterTriValueDrawer(typeof(StringDrawer), TriDrawerOrder.Fallback)]
[assembly: RegisterTriValueDrawer(typeof(ColorDrawer), TriDrawerOrder.Fallback)]
[assembly: RegisterTriValueDrawer(typeof(Color32Drawer), TriDrawerOrder.Fallback)]
[assembly: RegisterTriValueDrawer(typeof(LayerMaskDrawer), TriDrawerOrder.Fallback)]
[assembly: RegisterTriValueDrawer(typeof(EnumDrawer), TriDrawerOrder.Fallback)]
[assembly: RegisterTriValueDrawer(typeof(Vector2Drawer), TriDrawerOrder.Fallback)]
[assembly: RegisterTriValueDrawer(typeof(Vector3Drawer), TriDrawerOrder.Fallback)]
[assembly: RegisterTriValueDrawer(typeof(Vector4Drawer), TriDrawerOrder.Fallback)]
[assembly: RegisterTriValueDrawer(typeof(RectDrawer), TriDrawerOrder.Fallback)]
[assembly: RegisterTriValueDrawer(typeof(AnimationCurveDrawer), TriDrawerOrder.Fallback)]
[assembly: RegisterTriValueDrawer(typeof(BoundsDrawer), TriDrawerOrder.Fallback)]
[assembly: RegisterTriValueDrawer(typeof(GradientDrawer), TriDrawerOrder.Fallback)]
[assembly: RegisterTriValueDrawer(typeof(Vector2IntDrawer), TriDrawerOrder.Fallback)]
[assembly: RegisterTriValueDrawer(typeof(Vector3IntDrawer), TriDrawerOrder.Fallback)]
[assembly: RegisterTriValueDrawer(typeof(RectIntDrawer), TriDrawerOrder.Fallback)]
[assembly: RegisterTriValueDrawer(typeof(BoundsIntDrawer), TriDrawerOrder.Fallback)]

namespace VirtueSky.Inspector.Drawers
{
public class StringDrawer : BuiltinDrawerBase<string>
{
protected override string OnValueGUI(Rect position, GUIContent label, string value)
{
return EditorGUI.TextField(position, label, value);
}
}

public class BooleanDrawer : BuiltinDrawerBase<bool>
{
protected override bool OnValueGUI(Rect position, GUIContent label, bool value)
{
return EditorGUI.Toggle(position, label, value);
}
}

public class IntegerDrawer : BuiltinDrawerBase<int>
{
protected override int OnValueGUI(Rect position, GUIContent label, int value)
{
return EditorGUI.IntField(position, label, value);
}
}

public class LongDrawer : BuiltinDrawerBase<long>
{
protected override long OnValueGUI(Rect position, GUIContent label, long value)
{
return EditorGUI.LongField(position, label, value);
}
}

public class FloatDrawer : BuiltinDrawerBase<float>
{
protected override float OnValueGUI(Rect position, GUIContent label, float value)
{
return EditorGUI.FloatField(position, label, value);
}
}

public class ColorDrawer : BuiltinDrawerBase<Color>
{
protected override Color OnValueGUI(Rect position, GUIContent label, Color value)
{
return EditorGUI.ColorField(position, label, value);
}
}

public class Color32Drawer : BuiltinDrawerBase<Color32>
{
protected override Color32 OnValueGUI(Rect position, GUIContent label, Color32 value)
{
return EditorGUI.ColorField(position, label, value);
}
}

public class LayerMaskDrawer : BuiltinDrawerBase<LayerMask>
{
protected override LayerMask OnValueGUI(Rect position, GUIContent label, LayerMask value)
{
var mask = InternalEditorUtility.LayerMaskToConcatenatedLayersMask(value);
var layers = InternalEditorUtility.layers;

position = EditorGUI.PrefixLabel(position, label);
return EditorGUI.MaskField(position, mask, layers);
}
}

public class EnumDrawer : BuiltinDrawerBase<Enum>
{
protected override Enum OnValueGUI(Rect position, GUIContent label, Enum value)
{
return EditorGUI.EnumPopup(position, label, value);
}
}

public class Vector2Drawer : BuiltinDrawerBase<Vector2>
{
public override int CompactModeLines => 2;

protected override Vector2 OnValueGUI(Rect position, GUIContent label, Vector2 value)
{
return EditorGUI.Vector2Field(position, label, value);
}
}

public class Vector3Drawer : BuiltinDrawerBase<Vector3>
{
public override int CompactModeLines => 2;

protected override Vector3 OnValueGUI(Rect position, GUIContent label, Vector3 value)
{
return EditorGUI.Vector3Field(position, label, value);
}
}

public class Vector4Drawer : BuiltinDrawerBase<Vector4>
{
public override int CompactModeLines => 2;

protected override Vector4 OnValueGUI(Rect position, GUIContent label, Vector4 value)
{
return EditorGUI.Vector4Field(position, label, value);
}
}

public class RectDrawer : BuiltinDrawerBase<Rect>
{
public override int CompactModeLines => 3;
public override int WideModeLines => 2;

protected override Rect OnValueGUI(Rect position, GUIContent label, Rect value)
{
return EditorGUI.RectField(position, label, value);
}
}

public class AnimationCurveDrawer : BuiltinDrawerBase<AnimationCurve>
{
protected override AnimationCurve OnValueGUI(Rect position, GUIContent label, AnimationCurve value)
{
return EditorGUI.CurveField(position, label, value);
}
}

public class BoundsDrawer : BuiltinDrawerBase<Bounds>
{
public override int CompactModeLines => 3;
public override int WideModeLines => 3;

protected override Bounds OnValueGUI(Rect position, GUIContent label, Bounds value)
{
return EditorGUI.BoundsField(position, label, value);
}
}

public class GradientDrawer : BuiltinDrawerBase<Gradient>
{
private static readonly GUIContent NullLabel = new GUIContent("Gradient is null");

protected override Gradient OnValueGUI(Rect position, GUIContent label, Gradient value)
{
if (value == null)
{
EditorGUI.LabelField(position, label, NullLabel);
return null;
}

return EditorGUI.GradientField(position, label, value);
}
}

public class Vector2IntDrawer : BuiltinDrawerBase<Vector2Int>
{
public override int CompactModeLines => 2;

protected override Vector2Int OnValueGUI(Rect position, GUIContent label, Vector2Int value)
{
return EditorGUI.Vector2IntField(position, label, value);
}
}

public class Vector3IntDrawer : BuiltinDrawerBase<Vector3Int>
{
public override int CompactModeLines => 2;

protected override Vector3Int OnValueGUI(Rect position, GUIContent label, Vector3Int value)
{
return EditorGUI.Vector3IntField(position, label, value);
}
}

public class RectIntDrawer : BuiltinDrawerBase<RectInt>
{
public override int CompactModeLines => 3;
public override int WideModeLines => 2;

protected override RectInt OnValueGUI(Rect position, GUIContent label, RectInt value)
{
return EditorGUI.RectIntField(position, label, value);
}
}

public class BoundsIntDrawer : BuiltinDrawerBase<BoundsInt>
{
public override int CompactModeLines => 3;
public override int WideModeLines => 3;

protected override BoundsInt OnValueGUI(Rect position, GUIContent label, BoundsInt value)
{
return EditorGUI.BoundsIntField(position, label, value);
}
}
}
3 changes: 3 additions & 0 deletions Inspector/Editor.Extras/Drawers/BuiltinDrawers.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 64464de

Please sign in to comment.