I dont even know what happened -_-

This commit is contained in:
2021-12-13 22:14:55 +05:30
parent 3560ff1ef7
commit 2b318387cf
333 changed files with 163323 additions and 37740 deletions

View File

@@ -0,0 +1,41 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using EasyButtons;
public class BulkMeshBoneSwapper : MonoBehaviour
{
public Transform srcRootBone;
[Button]
void Recalculate()
{
SkinnedMeshRenderer[] meshes = GetComponentsInChildren<SkinnedMeshRenderer>();
for (int x = 0; x < meshes.Length; x++)
{
if(meshes[x]==null){Debug.Log("Ignoring null object : " + meshes[x].name);continue;}
// meshes[x].rootBone = srcRootBone;
//target.bones = src.bones;
Transform[] bonesT = new Transform[meshes[x].bones.Length];
for (int i = 0; i < meshes[x].bones.Length; i++)
{
Transform targetBone = meshes[x].bones[i];
if(targetBone==null){continue;}
string targetBoneName = targetBone.name;
foreach (Transform sourceBone in srcRootBone.GetComponentsInChildren<Transform>())
{
if (targetBoneName == sourceBone.name)
{
Debug.Log("Switching bone : " + targetBoneName);
bonesT[i] = sourceBone;
break;
}
}
}
meshes[x].bones = bonesT;
if(meshes[x].sharedMesh==null){Debug.Log("Ignoring null mesh : " + meshes[x].name);continue;}
//meshes[x].sharedMesh.RecalculateNormals();
//meshes[x].sharedMesh.RecalculateBounds();
}
}
}

View File

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

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "Data", menuName = "ScriptableObjects/CharacterPreset", order = 1)]
public class Characters : ScriptableObject
{
[SerializeField]
public CharacterPreset[] characters;
}
[Serializable]
public class CharacterPreset
{
public string name ;
public int characterId ;
}
[Serializable]
public class CharacterObjects
{
[SerializeField]public string name ;
public int id;
public GameObject[] body;
public GameObject[] hair;
public GameObject[] eyeWears;
public GameObject[] tops;
public GameObject[] gloves;
public GameObject[] bottoms;
public GameObject[] shoes;
public CharacterObjects(int _id,string _characterName){
id=_id;
name = _characterName;
}
}

View File

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

View File

@@ -0,0 +1,46 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class EnumSelect : MonoBehaviour
{
public EventTrigger prevBtn;
public EventTrigger nextBtn;
public Text label;
public string[] choices;
public int curIndex;
public string value => choices[curIndex];
public UnityEvent OnValueChanged;
void Start()
{
update();
EventTrigger.Entry entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.PointerDown;
entry.callback.AddListener(OnSelectNext);
nextBtn.triggers.Add(entry);
EventTrigger.Entry entry2 = new EventTrigger.Entry();
entry2.eventID = EventTriggerType.PointerDown;
entry2.callback.AddListener(OnSelectPrev);
prevBtn.triggers.Add(entry2);
}
void OnSelectNext(BaseEventData e){
curIndex = (curIndex < choices.Length-1) ? curIndex+1 : 0;
update();
}
void OnSelectPrev(BaseEventData e){
curIndex = (curIndex > 0) ? curIndex-1 : choices.Length;
update();
}
void update(){
label.text = choices[curIndex];
}
}

View File

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

View File

@@ -5,11 +5,32 @@ using EasyButtons;
public class MeshCombine : MonoBehaviour
{
public SkinnedMeshRenderer target;
public SkinnedMeshRenderer src;
public Transform sourceRootBone;
public Transform[] bones;
[Button]
void Recalculate(){
target.rootBone = src.rootBone;
target.bones = src.bones;
target.rootBone = sourceRootBone;
//target.bones = src.bones;
Transform[] bonesT = new Transform[target.bones.Length];
for(int i = 0; i < target.bones.Length; i++){
Transform targetBone = target.bones[i];
string targetBoneName = targetBone.name;
foreach(Transform sourceBone in sourceRootBone.GetComponentsInChildren<Transform>()){
if(targetBoneName == sourceBone.name){
Debug.Log("Switching bone : " + targetBoneName );
bonesT[i] = sourceBone;
break;
}
}
}
target.bones= bonesT;
bones= target.bones;
target.sharedMesh.RecalculateNormals();
target.sharedMesh.RecalculateBounds();
}
[Button]
void GetSelfRenderer(){
target = GetComponent<SkinnedMeshRenderer>();
}
}

