Initial files

This commit is contained in:
2024-04-21 16:38:26 +02:00
parent c69c668ae6
commit cf04700131
554 changed files with 131197 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
using System.Collections;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
public class Downloader : MonoBehaviour
{
public static IEnumerator DownloadText(string url, System.Action<string> callback)
{
Error.Log("Downloading " + url, Color.green);
UnityWebRequest www = UnityWebRequest.Get(url);
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{
Debug.LogError(www.error);
callback?.Invoke("");
}
else
{
callback?.Invoke(www.downloadHandler.text);
}
}
public static IEnumerator DownloadAsset(string url, string path, System.Action<byte[]> callback)
{
Error.Log("Downloading " + url, Color.green);
using UnityWebRequest www = UnityWebRequest.Get(url);
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{
Debug.LogError(www.error);
callback?.Invoke(new byte[0]);
}
else
{
Directory.CreateDirectory(Path.GetDirectoryName(path));
File.WriteAllBytes(path, www.downloadHandler.data);
callback?.Invoke(www.downloadHandler.data);
}
}
}

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 303ecca0d23f1ae43aad031f29d2691c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,110 @@
/* Title : Attribute for show a field if other field is true or false.
* Author : Anth
*/
using UnityEngine;
using UnityEditor;
/// <summary>
/// Atttribute for show a field if other field is true or false.
/// </summary>
[System.AttributeUsage(System.AttributeTargets.Field, Inherited = false, AllowMultiple = true)]
public sealed class ShowIfAttribute : PropertyAttribute
{
public string ConditionalSourceField;
public bool expectedValue;
public bool HideInInspector;
/// <summary>
/// Create the attribute for show a field x if field y is true or false.
/// </summary>
/// <param name="ConditionalSourceField">name of field y type boolean </param>
/// <param name="expectedValue"> what value should have the field y for show the field x</param>
/// <param name="HideInInspector"> if should hide in the inspector or only disable</param>
public ShowIfAttribute(string ConditionalSourceField, bool expectedValue, bool HideInInspector = false)
{
this.ConditionalSourceField = ConditionalSourceField;
this.expectedValue = expectedValue;
this.HideInInspector = HideInInspector;
}
}
[CustomPropertyDrawer(typeof(ShowIfAttribute))]
public class ConditionalHidePropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
#if UNITY_EDITOR
ShowIfAttribute condHAtt = (ShowIfAttribute)attribute;
bool enabled = GetConditionalSourceField(property, condHAtt);
GUI.enabled = enabled;
// if is enable draw the label
if (enabled)
EditorGUI.PropertyField(position, property, label, true);
// if is not enabled but we want not hide it, then draw it disabled
else if (!condHAtt.HideInInspector)
EditorGUI.PropertyField(position, property, label, false);
// else hide it ,dont draw it
else return;
#endif
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
#if UNITY_EDITOR
ShowIfAttribute condHAtt = (ShowIfAttribute)attribute;
bool enabled = GetConditionalSourceField(property, condHAtt);
// if is enable draw the label
if (enabled)
{
return EditorGUI.GetPropertyHeight(property, label, true);
}
// if is not enabled but we want not hide it, then draw it disabled
else
{
if (!condHAtt.HideInInspector)
return EditorGUI.GetPropertyHeight(property, label, false);
// else hide it
else
return -EditorGUIUtility.standardVerticalSpacing; // Oculta el campo visualmente.
}
#else
return 0f;
#endif
}
/// <summary>
/// Get if the conditional what expected is true.
/// </summary>
/// <param name="property"> is used for get the value of the property and check if return enable true or false </param>
/// <param name="condHAtt"> is the attribute what contains the values what we need </param>
/// <returns> only if the field y is same to the value expected return true</returns>
private bool GetConditionalSourceField(SerializedProperty property, ShowIfAttribute condHAtt)
{
#if UNITY_EDITOR
bool enabled = false;
string propertyPath = property.propertyPath;
string conditionPath = propertyPath.Replace(property.name, condHAtt.ConditionalSourceField);
SerializedProperty sourcePropertyValue = property.serializedObject.FindProperty(conditionPath);
if (sourcePropertyValue != null)
{
enabled = sourcePropertyValue.boolValue;
if (enabled == condHAtt.expectedValue) enabled = true;
else enabled = false;
}
else
{
string warning = "ConditionalHideAttribute: No se encuentra el campo booleano [" + condHAtt.ConditionalSourceField + "] en " + property.propertyPath;
warning += " Aseg<65>rate de especificar correctamente el nombre del campo condicional.";
Debug.LogWarning(warning);
}
return enabled;
#else
return false;
#endif
}
}

View File

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

View File

@@ -0,0 +1,31 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Error : MonoBehaviour
{
public static GameObject ErrorText;
public static GameObject CanvasContent;
private void Awake()
{
ErrorText = Resources.Load(Strings.ErrorTextPrefab) as GameObject;
CanvasContent = GameObject.Find(Strings.ErrorContent);
}
public static void Log(Color color, string message, float time = 5)
{
Log(message, color, time);
}
public static void Log(string message, Color color, float time = 5)
{
Debug.Log(message);
if (CanvasContent == null) return;
Text text = Instantiate(ErrorText, CanvasContent.transform).GetComponent<Text>();
text.text = message;
text.color = color;
Destroy(text.gameObject, CanvasContent.transform.childCount+1 * time);
}
}

View File

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

View File

@@ -0,0 +1,53 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class Extensions
{
#region Transform
public static void SetTransform(this Transform current, SerializableTransform target)
{
current.localPosition = target.Position;
current.localEulerAngles = target.Rotation;
current.localScale = target.Scale;
}
public static void LerpTransform(this Transform current, SerializableTransform source, SerializableTransform target, float amount)
{
current.localPosition = Vector3.Lerp(source.Position, target.Position, amount);
current.localEulerAngles = Quaternion.Lerp(Quaternion.Euler(source.Rotation), Quaternion.Euler(target.Rotation), amount).eulerAngles;
current.localScale = Vector3.Lerp(source.Scale, target.Scale, amount);
}
public static void ResetTransform(this Transform trans)
{
trans.localPosition = Vector3.zero;
trans.localEulerAngles = Vector3.zero;
trans.localScale = Vector3.one;
}
#endregion
#region GameObject
public static GameObject CopyTransfrom(this GameObject go, GameObject other)
{
go.transform.position = other.transform.position;
go.transform.rotation = other.transform.rotation;
go.transform.localScale = other.transform.localScale;
return go;
}
public static T Get<T>(this GameObject go)
{
return go.GetComponent<T>();
}
public static T GetChild<T>(this GameObject go)
{
return go.GetComponentInChildren<T>();
}
public static T[] GetChildren<T>(this GameObject go)
{
return go.GetComponentsInChildren<T>();
}
#endregion
}

View File

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

View File

@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Networking.Types;
[System.Serializable]
public class SerializableBone
{
public string Name = "";
//public string ParentName = "";
public List<BoneTags> Tags = new List<BoneTags>();
public SerializableTransform Transform = new SerializableTransform();
/// <summary> Reference to original bone for runtime. Not saved to file. </summary>
[NonSerialized] public Transform Bone;
public SerializableBone(){}
public SerializableBone(SerializableBone bone)
{
this.Name = bone.Name;
this.Tags = bone.Tags.ToList();
this.Transform = new SerializableTransform(bone.Transform);
}
public SerializableBone(Transform t, bool generateTags = true, List<BoneTags> tags = null)
{
if(tags == null) tags = new List<BoneTags>();
if (generateTags)
{
if (t.name.EndsWith("_l"))
{
tags.Add(BoneTags.Left);
}
else if (t.name.EndsWith("_r"))
{
tags.Add(BoneTags.Right);
}
//if(t.GetComponentInParent<Osage>() != null)
//{
// tags.Add(BoneTags.Dynamic);
//}
}
Name = t.name;
Tags = tags;
Transform = new SerializableTransform(t, Space.Self);
//ParentName = t.parent == null ? "root" : t.parent.name;
Bone = t;
}
//feel free to add more. do not change order!
public enum BoneTags
{
Left,
Right,
Dynamic,
Humanoid,
Finger,
Face,
Untagged,
IK,
}
#region JSON
public bool ShouldSerializeTags() { return Tags.Count > 0; }
#endregion
}

