Initial commit

This commit is contained in:
AbstractConcept 2022-09-13 00:36:34 -05:00
commit 3c7cc0c973
8391 changed files with 704313 additions and 0 deletions

View file

@ -0,0 +1,142 @@
using UnityEngine;
using System;
namespace UnityEditor.U2D.Animation
{
internal interface ISkeletonStyle
{
Color GetColor(BoneCache bone);
Color GetPreviewColor(int index);
Color GetParentLinkColor(BoneCache bone);
Color GetParentLinkPreviewColor(int index);
Color GetOutlineColor(BoneCache bone, bool isSelected, bool isHovered);
Color GetPreviewOutlineColor(int index);
float GetOutlineScale(bool isSelected);
}
internal abstract class SkeletonStyleBase : ISkeletonStyle
{
private const float kOutlineScale = 1.35f;
private const float kSelectedOutlineScale = 1.55f;
public Color GetColor(BoneCache bone)
{
return SetAlpha(GetBoneColorRaw(bone), GetAlpha(bone), VisibilityToolSettings.boneOpacity);
}
public Color GetPreviewColor(int index)
{
return GetBoneColorRaw(index);
}
public Color GetParentLinkColor(BoneCache bone)
{
return SetAlpha(GetBoneColorRaw(bone), 0.2f * GetAlpha(bone), VisibilityToolSettings.boneOpacity);
}
public Color GetParentLinkPreviewColor(int index)
{
return SetAlpha(GetBoneColorRaw(index), 0.2f, 1f);
}
public Color GetOutlineColor(BoneCache bone, bool isSelected, bool isHovered)
{
var skinningCache = bone.skinningCache;
if (isSelected)
return SelectionOutlineSettings.outlineColor;
if (isHovered)
return Handles.preselectionColor;
return SetAlpha(CalculateOutlineColor(GetBoneColorRaw(bone), VisibilityToolSettings.boneOpacity), GetAlpha(bone), VisibilityToolSettings.boneOpacity);
}
public Color GetPreviewOutlineColor(int index)
{
return CalculateOutlineColor(GetBoneColorRaw(index), 1f);
}
public float GetOutlineScale(bool isSelected)
{
if (isSelected)
return 1f + (kSelectedOutlineScale - 1f) * SelectionOutlineSettings.selectedBoneOutlineSize;
return kOutlineScale;
}
private Color CalculateOutlineColor(Color color, float opacity)
{
color *= 0.35f;
return SetAlpha(color, 0.75f, opacity);
}
private Color SetAlpha(Color color, float alpha, float opacity)
{
color.a = alpha * opacity;
return color;
}
protected virtual float GetAlpha(BoneCache bone)
{
return 1f;
}
protected abstract Color GetBoneColorRaw(BoneCache bone);
protected abstract Color GetBoneColorRaw(int index);
}
internal class BoneColorSkeletonStyle : SkeletonStyleBase
{
protected override Color GetBoneColorRaw(BoneCache bone)
{
return bone.bindPoseColor;
}
protected override Color GetBoneColorRaw(int index)
{
return ModuleUtility.CalculateNiceColor(index, 6);
}
protected override float GetAlpha(BoneCache bone)
{
return 0.9f;
}
}
internal class WeightmapSkeletonStyle : SkeletonStyleBase
{
protected override Color GetBoneColorRaw(BoneCache bone)
{
return bone.bindPoseColor;
}
protected override Color GetBoneColorRaw(int index)
{
return ModuleUtility.CalculateNiceColor(index, 6);
}
protected override float GetAlpha(BoneCache bone)
{
var skinningCache = bone.skinningCache;
var selectedSprite = skinningCache.selectedSprite;
var alpha = 0.9f;
if (skinningCache.mode == SkinningMode.Character && skinningCache.selectedSprite != null)
{
var characterPart = selectedSprite.GetCharacterPart();
if (characterPart.Contains(bone) == false)
alpha = 0.25f;
}
return alpha;
}
}
internal static class SkeletonStyles
{
public static readonly ISkeletonStyle Default = new BoneColorSkeletonStyle();
public static readonly ISkeletonStyle WeightMap = new WeightmapSkeletonStyle();
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7600825fd0008354ea24e17c94591a19
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,198 @@
using System;
using UnityEditor.U2D.Layout;
using UnityEngine;
namespace UnityEditor.U2D.Animation
{
internal class SkeletonTool : BaseTool
{
[SerializeField]
private SkeletonController m_SkeletonController;
private SkeletonToolView m_SkeletonToolView;
private RectBoneSelector m_RectBoneSelector = new RectBoneSelector();
private RectSelectionTool<BoneCache> m_RectSelectionTool = new RectSelectionTool<BoneCache>();
private UnselectTool<BoneCache> m_UnselectTool = new UnselectTool<BoneCache>();
public bool enableBoneInspector { get; set; }
public SkeletonMode mode
{
get { return m_SkeletonController.view.mode; }
set { m_SkeletonController.view.mode = value; }
}
public bool editBindPose
{
get { return m_SkeletonController.editBindPose; }
set { m_SkeletonController.editBindPose = value; }
}
public ISkeletonStyle skeletonStyle
{
get { return m_SkeletonController.styleOverride; }
set { m_SkeletonController.styleOverride = value; }
}
public override int defaultControlID
{
get { return 0; }
}
public BoneCache hoveredBone
{
get { return m_SkeletonController.hoveredBone; }
}
public SkeletonCache skeleton
{
get { return m_SkeletonController.skeleton; }
private set { m_SkeletonController.skeleton = value; }
}
internal override void OnCreate()
{
m_SkeletonController = new SkeletonController();
m_SkeletonController.view = new SkeletonView(new GUIWrapper());
m_SkeletonController.view.InvalidID = 0;
m_SkeletonController.selection = skinningCache.skeletonSelection;
m_SkeletonToolView = new SkeletonToolView();
m_SkeletonToolView.onBoneNameChanged += BoneNameChanged;
m_SkeletonToolView.onBoneDepthChanged += BoneDepthChanged;
m_RectBoneSelector.selection = skinningCache.skeletonSelection;
m_RectSelectionTool.rectSelector = m_RectBoneSelector;
m_RectSelectionTool.cacheUndo = skinningCache;
m_RectSelectionTool.onSelectionUpdate += () =>
{
skinningCache.events.boneSelectionChanged.Invoke();
};
m_UnselectTool.cacheUndo = skinningCache;
m_UnselectTool.selection = skinningCache.skeletonSelection;
m_UnselectTool.onUnselect += () =>
{
skinningCache.events.boneSelectionChanged.Invoke();
};
}
public override void Initialize(LayoutOverlay layout)
{
m_SkeletonToolView.Initialize(layout);
}
protected override void OnActivate()
{
SetupSkeleton(skinningCache.GetEffectiveSkeleton(skinningCache.selectedSprite));
UpdateBoneInspector();
skinningCache.events.boneSelectionChanged.AddListener(BoneSelectionChanged);
skinningCache.events.selectedSpriteChanged.AddListener(SelectedSpriteChanged);
skinningCache.events.skinningModeChanged.AddListener(SkinningModeChanged);
skinningCache.events.boneDepthChanged.AddListener(BoneDataChanged);
skinningCache.events.boneNameChanged.AddListener(BoneDataChanged);
skeletonStyle = null;
}
protected override void OnDeactivate()
{
m_SkeletonToolView.Hide();
m_SkeletonController.Reset();
skinningCache.events.boneSelectionChanged.RemoveListener(BoneSelectionChanged);
skinningCache.events.selectedSpriteChanged.RemoveListener(SelectedSpriteChanged);
skinningCache.events.skinningModeChanged.RemoveListener(SkinningModeChanged);
skinningCache.events.boneDepthChanged.RemoveListener(BoneDataChanged);
skinningCache.events.boneNameChanged.RemoveListener(BoneDataChanged);
skeletonStyle = null;
}
void BoneDataChanged(BoneCache bone)
{
if(m_SkeletonToolView.target == bone)
m_SkeletonToolView.Update(bone.name, Mathf.RoundToInt(bone.depth));
}
private void SelectedSpriteChanged(SpriteCache sprite)
{
SetupSkeleton(skinningCache.GetEffectiveSkeleton(sprite));
}
private void BoneSelectionChanged()
{
UpdateBoneInspector();
}
private void UpdateBoneInspector()
{
var selectedBone = skinningCache.skeletonSelection.activeElement;
var selectionCount = skinningCache.skeletonSelection.Count;
m_SkeletonToolView.Hide();
if (enableBoneInspector && selectedBone != null && selectionCount == 1)
{
m_SkeletonToolView.Update(selectedBone.name, Mathf.RoundToInt(selectedBone.depth));
m_SkeletonToolView.Show(selectedBone);
}
}
private void SkinningModeChanged(SkinningMode mode)
{
SetupSkeleton(skinningCache.GetEffectiveSkeleton(skinningCache.selectedSprite));
}
private void SetupSkeleton(SkeletonCache sk)
{
m_RectBoneSelector.bones = null;
skeleton = sk;
if (skeleton != null)
m_RectBoneSelector.bones = skeleton.bones;
}
protected override void OnGUI()
{
m_SkeletonController.view.defaultControlID = 0;
if (skeleton != null && mode != SkeletonMode.Disabled)
{
m_RectSelectionTool.OnGUI();
m_SkeletonController.view.defaultControlID = m_RectSelectionTool.controlID;
}
m_SkeletonController.OnGUI();
m_UnselectTool.OnGUI();
}
private void BoneNameChanged(BoneCache selectedBone, string name)
{
if (selectedBone != null)
{
if (string.Compare(selectedBone.name, name) == 0)
return;
if(string.IsNullOrEmpty(name) || string.IsNullOrWhiteSpace(name))
m_SkeletonToolView.Update(selectedBone.name, Mathf.RoundToInt(selectedBone.depth));
else
{
using (skinningCache.UndoScope(TextContent.boneName))
{
selectedBone.name = name;
skinningCache.events.boneNameChanged.Invoke(selectedBone);
}
}
}
}
private void BoneDepthChanged(BoneCache selectedBone, int depth)
{
if (selectedBone != null)
{
if (Mathf.RoundToInt(selectedBone.depth) == depth)
return;
using (skinningCache.UndoScope(TextContent.boneDepth))
{
selectedBone.depth = depth;
skinningCache.events.boneDepthChanged.Invoke(selectedBone);
}
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: acc0de355e663464684a1b81871fe30b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,46 @@
using System;
using UnityEditor.U2D.Layout;
namespace UnityEditor.U2D.Animation
{
internal class SkeletonToolView
{
private BoneInspectorPanel m_BoneInspectorPanel;
public event Action<BoneCache, string> onBoneNameChanged = (b, s) => {};
public event Action<BoneCache, int> onBoneDepthChanged = (b, i) => {};
public SkeletonToolView()
{
m_BoneInspectorPanel = BoneInspectorPanel.GenerateFromUXML();
m_BoneInspectorPanel.onBoneNameChanged += (b, n) => onBoneNameChanged(b, n);
m_BoneInspectorPanel.onBoneDepthChanged += (b, d) => onBoneDepthChanged(b, d);
Hide();
}
public void Initialize(LayoutOverlay layout)
{
layout.rightOverlay.Add(m_BoneInspectorPanel);
}
public void Show(BoneCache target)
{
m_BoneInspectorPanel.target = target;
m_BoneInspectorPanel.SetHiddenFromLayout(false);
}
public BoneCache target => m_BoneInspectorPanel.target;
public void Hide()
{
m_BoneInspectorPanel.HidePanel();
m_BoneInspectorPanel.target = null;
}
public void Update(string name, int depth)
{
m_BoneInspectorPanel.boneName = name;
m_BoneInspectorPanel.boneDepth = depth;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 26ec4641af523f44f8f62994a423b3b4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,68 @@
using System;
using UnityEngine;
namespace UnityEditor.U2D.Animation
{
internal class SkeletonToolWrapper : BaseTool
{
private SkeletonTool m_SkeletonTool;
private SkeletonMode m_Mode;
public SkeletonTool skeletonTool
{
get { return m_SkeletonTool; }
set { m_SkeletonTool = value; }
}
public SkeletonMode mode
{
get { return m_Mode; }
set { m_Mode = value; }
}
public bool editBindPose { get; set; }
public override int defaultControlID
{
get
{
Debug.Assert(skeletonTool != null);
return skeletonTool.defaultControlID;
}
}
protected override void OnActivate()
{
Debug.Assert(skeletonTool != null);
skeletonTool.enableBoneInspector = true;
skeletonTool.Activate();
}
protected override void OnDeactivate()
{
skeletonTool.enableBoneInspector = false;
skeletonTool.Deactivate();
}
private SkeletonMode OverrideMode()
{
var modeOverride = mode;
//Disable SkeletonManipulation if character exists and we are in SpriteSheet mode
if (skinningCache.mode == SkinningMode.SpriteSheet && skinningCache.hasCharacter && editBindPose)
modeOverride = SkeletonMode.Selection;
return modeOverride;
}
protected override void OnGUI()
{
Debug.Assert(skeletonTool != null);
skeletonTool.mode = OverrideMode();
skeletonTool.editBindPose = editBindPose;
skeletonTool.DoGUI();
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4d7d16e2d9869a84190616f30b11be2d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: