So, I have finally got SkinExample working! See my modified code!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine;
using Spine.Unity;
using AC;
public class SkinExample : MonoBehaviour
{
// Drag your skeleton onto this component slot in Unity:
private SkeletonAnimation skeletonAnimation;
private Skeleton skeleton;
// Start is called before the first frame update
void Start()
{
//try {
// skeletonAnimation = GetComponent<SkeletonAnimation>();
//} catch (MissingComponentException e) {
// Debug.LogWarning(e.Message);
// skeletonAnimation = gameObject.AddComponent<SkeletonAnimation>();
//}
//if(skeletonAnimation != null) {
// spineAnimationState = skeletonAnimation.AnimationState;
// spineAnimationState.Data.DefaultMix = 0.01f;
// skeleton = skeletonAnimation.Skeleton;
// Debug.Log((skeleton == null) ? name + " skeleton null!" : name + " skeleton here!");
//}
print("Start");
ChangeSkin();
//prepare skin function
//newSkin = new Skin("new-skin"); // 1. Create a new empty skin
//newSkin.AddSkin(skeleton.Data.FindSkin("Clothes/Suit")); // 2. Add items
//newSkin.AddSkin(skeleton.Data.FindSkin("Accessories/BriefcaseL")); // 2. Add items
}
Skin newSkin;
/// <summary>
/// Info found here: http://en.esotericsoftware.com/spine-runtime-skins#Skin-changes
/// </summary>
public void ChangeSkin()
{
Invoke("DelayedChange", 10f);
}
public void DelayedChange()
{
print("CHANGED SKIN");
skeletonAnimation = KickStarter.player.GetComponentInChildren<SkeletonAnimation>();
skeleton = skeletonAnimation.Skeleton;
newSkin = new Skin("new-skin"); // 1. Create a new empty skin
newSkin.AddSkin(skeleton.Data.FindSkin("Clothes/Suit")); // 2. Add items
newSkin.AddSkin(skeleton.Data.FindSkin("Accessories/BriefcaseL")); // 2. Add items
print("Update Skin " + skeletonAnimation.transform.position.x);
skeleton.SetSkin(newSkin); // 1. Set the active skin
skeleton.SetSlotsToSetupPose();
//skeletonAnimation.AnimationState.Apply(skeleton); // 3. Use AnimationState to set attachments active in the current movement.
// 4. Set attachments that were manually changed.
//skel.skeleton.SetSkin("Clothes/Suit");
//skel.skeleton.SetSlotsToSetupPose(); // 2. Use setup pose to set base attachments.
//spineAnimationState.Apply(skel.skeleton); // 3. Use AnimationState to set attachments active in the current movement.
// 4. Set attachments that were manually changed.
}
public void LateUpdate()
{
DelayedChange();
if (newSkin != null)
{
//newSkin = new Skin("new-skin"); // 1. Create a new empty skin
//newSkin.AddSkin(skeleton.Data.FindSkin("Clothes/Suit")); // 2. Add items
//newSkin.AddSkin(skeleton.Data.FindSkin("Accessories/BriefcaseL")); // 2. Add items
//print("Update Skin " + skeletonAnimation.transform.position.x);
//skeleton.SetSkin(newSkin); // 1. Set the active skin
//skeleton.SetSlotsToSetupPose();
//skeletonAnimation.AnimationState.Apply(skeleton); // 3. Use AnimationState to set attachments active in the current movement.
}
}
}
If you are therefore able to help me turn this into a CustomActionScript that would be so handy! We can stick it on the WIKI!
I need to be able to turn on and off particular skins on scene start and within player interactions, ie turn off briefcase accessory and then ad it on pick up briefcase when wearing Suit etc. That doable?
The DelayedChange function is being called in three ways - in Start, LateUpdate, and ChangeSkin. Are you invoking ChangeSkin, and are the calls from Start/LateUpdate necessary?
Ok ignore last post, it does work. Adapted code below. I can call event and set change skins. Is there a way to make this custom action script and call particular skin rather than it being in the script?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine;
using Spine.Unity;
using AC;
public class SkinExample : MonoBehaviour
{
// Drag your skeleton onto this component slot in Unity:
private SkeletonAnimation skeletonAnimation;
private Skeleton skeleton;
newSkin = new Skin("new-skin"); // 1. Create a new empty skin
newSkin.AddSkin(skeleton.Data.FindSkin("Clothes/Suit")); // 2. Add items
newSkin.AddSkin(skeleton.Data.FindSkin("Accessories/BriefcaseL")); // 2. Add items
print("Update Skin " + skeletonAnimation.transform.position.x);
skeleton.SetSkin(newSkin); // 1. Set the active skin
skeleton.SetSlotsToSetupPose();
//skeletonAnimation.AnimationState.Apply(skeleton); // 3. Use AnimationState to set attachments active in the current movement.
// 4. Set attachments that were manually changed.
//skel.skeleton.SetSkin("Clothes/Suit");
//skel.skeleton.SetSlotsToSetupPose(); // 2. Use setup pose to set base attachments.
//spineAnimationState.Apply(skel.skeleton); // 3. Use AnimationState to set attachments active in the current movement.
// 4. Set attachments that were manually changed.
}
ok so, it works with the Start and Late update functions:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine;
using Spine.Unity;
using AC;
public class SkinExample : MonoBehaviour
{
// Drag your skeleton onto this component slot in Unity:
private SkeletonAnimation skeletonAnimation;
private Skeleton skeleton;
// Start is called before the first frame update
void Start()
{
//try {
// skeletonAnimation = GetComponent<SkeletonAnimation>();
//} catch (MissingComponentException e) {
// Debug.LogWarning(e.Message);
// skeletonAnimation = gameObject.AddComponent<SkeletonAnimation>();
//}
//if(skeletonAnimation != null) {
// spineAnimationState = skeletonAnimation.AnimationState;
// spineAnimationState.Data.DefaultMix = 0.01f;
// skeleton = skeletonAnimation.Skeleton;
// Debug.Log((skeleton == null) ? name + " skeleton null!" : name + " skeleton here!");
//}
print("Start");
ChangeSkin();
//prepare skin function
//newSkin = new Skin("new-skin"); // 1. Create a new empty skin
//newSkin.AddSkin(skeleton.Data.FindSkin("Clothes/Suit")); // 2. Add items
//newSkin.AddSkin(skeleton.Data.FindSkin("Accessories/BriefcaseL")); // 2. Add items
}
Skin newSkin;
/// <summary>
/// Info found here: http://en.esotericsoftware.com/spine-runtime-skins#Skin-changes
/// </summary>
public void ChangeSkin()
{
Invoke("DelayedChange", 10f);
}
public void DelayedChange()
{
print("CHANGED SKIN");
skeletonAnimation = KickStarter.player.GetComponentInChildren<SkeletonAnimation>();
skeleton = skeletonAnimation.Skeleton;
newSkin = new Skin("new-skin"); // 1. Create a new empty skin
newSkin.AddSkin(skeleton.Data.FindSkin("Clothes/Suit")); // 2. Add items
newSkin.AddSkin(skeleton.Data.FindSkin("Accessories/BriefcaseL")); // 2. Add items
print("Update Skin " + skeletonAnimation.transform.position.x);
skeleton.SetSkin(newSkin); // 1. Set the active skin
skeleton.SetSlotsToSetupPose();
//skeletonAnimation.AnimationState.Apply(skeleton); // 3. Use AnimationState to set attachments active in the current movement.
// 4. Set attachments that were manually changed.
//skel.skeleton.SetSkin("Clothes/Suit");
//skel.skeleton.SetSlotsToSetupPose(); // 2. Use setup pose to set base attachments.
//spineAnimationState.Apply(skel.skeleton); // 3. Use AnimationState to set attachments active in the current movement.
// 4. Set attachments that were manually changed.
}
public void LateUpdate()
{
DelayedChange();
if (newSkin != null)
{
//newSkin = new Skin("new-skin"); // 1. Create a new empty skin
//newSkin.AddSkin(skeleton.Data.FindSkin("Clothes/Suit")); // 2. Add items
//newSkin.AddSkin(skeleton.Data.FindSkin("Accessories/BriefcaseL")); // 2. Add items
//print("Update Skin " + skeletonAnimation.transform.position.x);
//skeleton.SetSkin(newSkin); // 1. Set the active skin
//skeleton.SetSlotsToSetupPose();
//skeletonAnimation.AnimationState.Apply(skeleton); // 3. Use AnimationState to set attachments active in the current movement.
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine;
using Spine.Unity;
using AC;
public class SkinExample : MonoBehaviour
{
// Drag your skeleton onto this component slot in Unity:
private SkeletonAnimation skeletonAnimation;
private Skeleton skeleton;
Skin newSkin;
/// <summary>
/// Info found here: http://en.esotericsoftware.com/spine-runtime-skins#Skin-changes
/// </summary>
public void ChangeSkin()
{
Invoke("DelayedChange", 10f);
}
public void DelayedChange()
{
print("CHANGED SKIN");
skeletonAnimation = KickStarter.player.GetComponentInChildren<SkeletonAnimation>();
skeleton = skeletonAnimation.Skeleton;
newSkin = new Skin("new-skin"); // 1. Create a new empty skin
newSkin.AddSkin(skeleton.Data.FindSkin("Clothes/Suit")); // 2. Add items
newSkin.AddSkin(skeleton.Data.FindSkin("Accessories/BriefcaseL")); // 2. Add items
print("Update Skin " + skeletonAnimation.transform.position.x);
skeleton.SetSkin(newSkin); // 1. Set the active skin
skeleton.SetSlotsToSetupPose();
//skeletonAnimation.AnimationState.Apply(skeleton); // 3. Use AnimationState to set attachments active in the current movement.
// 4. Set attachments that were manually changed.
//skel.skeleton.SetSkin("Clothes/Suit");
//skel.skeleton.SetSlotsToSetupPose(); // 2. Use setup pose to set base attachments.
//spineAnimationState.Apply(skel.skeleton); // 3. Use AnimationState to set attachments active in the current movement.
// 4. Set attachments that were manually changed.
}
}
Assets/Sleepytime Village/Scripts/CustomActions/ActionSkinSwap.cs(41,34): error CS0119: 'Component.GetComponent<T>()' is a method, which is not valid in the given context
And I'm guessing due t this I cannot place SkinSetter script on the player spritechild
Comments
So, I have finally got SkinExample working! See my modified code!
If you are therefore able to help me turn this into a CustomActionScript that would be so handy! We can stick it on the WIKI!
I need to be able to turn on and off particular skins on scene start and within player interactions, ie turn off briefcase accessory and then ad it on pick up briefcase when wearing Suit etc. That doable?
The DelayedChange function is being called in three ways - in Start, LateUpdate, and ChangeSkin. Are you invoking ChangeSkin, and are the calls from Start/LateUpdate necessary?
Not sure, the script is just on a game object in scene currently
I will want to call change skin i guess?
I got some help with it so I am unsure myself
Remove the Start and LateUpdate functions then, and call ChangeSkin with an Action - does it work?
Not sure what exactly to remove in the script?
If i have done it correctly, it does not change the skin with script modified when calling action
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine;
using Spine.Unity;
using AC;
public class SkinExample : MonoBehaviour
{
// Drag your skeleton onto this component slot in Unity:
private SkeletonAnimation skeletonAnimation;
private Skeleton skeleton;
Skin newSkin;
/// <summary>
/// Info found here: http://en.esotericsoftware.com/spine-runtime-skins#Skin-changes
/// </summary>
public void ChangeSkin()
{
Invoke("DelayedChange", 10f);
}
public void DelayedChange()
{
print("CHANGED SKIN");
skeletonAnimation = KickStarter.player.GetComponentInChildren<SkeletonAnimation>();
skeleton = skeletonAnimation.Skeleton;
newSkin = new Skin("new-skin"); // 1. Create a new empty skin
newSkin.AddSkin(skeleton.Data.FindSkin("Clothes/Suit")); // 2. Add items
newSkin.AddSkin(skeleton.Data.FindSkin("Accessories/BriefcaseL")); // 2. Add items
print("Update Skin " + skeletonAnimation.transform.position.x);
skeleton.SetSkin(newSkin); // 1. Set the active skin
skeleton.SetSlotsToSetupPose();
//skeletonAnimation.AnimationState.Apply(skeleton); // 3. Use AnimationState to set attachments active in the current movement.
// 4. Set attachments that were manually changed.
//skel.skeleton.SetSkin("Clothes/Suit");
//skel.skeleton.SetSlotsToSetupPose(); // 2. Use setup pose to set base attachments.
//spineAnimationState.Apply(skel.skeleton); // 3. Use AnimationState to set attachments active in the current movement.
// 4. Set attachments that were manually changed.
}
}
Hi Chris, almost there except it updates and reverts back after first setting the skin as soon as I move the Player
See video:
https://www.dropbox.com/s/p1znwtuzatcwspu/WalkRemovesSkin.mov?dl=0
You should be getting the same issue with your original script, in that case - the Action is just adapting that code.
ok so, it works with the Start and Late update functions:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine;
using Spine.Unity;
using AC;
public class SkinExample : MonoBehaviour
{
}
but not without them it seems?
As when i change to this code it doesn't work:
Create and attach to your Player a new C# file, SkinSetter:
Then update the Action:
Assets/Sleepytime Village/Scripts/CustomActions/ActionSkinSwap.cs(41,34): error CS0119: 'Component.GetComponent<T>()' is a method, which is not valid in the given context
And I'm guessing due t this I cannot place SkinSetter script on the player spritechild
I think that some other code runs after and puts it back to the default skin
It happens in SetCurrentDirection?
Fixed a typo in the Action code.
It works!