View File

@@ -0,0 +1,106 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using System;
[RequireComponent(typeof(EventTrigger))]
public class ButtonV2 : MonoBehaviour
{
EventTrigger trigger;
public Image image;
public Text text;
[SerializeField]
public BasicUIEffect imageFx;
[SerializeField]
public BasicUIEffect textFx;
public float fxSpeed = 0.1f;
public AudioClip hoverSfx;
public AudioClip selectSfx;
void Start()
{
trigger = GetComponent<EventTrigger>();
EventTrigger.Entry entry1 = new EventTrigger.Entry();
entry1.eventID = EventTriggerType.PointerEnter;
entry1.callback.AddListener(OnMouseEnter);
EventTrigger.Entry entry2 = new EventTrigger.Entry();
entry2.eventID = EventTriggerType.PointerExit;
entry2.callback.AddListener(OnMouseExit);
EventTrigger.Entry entry3 = new EventTrigger.Entry();
entry3.eventID = EventTriggerType.PointerDown;
entry3.callback.AddListener((BaseEventData e)=>{AudioSource.PlayClipAtPoint(selectSfx, Vector3.zero); OnMouseExit(e);});
EventTrigger.Entry entry4 = new EventTrigger.Entry();
entry4.eventID = EventTriggerType.PointerUp;
entry4.callback.AddListener(OnMouseEnter);
trigger.triggers.Add(entry1);
trigger.triggers.Add(entry2);
trigger.triggers.Add(entry3);
trigger.triggers.Add(entry4);
if(image!=null)defSizeImg = image.rectTransform.sizeDelta;
if(text!=null)defTextImg = text.rectTransform.sizeDelta;
}
Vector2 defSizeImg;
Vector2 defTextImg;
// Update is called once per frame
void Update()
{
if (active)
{
if (image != null)
{
image.color = Color.Lerp(image.color, imageFx.activeColor, fxSpeed);
image.rectTransform.sizeDelta = Vector2.Lerp(image.rectTransform.sizeDelta, defTextImg * imageFx.activeSize, fxSpeed);
}
if (text != null)
{
text.color = Color.Lerp(text.color, textFx.activeColor, fxSpeed);
text.rectTransform.sizeDelta = Vector2.Lerp(text.rectTransform.sizeDelta, defTextImg * imageFx.activeSize, fxSpeed);
}
}
else
{
if (image != null)
{
image.color = Color.Lerp(image.color, imageFx.idleColor, fxSpeed);
image.rectTransform.sizeDelta = Vector2.Lerp(image.rectTransform.sizeDelta, defTextImg, fxSpeed);
}
if (text != null)
{
text.color = Color.Lerp(text.color, textFx.idleColor, fxSpeed);
text.rectTransform.sizeDelta = Vector2.Lerp(text.rectTransform.sizeDelta, defTextImg, fxSpeed);
}
}
}
bool active = false;
void OnMouseEnter(BaseEventData e)
{
active = true;
if (hoverSfx != null) AudioSource.PlayClipAtPoint(hoverSfx, Vector3.zero);
}
void OnMouseExit(BaseEventData e)
{
active = false;
}
}
[Serializable]
public class BasicUIEffect
{
public Color idleColor;
public Color activeColor;
public float activeSize;
}

View File

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

View File

@@ -0,0 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterCustomizeMenu : MonoBehaviour
{
public CharacterCustomizer character;
public EnumSelect bodySelector;
void Start()
{
bodySelector.OnValueChanged.AddListener(OnBodyChanged);
}
// Update is called once per frame
void Update()
{
}
void OnBodyChanged(){
character.ChangeCharacter(bodySelector.value);
}
}

View File

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

View File

