private void PrepareBones(SpriteSkin spriteSkin) { Debug.Assert(spriteSkin != null); Debug.Assert(view.CanLayout()); if (!spriteSkin.isActiveAndEnabled || !spriteSkin.isValid || !spriteSkin.spriteRenderer.enabled) { return; } var sprite = spriteSkin.spriteRenderer.sprite; var boneTransforms = spriteSkin.boneTransforms; var spriteBones = spriteSkin.spriteBones; var alpha = 1f; for (int i = 0; i < boneTransforms.Length; ++i) { var boneTransform = boneTransforms[i]; if (boneTransform == null || m_BoneData.ContainsKey(boneTransform)) { continue; } var bone = spriteBones[i]; if (view.IsActionHot(SkeletonAction.None)) { m_CachedBones.Add(boneTransform); } m_BoneData.Add(boneTransform, new Vector2(bone.length, alpha)); } }
private void ResetBoundsIfNeeded(SpriteSkin spriteSkin) { if (spriteSkin.isValid && spriteSkin.bounds == new Bounds()) { spriteSkin.CalculateBounds(); } }
public void Setup() { var go = new GameObject("TestObject"); m_SkinnedSprite = Resources.Load <Sprite>("bird"); m_SpriteSkin = go.AddComponent <SpriteSkin>(); m_SpriteSkin.spriteRenderer.sprite = m_SkinnedSprite; m_SpriteSkin.CreateBoneHierarchy(); m_SkeletonView = Substitute.For <ISkeletonView>(); m_SkeletonView.hotBoneID.Returns(x => m_HotBoneID); m_SkeletonView.hoveredBoneID.Returns(x => m_HoveredBoneID); m_SkeletonView.hoveredBodyID.Returns(x => m_HoveredBodyID); m_SkeletonView.hoveredJointID.Returns(x => m_HoveredJointID); m_SkeletonView.hoveredTailID.Returns(x => m_HoveredTailID); m_SkeletonView.IsActionHot(Arg.Any <SkeletonAction>()).Returns(x => m_HotAction == (SkeletonAction)x[0]); m_SkeletonView.CanLayout().Returns(x => true); m_Undo = Substitute.For <IUndo>(); m_BoneGizmoToggle = Substitute.For <IBoneGizmoToggle>(); m_BoneGizmoToggle.enableGizmos.Returns(x => true); m_BoneGizmoController = new BoneGizmoController(m_SkeletonView, m_Undo, m_BoneGizmoToggle); m_HotBoneID = 0; m_HoveredBodyID = 0; m_HoveredBoneID = 0; m_HoveredJointID = 0; m_HoveredTailID = 0; m_HotAction = SkeletonAction.None; }
public void Setup() { EditorWindow.GetWindow <SceneView>(); s_SceneView = SceneView.sceneViews[0] as SceneView; s_SceneView.position = new Rect(60f, 90f, 640f, 480f); s_SceneView.in2DMode = true; s_SceneView.pivot = new Vector3(0f, 0f, -10f); s_SceneView.rotation = Quaternion.identity; s_SceneView.size = 6.0f; s_SceneView.orthographic = true; s_SceneView.Focus(); var go = new GameObject("TestObject"); riggedSprite = Resources.Load <Sprite>("bird"); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(riggedSprite)); m_SpriteSkin = go.AddComponent <SpriteSkin>(); m_SpriteSkin.spriteRenderer.sprite = riggedSprite; m_SpriteSkin.CreateBoneHierarchy(); IBoneGizmoToggle boneGizmoToggle = Substitute.For <IBoneGizmoToggle>(); boneGizmoToggle.enableGizmos.Returns(x => { return(true); }); BoneGizmo.instance.Initialize(); BoneGizmo.instance.boneGizmoController.boneGizmoToggle = boneGizmoToggle; }
public void Setup() { riggedSprite = AssetDatabase.LoadAssetAtPath <Sprite>("Assets/Temp/bird.png"); staticSprite = AssetDatabase.LoadAssetAtPath <Sprite>("Assets/Temp/star.png"); m_SpriteSkin = new GameObject("TestObject1").AddComponent <SpriteSkin>(); m_SpriteSkin.spriteRenderer.sprite = riggedSprite; m_SpriteSkin.CreateBoneHierarchy(); }
public void OnEnable() { m_SpriteKey = serializedObject.FindProperty("m_SpriteKey"); m_LabelHash = serializedObject.FindProperty("m_labelHash"); m_CategoryHash = serializedObject.FindProperty("m_CategoryHash"); m_SpriteSkin = (target as SpriteResolver).GetComponent <SpriteSkin>(); UpdateSpriteLibrary(); spriteResolver.onDeserializedCallback += SpriteResolverDeserializedCallback; }
public void Setup() { riggedSprite = Resources.Load <Sprite>("bird"); staticSprite = Resources.Load <Sprite>("star"); m_SpriteSkin = new GameObject("TestObject1").AddComponent <SpriteSkin>(); m_SpriteSkin.spriteRenderer.sprite = riggedSprite; m_SpriteSkin.CreateBoneHierarchy(); }
public void OnEnable() { m_SpriteCategoryHash = serializedObject.FindProperty("m_CategoryHash"); m_SpritelabelHash = serializedObject.FindProperty("m_labelHash"); m_SpriteSkin = (target as SpriteResolver).GetComponent <SpriteSkin>(); m_PreviousCategoryHash = SpriteResolver.ConvertFloatToInt(m_SpriteCategoryHash.floatValue); m_PreviouslabelHash = SpriteResolver.ConvertFloatToInt(m_SpritelabelHash.floatValue); UpdateSpriteLibrary(); }
private void AssertDeformation(SpriteSkin spriteSkin, Vector3[] expectedVertices) { var deformedVertices = new NativeArray <Vector3>(spriteSkin.spriteRenderer.sprite.GetVertexCount(), Allocator.Persistent); DeformJob(spriteSkin, deformedVertices).Complete(); for (var i = 0; i < deformedVertices.Length; ++i) { Assert.That(deformedVertices[i], Is.EqualTo(expectedVertices[i]).Using(vec3Compare)); } deformedVertices.Dispose(); }
private void OnEnable() { m_SpriteSkin = (SpriteSkin)target; m_RootBoneProperty = serializedObject.FindProperty("m_RootBone"); m_BoneTransformsProperty = serializedObject.FindProperty("m_BoneTransforms"); m_BoundsProperty = serializedObject.FindProperty("m_Bounds"); m_CurrentSprite = m_SpriteSkin.spriteRenderer.sprite; m_BoundsHandle.axes = BoxBoundsHandle.Axes.X | BoxBoundsHandle.Axes.Y; m_BoundsHandle.SetColor(s_BoundingBoxHandleColor); SetupReorderableList(); Undo.undoRedoPerformed += UndoRedoPerformed; }
private JobHandle DeformJob(SpriteSkin spriteSkin, NativeArray <Vector3> deformedVertices) { var sprite = spriteSkin.spriteRenderer.sprite; var bindPoses = sprite.GetBindPoses(); var boneWeights = sprite.GetBoneWeights(); var transformMatrices = new NativeArray <Matrix4x4>(spriteSkin.boneTransforms.Length, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); for (int i = 0; i < spriteSkin.boneTransforms.Length; ++i) { transformMatrices[i] = spriteSkin.boneTransforms[i].localToWorldMatrix; } return(SpriteSkinUtility.Deform(sprite.GetVertexAttribute <Vector3>(VertexAttribute.Position), boneWeights, spriteSkin.transform.worldToLocalMatrix, bindPoses, transformMatrices, deformedVertices)); }
private SpriteSkin parentSkin; //The parent object's SpriteSkin component. Used only by child objects. //During start, find the SpriteRenderer and load all spritesheet frames into the array. //Again, spritesheets need to be in the Resources folder for the Resources.LoadAll to work. void Start() { if (spriteRenderer == null) { spriteRenderer = GetComponentInParent <SpriteRenderer>(); //Set spriteRenderer to current sprite's renderer. } if (newSprite != null) { newSpritesheet = Resources.LoadAll <Sprite>(folderPath + newSprite.name); //Load all sprites within newSpritesheet. } if (isChildSprite == true) { parentSkin = transform.parent.GetComponent <SpriteSkin>(); //Get the base sprite's SpriteSkin component if this is a child sprite. } }
private void AssertDeformation(SpriteSkin spriteSkin, float3[] expectedVertices) { var deformedVertices = new NativeArray <Vector3>(spriteSkin.spriteRenderer.sprite.GetVertexCount(), Allocator.Temp); DeformJob(spriteSkin, deformedVertices); for (var i = 0; i < deformedVertices.Length; ++i) { var v3 = deformedVertices[i]; var f3 = new float3(v3.x, v3.y, v3.z); Assert.That(f3, Is.EqualTo(expectedVertices[i]).Using(float3Compare)); } deformedVertices.Dispose(); }
private UnityEngine.U2D.SpriteBone[] GetSpriteBones(SpriteSkin spriteSkin) { Debug.Assert(spriteSkin.isValid); var sprite = spriteSkin.spriteRenderer.sprite; UnityEngine.U2D.SpriteBone[] spriteBones; if (!m_SpriteBones.TryGetValue(sprite, out spriteBones)) { spriteBones = sprite.GetBones(); m_SpriteBones[sprite] = sprite.GetBones(); } return(spriteBones); }
private void OnEnable() { m_SpriteSkin = (SpriteSkin)target; m_RootBoneProperty = serializedObject.FindProperty("m_RootBone"); #if ENABLE_ANIMATION_PERFORMANCE m_UseBatching = serializedObject.FindProperty("m_UseBatching"); #endif m_BoneTransformsProperty = serializedObject.FindProperty("m_BoneTransforms"); m_AlwaysUpdateProperty = serializedObject.FindProperty("m_AlwaysUpdate"); m_CurrentSprite = m_SpriteSkin.spriteRenderer.sprite; m_BoundsHandle.axes = BoxBoundsHandle.Axes.X | BoxBoundsHandle.Axes.Y; m_BoundsHandle.SetColor(s_BoundingBoxHandleColor); SetupReorderableList(); Undo.undoRedoPerformed += UndoRedoPerformed; }
private void AssertDeformAABB(SpriteSkin spriteSkin, Bounds expectedBounds) { var deformedVertices = new NativeArray <Vector3>(spriteSkin.spriteRenderer.sprite.GetVertexCount(), Allocator.Persistent); var minMax = new NativeArray <Vector3>(2, Allocator.Persistent); SpriteSkinUtility.CalculateBounds(deformedVertices, minMax, DeformJob(spriteSkin, deformedVertices)).Complete(); var newBounds = new Bounds(); newBounds.SetMinMax(minMax[0], minMax[1]); Assert.That(newBounds.center, Is.EqualTo(expectedBounds.center).Using(vec3Compare)); Assert.That(newBounds.extents, Is.EqualTo(expectedBounds.extents).Using(vec3Compare)); deformedVertices.Dispose(); minMax.Dispose(); }
void Awake() { if (Target == null) { Target = GetComponent <SpriteSkin>(); } if (Renderer == null) { Renderer = GetComponent <SpriteRenderer>(); } if (Target.DeformedVerticesAvailable) { ref var vertices = ref Target.DeformedVertices; Target_OnSkinChanging(ref vertices); Target.FinishDeformation(ref vertices); }
public void Setup() { var go = new GameObject("TestObject"); m_SkinnedSprite = AssetDatabase.LoadAssetAtPath <Sprite>("Assets/Temp/bird.png"); m_SpriteSkin = go.AddComponent <SpriteSkin>(); m_SpriteSkin.spriteRenderer.sprite = m_SkinnedSprite; m_SpriteSkin.CreateBoneHierarchy(); m_BoneGizmoView = Substitute.For <IBoneGizmoView>(); m_BoneGizmoView.IsBoneVisible(Arg.Any <Transform>(), Arg.Any <float>(), Arg.Any <float>()).Returns(x => { return(true); }); m_BoneGizmoView.IsActionHot(BoneGizmoAction.None).Returns(x => { return(true); }); m_BoneGizmoView.CanLayout().Returns(x => { return(true); }); m_UndoObject = Substitute.For <IUndoObject>(); m_BoneGizmoToggle = Substitute.For <IBoneGizmoToggle>(); m_BoneGizmoToggle.enableGizmos.Returns(x => { return(true); }); m_BoneGizmoController = new BoneGizmoController(m_BoneGizmoView, m_UndoObject, m_BoneGizmoToggle); }
private float AlphaFromSpriteSkin(SpriteSkin spriteSkin) { Debug.Assert(spriteSkin != null); Debug.Assert(spriteSkin.spriteBones != null); var spriteBones = spriteSkin.spriteBones; var size = m_BoneGizmoView.GetHandleSize(spriteSkin.transform.position); var scaleFactorSqr = 1f; for (int i = 0; i < spriteBones.Length; ++i) { var spriteBone = spriteBones[i]; var transform = spriteSkin.boneTransforms[i]; var endPoint = transform.TransformPoint(Vector3.right * spriteBone.length); scaleFactorSqr = Mathf.Max(scaleFactorSqr, (transform.position - endPoint).sqrMagnitude); } var scaleFactor = Mathf.Sqrt(scaleFactorSqr); return(AlphaFromSize(size, kFadeStart * scaleFactor, kFadeEnd * scaleFactor)); }
private void Rebind() { foreach (var t in targets) { var spriteSkin = t as SpriteSkin; if (spriteSkin.spriteRenderer.sprite == null || spriteSkin.rootBone == null) { continue; } var spriteBones = spriteSkin.spriteRenderer.sprite.GetBones(); var transforms = new Transform[spriteBones.Length]; if (SpriteSkin.GetSpriteBonesTransforms(spriteBones, spriteSkin.rootBone, transforms)) { spriteSkin.boneTransforms = transforms; } ResetBoundsIfNeeded(spriteSkin); } serializedObject.Update(); m_NeedsRebind = false; }
private void InstantiateDeathBody() { for (int i = 0; i < bodyParts.Length; i++) { GameObject gO = Instantiate(bodyParts[i].gameObject, bodyParts[i].gameObject.transform.position, bodyParts[i].transform.rotation); gO.transform.localScale = mainBody.transform.localScale; SpriteSkin ss = gO.GetComponent <SpriteSkin>(); if (ss != null) { Destroy(ss); } Collider2D col = gO.GetComponent <Collider2D>(); if (col != null) { Destroy(col); } CircleCollider2D pCol = gO.AddComponent <CircleCollider2D>(); Rigidbody2D rb = gO.AddComponent <Rigidbody2D>(); rb.AddForce((gO.transform.position - forceTransform.position).normalized * 5.0f, ForceMode2D.Impulse); instantiated.Add(gO); } }
private void DeformJob(SpriteSkin spriteSkin, NativeArray <Vector3> deformableVertices) { SpriteSkinUtility.Deform(spriteSkin.spriteRenderer.sprite, spriteSkin.transform.worldToLocalMatrix, m_SpriteSkin.boneTransforms, ref deformableVertices); }
void OnEnable() { m_SpriteSkin = (SpriteSkin)target; m_RootBoneProperty = serializedObject.FindProperty("m_RootBone"); m_BoneTransformsProperty = serializedObject.FindProperty("m_BoneTransforms"); }
void Start() { _skin = GetComponent <SpriteSkin>(); _eyeLocalRestPosition = _skin.boneTransforms[eyeBoneIndex].localPosition; }