View File

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

View File

@@ -0,0 +1,108 @@
using System;
using UnityEngine;
namespace SerializableTypes
{
/// <summary> Serializable version of UnityEngine.Vector3. </summary>
[Serializable]
public struct SVector3
{
public float x;
public float y;
public float z;
public SVector3(float x, float y, float z)
{
this.x = x;
this.y = y;
this.z = z;
}
public override string ToString()
=> $"[x, y, z]";
public static implicit operator Vector3(SVector3 s)
=> new Vector3(s.x, s.y, s.z);
public static implicit operator SVector3(Vector3 v)
=> new SVector3(v.x, v.y, v.z);
public static SVector3 operator +(SVector3 a, SVector3 b)
=> new SVector3(a.x + b.x, a.y + b.y, a.z + b.z);
public static SVector3 operator -(SVector3 a, SVector3 b)
=> new SVector3(a.x - b.x, a.y - b.y, a.z - b.z);
public static SVector3 operator -(SVector3 a)
=> new SVector3(-a.x, -a.y, -a.z);
public static SVector3 operator *(SVector3 a, float m)
=> new SVector3(a.x * m, a.y * m, a.z * m);
public static SVector3 operator *(float m, SVector3 a)
=> new SVector3(a.x * m, a.y * m, a.z * m);
public static SVector3 operator /(SVector3 a, float d)
=> new SVector3(a.x / d, a.y / d, a.z / d);
}
/// <summary> Serializable version of UnityEngine.Quaternion. </summary>
[Serializable]
public struct SQuaternion
{
public float x;
public float y;
public float z;
public float w;
public SQuaternion(float x, float y, float z, float w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
public override string ToString()
=> $"[{x}, {y}, {z}, {w}]";
public static implicit operator Quaternion(SQuaternion s)
=> new Quaternion(s.x, s.y, s.z, s.w);
public static implicit operator SQuaternion(Quaternion q)
=> new SQuaternion(q.x, q.y, q.z, q.w);
}
/// <summary> Serializable version of UnityEngine.Color32 without transparency. </summary>
[Serializable]
public struct SColor32
{
public byte r;
public byte g;
public byte b;
public SColor32(byte r, byte g, byte b)
{
this.r = r;
this.g = g;
this.b = b;
}
public SColor32(Color32 c)
{
r = c.r;
g = c.g;
b = c.b;
}
public override string ToString()
=> $"[{r}, {g}, {b}]";
public static implicit operator Color32(SColor32 rValue)
=> new Color32(rValue.r, rValue.g, rValue.b, a: byte.MaxValue);
public static implicit operator SColor32(Color32 rValue)
=> new SColor32(rValue.r, rValue.g, rValue.b);
}
}

View File

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

View File

@@ -0,0 +1,73 @@
using SerializableTypes;
using System.ComponentModel;
using UnityEngine;
[System.Serializable]
public class SerializableTransform
{
public Space Space = Space.Self;
public SVector3 Position = Vector3.zero;
public SVector3 Rotation = Vector3.zero;
public SVector3 Scale = Vector3.one;
public SerializableTransform(){}
public SerializableTransform(Transform t, Space space = UnityEngine.Space.Self)
{
Space = space;
if (space == Space.World)
{
Position = t.position;
Rotation = t.eulerAngles;
Scale = t.localScale; //lossyscale is read-only, so can't be used later
}
else
{
Position = t.localPosition;
Rotation = t.localEulerAngles;
Scale = t.localScale;
}
}
public SerializableTransform(SerializableTransform q)
{
Space = q.Space;
Position = q.Position;
Rotation = q.Rotation;
Scale = q.Scale;
}
public void ApplyTo(Transform t)
{
if (Space == Space.World)
{
t.position = Position;
t.eulerAngles = Rotation;
t.localScale = Scale;
}
else
{
t.localPosition = Position;
t.localEulerAngles = Rotation;
t.localScale = Scale;
}
}
public SerializableTransform LerpWith(SerializableTransform target, float amount)
{
return new SerializableTransform()
{
Position = Vector3.Lerp(this.Position, target.Position, amount),
Rotation = Quaternion.Lerp(Quaternion.Euler(this.Rotation), Quaternion.Euler(target.Rotation), amount).eulerAngles,
Scale = Vector3.Lerp(this.Scale, target.Scale, amount)
};
}
#region JSON
public bool ShouldSerializeSpace() { return (Space != Space.Self); }
public bool ShouldSerializePosition() { return (Position != Vector3.zero); }
public bool ShouldSerializeRotation() { return (Rotation != Vector3.zero); }
public bool ShouldSerializeScale() { return (Scale != Vector3.one); }
#endregion
}

View File

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

View File

@@ -0,0 +1,67 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
[System.Serializable]
public class Settings
{
public static Settings Instance = new Settings();
public static string GameVersion => Instance.gameVersion;
public static string AssetsUrl => Instance.assetsUrl;
public static string ScreenshotDirectory => Format(Instance.screenshotDirectory);
public static string SavePoseDirectory => Format(Instance.savePoseDirectory);
public static string SaveSceneDirectory => Format(Instance.saveSceneDirectory);
public static string AssetsDirectory => Format(Instance.assetsDirectory);
public static string AssetListDirectory => Format(Instance.assetListDirectory);
public static string CacheDirectory => Format(Instance.cacheDirectory);
public static string LooseAssetsDirectory => Format(Instance.looseAssetsDirectory);
public string gameVersion = "2.9.0";
public string assetsUrl = "https://parade-mobile-prod-cdn.kemono-friends-3.jp/AssetBundles/139.0/6fe6f44c2162621fcc3d8246188789ca/139.0";
public string screenshotDirectory = "{VIEWERDIR}/Screenshots";
public string savePoseDirectory = "{VIEWERDIR}/Poses";
public string saveSceneDirectory = "{VIEWERDIR}/Scenes";
public string assetsDirectory = "{KF3ASSETS}/assets";
public string assetListDirectory = "{KF3ASSETS}";
public string cacheDirectory = "{KF3CACHE}";
public string looseAssetsDirectory = "{VIEWERDIR}/Assets";
public bool showHints = true;
public static void Save()
{
string savePath = Path.GetFullPath(Application.dataPath + "/../Settings.txt");
File.WriteAllText(savePath, JsonUtility.ToJson(Settings.Instance, true));
Error.Log(Color.green, $"Settings file saved in {savePath}");
}
public static void Load()
{
string savePath = Path.GetFullPath(Application.dataPath + "/../Settings.txt");
Debug.Log(savePath);
if (!File.Exists(savePath))
{
Save();
}
Instance = JsonUtility.FromJson<Settings>(File.ReadAllText(savePath));
}
public static string Format(string value)
{
value = value.Replace("{VIEWERDIR}", Application.dataPath + "/../")
.Replace("{KF3ASSETS}", Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "Low/Appirits/けもフレ3/StreamingAssets/")
.Replace("{KF3CACHE}", Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "/Temp/Appirits/けもフレ3/");
if (!Directory.Exists(value))
{
Directory.CreateDirectory(value);
Error.Log(Color.yellow, "Created directory: " + Path.GetFullPath(value));
}
return value;
}
}

View File

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

View File

@@ -0,0 +1,3 @@
{
"name": "SharedBasic"
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 24ad1c085c49dc34dbe16c3d92c6f299
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,12 @@
public static class Strings
{
public static string
ErrorContent = "Canvas/ErrorScrollView/Viewport/Content";
public static string NoValueSelectedString = "No Value";
public static string CharaErrorPrefab = "icon_chara_error";
public static string PopupButtonPrefab = "PopupButton";
public static string ErrorTextPrefab = "ErrorText";
}

View File

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