@@ -0,0 +1,92 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterCustomizer : MonoBehaviour
{
[SerializeField] Characters charactersData;
public List<CharacterObjects> characterObjects;
[EasyButtons.Button]
void clearDuplicates(){
List<int> duplicates = new List<int>();
for(int i =0; i < characterObjects.Count; i++){
if(duplicates.Contains(characterObjects[i].id)){
characterObjects.RemoveAt(i);
}else{
duplicates.Add(characterObjects[i].id);
}
}
}
[EasyButtons.Button]
void clearEmptyObjectsRows(){
for(int i =0; i < characterObjects.Count; i++){
bool exist = false;
foreach(CharacterPreset preset in charactersData.characters){
if(preset.characterId == characterObjects[i].id){ exist=true;break;}
}
if(!exist){characterObjects.RemoveAt(i);}
}
}
[EasyButtons.Button]
void refresh(){
validateCharacterData();
}
void OnValidate()
{
validateCharacterData();
}
void validateCharacterData()
{
charactersData = Resources.Load<Characters>("characters");
if (charactersData == null) { Debug.LogError("No Character Data Found!"); return; }
clearEmptyObjectsRows();
foreach(CharacterPreset preset in charactersData.characters){
bool exists = false;
for(int i =0; i < characterObjects.Count; i++){
if(characterObjects[i].id == preset.characterId){
if(characterObjects[i].name != preset.name){characterObjects[i].name=preset.name;}
exists=true;
}
}
if(!exists){characterObjects.Add(new CharacterObjects(preset.characterId,preset.name));}
}
}
public void ChangeCharacter(int characterId){
foreach(CharacterObjects obj in characterObjects){
if(obj.id == characterId){
foreach(GameObject go in obj.body){go.SetActive(true);}
}else{
foreach(GameObject go in obj.body){go.SetActive(false);}
foreach(GameObject go in obj.hair){go.SetActive(false);}
foreach(GameObject go in obj.gloves){go.SetActive(false);}
foreach(GameObject go in obj.eyeWears){go.SetActive(false);}
foreach(GameObject go in obj.tops){go.SetActive(false);}
foreach(GameObject go in obj.bottoms){go.SetActive(false);}
}
}
}
public void ChangeCharacter(string characterName){
ChangeCharacter(GetCharacterId(characterName));
}
public int GetCharacterId(string name){
foreach(CharacterPreset preset in charactersData.characters){
if(preset.name == name){return preset.characterId;}
}
return -1;
}
}

View File

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

View File

@@ -0,0 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class CharacterRotate : MonoBehaviour
{
public EventTrigger trigger;
public Vector3 speed;
public Transform character;
void Start()
{
EventTrigger.Entry entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.Drag;
entry.callback.AddListener(OnMouseDrag);
trigger.triggers.Add(entry);
}
void OnMouseDrag(BaseEventData eventData){
PointerEventData e = (PointerEventData) eventData as PointerEventData;
character.Rotate(speed * e.delta.x);
}
}

View File

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

56
Assets/Scripts/RigSync.cs Normal file
View File

@@ -0,0 +1,56 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using EasyButtons;
public class RigSync : MonoBehaviour
{
public Transform targetRootBone;
public Transform sourceRootBone;
[SerializeField]public List<TransformDic> boneDic;
[Button]
void CalculateDic()
{
boneDic = new List<TransformDic>();
foreach(Transform target in targetRootBone.GetComponentsInChildren<Transform>()){
foreach(Transform souce in sourceRootBone.GetComponentsInChildren<Transform>()){
if(target.name == souce.name){
boneDic.Add(new TransformDic(souce, target));
break;
}
}
}
}
// Update is called once per frame
void LateUpdate()
{
foreach(TransformDic bonePair in boneDic){
bonePair.value.position = Vector3.Lerp(bonePair.value.position, bonePair.key.position + bonePair.offset, 0.1f);
// bonePair.value.rotation = Quaternion.Lerp(bonePair.value.rotation, bonePair.key.rotation, 0.1f);
bonePair.value.rotation = bonePair.key.rotation;
}
}
}
[Serializable]
public class TransformDic{
public string name;
public Transform key;
public Transform value;
public Vector3 offset;
public TransformDic(){
key = null;
value=null;
}
public TransformDic(Transform _key, Transform _value){
name = _key.name;
key=_key;
value=_value;
offset=_value.position - _key.position;
}
}

View File

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