new character

This commit is contained in:
2022-03-29 12:28:30 +03:00
parent c10f3421f5
commit a71043121f
791 changed files with 99475 additions and 45 deletions

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 8cbf280ac32285b43ad7edce04a0df2f
folderAsset: yes
timeCreated: 1573240507
licenseType: Store
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,135 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace CartoonHeroes
{
[CustomEditor(typeof(SetCharacter))]
[CanEditMultipleObjects]
public class SetCharacterEditor : Editor
{
const int defaultSpace = 8;
public override void OnInspectorGUI()
{
SetCharacter setCharacter = (SetCharacter)target;
serializedObject.Update();
GUILayout.Space(defaultSpace);
setCharacter.characterRoot = EditorGUILayout.ObjectField("Character Root", setCharacter.characterRoot, typeof(Transform), true) as Transform;
GUILayout.Space(defaultSpace);
if(GUILayout.Button("Add Item Group"))
{
if(setCharacter.itemGroups == null)
{
setCharacter.itemGroups = new SetCharacter.ItemGroup[1];
}
else
{
SetCharacter.ItemGroup[] itemGroups_Temp = new SetCharacter.ItemGroup[setCharacter.itemGroups.Length];
itemGroups_Temp = setCharacter.itemGroups.Clone() as SetCharacter.ItemGroup[];
setCharacter.itemGroups = new SetCharacter.ItemGroup[setCharacter.itemGroups.Length + 1];
for(int i = 0; i < itemGroups_Temp.Length; i++)
{
setCharacter.itemGroups[i] = itemGroups_Temp[i];
}
}
SetCharacter.ItemGroup newItemGroup = setCharacter.itemGroups[setCharacter.itemGroups.Length - 1] = new SetCharacter.ItemGroup();
newItemGroup.name = "New Item Group " + (setCharacter.itemGroups.Length-1).ToString();
newItemGroup.items = new SetCharacter.Item[1];
newItemGroup.slots = 1;
}
if (setCharacter.itemGroups != null && setCharacter.itemGroups.Length > 0)
{
GUILayout.Space(defaultSpace);
for (int i = 0; i < setCharacter.itemGroups.Length; i++)
{
//GUILayout.Label(itemGroups[i].name);
setCharacter.itemGroups[i].name = EditorGUILayout.TextField("Group Name: ", setCharacter.itemGroups[i].name);
setCharacter.itemGroups[i].slots = EditorGUILayout.IntField("Slots", setCharacter.itemGroups[i].slots);
setCharacter.itemGroups[i].slots = Mathf.Clamp(setCharacter.itemGroups[i].slots, 1, 100);
if(setCharacter.itemGroups[i].slots != setCharacter.itemGroups[i].items.Length)
{
SetCharacter.Item[] items_Temp = new SetCharacter.Item[setCharacter.itemGroups[i].items.Length];
items_Temp = setCharacter.itemGroups[i].items.Clone() as SetCharacter.Item[];
setCharacter.itemGroups[i].items = new SetCharacter.Item[setCharacter.itemGroups[i].slots];
for(int n = 0; n < setCharacter.itemGroups[i].items.Length && n < items_Temp.Length; n++)
{
setCharacter.itemGroups[i].items[n] = items_Temp[n];
}
}
for(int n = 0; n < setCharacter.itemGroups[i].items.Length; n++)
{
EditorGUILayout.BeginHorizontal();
if (!setCharacter.HasItem(setCharacter.itemGroups[i], n))
{
if (GUILayout.Button("Add Item"))
{
GameObject addedObj = setCharacter.AddItem(setCharacter.itemGroups[i], n);
Undo.RegisterCreatedObjectUndo(addedObj, "Added Item");
}
}
else
{
if (GUILayout.Button("Remove Item"))
{
List<GameObject> removedObjs = setCharacter.GetRemoveObjList(setCharacter.itemGroups[i], n);
Undo.SetCurrentGroupName("Removed Item");
for(int m = 0; m < removedObjs.Count; m ++)
{
if(removedObjs[m] != null)
{
Undo.DestroyObjectImmediate(removedObjs[m]);
}
}
Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
}
}
if(setCharacter.itemGroups[i] != null && setCharacter.itemGroups[i].items[n] != null)
{
setCharacter.itemGroups[i].items[n].prefab = EditorGUILayout.ObjectField(setCharacter.itemGroups[i].items[n].prefab, typeof(GameObject), true) as GameObject;
}
EditorGUILayout.EndHorizontal();
}
if(GUILayout.Button("Delete Group: " + setCharacter.itemGroups[i].name))
{
SetCharacter.ItemGroup[] itemGroups_Temp = new SetCharacter.ItemGroup[setCharacter.itemGroups.Length - 1];
for (int n = 0; n < i; n++)
{
itemGroups_Temp[n] = setCharacter.itemGroups[n];
}
for(int n = i+1; n < setCharacter.itemGroups.Length; n++)
{
itemGroups_Temp[n - 1] = setCharacter.itemGroups[n];
}
setCharacter.itemGroups = itemGroups_Temp;
}
GUILayout.Space(defaultSpace);
}
}
serializedObject.ApplyModifiedProperties();
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: fd027a1f114b03f468aea62fef4cf034
timeCreated: 1573240657
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,237 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace CartoonHeroes
{
public class SetCharacter : MonoBehaviour
{
public Transform characterRoot;
public ItemGroup[] itemGroups;
const string namePrefix = "Set Character_";
const string hideString = "(Hide)";
public GameObject disabledGraySkeleton;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
[System.Serializable]
public class ItemGroup
{
public string name;
public Item[] items;
public int slots;
}
[System.Serializable]
public class Item
{
public GameObject prefab;
}
public GameObject AddItem(ItemGroup itemGroup, int itemSlot)
{
Item item = itemGroup.items[itemSlot];
GameObject itemInstance = GameObject.Instantiate(item.prefab);
itemInstance.name = itemInstance.name.Substring(0, itemInstance.name.Length - "(Clone)".Length);
RemoveAnimator(itemInstance);
ParentObjectAndBones(itemInstance);
SetGraySkeletonVisibility(!VisibleItems());
return itemInstance;
}
public bool VisibleItems()
{
for(int i = 0; i < itemGroups.Length; i++)
{
for(int n = 0; n < itemGroups[i].items.Length; n++)
{
if(HasItem(itemGroups[i], n))
{
return true;
}
}
}
return false;
}
public void SetGraySkeletonVisibility(bool set)
{
if (!set)
{
Transform[] allCharacterChildren = GetAllCharacterChildren();
for (int i = 0; i < allCharacterChildren.Length; i++)
{
if (allCharacterChildren[i].name.Contains(hideString))
{
disabledGraySkeleton = allCharacterChildren[i].gameObject;
allCharacterChildren[i].gameObject.SetActive(false);
break;
}
}
}
else {
if (disabledGraySkeleton != null)
{
disabledGraySkeleton.SetActive(true);
}
}
}
public bool HasItem(ItemGroup itemGroup, int itemSlot)
{
if (itemGroup.items[itemSlot] != null && itemGroup.items[itemSlot].prefab != null)
{
Transform root = GetRoot();
Transform prefab = itemGroup.items[itemSlot].prefab.transform;
for (int i = 0; i < root.childCount; i++)
{
Transform child = root.GetChild(i);
if (child.name.Contains(prefab.name) && child.name.Contains(namePrefix))
{
return true;
}
}
}
return false;
}
public void ParentObjectAndBones(GameObject itemInstance)
{
Transform[] allCharacterChildren = GetAllCharacterChildren();
Transform[] allItemChildren = itemInstance.GetComponentsInChildren<Transform>();
itemInstance.transform.position = transform.position;
itemInstance.transform.parent = transform;
string[] allItemChildren_NewNames= new string[allItemChildren.Length];
for(int i = 0; i < allItemChildren.Length; i++)
{
//Match and parent bones
for (int n = 0; n < allCharacterChildren.Length; n++)
{
if(allItemChildren[i].name == allCharacterChildren[n].name)
{
MatchTransform(allItemChildren[i], allCharacterChildren[n]);
allItemChildren[i].parent = allCharacterChildren[n];
}
}
//Rename
allItemChildren_NewNames[i] = allItemChildren[i].name;
if (!allItemChildren[i].name.Contains(namePrefix))
{
allItemChildren_NewNames[i] = namePrefix + allItemChildren[i].name;
}
if (!allItemChildren[i].name.Contains(itemInstance.name))
{
allItemChildren_NewNames[i] += "_" + itemInstance.name;
}
}
for(int i = 0; i < allItemChildren.Length; i++)
{
allItemChildren[i].name = allItemChildren_NewNames[i];
}
}
public Transform GetRoot()
{
Transform root;
if (characterRoot == null)
{
root = transform;
}
else
{
root = characterRoot;
}
return root;
}
public Transform[] GetAllCharacterChildren()
{
Transform root = GetRoot();
Transform[] allCharacterChildren = root.GetComponentsInChildren<Transform>();
/*List<Transform> allCharacterChildren_List = new List<Transform>();
for(int i = 0; i < allCharacterChildren.Length; i++){
if(allCharacterChildren[i].GetComponent<SkinnedMeshRenderer>() != null || allCharacterChildren[i].GetComponent<Animator>() != null)
{
continue;
}
allCharacterChildren_List.Add(allCharacterChildren[i]);
}
allCharacterChildren = allCharacterChildren_List.ToArray();*/
return allCharacterChildren;
}
public bool BelongsToItem(Transform obj, ItemGroup itemGroup, int itemSlot)
{
if(obj == null || itemGroup.items[itemSlot].prefab == null)
{
return false;
}
return (obj.name.Contains(namePrefix) && obj.name.Contains(itemGroup.items[itemSlot].prefab.name));
}
public void RemoveAnimator(GameObject item)
{
Animator animator = item.GetComponent<Animator>();
if(animator != null)
{
DestroyImmediate(animator);
}
}
public void MatchTransform(Transform obj, Transform target)
{
obj.position = target.position;
obj.rotation = target.rotation;
}
public List<GameObject> GetRemoveObjList(ItemGroup itemGroup, int itemSlot)
{
Transform[] allChildren = GetAllCharacterChildren();
List<GameObject> removeList = new List<GameObject>();
for (int i = 0; i < allChildren.Length; i++)
{
if(BelongsToItem(allChildren[i], itemGroup, itemSlot))
{
//DestroyImmediate(allChildren[i].gameObject);
removeList.Add(allChildren[i].gameObject);
}
}
SetGraySkeletonVisibility(!VisibleItems());
return removeList;
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 63cbfa81008c7294a85576892c8f674a
timeCreated: 1573221839
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: