init
This commit is contained in:
commit
c7d8c303a6
499 changed files with 2349700 additions and 0 deletions
760
Assets/ABI.CCK/Scripts/Editor/CCK_BuildManagerWindow.cs
Executable file
760
Assets/ABI.CCK/Scripts/Editor/CCK_BuildManagerWindow.cs
Executable file
|
@ -0,0 +1,760 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using System.Xml.XPath;
|
||||
using ABI.CCK.Components;
|
||||
using ABI.CCK.Scripts.Runtime;
|
||||
using Abi.Newtonsoft.Json;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public class CCK_BuildManagerWindow : EditorWindow
|
||||
{
|
||||
public static string Version = "3.4 RELEASE";
|
||||
public static int BuildID = 90;
|
||||
private const string CCKVersion = "3.4 RELEASE (Build 92)";
|
||||
|
||||
private string[] SupportedUnityVersions = new[]
|
||||
{
|
||||
"2019.4.0f1", "2019.4.1f1", "2019.4.2f1", "2019.4.3f1", "2019.4.4f1", "2019.4.5f1", "2019.4.6f1",
|
||||
"2019.4.7f1", "2019.4.8f1", "2019.4.9f1", "2019.4.10f1", "2019.4.11f1", "2019.4.12f1",
|
||||
"2019.4.13f1", "2019.4.14f1", "2019.4.15f1", "2019.4.16f1", "2019.4.17f1", "2019.4.18f1",
|
||||
"2019.4.19f1", "2019.4.20f1", "2019.4.21f1", "2019.4.22f1", "2019.4.23f1", "2019.4.24f1",
|
||||
"2019.4.25f1", "2019.4.26f1", "2019.4.27f1", "2019.4.28f1", "2019.4.29f1", "2019.4.30f1",
|
||||
"2019.4.31f1"
|
||||
};
|
||||
|
||||
string _username;
|
||||
string _key;
|
||||
|
||||
public Texture2D abiLogo;
|
||||
private bool _attemptingToLogin;
|
||||
private bool _loggedIn;
|
||||
private bool _hasAttemptedToLogin;
|
||||
private bool _allowedToUpload;
|
||||
private string _apiUserRank;
|
||||
private string _apiCreatorRank;
|
||||
Vector2 scrollPosAvatar;
|
||||
Vector2 scrollPosSpawnable;
|
||||
Vector2 scrollPosWorld;
|
||||
|
||||
private int _tab;
|
||||
private Vector2 _scroll;
|
||||
|
||||
private static PropertyInfo _legacyBlendShapeImporter;
|
||||
|
||||
private static PropertyInfo legacyBlendShapeImporter
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_legacyBlendShapeImporter != null)
|
||||
{
|
||||
return _legacyBlendShapeImporter;
|
||||
}
|
||||
|
||||
Type modelImporterType = typeof(ModelImporter);
|
||||
_legacyBlendShapeImporter = modelImporterType.GetProperty(
|
||||
"legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes",
|
||||
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public
|
||||
);
|
||||
|
||||
return _legacyBlendShapeImporter;
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Alpha Blend Interactive/Control Panel (Builder and Settings)", false, 200)]
|
||||
static void Init()
|
||||
{
|
||||
CCK_BuildManagerWindow window = (CCK_BuildManagerWindow)GetWindow(typeof(CCK_BuildManagerWindow), false, $"CCK :: Control Panel");
|
||||
window.Show();
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
EditorApplication.update -= EditorUpdate;
|
||||
EditorApplication.playModeStateChanged -= OnEditorStateUpdated;
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
abiLogo = (Texture2D) AssetDatabase.LoadAssetAtPath("Assets/ABI.CCK/GUIAssets/abibig.png", typeof(Texture2D));
|
||||
|
||||
EditorApplication.update -= EditorUpdate;
|
||||
EditorApplication.update += EditorUpdate;
|
||||
EditorApplication.playModeStateChanged -= OnEditorStateUpdated;
|
||||
EditorApplication.playModeStateChanged += OnEditorStateUpdated;
|
||||
|
||||
_username = EditorPrefs.GetString("m_ABI_Username");
|
||||
_key = EditorPrefs.GetString("m_ABI_Key");
|
||||
Login();
|
||||
}
|
||||
|
||||
void OnEditorStateUpdated(PlayModeStateChange state)
|
||||
{
|
||||
if (state == PlayModeStateChange.EnteredEditMode)
|
||||
{
|
||||
EditorPrefs.SetBool("m_ABI_isBuilding", false);
|
||||
EditorPrefs.SetString("m_ABI_TempVersion", Version);
|
||||
if (File.Exists(Application.dataPath + "/ABI.CCK/Resources/Cache/_CVRAvatar.prefab")) File.Delete(Application.dataPath + "/ABI.CCK/Resources/Cache/_CVRAvatar.prefab");
|
||||
if (File.Exists(Application.dataPath + "/ABI.CCK/Resources/Cache/_CVRSpawnable.prefab")) File.Delete(Application.dataPath + "/ABI.CCK/Resources/Cache/_CVRSpawnable.prefab");
|
||||
if (File.Exists(Application.dataPath + "/ABI.CCK/Resources/Cache/_CVRWorld.prefab")) File.Delete(Application.dataPath + "/ABI.CCK/Resources/Cache/_CVRWorld.prefab");
|
||||
if (File.Exists(Application.persistentDataPath + "/bundle.cvravatar")) File.Delete(Application.persistentDataPath + "/bundle.cvravatar");
|
||||
if (File.Exists(Application.persistentDataPath + "/bundle.cvravatar.manifest")) File.Delete(Application.persistentDataPath + "/bundle.cvravatar.manifest");
|
||||
if (File.Exists(Application.persistentDataPath + "/bundle.cvrprop")) File.Delete(Application.persistentDataPath + "/bundle.cvrprop");
|
||||
if (File.Exists(Application.persistentDataPath + "/bundle.cvrprop.manifest")) File.Delete(Application.persistentDataPath + "/bundle.cvrprop.manifest");
|
||||
if (File.Exists(Application.persistentDataPath + "/bundle.cvrworld")) File.Delete(Application.persistentDataPath + "/bundle.cvrworld");
|
||||
if (File.Exists(Application.persistentDataPath + "/bundle.cvrworld.manifest")) File.Delete(Application.persistentDataPath + "/bundle.cvrworld.manifest");
|
||||
if (File.Exists(Application.persistentDataPath + "/bundle.png")) File.Delete(Application.persistentDataPath + "/bundle.png");
|
||||
if (File.Exists(Application.persistentDataPath + "/bundle.png.manifest")) File.Delete(Application.persistentDataPath + "/bundle.png.manifest");
|
||||
if (File.Exists(Application.persistentDataPath + "/bundle_pano_1024.png")) File.Delete(Application.persistentDataPath + "/bundle_pano_1024.png");
|
||||
if (File.Exists(Application.persistentDataPath + "/bundle_pano_1024.png.manifest")) File.Delete(Application.persistentDataPath + "/bundle_pano_1024.png.manifest");
|
||||
if (File.Exists(Application.persistentDataPath + "/bundle_pano_4096.png")) File.Delete(Application.persistentDataPath + "/bundle_pano_4096.png");
|
||||
if (File.Exists(Application.persistentDataPath + "/bundle_pano_4096.png.manifest")) File.Delete(Application.persistentDataPath + "/bundle_pano_4096.png.manifest");
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
if (state == PlayModeStateChange.EnteredPlayMode && EditorPrefs.GetBool("m_ABI_isBuilding"))
|
||||
{
|
||||
var ui = Instantiate(AssetDatabase.LoadAssetAtPath<GameObject>("Assets/ABI.CCK/GUIAssets/CCK_UploaderHead.prefab"));
|
||||
OnGuiUpdater up = ui.GetComponentInChildren<OnGuiUpdater>();
|
||||
if (File.Exists(Application.dataPath + "/ABI.CCK/Resources/Cache/_CVRAvatar.prefab"))up.asset = Resources.Load<GameObject>("Cache/_CVRAvatar").GetComponent<CVRAssetInfo>();
|
||||
if (File.Exists(Application.dataPath + "/ABI.CCK/Resources/Cache/_CVRSpawnable.prefab"))up.asset = Resources.Load<GameObject>("Cache/_CVRSpawnable").GetComponent<CVRAssetInfo>();
|
||||
if (File.Exists(Application.dataPath + "/ABI.CCK/Resources/Cache/_CVRWorld.prefab"))up.asset = Resources.Load<GameObject>("Cache/_CVRWorld").GetComponent<CVRAssetInfo>();
|
||||
}
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
var centeredStyle = GUI.skin.GetStyle("Label");
|
||||
centeredStyle.alignment = TextAnchor.UpperCenter;
|
||||
|
||||
GUILayout.Label(abiLogo, centeredStyle);
|
||||
EditorGUILayout.BeginVertical();
|
||||
|
||||
_tab = GUILayout.Toolbar (_tab, new string[] {CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_HEADING_BUILDER"), CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_HEADING_SETTINGS")});
|
||||
|
||||
_scroll = EditorGUILayout.BeginScrollView(_scroll);
|
||||
|
||||
switch (_tab)
|
||||
{
|
||||
case 0:
|
||||
if (!_loggedIn)
|
||||
{
|
||||
Tab_LogIn();
|
||||
}
|
||||
else
|
||||
{
|
||||
Tab_LoggedIn();
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
Tab_Settings();
|
||||
break;
|
||||
}
|
||||
|
||||
EditorGUILayout.EndScrollView();
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
private void Tab_LogIn()
|
||||
{
|
||||
EditorGUILayout.LabelField("ABI Community Hub Access", EditorStyles.boldLabel);
|
||||
EditorGUILayout.LabelField(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_INFOTEXT_SIGNIN1"));
|
||||
EditorGUILayout.LabelField(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_INFOTEXT_SIGNIN2"));
|
||||
EditorGUILayout.LabelField(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_INFOTEXT_SIGNIN3"));
|
||||
EditorGUILayout.Space();
|
||||
_username = EditorGUILayout.TextField(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_LOGIN_TEXT_USERNAME"), _username);
|
||||
_key = EditorGUILayout.PasswordField(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_LOGIN_TEXT_ACCESSKEY"), _key);
|
||||
|
||||
if (GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_LOGIN_BUTTON")))
|
||||
{
|
||||
Login();
|
||||
}
|
||||
|
||||
if (_hasAttemptedToLogin && !_loggedIn)
|
||||
{
|
||||
GUILayout.Label(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_LOGIN_CREDENTIALS_INCORRECT"));
|
||||
}
|
||||
}
|
||||
|
||||
private void Tab_LoggedIn()
|
||||
{
|
||||
EditorGUILayout.LabelField(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_HEADING_ACCOUNT_INFO"), EditorStyles.boldLabel);
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_INFOTEXT_AUTHENTICATED_AS"), _username);
|
||||
EditorGUILayout.LabelField(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_INFOTEXT_USER_RANK"), _apiUserRank);
|
||||
EditorGUILayout.LabelField("CCK version ", CCKVersion);
|
||||
EditorGUILayout.Space();
|
||||
if (GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_LOGOUT_BUTTON"))){
|
||||
bool logout = EditorUtility.DisplayDialog(
|
||||
CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_LOGOUT_DIALOG_TITLE"),
|
||||
CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_LOGOUT_DIALOG_BODY"),
|
||||
CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_LOGOUT_DIALOG_ACCEPT"),
|
||||
CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_LOGOUT_DIALOG_DECLINE"));
|
||||
if (logout) Logout();
|
||||
}
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_INFOTEXT_DOCUMENTATION"), MessageType.Info);
|
||||
if (GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_HEADING_DOCUMENTATION"))) Application.OpenURL("https://docs.abinteractive.net");
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_WARNING_FEEDBACK"), MessageType.Info);
|
||||
if (GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_HEADING_FEEDBACK"))) Application.OpenURL("https://hub.abinteractive.net/feedback");
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_WARNING_FOLDERPATH"), MessageType.Warning);
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_HEADING_FOUNDCONTENT"), EditorStyles.boldLabel);
|
||||
List<CVRAvatar> avatars = new List<CVRAvatar>();
|
||||
List<CVRSpawnable> spawnables = new List<CVRSpawnable>();
|
||||
List<CVRWorld> worlds = new List<CVRWorld>();
|
||||
|
||||
foreach (CVRWorld w in Resources.FindObjectsOfTypeAll<CVRWorld>())
|
||||
{
|
||||
if (w.gameObject.activeInHierarchy) worlds.Add(w);
|
||||
}
|
||||
|
||||
foreach (CVRSpawnable s in Resources.FindObjectsOfTypeAll<CVRSpawnable>())
|
||||
{
|
||||
if (s.gameObject.activeInHierarchy) spawnables.Add(s);
|
||||
}
|
||||
|
||||
foreach (CVRAvatar a in Resources.FindObjectsOfTypeAll<CVRAvatar>())
|
||||
{
|
||||
if (a.gameObject.activeInHierarchy) avatars.Add(a);
|
||||
}
|
||||
|
||||
if (worlds.Count <= 0 && avatars.Count > 0 && SupportedUnityVersions.Contains(Application.unityVersion))
|
||||
{
|
||||
if (avatars.Count <= 0) EditorGUILayout.LabelField(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_UPLOADER_NO_AVATARS_FOUND"));
|
||||
else
|
||||
{
|
||||
if (avatars.Count > 0)
|
||||
{
|
||||
var counter = 0;
|
||||
scrollPosAvatar = EditorGUILayout.BeginScrollView(scrollPosAvatar);
|
||||
foreach (CVRAvatar a in avatars)
|
||||
{
|
||||
counter++;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.Space();
|
||||
GUILayout.Label("Avatar Object #" + counter);
|
||||
OnGUIAvatar(a);
|
||||
}
|
||||
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (worlds.Count <= 0 && spawnables.Count > 0 && SupportedUnityVersions.Contains(Application.unityVersion))
|
||||
{
|
||||
if (spawnables.Count <= 0) EditorGUILayout.LabelField(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_UPLOADER_NO_SPAWNABLES_FOUND"));
|
||||
else
|
||||
{
|
||||
if (spawnables.Count > 0)
|
||||
{
|
||||
var counter = 0;
|
||||
scrollPosSpawnable = EditorGUILayout.BeginScrollView(scrollPosSpawnable);
|
||||
foreach (CVRSpawnable s in spawnables)
|
||||
{
|
||||
counter++;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.Space();
|
||||
GUILayout.Label("Spawnable Object #" + counter);
|
||||
OnGUISpawnable(s);
|
||||
}
|
||||
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (avatars.Count <= 0 && worlds.Count == 1 && SupportedUnityVersions.Contains(Application.unityVersion))
|
||||
{
|
||||
int errors = 0;
|
||||
int overallMissingScripts = 0;
|
||||
|
||||
overallMissingScripts = CCK_Tools.CleanMissingScripts(CCK_Tools.SearchType.Scene , false, null);
|
||||
if (overallMissingScripts > 0) errors++;
|
||||
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_INFOTEXT_WORLDS_NO_AVATARS"), MessageType.Info);
|
||||
|
||||
//Error
|
||||
if (overallMissingScripts > 0) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_ERROR_WORLD_MISSING_SCRIPTS"), MessageType.Error);
|
||||
|
||||
//Warning
|
||||
if (worlds[0].spawns.Length == 0) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_WORLDS_WARNING_SPAWNPOINT"), MessageType.Warning);
|
||||
|
||||
//Info
|
||||
if (worlds[0].referenceCamera == null) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_WORLDS_INFO_REFERENCE_CAMERA"), MessageType.Info);
|
||||
if (worlds[0].respawnHeightY <= -500) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_WORLDS_INFO_RESPAWN_HEIGHT"), MessageType.Info);
|
||||
|
||||
if (GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_UPLOAD_WORLD_BUTTON")) && errors <= 0)
|
||||
{
|
||||
CCK_BuildUtility.BuildAndUploadMapAsset(EditorSceneManager.GetActiveScene(), worlds[0].gameObject);
|
||||
}
|
||||
if (overallMissingScripts > 0) if (GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_UTIL_REMOVE_MISSING_SCRIPTS_BUTTON"))) CCK_Tools.CleanMissingScripts(CCK_Tools.SearchType.Scene , true, null);
|
||||
}
|
||||
if (avatars.Count <= 0 && worlds.Count > 1 && SupportedUnityVersions.Contains(Application.unityVersion))
|
||||
{
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_WORLDS_ERROR_MULTIPLE_CVR_WORLD"), MessageType.Error);
|
||||
}
|
||||
if (avatars.Count > 0 && worlds.Count > 0 && SupportedUnityVersions.Contains(Application.unityVersion))
|
||||
{
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_WORLDS_ERROR_WORLD_CONTAINS_AVATAR"), MessageType.Error);
|
||||
}
|
||||
if (avatars.Count <= 0 && worlds.Count <= 0 && SupportedUnityVersions.Contains(Application.unityVersion))
|
||||
{
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_WORLDS_ERROR_NO_CONTENT"), MessageType.Info);
|
||||
}
|
||||
if (!SupportedUnityVersions.Contains(Application.unityVersion))
|
||||
{
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_WORLDS_ERROR_UNITY_UNSUPPORTED"), MessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
void Tab_Settings()
|
||||
{
|
||||
EditorGUILayout.LabelField(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_SETTINGS_HEADER"), EditorStyles.boldLabel);
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
EditorGUILayout.BeginVertical();
|
||||
EditorGUILayout.LabelField(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_SETTINGS_CONTENT_REGION"));
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
EditorGUILayout.BeginVertical();
|
||||
var region = EditorGUILayout.Popup(EditorPrefs.GetInt("ABI_PREF_UPLOAD_REGION", 0), new []{"Europe", "United States", "Asia"});
|
||||
EditorPrefs.SetInt("ABI_PREF_UPLOAD_REGION", region);
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_SETTINGS_HINT_CONTENT_REGION"), MessageType.Info);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
EditorGUILayout.BeginVertical();
|
||||
EditorGUILayout.LabelField(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_SETTINGS_CCK_LANGUAGE"));
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
EditorGUILayout.BeginVertical();
|
||||
string selectedLanguage = EditorPrefs.GetString("ABI_CCKLocals", "English");
|
||||
int selectedIndex = CCKLocalizationProvider.GetKnownLanguages().FindIndex(match => match == selectedLanguage);
|
||||
if (selectedIndex < 0) selectedIndex = 0;
|
||||
selectedIndex = EditorGUILayout.Popup(selectedIndex, CCKLocalizationProvider.GetKnownLanguages().ToArray());
|
||||
EditorPrefs.SetString("ABI_CCKLocals", CCKLocalizationProvider.GetKnownLanguages()[selectedIndex]);
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_SETTINGS_HINT_CCK_LANGUAGE"), MessageType.Info);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
void OnGUIAvatar(CVRAvatar avatar)
|
||||
{
|
||||
GameObject avatarObject = avatar.gameObject;
|
||||
GUI.enabled = true;
|
||||
EditorGUILayout.InspectorTitlebar(avatarObject.activeInHierarchy, avatarObject);
|
||||
int errors = 0;
|
||||
int overallPolygonsCount = 0;
|
||||
int overallSkinnedMeshRenderer = 0;
|
||||
int overallUniqueMaterials = 0;
|
||||
int overallMissingScripts = 0;
|
||||
foreach (MeshFilter filter in avatar.gameObject.GetComponentsInChildren<MeshFilter>())
|
||||
{
|
||||
if (filter.sharedMesh != null) overallPolygonsCount = overallPolygonsCount + filter.sharedMesh.triangles.Length / 3;
|
||||
}
|
||||
foreach (SkinnedMeshRenderer renderer in avatar.gameObject.GetComponentsInChildren<SkinnedMeshRenderer>())
|
||||
{
|
||||
overallSkinnedMeshRenderer++;
|
||||
if (renderer.sharedMaterials != null) overallUniqueMaterials = overallUniqueMaterials + renderer.sharedMaterials.Length;
|
||||
}
|
||||
overallMissingScripts = CCK_Tools.CleanMissingScripts(CCK_Tools.SearchType.Selection ,false,avatarObject);
|
||||
if (overallMissingScripts > 0) errors++;
|
||||
|
||||
//Errors
|
||||
if (overallMissingScripts > 0) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_ERROR_AVATAR_MISSING_SCRIPTS"), MessageType.Error);
|
||||
var animator = avatar.GetComponent<Animator>();
|
||||
if (animator == null)
|
||||
{
|
||||
errors++;
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_ERROR_ANIMATOR"), MessageType.Error);
|
||||
}
|
||||
if (animator != null && animator.avatar == null)
|
||||
{
|
||||
//errors++;
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_WARNING_GENERIC"), MessageType.Warning);
|
||||
}
|
||||
|
||||
//Warnings
|
||||
if (overallPolygonsCount > 100000) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_WARNING_POLYGONS").Replace("{X}", overallPolygonsCount.ToString()), MessageType.Warning);
|
||||
if (overallSkinnedMeshRenderer > 10) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_WARNING_SKINNED_MESH_RENDERERS").Replace("{X}", overallSkinnedMeshRenderer.ToString()), MessageType.Warning);
|
||||
if (overallUniqueMaterials > 20) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_WARNING_MATERIALS").Replace("{X}", overallUniqueMaterials.ToString()), MessageType.Warning);
|
||||
if (avatar.viewPosition == Vector3.zero) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_WARNING_VIEWPOINT"), MessageType.Warning);
|
||||
if (animator != null && animator.avatar != null && !animator.avatar.isHuman) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_WARNING_NON_HUMANOID"), MessageType.Warning);
|
||||
|
||||
var avatarMeshes = getAllAssetMeshesInAvatar(avatarObject);
|
||||
if (CheckForLegacyBlendShapeNormals(avatarMeshes))
|
||||
{
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_WARNING_LEGACY_BLENDSHAPES"), MessageType.Warning);
|
||||
if(GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_FIX_IMPORT_SETTINGS")))
|
||||
{
|
||||
FixLegacyBlendShapeNormals(avatarMeshes);
|
||||
}
|
||||
}
|
||||
|
||||
//Info
|
||||
if (overallPolygonsCount >= 50000 && overallPolygonsCount <= 100000) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_INFO_POLYGONS").Replace("{X}", overallPolygonsCount.ToString()), MessageType.Info);
|
||||
if (overallSkinnedMeshRenderer >= 5 && overallSkinnedMeshRenderer <= 10) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_INFO_SKINNED_MESH_RENDERERS").Replace("{X}", overallSkinnedMeshRenderer.ToString()), MessageType.Info);
|
||||
if (overallUniqueMaterials >= 10 && overallUniqueMaterials <= 20) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_INFO_MATERIALS").Replace("{X}", overallUniqueMaterials.ToString()), MessageType.Info);
|
||||
if (avatar.viewPosition.y <= 0.5f) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_INFO_SMALL"), MessageType.Info);
|
||||
if (avatar.viewPosition.y > 3f) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_INFO_HUGE"), MessageType.Info);
|
||||
|
||||
if (errors <= 0) if (GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_AVATAR_UPLOAD_BUTTON"))) CCK_BuildUtility.BuildAndUploadAvatar(avatarObject);
|
||||
if (overallMissingScripts > 0) if (GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_UTIL_REMOVE_MISSING_SCRIPTS_BUTTON"))) CCK_Tools.CleanMissingScripts(CCK_Tools.SearchType.Selection ,true,avatarObject);
|
||||
|
||||
}
|
||||
|
||||
void OnGUISpawnable(CVRSpawnable s)
|
||||
{
|
||||
GameObject spawnableObject = s.gameObject;
|
||||
GUI.enabled = true;
|
||||
EditorGUILayout.InspectorTitlebar(spawnableObject.activeInHierarchy, spawnableObject);
|
||||
int errors = 0;
|
||||
int overallPolygonsCount = 0;
|
||||
int overallSkinnedMeshRenderer = 0;
|
||||
int overallUniqueMaterials = 0;
|
||||
int overallMissingScripts = 0;
|
||||
foreach (MeshFilter filter in s.gameObject.GetComponentsInChildren<MeshFilter>())
|
||||
{
|
||||
if (filter.sharedMesh != null) overallPolygonsCount = overallPolygonsCount + filter.sharedMesh.triangles.Length / 3;
|
||||
}
|
||||
foreach (SkinnedMeshRenderer renderer in s.gameObject.GetComponentsInChildren<SkinnedMeshRenderer>())
|
||||
{
|
||||
overallSkinnedMeshRenderer++;
|
||||
if (renderer.sharedMaterials != null) overallUniqueMaterials = overallUniqueMaterials + renderer.sharedMaterials.Length;
|
||||
}
|
||||
overallMissingScripts = CCK_Tools.CleanMissingScripts(CCK_Tools.SearchType.Selection ,false, spawnableObject);
|
||||
if (overallMissingScripts > 0) errors++;
|
||||
|
||||
//Errors
|
||||
if (overallMissingScripts > 0) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_PROPS_ERROR_MISSING_SCRIPT"), MessageType.Error);
|
||||
|
||||
//Warnings
|
||||
if (overallPolygonsCount > 100000) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_PROPS_WARNING_POLYGONS").Replace("{X}", overallPolygonsCount.ToString()), MessageType.Warning);
|
||||
if (overallSkinnedMeshRenderer > 10) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_PROPS_WARNING_SKINNED_MESH_RENDERERS").Replace("{X}", overallSkinnedMeshRenderer.ToString()), MessageType.Warning);
|
||||
if (overallUniqueMaterials > 20) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_PROPS_WARNING_MATERIALS").Replace("{X}", overallUniqueMaterials.ToString()), MessageType.Warning);
|
||||
|
||||
var spawnableMeshes = getAllAssetMeshesInAvatar(spawnableObject);
|
||||
if (CheckForLegacyBlendShapeNormals(spawnableMeshes))
|
||||
{
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_PROPS_WARNING_LEGACY_BLENDSHAPES"), MessageType.Warning);
|
||||
if(GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_FIX_IMPORT_SETTINGS")))
|
||||
{
|
||||
FixLegacyBlendShapeNormals(spawnableMeshes);
|
||||
}
|
||||
}
|
||||
|
||||
//Info
|
||||
if (overallPolygonsCount >= 50000 && overallPolygonsCount <= 100000) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_PROPS_INFO_POLYGONS").Replace("{X}", overallPolygonsCount.ToString()), MessageType.Info);
|
||||
if (overallSkinnedMeshRenderer >= 5 && overallSkinnedMeshRenderer <= 10) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_PROPS_INFO_SKINNED_MESH_RENDERERS").Replace("{X}", overallSkinnedMeshRenderer.ToString()), MessageType.Info);
|
||||
if (overallUniqueMaterials >= 10 && overallUniqueMaterials <= 20) EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_PROPS_INFO_MATERIALS").Replace("{X}", overallUniqueMaterials.ToString()), MessageType.Info);
|
||||
|
||||
if (errors <= 0 && overallMissingScripts <= 0) if (GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_PROPS_UPLOAD_BUTTON"))) CCK_BuildUtility.BuildAndUploadSpawnable(spawnableObject);
|
||||
if (overallMissingScripts > 0) if (GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_UTIL_REMOVE_MISSING_SCRIPTS_BUTTON"))) CCK_Tools.CleanMissingScripts(CCK_Tools.SearchType.Selection ,true, spawnableObject);
|
||||
}
|
||||
|
||||
private List<String> getAllAssetMeshesInAvatar(GameObject avatar)
|
||||
{
|
||||
var assetPathList = new List<String>();
|
||||
|
||||
foreach (var sMeshRenderer in avatar.GetComponentsInChildren<SkinnedMeshRenderer>(true))
|
||||
{
|
||||
if(sMeshRenderer == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var currentMesh = sMeshRenderer.sharedMesh;
|
||||
|
||||
if(currentMesh == null)
|
||||
{
|
||||
Debug.LogWarning(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_WARNING_MESH_FILTER_MESH_EMPTY") + $": {sMeshRenderer.transform.name}");
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!AssetDatabase.Contains(currentMesh))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string meshAssetPath = AssetDatabase.GetAssetPath(currentMesh);
|
||||
if(string.IsNullOrEmpty(meshAssetPath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (assetPathList.Contains(meshAssetPath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
assetPathList.Add(meshAssetPath);
|
||||
}
|
||||
|
||||
foreach (var meshFilter in avatar.GetComponentsInChildren<MeshFilter>(true))
|
||||
{
|
||||
if(meshFilter == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var currentMesh = meshFilter.sharedMesh;
|
||||
|
||||
if(currentMesh == null)
|
||||
{
|
||||
Debug.LogWarning(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_WARNING_MESH_FILTER_MESH_EMPTY") + $": {meshFilter.transform.name}");
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!AssetDatabase.Contains(currentMesh))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string meshAssetPath = AssetDatabase.GetAssetPath(currentMesh);
|
||||
if(string.IsNullOrEmpty(meshAssetPath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (assetPathList.Contains(meshAssetPath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
assetPathList.Add(meshAssetPath);
|
||||
}
|
||||
|
||||
foreach (var pRenderer in avatar.GetComponentsInChildren<ParticleSystemRenderer>(true))
|
||||
{
|
||||
if(pRenderer == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var particleMeshes = new Mesh[pRenderer.meshCount];
|
||||
pRenderer.GetMeshes(particleMeshes);
|
||||
|
||||
foreach (var particleMesh in particleMeshes)
|
||||
{
|
||||
if(particleMesh == null)
|
||||
{
|
||||
Debug.LogWarning(CCKLocalizationProvider.GetLocalizedText("ABI_UI_BUILDPANEL_WARNING_MESH_FILTER_MESH_EMPTY") + $": {pRenderer.transform.name}");
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!AssetDatabase.Contains(particleMesh))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string meshAssetPath = AssetDatabase.GetAssetPath(particleMesh);
|
||||
if(string.IsNullOrEmpty(meshAssetPath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (assetPathList.Contains(meshAssetPath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
assetPathList.Add(meshAssetPath);
|
||||
}
|
||||
}
|
||||
|
||||
return assetPathList;
|
||||
}
|
||||
|
||||
private bool CheckForLegacyBlendShapeNormals(List<String> assetPaths)
|
||||
{
|
||||
foreach (var assetPath in assetPaths)
|
||||
{
|
||||
|
||||
var modelImporter = AssetImporter.GetAtPath(assetPath) as ModelImporter;
|
||||
if(modelImporter == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(modelImporter.importBlendShapeNormals != ModelImporterNormals.Calculate)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if((bool)legacyBlendShapeImporter.GetValue(modelImporter))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void FixLegacyBlendShapeNormals(List<String> assetPaths)
|
||||
{
|
||||
foreach (var assetPath in assetPaths)
|
||||
{
|
||||
var modelImporter = AssetImporter.GetAtPath(assetPath) as ModelImporter;
|
||||
if(modelImporter == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(modelImporter.importBlendShapeNormals != ModelImporterNormals.Calculate)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
legacyBlendShapeImporter.SetValue(modelImporter, true);
|
||||
modelImporter.SaveAndReimport();
|
||||
}
|
||||
}
|
||||
|
||||
private void EditorUpdate()
|
||||
{
|
||||
/*if (!_attemptingToLogin || _webRequest is null || !_webRequest.isDone) return;
|
||||
|
||||
if (_webRequest.isNetworkError || _webRequest.isHttpError)
|
||||
{
|
||||
Debug.LogError("[ABI:CCK] Web Request Error while trying to authenticate.");
|
||||
return;
|
||||
}
|
||||
|
||||
var result = _webRequest.downloadHandler.text;
|
||||
if (string.IsNullOrEmpty(result)) return;
|
||||
|
||||
LoginResponse usr = Abi.Newtonsoft.Json.JsonConvert.DeserializeObject<LoginResponse>(result);
|
||||
if (usr == null) return;
|
||||
|
||||
if (usr.IsValidCredential)
|
||||
{
|
||||
_apiUserRank = usr.UserRank;
|
||||
Debug.Log("[ABI:CCK] Successfully authenticated as " + _username + " using AlphaLink Public API.");
|
||||
EditorPrefs.SetString("m_ABI_Username", _username);
|
||||
EditorPrefs.SetString("m_ABI_Key", _key);
|
||||
_loggedIn = true;
|
||||
_hasAttemptedToLogin = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("[ABI:CCK] Unable to authenticate using provided credentials. API responded with: " + usr.ApiMessage + ".");
|
||||
_loggedIn = false;
|
||||
_hasAttemptedToLogin = true;
|
||||
_username = _key = string.Empty;
|
||||
}
|
||||
|
||||
_webRequest = null;
|
||||
_attemptingToLogin = false;*/
|
||||
}
|
||||
|
||||
private void Logout()
|
||||
{
|
||||
_loggedIn = false;
|
||||
_username = _key = string.Empty;
|
||||
EditorPrefs.SetString("m_ABI_Username", _username);
|
||||
EditorPrefs.SetString("m_ABI_Key", _key);
|
||||
}
|
||||
|
||||
public async Task Login()
|
||||
{
|
||||
if (!_attemptingToLogin)
|
||||
{
|
||||
_attemptingToLogin = true;
|
||||
|
||||
using (HttpClient httpclient = new HttpClient())
|
||||
{
|
||||
HttpResponseMessage response;
|
||||
response = await httpclient.PostAsync(
|
||||
"https://api.abinteractive.net/1/cck/validateKey",
|
||||
new StringContent(JsonConvert.SerializeObject(new {Username = _username, AccessKey = _key}),
|
||||
Encoding.UTF8, "application/json")
|
||||
);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string result = await response.Content.ReadAsStringAsync();
|
||||
BaseResponse<LoginResponse> usr = Abi.Newtonsoft.Json.JsonConvert.DeserializeObject<BaseResponse<LoginResponse>>(result);
|
||||
|
||||
if (usr == null || usr.Data == null) return;
|
||||
|
||||
if (usr.Data.isValidCredentials)
|
||||
{
|
||||
_apiUserRank = usr.Data.userRank;
|
||||
Debug.Log("[ABI:CCK] Successfully authenticated as " + _username + " using AlphaLink Public API.");
|
||||
EditorPrefs.SetString("m_ABI_Username", _username);
|
||||
EditorPrefs.SetString("m_ABI_Key", _key);
|
||||
_loggedIn = true;
|
||||
_hasAttemptedToLogin = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("[ABI:CCK] Unable to authenticate using provided credentials. API responded with: " + usr.Message + ".");
|
||||
_loggedIn = false;
|
||||
_hasAttemptedToLogin = true;
|
||||
_username = _key = string.Empty;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("[ABI:CCK] Web Request Error while trying to authenticate.");
|
||||
}
|
||||
}
|
||||
_attemptingToLogin = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class LoginResponse
|
||||
{
|
||||
public bool isValidCredentials { get; set; }
|
||||
public bool isAccountUnlocked { get; set; }
|
||||
public string userId { get; set; }
|
||||
public string userRank { get; set; }
|
||||
}
|
||||
|
||||
public class BaseResponse<T>
|
||||
{
|
||||
public string Message { get; set; }
|
||||
public T Data { get; set; }
|
||||
|
||||
public BaseResponse(string message = null, T data = default)
|
||||
{
|
||||
Message = message;
|
||||
Data = data;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return JsonConvert.SerializeObject(this);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/ABI.CCK/Scripts/Editor/CCK_BuildManagerWindow.cs.meta
Executable file
11
Assets/ABI.CCK/Scripts/Editor/CCK_BuildManagerWindow.cs.meta
Executable file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6256dd53c6120f64886f6a899d82f4d0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
293
Assets/ABI.CCK/Scripts/Editor/CCK_BuildUtility.cs
Executable file
293
Assets/ABI.CCK/Scripts/Editor/CCK_BuildUtility.cs
Executable file
|
@ -0,0 +1,293 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
public class CCK_BuildUtility
|
||||
{
|
||||
public static PreAvatarBundleEvent PreAvatarBundleEvent = new PreAvatarBundleEvent();
|
||||
public static PrePropBundleEvent PrePropBundleEvent = new PrePropBundleEvent();
|
||||
|
||||
public static void BuildAndUploadAvatar(GameObject avatarObject)
|
||||
{
|
||||
//GameObject avatarCopy = null;
|
||||
var origInfo = avatarObject.GetComponent<CVRAssetInfo>();
|
||||
|
||||
/*try
|
||||
{
|
||||
avatarCopy = GameObject.Instantiate(avatarObject);
|
||||
PrefabUtility.UnpackPrefabInstance(avatarCopy, PrefabUnpackMode.Completely, InteractionMode.UserAction);
|
||||
Debug.Log("[CCK:BuildUtility] To prevent problems, the prefab has been unpacked. Your game object is no longer linked to the prefab instance.");
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.Log("[CCK:BuildUtility] Object is not a prefab. No need to unpack.");
|
||||
}*/
|
||||
|
||||
//CVRAssetInfo info = avatarCopy.GetComponent<CVRAssetInfo>();
|
||||
if (string.IsNullOrEmpty(origInfo.objectId))
|
||||
{
|
||||
origInfo.objectId = Guid.NewGuid().ToString();
|
||||
//origInfo.guid = info.guid;
|
||||
try
|
||||
{
|
||||
PrefabUtility.ApplyPrefabInstance(avatarObject, InteractionMode.UserAction);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.Log("[CCK:BuildUtility] Object is not a prefab. No need to Apply To Instance.");
|
||||
}
|
||||
}
|
||||
|
||||
PreAvatarBundleEvent.Invoke(avatarObject);
|
||||
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
|
||||
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
|
||||
|
||||
PrefabUtility.SaveAsPrefabAsset(avatarObject, "Assets/ABI.CCK/Resources/Cache/_CVRAvatar.prefab");
|
||||
//GameObject.DestroyImmediate(avatarCopy);
|
||||
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
|
||||
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
|
||||
|
||||
AssetBundleBuild assetBundleBuild = new AssetBundleBuild();
|
||||
assetBundleBuild.assetNames = new[] {"Assets/ABI.CCK/Resources/Cache/_CVRAvatar.prefab"};
|
||||
assetBundleBuild.assetBundleName = "bundle.cvravatar";
|
||||
|
||||
BuildPipeline.BuildAssetBundles(Application.persistentDataPath, new[] {assetBundleBuild},
|
||||
BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
EditorPrefs.SetBool("m_ABI_isBuilding", true);
|
||||
EditorApplication.isPlaying = true;
|
||||
}
|
||||
|
||||
public static void BuildAndUploadSpawnable(GameObject s)
|
||||
{
|
||||
GameObject sCopy = null;
|
||||
var origInfo = s.GetComponent<CVRAssetInfo>();
|
||||
var spawnable = s.GetComponent<CVRSpawnable>();
|
||||
spawnable.spawnableType = CVRSpawnable.SpawnableType.StandaloneSpawnable;
|
||||
|
||||
PrePropBundleEvent.Invoke(s);
|
||||
|
||||
try
|
||||
{
|
||||
sCopy = GameObject.Instantiate(s);
|
||||
PrefabUtility.UnpackPrefabInstance(sCopy, PrefabUnpackMode.Completely, InteractionMode.UserAction);
|
||||
Debug.Log("[CCK:BuildUtility] To prevent problems, the prefab has been unpacked. Your game object is no longer linked to the prefab instance.");
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.Log("[CCK:BuildUtility] Object is not a prefab. No need to unpack.");
|
||||
}
|
||||
|
||||
CVRAssetInfo info = sCopy.GetComponent<CVRAssetInfo>();
|
||||
if (string.IsNullOrEmpty(info.objectId))
|
||||
{
|
||||
info.objectId = Guid.NewGuid().ToString();
|
||||
origInfo.objectId = info.objectId;
|
||||
try
|
||||
{
|
||||
PrefabUtility.ApplyPrefabInstance(s, InteractionMode.UserAction);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.Log("[CCK:BuildUtility] Object is not a prefab. No need to Apply To Instance.");
|
||||
}
|
||||
}
|
||||
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
|
||||
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
|
||||
|
||||
PrefabUtility.SaveAsPrefabAsset(sCopy, "Assets/ABI.CCK/Resources/Cache/_CVRSpawnable.prefab");
|
||||
GameObject.DestroyImmediate(sCopy);
|
||||
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
|
||||
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
|
||||
|
||||
AssetBundleBuild assetBundleBuild = new AssetBundleBuild();
|
||||
assetBundleBuild.assetNames = new[] {"Assets/ABI.CCK/Resources/Cache/_CVRSpawnable.prefab"};
|
||||
assetBundleBuild.assetBundleName = "bundle.cvrprop";
|
||||
|
||||
BuildPipeline.BuildAssetBundles(Application.persistentDataPath, new[] {assetBundleBuild},
|
||||
BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
EditorPrefs.SetBool("m_ABI_isBuilding", true);
|
||||
EditorApplication.isPlaying = true;
|
||||
}
|
||||
|
||||
public static void BuildAndUploadMapAsset(Scene scene, GameObject descriptor)
|
||||
{
|
||||
SetupNetworkUUIDs();
|
||||
|
||||
EditorSceneManager.MarkSceneDirty(scene);
|
||||
|
||||
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
|
||||
|
||||
CVRAssetInfo info = descriptor.GetComponent<CVRAssetInfo>();
|
||||
if (string.IsNullOrEmpty(info.objectId)) info.objectId = Guid.NewGuid().ToString();
|
||||
|
||||
PrefabUtility.SaveAsPrefabAsset(descriptor, "Assets/ABI.CCK/Resources/Cache/_CVRWorld.prefab");
|
||||
|
||||
AssetBundleBuild assetBundleBuild = new AssetBundleBuild();
|
||||
assetBundleBuild.assetNames = new[] {scene.path};
|
||||
assetBundleBuild.assetBundleName = "bundle.cvrworld";
|
||||
|
||||
BuildPipeline.BuildAssetBundles(Application.persistentDataPath, new[] {assetBundleBuild},
|
||||
BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
EditorPrefs.SetBool("m_ABI_isBuilding", true);
|
||||
EditorApplication.isPlaying = true;
|
||||
}
|
||||
|
||||
public static void SetupNetworkUUIDs()
|
||||
{
|
||||
CVRInteractable[] interactables = Resources.FindObjectsOfTypeAll<CVRInteractable>();
|
||||
CVRObjectSync[] objectSyncs = Resources.FindObjectsOfTypeAll<CVRObjectSync>();
|
||||
CVRVideoPlayer[] videoPlayers = Resources.FindObjectsOfTypeAll<CVRVideoPlayer>();
|
||||
|
||||
CVRSpawnable[] spawnables = Resources.FindObjectsOfTypeAll<CVRSpawnable>();
|
||||
|
||||
GameInstanceController[] gameInstances = Resources.FindObjectsOfTypeAll<GameInstanceController>();
|
||||
|
||||
GunController[] gunControllers = Resources.FindObjectsOfTypeAll<GunController>();
|
||||
|
||||
List<string> UsedGuids = new List<string>();
|
||||
|
||||
foreach (var interactable in interactables)
|
||||
{
|
||||
foreach (var action in interactable.actions)
|
||||
{
|
||||
string guid;
|
||||
do
|
||||
{
|
||||
guid = Guid.NewGuid().ToString();
|
||||
} while (!string.IsNullOrEmpty(UsedGuids.Find(match => match == guid)));
|
||||
UsedGuids.Add(guid);
|
||||
|
||||
action.guid = guid;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var objectSync in objectSyncs)
|
||||
{
|
||||
string guid;
|
||||
do
|
||||
{
|
||||
guid = Guid.NewGuid().ToString();
|
||||
} while (!string.IsNullOrEmpty(UsedGuids.Find(match => match == guid)));
|
||||
UsedGuids.Add(guid);
|
||||
|
||||
var newserializedObject = new SerializedObject(objectSync);
|
||||
newserializedObject.Update();
|
||||
SerializedProperty _guidProperty = newserializedObject.FindProperty("guid");
|
||||
_guidProperty.stringValue = guid;
|
||||
newserializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
foreach (var player in videoPlayers)
|
||||
{
|
||||
Guid res;
|
||||
if (player.playerId == null || !Guid.TryParse(player.playerId, out res))
|
||||
{
|
||||
string guid;
|
||||
do
|
||||
{
|
||||
guid = Guid.NewGuid().ToString();
|
||||
} while (!string.IsNullOrEmpty(UsedGuids.Find(match => match == guid)));
|
||||
UsedGuids.Add(guid);
|
||||
|
||||
player.playerId = guid;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var spawnable in spawnables)
|
||||
{
|
||||
string guid;
|
||||
do
|
||||
{
|
||||
guid = Guid.NewGuid().ToString();
|
||||
} while (!string.IsNullOrEmpty(UsedGuids.Find(match => match == guid)));
|
||||
|
||||
if (spawnable.preGeneratedInstanceId == "")
|
||||
{
|
||||
UsedGuids.Add(guid);
|
||||
spawnable.preGeneratedInstanceId = "ws~" + guid;
|
||||
}
|
||||
else
|
||||
{
|
||||
UsedGuids.Add(spawnable.preGeneratedInstanceId);
|
||||
}
|
||||
|
||||
spawnable.spawnableType = CVRSpawnable.SpawnableType.WorldSpawnable;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
foreach (GameInstanceController gameInstance in gameInstances)
|
||||
{
|
||||
if (gameInstance.teams.Count == 0)
|
||||
{
|
||||
var team = new Team();
|
||||
team.name = "Team";
|
||||
team.color = Color.red;
|
||||
team.playerLimit = 16;
|
||||
team.index = i;
|
||||
gameInstance.teams.Add(team);
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var team in gameInstance.teams)
|
||||
{
|
||||
team.index = i;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var gunController in gunControllers)
|
||||
{
|
||||
string guid;
|
||||
do
|
||||
{
|
||||
guid = Guid.NewGuid().ToString();
|
||||
} while (!string.IsNullOrEmpty(UsedGuids.Find(match => match == guid)));
|
||||
UsedGuids.Add(guid);
|
||||
|
||||
var newserializedObject = new SerializedObject(gunController);
|
||||
newserializedObject.Update();
|
||||
SerializedProperty _guidProperty = newserializedObject.FindProperty("referenceID");
|
||||
_guidProperty.stringValue = guid;
|
||||
newserializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class PreAvatarBundleEvent : UnityEvent<GameObject>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class PrePropBundleEvent : UnityEvent<GameObject>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
Assets/ABI.CCK/Scripts/Editor/CCK_BuildUtility.cs.meta
Executable file
11
Assets/ABI.CCK/Scripts/Editor/CCK_BuildUtility.cs.meta
Executable file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9e48b14602d7465469888e735bd3a915
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
395
Assets/ABI.CCK/Scripts/Editor/CCK_CVRAdvancedAvatarSettingsTriggerEditor.cs
Executable file
395
Assets/ABI.CCK/Scripts/Editor/CCK_CVRAdvancedAvatarSettingsTriggerEditor.cs
Executable file
|
@ -0,0 +1,395 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using AnimatorController = UnityEditor.Animations.AnimatorController;
|
||||
using AnimatorControllerParameterType = UnityEngine.AnimatorControllerParameterType;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(CVRAdvancedAvatarSettingsTrigger))]
|
||||
public class CCK_CVRAdvancedAvatarSettingsTriggerEditor : UnityEditor.Editor
|
||||
{
|
||||
private CVRAdvancedAvatarSettingsTrigger trigger;
|
||||
private AnimatorController animator;
|
||||
private CVRAdvancedAvatarSettingsTriggerTask enterEntity;
|
||||
private CVRAdvancedAvatarSettingsTriggerTask exitEntity;
|
||||
private CVRAdvancedAvatarSettingsTriggerTaskStay stayEntity;
|
||||
private ReorderableList _onEnterList;
|
||||
private ReorderableList _onExitList;
|
||||
private ReorderableList _onStayList;
|
||||
private List<string> animatorParameters;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
trigger = (CVRAdvancedAvatarSettingsTrigger) target;
|
||||
var avatar = trigger.GetComponentInParent<CVRAvatar>();
|
||||
animator = null;
|
||||
animatorParameters = new List<string>();
|
||||
animatorParameters.Add("-none-");
|
||||
|
||||
if (avatar != null && avatar.overrides != null && avatar.overrides.runtimeAnimatorController != null)
|
||||
{
|
||||
animator = (AnimatorController) avatar.overrides.runtimeAnimatorController;
|
||||
foreach (var parameter in animator.parameters)
|
||||
{
|
||||
if ((parameter.type == AnimatorControllerParameterType.Float ||
|
||||
parameter.type == AnimatorControllerParameterType.Bool ||
|
||||
parameter.type == AnimatorControllerParameterType.Int)
|
||||
&& parameter.name.Length > 0 &&
|
||||
!CCK_CVRAvatarEditor.coreParameters.Contains(parameter.name) && parameter.name.Substring(0, 1) != "#")
|
||||
{
|
||||
animatorParameters.Add(parameter.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var triggers = trigger.GetComponents<CVRAdvancedAvatarSettingsTrigger>();
|
||||
|
||||
if (triggers.Length > 1)
|
||||
{
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ADVAVTR_TRIGGER_MULTIPLE_TRIGGER_HELPBOX"), MessageType.Error);
|
||||
}
|
||||
|
||||
trigger.areaSize = EditorGUILayout.Vector3Field("Area Size", trigger.areaSize);
|
||||
|
||||
trigger.areaOffset = EditorGUILayout.Vector3Field("Area Offset", trigger.areaOffset);
|
||||
|
||||
if (!trigger.useAdvancedTrigger)
|
||||
{
|
||||
if (animator == null)
|
||||
{
|
||||
trigger.settingName = EditorGUILayout.TextField("Setting Name", trigger.settingName);
|
||||
}
|
||||
else
|
||||
{
|
||||
var animatorParams = animatorParameters.ToArray();
|
||||
var index = animatorParameters.FindIndex(match => match == trigger.settingName);
|
||||
index = Mathf.Max(EditorGUILayout.Popup("Setting Name", index, animatorParams), 0);
|
||||
trigger.settingName = animatorParams[index];
|
||||
}
|
||||
|
||||
|
||||
trigger.settingValue = EditorGUILayout.FloatField("Setting Value", trigger.settingValue);
|
||||
|
||||
trigger.useAdvancedTrigger = EditorGUILayout.Toggle("Enabled Advanced Mode", trigger.useAdvancedTrigger);
|
||||
}
|
||||
else
|
||||
{
|
||||
trigger.useAdvancedTrigger = EditorGUILayout.Toggle("Enabled Advanced Mode", trigger.useAdvancedTrigger);
|
||||
|
||||
var list = serializedObject.FindProperty("allowedPointer");
|
||||
EditorGUILayout.PropertyField(list, new GUIContent("Allowed Pointers"), true);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ADVAVTR_TRIGGER_ALLOWED_POINTERS_HELPBOX"), MessageType.Info);
|
||||
|
||||
trigger.isNetworkInteractable = EditorGUILayout.Toggle("Network Interactable", trigger.isNetworkInteractable);
|
||||
|
||||
list = serializedObject.FindProperty("allowedTypes");
|
||||
EditorGUILayout.PropertyField(list, new GUIContent("Allowed Types"), true);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ADVAVTR_TRIGGER_ALLOWED_TYPES_HELPBOX"), MessageType.Info);
|
||||
|
||||
trigger.allowParticleInteraction = EditorGUILayout.Toggle("Enabled Particle Interaction", trigger.allowParticleInteraction);
|
||||
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ADVAVTR_TRIGGER_PARTICLE_HELPBOX"), MessageType.Info);
|
||||
|
||||
if (_onEnterList == null)
|
||||
{
|
||||
_onEnterList = new ReorderableList(trigger.enterTasks, typeof(CVRAdvancedAvatarSettingsTriggerTask),
|
||||
false, true, true, true);
|
||||
_onEnterList.drawHeaderCallback = OnDrawHeaderEnter;
|
||||
_onEnterList.drawElementCallback = OnDrawElementEnter;
|
||||
_onEnterList.elementHeightCallback = OnHeightElementEnter;
|
||||
_onEnterList.onAddCallback = OnAddEnter;
|
||||
_onEnterList.onChangedCallback = OnChangedEnter;
|
||||
}
|
||||
|
||||
_onEnterList.DoLayoutList();
|
||||
|
||||
if (_onExitList == null)
|
||||
{
|
||||
_onExitList = new ReorderableList(trigger.exitTasks, typeof(CVRAdvancedAvatarSettingsTriggerTask),
|
||||
false, true, true, true);
|
||||
_onExitList.drawHeaderCallback = OnDrawHeaderExit;
|
||||
_onExitList.drawElementCallback = OnDrawElementExit;
|
||||
_onExitList.elementHeightCallback = OnHeightElementExit;
|
||||
_onExitList.onAddCallback = OnAddExit;
|
||||
_onExitList.onChangedCallback = OnChangedExit;
|
||||
}
|
||||
|
||||
_onExitList.DoLayoutList();
|
||||
|
||||
if (_onStayList == null)
|
||||
{
|
||||
_onStayList = new ReorderableList(trigger.stayTasks, typeof(CVRAdvancedAvatarSettingsTriggerTaskStay),
|
||||
false, true, true, true);
|
||||
_onStayList.drawHeaderCallback = OnDrawHeaderStay;
|
||||
_onStayList.drawElementCallback = OnDrawElementStay;
|
||||
_onStayList.elementHeightCallback = OnHeightElementStay;
|
||||
_onStayList.onAddCallback = OnAddStay;
|
||||
_onStayList.onChangedCallback = OnChangedStay;
|
||||
}
|
||||
|
||||
_onStayList.DoLayoutList();
|
||||
|
||||
if (trigger.stayTasks.Count > 0)
|
||||
{
|
||||
trigger.sampleDirection = (CVRAdvancedAvatarSettingsTrigger.SampleDirection)
|
||||
EditorGUILayout.EnumPopup("Sample Direction", trigger.sampleDirection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDrawHeaderEnter(Rect rect)
|
||||
{
|
||||
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
GUI.Label(_rect, "On Enter Trigger");
|
||||
}
|
||||
|
||||
private void OnDrawElementEnter(Rect rect, int index, bool isactive, bool isfocused)
|
||||
{
|
||||
if (index > trigger.enterTasks.Count) return;
|
||||
enterEntity = trigger.enterTasks[index];
|
||||
|
||||
Rect _rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Setting Name");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
|
||||
if (animator == null)
|
||||
{
|
||||
enterEntity.settingName = EditorGUI.TextField(_rect, enterEntity.settingName);
|
||||
}
|
||||
else
|
||||
{
|
||||
_rect.y += 1;
|
||||
var animatorParams = animatorParameters.ToArray();
|
||||
var selected = animatorParameters.FindIndex(match => match == enterEntity.settingName);
|
||||
selected = Mathf.Max(EditorGUI.Popup(_rect, selected, animatorParams), 0);
|
||||
enterEntity.settingName = animatorParams[selected];
|
||||
}
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Setting Value");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
enterEntity.settingValue = EditorGUI.FloatField(_rect, enterEntity.settingValue);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Delay");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
enterEntity.delay = EditorGUI.FloatField(_rect, enterEntity.delay);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Hold Time");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
enterEntity.holdTime = EditorGUI.FloatField(_rect, enterEntity.holdTime);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Update Method");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
enterEntity.updateMethod = (CVRAdvancedAvatarSettingsTriggerTask.UpdateMethod) EditorGUI.EnumPopup(_rect, enterEntity.updateMethod);
|
||||
}
|
||||
|
||||
private float OnHeightElementEnter(int index)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight * 6.25f;
|
||||
}
|
||||
|
||||
private void OnAddEnter(ReorderableList list)
|
||||
{
|
||||
trigger.enterTasks.Add(new CVRAdvancedAvatarSettingsTriggerTask());
|
||||
Repaint();
|
||||
}
|
||||
|
||||
private void OnChangedEnter(ReorderableList list)
|
||||
{
|
||||
//EditorUtility.SetDirty(target);
|
||||
}
|
||||
|
||||
private void OnDrawHeaderExit(Rect rect)
|
||||
{
|
||||
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
GUI.Label(_rect, "On Exit Trigger");
|
||||
}
|
||||
|
||||
private void OnDrawElementExit(Rect rect, int index, bool isactive, bool isfocused)
|
||||
{
|
||||
if (index > trigger.exitTasks.Count) return;
|
||||
exitEntity = trigger.exitTasks[index];
|
||||
|
||||
Rect _rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Setting Name");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
|
||||
if (animator == null)
|
||||
{
|
||||
exitEntity.settingName = EditorGUI.TextField(_rect, exitEntity.settingName);
|
||||
}
|
||||
else
|
||||
{
|
||||
_rect.y += 1;
|
||||
var animatorParams = animatorParameters.ToArray();
|
||||
var selected = animatorParameters.FindIndex(match => match == exitEntity.settingName);
|
||||
selected = Mathf.Max(EditorGUI.Popup(_rect, selected, animatorParams), 0);
|
||||
exitEntity.settingName = animatorParams[selected];
|
||||
}
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Setting Value");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
exitEntity.settingValue = EditorGUI.FloatField(_rect, exitEntity.settingValue);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Delay");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
exitEntity.delay = EditorGUI.FloatField(_rect, exitEntity.delay);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Update Method");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
exitEntity.updateMethod = (CVRAdvancedAvatarSettingsTriggerTask.UpdateMethod) EditorGUI.EnumPopup(_rect, exitEntity.updateMethod);
|
||||
}
|
||||
|
||||
private float OnHeightElementExit(int index)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight * 5f;
|
||||
}
|
||||
|
||||
private void OnAddExit(ReorderableList list)
|
||||
{
|
||||
trigger.exitTasks.Add(new CVRAdvancedAvatarSettingsTriggerTask());
|
||||
Repaint();
|
||||
}
|
||||
|
||||
private void OnChangedExit(ReorderableList list)
|
||||
{
|
||||
//EditorUtility.SetDirty(target);
|
||||
}
|
||||
|
||||
private void OnDrawHeaderStay(Rect rect)
|
||||
{
|
||||
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
GUI.Label(_rect, "On Stay Trigger");
|
||||
}
|
||||
|
||||
private void OnDrawElementStay(Rect rect, int index, bool isactive, bool isfocused)
|
||||
{
|
||||
if (index > trigger.stayTasks.Count) return;
|
||||
stayEntity = trigger.stayTasks[index];
|
||||
|
||||
Rect _rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Setting Name");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
|
||||
if (animator == null)
|
||||
{
|
||||
stayEntity.settingName = EditorGUI.TextField(_rect, stayEntity.settingName);
|
||||
}
|
||||
else
|
||||
{
|
||||
_rect.y += 1;
|
||||
var animatorParams = animatorParameters.ToArray();
|
||||
var selected = animatorParameters.FindIndex(match => match == stayEntity.settingName);
|
||||
selected = Mathf.Max(EditorGUI.Popup(_rect, selected, animatorParams), 0);
|
||||
stayEntity.settingName = animatorParams[selected];
|
||||
}
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Update Method");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
|
||||
stayEntity.updateMethod = (CVRAdvancedAvatarSettingsTriggerTaskStay.UpdateMethod) EditorGUI.EnumPopup(_rect, stayEntity.updateMethod);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
if (stayEntity.updateMethod == CVRAdvancedAvatarSettingsTriggerTaskStay.UpdateMethod.SetFromPosition)
|
||||
{
|
||||
EditorGUI.LabelField(_rect, "Min Value");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
stayEntity.minValue = EditorGUI.FloatField(_rect, stayEntity.minValue);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Max Value");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
stayEntity.maxValue = EditorGUI.FloatField(_rect, stayEntity.maxValue);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.LabelField(_rect, "Change per sec");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
stayEntity.minValue = EditorGUI.FloatField(_rect, stayEntity.minValue);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private float OnHeightElementStay(int index)
|
||||
{
|
||||
if (index > trigger.stayTasks.Count) return EditorGUIUtility.singleLineHeight * 3.75f;
|
||||
stayEntity = trigger.stayTasks[index];
|
||||
|
||||
if (stayEntity.updateMethod == CVRAdvancedAvatarSettingsTriggerTaskStay.UpdateMethod.SetFromPosition)
|
||||
return EditorGUIUtility.singleLineHeight * 5f;
|
||||
|
||||
return EditorGUIUtility.singleLineHeight * 3.75f;
|
||||
}
|
||||
|
||||
private void OnAddStay(ReorderableList list)
|
||||
{
|
||||
trigger.stayTasks.Add(new CVRAdvancedAvatarSettingsTriggerTaskStay());
|
||||
Repaint();
|
||||
}
|
||||
|
||||
private void OnChangedStay(ReorderableList list)
|
||||
{
|
||||
//EditorUtility.SetDirty(target);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1a5214eab1704b85ad3364035297e7fb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
287
Assets/ABI.CCK/Scripts/Editor/CCK_CVRAnimatorDriverEditor.cs
Executable file
287
Assets/ABI.CCK/Scripts/Editor/CCK_CVRAnimatorDriverEditor.cs
Executable file
|
@ -0,0 +1,287 @@
|
|||
using System.Collections.Generic;
|
||||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using AnimatorController = UnityEditor.Animations.AnimatorController;
|
||||
using AnimatorControllerParameterType = UnityEngine.AnimatorControllerParameterType;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(ABI.CCK.Components.CVRAnimatorDriver))]
|
||||
public class CCK_CVRAnimatorDriverEditor : UnityEditor.Editor
|
||||
{
|
||||
private CVRAnimatorDriver _driver;
|
||||
|
||||
private ReorderableList reorderableList;
|
||||
|
||||
private List<string> animatorParamNameList = new List<string>();
|
||||
private List<AnimatorControllerParameterType> animatorParamTypeList = new List<AnimatorControllerParameterType>();
|
||||
|
||||
private Dictionary<AnimatorControllerParameterType, int> typeList = new Dictionary<AnimatorControllerParameterType, int>()
|
||||
{
|
||||
{AnimatorControllerParameterType.Float, 0},
|
||||
{AnimatorControllerParameterType.Int, 1},
|
||||
{AnimatorControllerParameterType.Bool, 2},
|
||||
{AnimatorControllerParameterType.Trigger, 3}
|
||||
};
|
||||
|
||||
private void InitializeList()
|
||||
{
|
||||
reorderableList = new ReorderableList(_driver.animators, typeof(Animator),
|
||||
false, true, true, true);
|
||||
reorderableList.drawHeaderCallback = OnDrawHeader;
|
||||
reorderableList.drawElementCallback = OnDrawElement;
|
||||
reorderableList.elementHeightCallback = OnHeightElement;
|
||||
reorderableList.onAddCallback = OnAdd;
|
||||
reorderableList.onChangedCallback = OnChanged;
|
||||
reorderableList.onRemoveCallback = OnRemove;
|
||||
}
|
||||
|
||||
private void OnRemove(ReorderableList list)
|
||||
{
|
||||
_driver.animators.RemoveAt(list.index);
|
||||
_driver.animatorParameters.RemoveAt(list.index);
|
||||
_driver.animatorParameterType.RemoveAt(list.index);
|
||||
Repaint();
|
||||
}
|
||||
|
||||
private void OnChanged(ReorderableList list)
|
||||
{
|
||||
//EditorUtility.SetDirty(target);
|
||||
}
|
||||
|
||||
private void OnAdd(ReorderableList list)
|
||||
{
|
||||
if (_driver.animators.Count >= 16) return;
|
||||
_driver.animators.Add(null);
|
||||
_driver.animatorParameters.Add(null);
|
||||
_driver.animatorParameterType.Add(0);
|
||||
Repaint();
|
||||
}
|
||||
|
||||
private float OnHeightElement(int index)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight * 3 * 1.25f;
|
||||
}
|
||||
|
||||
private void OnDrawElement(Rect rect, int index, bool isactive, bool isfocused)
|
||||
{
|
||||
if (index > _driver.animators.Count) return;
|
||||
|
||||
rect.y += 2;
|
||||
rect.x += 12;
|
||||
rect.width -= 12;
|
||||
Rect _rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Animator");
|
||||
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
var animator = (Animator) EditorGUI.ObjectField(_rect, _driver.animators[index], typeof(Animator), true);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(target, "Animator Driver Animator changed");
|
||||
EditorUtility.SetDirty(_driver);
|
||||
_driver.animators[index] = animator;
|
||||
}
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Parameter");
|
||||
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
|
||||
animatorParamNameList.Clear();
|
||||
animatorParamTypeList.Clear();
|
||||
|
||||
animatorParamNameList.Add("-none-");
|
||||
animatorParamTypeList.Add(AnimatorControllerParameterType.Bool);
|
||||
|
||||
var oldIndex = 0;
|
||||
var i = 1;
|
||||
|
||||
if (_driver.animators[index] != null && _driver.animators[index].runtimeAnimatorController != null)
|
||||
{
|
||||
var controller = (AnimatorController) _driver.animators[index].runtimeAnimatorController;
|
||||
foreach (var parameter in controller.parameters)
|
||||
{
|
||||
animatorParamNameList.Add(parameter.name);
|
||||
animatorParamTypeList.Add(parameter.type);
|
||||
|
||||
if (_driver.animatorParameters[index] == parameter.name)
|
||||
{
|
||||
oldIndex = i;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
var parameterIndex = EditorGUI.Popup(_rect, oldIndex, animatorParamNameList.ToArray());
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(target, "Animator Driver Parameter changed");
|
||||
EditorUtility.SetDirty(_driver);
|
||||
_driver.animatorParameters[index] = animatorParamNameList[parameterIndex];
|
||||
_driver.animatorParameterType[index] = typeList[animatorParamTypeList[parameterIndex]];
|
||||
}
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Value");
|
||||
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
var value = EditorGUI.FloatField(_rect, GetAnimatorParameterValue(index));
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(target, "Animator Driver Value changed");
|
||||
EditorUtility.SetDirty(_driver);
|
||||
SetAnimatorParameterValue(index, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDrawHeader(Rect rect)
|
||||
{
|
||||
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
GUI.Label(_rect, "Animator Parameters");
|
||||
}
|
||||
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (_driver == null) _driver = (CVRAnimatorDriver) target;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
if (reorderableList == null) InitializeList();
|
||||
reorderableList.DoLayoutList();
|
||||
}
|
||||
|
||||
public float GetAnimatorParameterValue(int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return _driver.animatorParameter01;
|
||||
break;
|
||||
case 1:
|
||||
return _driver.animatorParameter02;
|
||||
break;
|
||||
case 2:
|
||||
return _driver.animatorParameter03;
|
||||
break;
|
||||
case 3:
|
||||
return _driver.animatorParameter04;
|
||||
break;
|
||||
case 4:
|
||||
return _driver.animatorParameter05;
|
||||
break;
|
||||
case 5:
|
||||
return _driver.animatorParameter06;
|
||||
break;
|
||||
case 6:
|
||||
return _driver.animatorParameter07;
|
||||
break;
|
||||
case 7:
|
||||
return _driver.animatorParameter08;
|
||||
break;
|
||||
case 8:
|
||||
return _driver.animatorParameter09;
|
||||
break;
|
||||
case 9:
|
||||
return _driver.animatorParameter10;
|
||||
break;
|
||||
case 10:
|
||||
return _driver.animatorParameter11;
|
||||
break;
|
||||
case 11:
|
||||
return _driver.animatorParameter12;
|
||||
break;
|
||||
case 12:
|
||||
return _driver.animatorParameter13;
|
||||
break;
|
||||
case 13:
|
||||
return _driver.animatorParameter14;
|
||||
break;
|
||||
case 14:
|
||||
return _driver.animatorParameter15;
|
||||
break;
|
||||
default:
|
||||
return _driver.animatorParameter16;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAnimatorParameterValue(int index, float value)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
_driver.animatorParameter01 = value;
|
||||
break;
|
||||
case 1:
|
||||
_driver.animatorParameter02 = value;
|
||||
break;
|
||||
case 2:
|
||||
_driver.animatorParameter03 = value;
|
||||
break;
|
||||
case 3:
|
||||
_driver.animatorParameter04 = value;
|
||||
break;
|
||||
case 4:
|
||||
_driver.animatorParameter05 = value;
|
||||
break;
|
||||
case 5:
|
||||
_driver.animatorParameter06 = value;
|
||||
break;
|
||||
case 6:
|
||||
_driver.animatorParameter07 = value;
|
||||
break;
|
||||
case 7:
|
||||
_driver.animatorParameter08 = value;
|
||||
break;
|
||||
case 8:
|
||||
_driver.animatorParameter09 = value;
|
||||
break;
|
||||
case 9:
|
||||
_driver.animatorParameter10 = value;
|
||||
break;
|
||||
case 10:
|
||||
_driver.animatorParameter11 = value;
|
||||
break;
|
||||
case 11:
|
||||
_driver.animatorParameter12 = value;
|
||||
break;
|
||||
case 12:
|
||||
_driver.animatorParameter13 = value;
|
||||
break;
|
||||
case 13:
|
||||
_driver.animatorParameter14 = value;
|
||||
break;
|
||||
case 14:
|
||||
_driver.animatorParameter15 = value;
|
||||
break;
|
||||
default:
|
||||
_driver.animatorParameter16 = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRAnimatorDriverEditor.cs.meta
Executable file
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRAnimatorDriverEditor.cs.meta
Executable file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f80fa88a5f324dc2baba380a78cf3ac2
|
||||
timeCreated: 1622860287
|
66
Assets/ABI.CCK/Scripts/Editor/CCK_CVRAssetInfoEditor.cs
Executable file
66
Assets/ABI.CCK/Scripts/Editor/CCK_CVRAssetInfoEditor.cs
Executable file
|
@ -0,0 +1,66 @@
|
|||
using System;
|
||||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
|
||||
[CustomEditor(typeof(ABI.CCK.Components.CVRAssetInfo))]
|
||||
public class CCK_CVRAssetInfoEditor : UnityEditor.Editor
|
||||
{
|
||||
private CVRAssetInfo _info;
|
||||
private string _newGuid;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (_info == null) _info = (CVRAssetInfo)target;
|
||||
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_HEADER_INFORMATION"), MessageType.Info);
|
||||
|
||||
if (!string.IsNullOrEmpty(_info.objectId))
|
||||
{
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_GUID_LABEL") + _info.objectId, MessageType.Info);
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
if (GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_DETACH_BUTTON")))
|
||||
{
|
||||
bool detach = EditorUtility.DisplayDialog(
|
||||
CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_DETACH_BUTTON_DIALOG_TITLE"),
|
||||
CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_DETACH_BUTTON_DIALOG_BODY"),
|
||||
CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_DETACH_BUTTON_DIALOG_ACCEPT"),
|
||||
CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_DETACH_BUTTON_DIALOG_DENY"));
|
||||
if (detach) DetachGuid();
|
||||
}
|
||||
|
||||
if (GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_COPY_BUTTON")))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_info.objectId))
|
||||
{
|
||||
GUIUtility.systemCopyBuffer = _info.objectId;
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
else
|
||||
{
|
||||
_newGuid = EditorGUILayout.TextField(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_ATTACH_LABEL"), _newGuid);
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_ATTACH_INFO"), MessageType.Warning);
|
||||
if (GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_ATTACH_BUTTON"))) ReattachGuid(_newGuid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void DetachGuid()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_info.objectId)) _info.objectId = string.Empty;
|
||||
}
|
||||
private void ReattachGuid(string Guid)
|
||||
{
|
||||
_info.objectId = Guid;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRAssetInfoEditor.cs.meta
Executable file
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRAssetInfoEditor.cs.meta
Executable file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 48b4c08063af4400ae880f2c7ee030ff
|
||||
timeCreated: 1574589249
|
1168
Assets/ABI.CCK/Scripts/Editor/CCK_CVRAvatarEditor.cs
Executable file
1168
Assets/ABI.CCK/Scripts/Editor/CCK_CVRAvatarEditor.cs
Executable file
File diff suppressed because it is too large
Load diff
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRAvatarEditor.cs.meta
Executable file
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRAvatarEditor.cs.meta
Executable file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e7b3dab747ad467fab76e5d43bb42298
|
||||
timeCreated: 1573835270
|
59
Assets/ABI.CCK/Scripts/Editor/CCK_CVRDescriptionEditor.cs
Executable file
59
Assets/ABI.CCK/Scripts/Editor/CCK_CVRDescriptionEditor.cs
Executable file
|
@ -0,0 +1,59 @@
|
|||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(ABI.CCK.Components.CVRDescription))]
|
||||
public class CCK_CVRDescriptionEditor : UnityEditor.Editor
|
||||
{
|
||||
private CVRDescription _description;
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (_description == null) _description = (CVRDescription) target;
|
||||
|
||||
if (_description.locked)
|
||||
{
|
||||
switch (_description.type)
|
||||
{
|
||||
case 0:
|
||||
EditorGUILayout.HelpBox(_description.description, MessageType.None);
|
||||
break;
|
||||
case 1:
|
||||
EditorGUILayout.HelpBox(_description.description, MessageType.Info);
|
||||
break;
|
||||
case 2:
|
||||
EditorGUILayout.HelpBox(_description.description, MessageType.Warning);
|
||||
break;
|
||||
case 3:
|
||||
EditorGUILayout.HelpBox(_description.description, MessageType.Error);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(_description.url))
|
||||
{
|
||||
if (GUILayout.Button("Read more about this topic"))
|
||||
{
|
||||
Application.OpenURL(_description.url);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.LabelField("Description");
|
||||
_description.description = EditorGUILayout.TextArea(_description.description);
|
||||
|
||||
EditorGUILayout.LabelField("Documentation Url");
|
||||
_description.url = EditorGUILayout.TextField(_description.url);
|
||||
|
||||
EditorGUILayout.LabelField("Icon Type");
|
||||
_description.type = EditorGUILayout.Popup(_description.type, new string[] { "None", "Info", "Warning", "Error" });
|
||||
|
||||
if (GUILayout.Button("Lock info"))
|
||||
{
|
||||
_description.locked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRDescriptionEditor.cs.meta
Executable file
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRDescriptionEditor.cs.meta
Executable file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 08bdd1015ea341a79650e069d11b4285
|
||||
timeCreated: 1643768897
|
132
Assets/ABI.CCK/Scripts/Editor/CCK_CVRFaceTrackingEditor.cs
Executable file
132
Assets/ABI.CCK/Scripts/Editor/CCK_CVRFaceTrackingEditor.cs
Executable file
|
@ -0,0 +1,132 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(ABI.CCK.Components.CVRFaceTracking))]
|
||||
public class CCK_CVRFaceTrackingEditor : UnityEditor.Editor
|
||||
{
|
||||
private CVRFaceTracking _faceTracking;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (_faceTracking == null) _faceTracking = (CVRFaceTracking) target;
|
||||
|
||||
_faceTracking.GetBlendShapeNames();
|
||||
|
||||
_faceTracking.UseFacialTracking = EditorGUILayout.Toggle("Enable Facial Tracking", _faceTracking.UseFacialTracking);
|
||||
|
||||
_faceTracking.BlendShapeStrength = EditorGUILayout.Slider("Blend Shape Weight", _faceTracking.BlendShapeStrength, 50f, 500f);
|
||||
|
||||
_faceTracking.FaceMesh = (SkinnedMeshRenderer)EditorGUILayout.ObjectField("Face Mesh", _faceTracking.FaceMesh, typeof(SkinnedMeshRenderer), true);
|
||||
|
||||
for (int i = 0; i < CVRFaceTracking.FaceBlendShapeNames.Length; i++)
|
||||
{
|
||||
int current = 0;
|
||||
for (int j = 0; j < _faceTracking.BlendShapeNames.Count; ++j)
|
||||
if (_faceTracking.FaceBlendShapes[i] == _faceTracking.BlendShapeNames[j])
|
||||
current = j;
|
||||
|
||||
int viseme = EditorGUILayout.Popup(CVRFaceTracking.FaceBlendShapeNames[i], current, _faceTracking.BlendShapeNames.ToArray());
|
||||
_faceTracking.FaceBlendShapes[i] = _faceTracking.BlendShapeNames[viseme];
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Auto select Blendshapes"))
|
||||
{
|
||||
_faceTracking.FindVisemes();
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginVertical("HelpBox");
|
||||
EditorGUILayout.LabelField("Face Tracking ");
|
||||
EditorGUILayout.BeginVertical("GroupBox");
|
||||
|
||||
_faceTracking.enableOverdriveBlendShapes = EditorGUILayout.Toggle("Enable Overdrive", _faceTracking.enableOverdriveBlendShapes);
|
||||
EditorGUILayout.HelpBox("By enabling overdrive the system expects the blendshapes to be at 500% when fully set. You can use the button below to generate 500% versions of the currently selected blendshapes.", MessageType.Info);
|
||||
|
||||
if (GUILayout.Button("Generate overdrive Blendshapes (Experimental)"))
|
||||
{
|
||||
GenerateOverdriveBlendShapes();
|
||||
}
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.HelpBox("We have prepared a way to generate a simple facial tracker support for your avatars without any requirement to use a 3D model software. For a more in-depth / detailed support, please create the required blendshapes using a 3D modeling software. More information can be found in our documentation.", MessageType.Info);
|
||||
|
||||
if (GUILayout.Button("Open Blendshape Generator (Experimental)"))
|
||||
{
|
||||
CCK_FaceTrackingUtilities window = (CCK_FaceTrackingUtilities)EditorWindow.GetWindow (typeof(CCK_FaceTrackingUtilities), true, "CCK :: Face Tracking Utilities");
|
||||
window.Avatar = _faceTracking.gameObject.GetComponent<CVRAvatar>();
|
||||
if (window.Avatar == null) window.Avatar = _faceTracking.gameObject.GetComponentInParent<CVRAvatar>();
|
||||
window.FaceTracking = _faceTracking;
|
||||
window.Tab = 1;
|
||||
window.Show();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Reset to original Mesh"))
|
||||
{
|
||||
if (_faceTracking.OriginalMesh != null)
|
||||
{
|
||||
_faceTracking.FaceMesh.sharedMesh = _faceTracking.OriginalMesh;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void GenerateOverdriveBlendShapes()
|
||||
{
|
||||
Mesh mesh;
|
||||
CVRAvatar avatar = _faceTracking.GetComponentInParent<CVRAvatar>();
|
||||
|
||||
if (_faceTracking.FaceMesh.sharedMesh != _faceTracking.OriginalMesh)
|
||||
{
|
||||
mesh = _faceTracking.FaceMesh.sharedMesh.Copy();
|
||||
|
||||
string pathToCurrentFolder = "Assets/FaceTracking.Generated";
|
||||
if (!AssetDatabase.IsValidFolder(pathToCurrentFolder)) AssetDatabase.CreateFolder("Assets", "FaceTracking.Generated");
|
||||
var meshPath = pathToCurrentFolder + "/" + avatar.transform.name + ".mesh";
|
||||
AssetDatabase.CreateAsset(mesh, meshPath);
|
||||
|
||||
_faceTracking.FaceMesh.sharedMesh = mesh;
|
||||
}
|
||||
else
|
||||
{
|
||||
mesh = _faceTracking.FaceMesh.sharedMesh;
|
||||
}
|
||||
|
||||
for (int i = 0; i < mesh.blendShapeCount; i++)
|
||||
{
|
||||
if (_faceTracking.FaceBlendShapes.Contains(mesh.GetBlendShapeName(i)))
|
||||
{
|
||||
var frameCount = mesh.GetBlendShapeFrameCount(i);
|
||||
var frameWeight = mesh.GetBlendShapeFrameWeight(i, frameCount - 1);
|
||||
if (!mesh.GetBlendShapeName(i).Contains("_overdrive"))
|
||||
{
|
||||
Vector3[] deltaVertices = new Vector3[mesh.vertexCount];
|
||||
Vector3[] deltaNormals = new Vector3[mesh.vertexCount];
|
||||
Vector3[] deltaTangents = new Vector3[mesh.vertexCount];
|
||||
mesh.GetBlendShapeFrameVertices(i, 0, deltaVertices, deltaNormals, deltaTangents);
|
||||
|
||||
for (int j=0; j < deltaVertices.Length; j++)
|
||||
{
|
||||
deltaVertices[j] = deltaVertices[j] * 5f;
|
||||
}
|
||||
|
||||
mesh.AddBlendShapeFrame(mesh.GetBlendShapeName(i)+"_overdrive", 100f, deltaVertices, deltaNormals, deltaTangents);
|
||||
var index = _faceTracking.FaceBlendShapes.ToList().FindIndex(m => m == mesh.GetBlendShapeName(i));
|
||||
_faceTracking.FaceBlendShapes[index] = mesh.GetBlendShapeName(i) + "_overdrive";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_faceTracking.GetBlendShapeNames();
|
||||
_faceTracking.enableOverdriveBlendShapes = true;
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRFaceTrackingEditor.cs.meta
Executable file
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRFaceTrackingEditor.cs.meta
Executable file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ac9db061851946bbb5d249c7bb013765
|
||||
timeCreated: 1621992840
|
55
Assets/ABI.CCK/Scripts/Editor/CCK_CVRGlobalMaterialPropertyUpdaterEditor.cs
Executable file
55
Assets/ABI.CCK/Scripts/Editor/CCK_CVRGlobalMaterialPropertyUpdaterEditor.cs
Executable file
|
@ -0,0 +1,55 @@
|
|||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(CVRGlobalMaterialPropertyUpdater))]
|
||||
public class CCK_CVRGlobalMaterialPropertyUpdaterEditor : UnityEditor.Editor
|
||||
{
|
||||
private CVRGlobalMaterialPropertyUpdater _target;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (_target == null) _target = (CVRGlobalMaterialPropertyUpdater) target;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
Material material = (Material) EditorGUILayout.ObjectField("Material", _target.material, typeof(Material));
|
||||
|
||||
CVRGlobalMaterialPropertyUpdater.PropertyType type = (CVRGlobalMaterialPropertyUpdater.PropertyType) EditorGUILayout.EnumPopup("Property Type", _target.propertyType);
|
||||
|
||||
string name = EditorGUILayout.TextField("Property Name", _target.propertyName);
|
||||
|
||||
int intval = 0;
|
||||
float floatval = 0f;
|
||||
Vector4 vectorval = Vector4.zero;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case CVRGlobalMaterialPropertyUpdater.PropertyType.paramInt:
|
||||
intval = EditorGUILayout.IntField("Value", _target.intValue);
|
||||
break;
|
||||
case CVRGlobalMaterialPropertyUpdater.PropertyType.paramFloat:
|
||||
floatval = EditorGUILayout.FloatField("Value", _target.floatValue);
|
||||
break;
|
||||
case CVRGlobalMaterialPropertyUpdater.PropertyType.paramVector4:
|
||||
vectorval = EditorGUILayout.Vector4Field("Value", _target.vector4Value);
|
||||
break;
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(target, "Changed CVRGlobalMaterialPropertyUpdater");
|
||||
|
||||
_target.material = material;
|
||||
_target.propertyType = type;
|
||||
_target.propertyName = name;
|
||||
|
||||
_target.intValue = intval;
|
||||
_target.floatValue = floatval;
|
||||
_target.vector4Value = vectorval;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 57c8fcff5e4d48a199de9d61afa43390
|
||||
timeCreated: 1644963336
|
62
Assets/ABI.CCK/Scripts/Editor/CCK_CVRGlobalShaderUpdaterEditor.cs
Executable file
62
Assets/ABI.CCK/Scripts/Editor/CCK_CVRGlobalShaderUpdaterEditor.cs
Executable file
|
@ -0,0 +1,62 @@
|
|||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(ABI.CCK.Components.CVRGlobalShaderUpdater))]
|
||||
public class CCK_CVRGlobalShaderUpdaterEditor : UnityEditor.Editor
|
||||
{
|
||||
private CVRGlobalShaderUpdater _globalShaderUpdater;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (_globalShaderUpdater == null) _globalShaderUpdater = (CVRGlobalShaderUpdater) target;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
bool updateValues = EditorGUILayout.Toggle("Update Values", _globalShaderUpdater.updateValues);
|
||||
|
||||
Vector4 CVR_CCK_Global_1 = Vector4.zero;
|
||||
Vector4 CVR_CCK_Global_2 = Vector4.zero;
|
||||
Vector4 CVR_CCK_Global_3 = Vector4.zero;
|
||||
Vector4 CVR_CCK_Global_4 = Vector4.zero;
|
||||
|
||||
if (updateValues)
|
||||
{
|
||||
CVR_CCK_Global_1 = EditorGUILayout.Vector4Field("CVR_CCK_Global_1", _globalShaderUpdater.CVR_CCK_Global_1);
|
||||
CVR_CCK_Global_2 = EditorGUILayout.Vector4Field("CVR_CCK_Global_2", _globalShaderUpdater.CVR_CCK_Global_2);
|
||||
CVR_CCK_Global_3 = EditorGUILayout.Vector4Field("CVR_CCK_Global_3", _globalShaderUpdater.CVR_CCK_Global_3);
|
||||
CVR_CCK_Global_4 = EditorGUILayout.Vector4Field("CVR_CCK_Global_4", _globalShaderUpdater.CVR_CCK_Global_4);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
bool updateTexture = EditorGUILayout.Toggle("Update Texture", _globalShaderUpdater.updateTexture);
|
||||
|
||||
RenderTexture renderTexture = null;
|
||||
string propertyName = "";
|
||||
|
||||
if (updateTexture)
|
||||
{
|
||||
renderTexture = (RenderTexture) EditorGUILayout.ObjectField("Render Texture", _globalShaderUpdater.renderTexture, typeof(RenderTexture));
|
||||
propertyName = EditorGUILayout.TextField("Property Name", _globalShaderUpdater.propertyName);
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(target, "Changed CVRGlobalShaderUpdater");
|
||||
|
||||
_globalShaderUpdater.updateValues = updateValues;
|
||||
_globalShaderUpdater.CVR_CCK_Global_1 = CVR_CCK_Global_1;
|
||||
_globalShaderUpdater.CVR_CCK_Global_2 = CVR_CCK_Global_2;
|
||||
_globalShaderUpdater.CVR_CCK_Global_3 = CVR_CCK_Global_3;
|
||||
_globalShaderUpdater.CVR_CCK_Global_4 = CVR_CCK_Global_4;
|
||||
|
||||
_globalShaderUpdater.updateTexture = updateTexture;
|
||||
_globalShaderUpdater.renderTexture = renderTexture;
|
||||
_globalShaderUpdater.propertyName = propertyName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRGlobalShaderUpdaterEditor.cs.meta
Executable file
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRGlobalShaderUpdaterEditor.cs.meta
Executable file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 92b8c0189baf4b43b7e078dc60873604
|
||||
timeCreated: 1644957427
|
99
Assets/ABI.CCK/Scripts/Editor/CCK_CVRHapticZoneEditor.cs
Executable file
99
Assets/ABI.CCK/Scripts/Editor/CCK_CVRHapticZoneEditor.cs
Executable file
|
@ -0,0 +1,99 @@
|
|||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(CVRHapticZone))]
|
||||
public class CCK_CVRHapticZoneEditor : UnityEditor.Editor
|
||||
{
|
||||
private CVRHapticZone _hapticZone;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (_hapticZone == null) _hapticZone = (CVRHapticZone) target;
|
||||
|
||||
_hapticZone.triggerForm = (CVRHapticZone.TriggerForm) EditorGUILayout.EnumPopup("Trigger Form", _hapticZone.triggerForm);
|
||||
|
||||
_hapticZone.center = EditorGUILayout.Vector3Field("Trigger Center", _hapticZone.center);
|
||||
|
||||
if (_hapticZone.triggerForm == CVRHapticZone.TriggerForm.Box)
|
||||
{
|
||||
_hapticZone.bounds = EditorGUILayout.Vector3Field("Trigger Bounds", _hapticZone.bounds);
|
||||
}
|
||||
else
|
||||
{
|
||||
_hapticZone.bounds.x = EditorGUILayout.FloatField("Trigger Radius", _hapticZone.bounds.x);
|
||||
}
|
||||
|
||||
GUILayout.BeginVertical("HelpBox");
|
||||
|
||||
GUILayout.BeginHorizontal ();
|
||||
_hapticZone.enableOnEnter = EditorGUILayout.Toggle (_hapticZone.enableOnEnter, GUILayout.Width(16));
|
||||
EditorGUILayout.LabelField ("On Enter", GUILayout.Width(150));
|
||||
GUILayout.EndHorizontal ();
|
||||
|
||||
if (_hapticZone.enableOnEnter)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.BeginVertical("GroupBox");
|
||||
|
||||
_hapticZone.onEnterIntensity = EditorGUILayout.Slider("Intensity", _hapticZone.onEnterIntensity, 0f, 1f);
|
||||
|
||||
GUILayout.EndVertical ();
|
||||
GUILayout.EndHorizontal ();
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
|
||||
GUILayout.BeginVertical("HelpBox");
|
||||
|
||||
GUILayout.BeginHorizontal ();
|
||||
_hapticZone.enableOnStay = EditorGUILayout.Toggle (_hapticZone.enableOnStay, GUILayout.Width(16));
|
||||
EditorGUILayout.LabelField ("On Stay", GUILayout.Width(150));
|
||||
GUILayout.EndHorizontal ();
|
||||
|
||||
if (_hapticZone.enableOnStay)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.BeginVertical("GroupBox");
|
||||
|
||||
_hapticZone.onStayIntensity = EditorGUILayout.Slider("Intensity", _hapticZone.onStayIntensity, 0f, 1f);
|
||||
|
||||
_hapticZone.onStayTiming = (CVRHapticZone.TriggerTiming) EditorGUILayout.EnumPopup("Timing", _hapticZone.onStayTiming);
|
||||
|
||||
if (_hapticZone.onStayTiming == CVRHapticZone.TriggerTiming.random)
|
||||
{
|
||||
_hapticZone.onStayChance = EditorGUILayout.Slider("Chance", _hapticZone.onStayChance, 0f, 1f);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical ();
|
||||
GUILayout.EndHorizontal ();
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
|
||||
GUILayout.BeginVertical("HelpBox");
|
||||
|
||||
GUILayout.BeginHorizontal ();
|
||||
_hapticZone.enableOnExit = EditorGUILayout.Toggle (_hapticZone.enableOnExit, GUILayout.Width(16));
|
||||
EditorGUILayout.LabelField ("On Exit", GUILayout.Width(150));
|
||||
GUILayout.EndHorizontal ();
|
||||
|
||||
if (_hapticZone.enableOnExit)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.BeginVertical("GroupBox");
|
||||
|
||||
_hapticZone.onExitIntensity = EditorGUILayout.Slider("Intensity", _hapticZone.onExitIntensity, 0f, 1f);
|
||||
|
||||
GUILayout.EndVertical ();
|
||||
GUILayout.EndHorizontal ();
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/ABI.CCK/Scripts/Editor/CCK_CVRHapticZoneEditor.cs.meta
Executable file
11
Assets/ABI.CCK/Scripts/Editor/CCK_CVRHapticZoneEditor.cs.meta
Executable file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a20c15de10fd4cc597d67a34c37fa9ec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
1047
Assets/ABI.CCK/Scripts/Editor/CCK_CVRInteractableEditor.cs
Executable file
1047
Assets/ABI.CCK/Scripts/Editor/CCK_CVRInteractableEditor.cs
Executable file
File diff suppressed because it is too large
Load diff
11
Assets/ABI.CCK/Scripts/Editor/CCK_CVRInteractableEditor.cs.meta
Executable file
11
Assets/ABI.CCK/Scripts/Editor/CCK_CVRInteractableEditor.cs.meta
Executable file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 748e23d846751944d9f9db5790811171
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
367
Assets/ABI.CCK/Scripts/Editor/CCK_CVRObjectLibraryEditor.cs
Executable file
367
Assets/ABI.CCK/Scripts/Editor/CCK_CVRObjectLibraryEditor.cs
Executable file
|
@ -0,0 +1,367 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(ABI.CCK.Components.CVRObjectLibrary)), CanEditMultipleObjects]
|
||||
public class CCK_CVRObjectLibraryEditor : UnityEditor.Editor
|
||||
{
|
||||
private CVRObjectLibrary _library;
|
||||
|
||||
private ReorderableList CategoryList = null;
|
||||
private CVRObjectCatalogCategory objectCatalogCategory = null;
|
||||
private List<string> popupListName = new List<string>();
|
||||
private List<string> popupListID = new List<string>();
|
||||
|
||||
private ReorderableList objectCatalogList = null;
|
||||
private CVRObjectCatalogEntry objectCatalogEntry = null;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (_library == null) _library = (CVRObjectLibrary) target;
|
||||
|
||||
EditorGUILayout.LabelField("Object Library");
|
||||
|
||||
InitializeCategoryList();
|
||||
CategoryList.DoLayoutList();
|
||||
popupListName.Clear();
|
||||
popupListID.Clear();
|
||||
foreach (var category in _library.objectCatalogCategories)
|
||||
{
|
||||
if (string.IsNullOrEmpty(category.id)) category.id = "b~" + System.Guid.NewGuid().ToString();
|
||||
popupListName.Add(string.IsNullOrEmpty(category.name) ? "-" : category.name);
|
||||
popupListID.Add(category.id);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
InitializeObjectCatalogList();
|
||||
objectCatalogList.displayAdd = _library.objectCatalogCategories.Count > 0;
|
||||
objectCatalogList.DoLayoutList();
|
||||
}
|
||||
|
||||
private void InitializeCategoryList()
|
||||
{
|
||||
if (CategoryList != null) return;
|
||||
|
||||
CategoryList = new ReorderableList(_library.objectCatalogCategories, typeof(CVRObjectCatalogCategory),
|
||||
false, true, true, true);
|
||||
CategoryList.drawHeaderCallback = OnDrawHeaderCategory;
|
||||
CategoryList.drawElementCallback = OnDrawElementCategory;
|
||||
CategoryList.elementHeightCallback = OnHeightElementCategory;
|
||||
CategoryList.onChangedCallback = OnChangedCategory;
|
||||
}
|
||||
|
||||
private void OnDrawHeaderCategory(Rect rect)
|
||||
{
|
||||
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
GUI.Label(_rect, "Categories");
|
||||
}
|
||||
|
||||
private void OnDrawElementCategory(Rect rect, int index, bool isactive, bool isfocused)
|
||||
{
|
||||
if (index > _library.objectCatalogCategories.Count) return;
|
||||
objectCatalogCategory = _library.objectCatalogCategories[index];
|
||||
|
||||
Rect _rect = new Rect(rect.x + 50, rect.y, 50, EditorGUIUtility.singleLineHeight);
|
||||
Rect initialRect = rect;
|
||||
|
||||
EditorGUI.LabelField(_rect, "Name");
|
||||
_rect.x += 50;
|
||||
_rect.width = rect.width - 50 - 50;
|
||||
|
||||
objectCatalogCategory.name = EditorGUI.TextField(_rect, objectCatalogCategory.name);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x + 50, rect.y, 50, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Image");
|
||||
_rect.x += 50;
|
||||
_rect.width = rect.width - 50 - 50;
|
||||
|
||||
objectCatalogCategory.image = (Texture2D) EditorGUI.ObjectField(_rect, objectCatalogCategory.image, typeof(Texture2D));
|
||||
|
||||
if (objectCatalogCategory.image != null)
|
||||
{
|
||||
GUI.DrawTexture(new Rect(initialRect.x, initialRect.y, 42, 42), objectCatalogCategory.image);
|
||||
}
|
||||
}
|
||||
|
||||
private float OnHeightElementCategory(int index)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight * 2.5f;
|
||||
}
|
||||
|
||||
private void OnChangedCategory(ReorderableList list)
|
||||
{
|
||||
EditorUtility.SetDirty(target);
|
||||
}
|
||||
|
||||
private void InitializeObjectCatalogList()
|
||||
{
|
||||
if (objectCatalogList != null) return;
|
||||
|
||||
objectCatalogList = new ReorderableList(_library.objectCatalogEntries, typeof(CVRObjectCatalogEntry),
|
||||
true, true, true, true);
|
||||
objectCatalogList.drawHeaderCallback = OnDrawHeaderEntry;
|
||||
objectCatalogList.drawElementCallback = OnDrawElementEntry;
|
||||
objectCatalogList.elementHeightCallback = OnHeightElementEntry;
|
||||
objectCatalogList.onChangedCallback = OnChangedEntry;
|
||||
}
|
||||
|
||||
private void OnDrawHeaderEntry(Rect rect)
|
||||
{
|
||||
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
GUI.Label(_rect, "Objects");
|
||||
}
|
||||
|
||||
private void OnDrawElementEntry(Rect rect, int index, bool isactive, bool isfocused)
|
||||
{
|
||||
if (index > _library.objectCatalogEntries.Count) return;
|
||||
objectCatalogEntry = _library.objectCatalogEntries[index];
|
||||
|
||||
while (objectCatalogEntry.guid == "")
|
||||
{
|
||||
var guid = "b~" + System.Guid.NewGuid().ToString();
|
||||
var guidValid = true;
|
||||
|
||||
foreach (var entry in _library.objectCatalogEntries)
|
||||
{
|
||||
if (entry.guid == guid) guidValid = false;
|
||||
}
|
||||
|
||||
if (!guidValid) continue;
|
||||
objectCatalogEntry.guid = guid;
|
||||
}
|
||||
|
||||
Rect _rect = new Rect(rect.x + 100, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
Rect initialRect = rect;
|
||||
|
||||
EditorGUI.LabelField(_rect, "Name");
|
||||
_rect.x += 60;
|
||||
_rect.width = rect.width - 160;
|
||||
|
||||
objectCatalogEntry.name = EditorGUI.TextField(_rect, objectCatalogEntry.name);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x + 100, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Prefab");
|
||||
_rect.x += 60;
|
||||
_rect.width = rect.width - 160;
|
||||
|
||||
objectCatalogEntry.prefab = (GameObject) EditorGUI.ObjectField(_rect, objectCatalogEntry.prefab, typeof(GameObject));
|
||||
|
||||
if (objectCatalogEntry.prefab != null)
|
||||
{
|
||||
var spawnable = objectCatalogEntry.prefab.GetComponent<CVRSpawnable>();
|
||||
var builder = objectCatalogEntry.prefab.GetComponent<CVRBuilderSpawnable>();
|
||||
|
||||
if (spawnable == null && builder == null) objectCatalogEntry.prefab = null;
|
||||
}
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x + 100, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Category");
|
||||
_rect.x += 60;
|
||||
_rect.width = rect.width - 160;
|
||||
|
||||
var catIndex = popupListID.IndexOf(objectCatalogEntry.categoryId);
|
||||
catIndex = EditorGUI.Popup(_rect, catIndex, popupListName.ToArray());
|
||||
if (catIndex >= 0) objectCatalogEntry.categoryId = popupListID[catIndex];
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x + 100, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Preview");
|
||||
_rect.x += 60;
|
||||
_rect.width = rect.width - 160;
|
||||
|
||||
objectCatalogEntry.preview = (Texture2D) EditorGUI.ObjectField(_rect, objectCatalogEntry.preview, typeof(Texture2D));
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
if (GUI.Button(_rect, "Generate Preview"))
|
||||
{
|
||||
GeneratePreviewImage(objectCatalogEntry);
|
||||
}
|
||||
|
||||
if (objectCatalogEntry.preview != null)
|
||||
{
|
||||
GUI.DrawTexture(new Rect(initialRect.x, initialRect.y, 88, 88), objectCatalogEntry.preview);
|
||||
}
|
||||
}
|
||||
|
||||
private void GeneratePreviewImage(CVRObjectCatalogEntry objectCatalogEntry)
|
||||
{
|
||||
if (objectCatalogEntry.prefab == null) return;
|
||||
|
||||
var path = "Assets/ABI.CCK/Resources/WorldObjectCatalog";
|
||||
var objectPosition = Vector3.down * 1000f;
|
||||
var rt = new RenderTexture(256, 256, 32);
|
||||
|
||||
if (!AssetDatabase.IsValidFolder(path))
|
||||
AssetDatabase.CreateFolder("Assets/ABI.CCK/Resources", "WorldObjectCatalog");
|
||||
|
||||
var obj = Instantiate(objectCatalogEntry.prefab, objectPosition, Quaternion.identity);
|
||||
|
||||
var renderers = obj.GetComponentsInChildren<Renderer>();
|
||||
Bounds b = new Bounds(Vector3.zero, Vector3.zero);
|
||||
|
||||
foreach (var renderer in renderers)
|
||||
{
|
||||
if (b.size.y == 0f)
|
||||
{
|
||||
b = renderer.bounds;
|
||||
}
|
||||
else
|
||||
{
|
||||
b.Encapsulate(renderer.bounds);
|
||||
}
|
||||
}
|
||||
|
||||
var transforms = obj.GetComponentsInChildren<Transform>();
|
||||
foreach (var transform in transforms)
|
||||
{
|
||||
transform.gameObject.layer = 12;
|
||||
}
|
||||
|
||||
var cam = new GameObject("Preview Capture", new[] {typeof(Camera), typeof(Light)}).GetComponent<Camera>();
|
||||
var light = cam.gameObject.GetComponent<Light>();
|
||||
light.type = LightType.Directional;
|
||||
light.cullingMask = 1 << 12;
|
||||
cam.aspect = 1f;
|
||||
cam.targetTexture = rt;
|
||||
cam.clearFlags = CameraClearFlags.Color;
|
||||
cam.backgroundColor = Color.black;
|
||||
cam.cullingMask = 1 << 12;
|
||||
|
||||
cam.transform.position = objectPosition + new Vector3(0f, b.extents.y, b.extents.y * 2f);
|
||||
cam.transform.eulerAngles = new Vector3(0f, 180f, 0f);
|
||||
Texture2D screenShot1 = new Texture2D(256, 256, TextureFormat.RGB24, false);
|
||||
cam.Render();
|
||||
RenderTexture.active = rt;
|
||||
screenShot1.ReadPixels(new Rect(0, 0, 256, 256), 0, 0);
|
||||
AssetDatabase.CreateAsset(screenShot1, path + "/ObjectCatalog_temp_1.asset");
|
||||
AssetDatabase.ImportAsset(path + "/ObjectCatalog_temp_1.asset", ImportAssetOptions.ForceUpdate);
|
||||
RenderTexture.active = null;
|
||||
|
||||
cam.transform.position = objectPosition + new Vector3(b.extents.y * 1.41f, b.extents.y, b.extents.y * 1.41f);
|
||||
cam.transform.eulerAngles = new Vector3(0f, 225f, 0f);
|
||||
Texture2D screenShot2 = new Texture2D(256, 256, TextureFormat.RGB24, false);
|
||||
cam.Render();
|
||||
RenderTexture.active = rt;
|
||||
screenShot2.ReadPixels(new Rect(0, 0, 256, 256), 0, 0);
|
||||
AssetDatabase.CreateAsset(screenShot2, path + "/ObjectCatalog_temp_2.asset");
|
||||
AssetDatabase.ImportAsset(path + "/ObjectCatalog_temp_2.asset", ImportAssetOptions.ForceUpdate);
|
||||
RenderTexture.active = null;
|
||||
|
||||
cam.transform.position = objectPosition + new Vector3(b.extents.y * 2f, b.extents.y, 0f);
|
||||
cam.transform.eulerAngles = new Vector3(0f, 270f, 0f);
|
||||
Texture2D screenShot3 = new Texture2D(256, 256, TextureFormat.RGB24, false);
|
||||
cam.Render();
|
||||
RenderTexture.active = rt;
|
||||
screenShot3.ReadPixels(new Rect(0, 0, 256, 256), 0, 0);
|
||||
AssetDatabase.CreateAsset(screenShot3, path + "/ObjectCatalog_temp_3.asset");
|
||||
AssetDatabase.ImportAsset(path + "/ObjectCatalog_temp_3.asset", ImportAssetOptions.ForceUpdate);
|
||||
RenderTexture.active = null;
|
||||
|
||||
cam.transform.position = objectPosition + new Vector3(b.extents.y * 1.41f, b.extents.y, b.extents.y * -1.41f);
|
||||
cam.transform.eulerAngles = new Vector3(0f, 315f, 0f);
|
||||
Texture2D screenShot4 = new Texture2D(256, 256, TextureFormat.RGB24, false);
|
||||
cam.Render();
|
||||
RenderTexture.active = rt;
|
||||
screenShot4.ReadPixels(new Rect(0, 0, 256, 256), 0, 0);
|
||||
AssetDatabase.CreateAsset(screenShot4, path + "/ObjectCatalog_temp_4.asset");
|
||||
AssetDatabase.ImportAsset(path + "/ObjectCatalog_temp_4.asset", ImportAssetOptions.ForceUpdate);
|
||||
RenderTexture.active = null;
|
||||
|
||||
cam.transform.position = objectPosition + new Vector3(0f, b.extents.y, b.extents.y * -2f);
|
||||
cam.transform.eulerAngles = new Vector3(0f, 0f, 0f);
|
||||
Texture2D screenShot5 = new Texture2D(256, 256, TextureFormat.RGB24, false);
|
||||
cam.Render();
|
||||
RenderTexture.active = rt;
|
||||
screenShot5.ReadPixels(new Rect(0, 0, 256, 256), 0, 0);
|
||||
AssetDatabase.CreateAsset(screenShot5, path + "/ObjectCatalog_temp_5.asset");
|
||||
AssetDatabase.ImportAsset(path + "/ObjectCatalog_temp_5.asset", ImportAssetOptions.ForceUpdate);
|
||||
RenderTexture.active = null;
|
||||
|
||||
cam.transform.position = objectPosition + new Vector3(b.extents.y * -1.41f, b.extents.y, b.extents.y * -1.41f);
|
||||
cam.transform.eulerAngles = new Vector3(0f, 45f, 0f);
|
||||
Texture2D screenShot6 = new Texture2D(256, 256, TextureFormat.RGB24, false);
|
||||
cam.Render();
|
||||
RenderTexture.active = rt;
|
||||
screenShot6.ReadPixels(new Rect(0, 0, 256, 256), 0, 0);
|
||||
AssetDatabase.CreateAsset(screenShot6, path + "/ObjectCatalog_temp_6.asset");
|
||||
AssetDatabase.ImportAsset(path + "/ObjectCatalog_temp_6.asset", ImportAssetOptions.ForceUpdate);
|
||||
RenderTexture.active = null;
|
||||
|
||||
cam.transform.position = objectPosition + new Vector3(b.extents.y * -2f, b.extents.y, 0f);
|
||||
cam.transform.eulerAngles = new Vector3(0f, 90f, 0f);
|
||||
Texture2D screenShot7 = new Texture2D(256, 256, TextureFormat.RGB24, false);
|
||||
cam.Render();
|
||||
RenderTexture.active = rt;
|
||||
screenShot7.ReadPixels(new Rect(0, 0, 256, 256), 0, 0);
|
||||
AssetDatabase.CreateAsset(screenShot7, path + "/ObjectCatalog_temp_7.asset");
|
||||
AssetDatabase.ImportAsset(path + "/ObjectCatalog_temp_7.asset", ImportAssetOptions.ForceUpdate);
|
||||
RenderTexture.active = null;
|
||||
|
||||
cam.transform.position = objectPosition + new Vector3(b.extents.y * -1.41f, b.extents.y, b.extents.y * 1.41f);
|
||||
cam.transform.eulerAngles = new Vector3(0f, 135f, 0f);
|
||||
Texture2D screenShot8 = new Texture2D(256, 256, TextureFormat.RGB24, false);
|
||||
cam.Render();
|
||||
RenderTexture.active = rt;
|
||||
screenShot8.ReadPixels(new Rect(0, 0, 256, 256), 0, 0);
|
||||
AssetDatabase.CreateAsset(screenShot8, path + "/ObjectCatalog_temp_8.asset");
|
||||
AssetDatabase.ImportAsset(path + "/ObjectCatalog_temp_8.asset", ImportAssetOptions.ForceUpdate);
|
||||
RenderTexture.active = null;
|
||||
|
||||
DestroyImmediate(obj);
|
||||
DestroyImmediate(cam.gameObject);
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
WorldObjectCatalogPreviewSelector window = (WorldObjectCatalogPreviewSelector) EditorWindow.GetWindow (
|
||||
typeof(WorldObjectCatalogPreviewSelector),
|
||||
true,
|
||||
"Select Catalog Object Preview"
|
||||
);
|
||||
|
||||
window.objectCatalogEntry = objectCatalogEntry;
|
||||
window.previewOption1 = screenShot1;
|
||||
window.previewOption2 = screenShot2;
|
||||
window.previewOption3 = screenShot3;
|
||||
window.previewOption4 = screenShot4;
|
||||
window.previewOption5 = screenShot5;
|
||||
window.previewOption6 = screenShot6;
|
||||
window.previewOption7 = screenShot7;
|
||||
window.previewOption8 = screenShot8;
|
||||
|
||||
var scale = WorldObjectCatalogPreviewSelector.previewWindowScale;
|
||||
|
||||
window.minSize = new Vector2(1152 * scale, 576 * scale);
|
||||
window.maxSize = new Vector2(1152 * scale, 576 * scale);
|
||||
|
||||
window.Show();
|
||||
}
|
||||
|
||||
private float OnHeightElementEntry(int index)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight * 6.25f;
|
||||
}
|
||||
|
||||
private void OnChangedEntry(ReorderableList list)
|
||||
{
|
||||
EditorUtility.SetDirty(target);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRObjectLibraryEditor.cs.meta
Executable file
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRObjectLibraryEditor.cs.meta
Executable file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c76a79943d5e4868b0dde5c509f543de
|
||||
timeCreated: 1630676300
|
262
Assets/ABI.CCK/Scripts/Editor/CCK_CVRParameterStream_Editor.cs
Executable file
262
Assets/ABI.CCK/Scripts/Editor/CCK_CVRParameterStream_Editor.cs
Executable file
|
@ -0,0 +1,262 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using AnimatorControllerParameterType = UnityEngine.AnimatorControllerParameterType;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(CVRParameterStream))]
|
||||
public class CCK_CVRParameterStream_Editor : UnityEditor.Editor
|
||||
{
|
||||
public static string[] coreParameters = {"MovementX", "MovementY", "Grounded", "Emote", "GestureLeft",
|
||||
"GestureRight", "Toggle", "Sitting", "Crouching", "CancelEmote", "Prone", "Flying"};
|
||||
|
||||
private CVRParameterStream stream;
|
||||
|
||||
private ReorderableList list;
|
||||
|
||||
private CVRAvatar avatar;
|
||||
private CVRSpawnable spawnable;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (stream == null) stream = (CVRParameterStream) target;
|
||||
|
||||
stream.referenceType = CVRParameterStream.ReferenceType.World;
|
||||
|
||||
avatar = stream.transform.GetComponentInParent<CVRAvatar>();
|
||||
if (avatar != null) stream.referenceType = CVRParameterStream.ReferenceType.Avatar;
|
||||
|
||||
spawnable = stream.transform.GetComponentInParent<CVRSpawnable>();
|
||||
if (spawnable != null) stream.referenceType = CVRParameterStream.ReferenceType.Spawnable;
|
||||
|
||||
if (stream.referenceType != CVRParameterStream.ReferenceType.Avatar)
|
||||
{
|
||||
EditorGUILayout.HelpBox("This Component is currently only supported for usage on Avatars.", MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
list = new ReorderableList(stream.entries, typeof(CVRParameterStreamEntry),
|
||||
true, true, true, true);
|
||||
list.drawHeaderCallback = DrawHeaderCallback;
|
||||
list.drawElementCallback = DrawElementCallback;
|
||||
list.elementHeightCallback = ElementHeightCallback;
|
||||
}
|
||||
|
||||
list.DoLayoutList();
|
||||
}
|
||||
|
||||
private float ElementHeightCallback(int index)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight * 1.25f * (((int) stream.entries[index].applicationType % 5 == 1?5f:4f) +
|
||||
(stream.entries[index].targetType == CVRParameterStreamEntry.TargetType.Animator ? 1f : 0f));
|
||||
}
|
||||
|
||||
private void DrawElementCallback(Rect rect, int index, bool isactive, bool isfocused)
|
||||
{
|
||||
if (index >= stream.entries.Count) return;
|
||||
|
||||
rect.y += 2f;
|
||||
|
||||
switch (stream.referenceType)
|
||||
{
|
||||
case CVRParameterStream.ReferenceType.World:
|
||||
stream.entries[index].type = (CVRParameterStreamEntry.Type) EditorGUI.EnumPopup(
|
||||
new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight),
|
||||
"Type",
|
||||
stream.entries[index].type
|
||||
);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
|
||||
stream.entries[index].targetType = (CVRParameterStreamEntry.TargetType) EditorGUI.Popup(
|
||||
new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight),
|
||||
"Output Type",
|
||||
(int) stream.entries[index].targetType,
|
||||
new []{"Animator", "VariableBuffer"}
|
||||
);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
|
||||
stream.entries[index].target = (GameObject) EditorGUI.ObjectField(
|
||||
new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight),
|
||||
"Target",
|
||||
stream.entries[index].target,
|
||||
typeof(GameObject),
|
||||
true
|
||||
);
|
||||
|
||||
if (stream.entries[index].target)
|
||||
{
|
||||
switch (stream.entries[index].targetType)
|
||||
{
|
||||
case CVRParameterStreamEntry.TargetType.Animator:
|
||||
var animator = stream.entries[index].target.GetComponent<Animator>();
|
||||
if (animator == null) stream.entries[index].target = null;
|
||||
break;
|
||||
case CVRParameterStreamEntry.TargetType.VariableBuffer:
|
||||
var varBuffer = stream.entries[index].target.GetComponent<CVRVariableBuffer>();
|
||||
if (varBuffer == null) stream.entries[index].target = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (stream.entries[index].target != null && stream.entries[index].targetType == CVRParameterStreamEntry.TargetType.Animator)
|
||||
{
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
|
||||
var _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
var animator = stream.entries[index].target.GetComponent<Animator>();
|
||||
|
||||
var parameters = new List<string>();
|
||||
parameters.Add("-none-");
|
||||
var parameterIndex = 0;
|
||||
if (animator != null)
|
||||
{
|
||||
if (animator.runtimeAnimatorController != null)
|
||||
{
|
||||
foreach (var parameter in ((UnityEditor.Animations.AnimatorController) animator.runtimeAnimatorController).parameters)
|
||||
{
|
||||
if (parameter.type == AnimatorControllerParameterType.Float ||
|
||||
parameter.type == AnimatorControllerParameterType.Int ||
|
||||
parameter.type == AnimatorControllerParameterType.Bool)
|
||||
{
|
||||
parameters.Add(parameter.name);
|
||||
}
|
||||
}
|
||||
|
||||
parameterIndex = parameters.FindIndex(match => match == stream.entries[index].parameterName);
|
||||
}
|
||||
}
|
||||
|
||||
if (parameterIndex < 0) parameterIndex = 0;
|
||||
|
||||
parameterIndex = EditorGUI.Popup(_rect, "Parameter", parameterIndex, parameters.ToArray());
|
||||
stream.entries[index].parameterName = parameters[parameterIndex];
|
||||
}
|
||||
break;
|
||||
|
||||
case CVRParameterStream.ReferenceType.Avatar:
|
||||
stream.entries[index].type = (CVRParameterStreamEntry.Type) EditorGUI.EnumPopup(
|
||||
new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight),
|
||||
"Type",
|
||||
stream.entries[index].type
|
||||
);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
|
||||
var _rectA = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rectA, "Output Type", "AdvancedAvatarAnimator");
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
|
||||
stream.entries[index].targetType = CVRParameterStreamEntry.TargetType.AvatarAnimator;
|
||||
|
||||
_rectA = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
var parametersA = new List<string>();
|
||||
parametersA.Add("-none-");
|
||||
var parameterIndexA = 0;
|
||||
if (avatar != null)
|
||||
{
|
||||
if (avatar.overrides != null)
|
||||
{
|
||||
foreach (var parameter in ((UnityEditor.Animations.AnimatorController) avatar.overrides.runtimeAnimatorController).parameters)
|
||||
{
|
||||
if ((parameter.type == AnimatorControllerParameterType.Float ||
|
||||
parameter.type == AnimatorControllerParameterType.Int ||
|
||||
parameter.type == AnimatorControllerParameterType.Bool) &&
|
||||
!coreParameters.Contains(parameter.name))
|
||||
{
|
||||
parametersA.Add(parameter.name);
|
||||
}
|
||||
}
|
||||
|
||||
parameterIndexA = parametersA.FindIndex(match => match == stream.entries[index].parameterName);
|
||||
}
|
||||
}
|
||||
|
||||
if (parameterIndexA < 0) parameterIndexA = 0;
|
||||
|
||||
parameterIndexA = EditorGUI.Popup(_rectA, "Parameter", parameterIndexA, parametersA.ToArray());
|
||||
stream.entries[index].parameterName = parametersA[parameterIndexA];
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
|
||||
stream.entries[index].applicationType = (CVRParameterStreamEntry.ApplicationType) EditorGUI.EnumPopup(
|
||||
new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight),
|
||||
"Value Application",
|
||||
stream.entries[index].applicationType
|
||||
);
|
||||
|
||||
if ((int) stream.entries[index].applicationType % 5 == 1)
|
||||
{
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
stream.entries[index].staticValue = EditorGUI.FloatField(
|
||||
new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight),
|
||||
"Static Value",
|
||||
stream.entries[index].staticValue
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case CVRParameterStream.ReferenceType.Spawnable:
|
||||
stream.entries[index].type = (CVRParameterStreamEntry.Type) EditorGUI.EnumPopup(
|
||||
new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight),
|
||||
"Type",
|
||||
stream.entries[index].type
|
||||
);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
|
||||
var _rectB = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rectB, "Output Type", "SpawnableCustomFloat");
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
|
||||
stream.entries[index].targetType = CVRParameterStreamEntry.TargetType.CustomFloat;
|
||||
|
||||
_rectB = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
var parametersB = new List<string>();
|
||||
parametersB.Add("-none-");
|
||||
var parameterIndexB = 0;
|
||||
if (spawnable != null)
|
||||
{
|
||||
foreach (var parameter in spawnable.syncValues)
|
||||
{
|
||||
if (!String.IsNullOrWhiteSpace(parameter.name))
|
||||
{
|
||||
parametersB.Add(parameter.name);
|
||||
}
|
||||
}
|
||||
|
||||
parameterIndexB = parametersB.FindIndex(match => match == stream.entries[index].parameterName);
|
||||
}
|
||||
|
||||
if (parameterIndexB < 0) parameterIndexB = 0;
|
||||
|
||||
parameterIndexB = EditorGUI.Popup(_rectB, "Parameter", parameterIndexB, parametersB.ToArray());
|
||||
stream.entries[index].parameterName = parametersB[parameterIndexB];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawHeaderCallback(Rect rect)
|
||||
{
|
||||
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
GUI.Label(_rect, "Entries");
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRParameterStream_Editor.cs.meta
Executable file
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRParameterStream_Editor.cs.meta
Executable file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ccf32f2df74b47f99d7e3910b3142b05
|
||||
timeCreated: 1625775851
|
28
Assets/ABI.CCK/Scripts/Editor/CCK_CVRPointerEditor.cs
Executable file
28
Assets/ABI.CCK/Scripts/Editor/CCK_CVRPointerEditor.cs
Executable file
|
@ -0,0 +1,28 @@
|
|||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
#if CCK_ADDIN_MAGICACLOTHSUPPORT
|
||||
using MagicaCloth;
|
||||
#endif
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(ABI.CCK.Components.CVRPointer), true)]
|
||||
public class CCK_CVRPointerEditor : UnityEditor.Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
#if CCK_ADDIN_MAGICACLOTHSUPPORT
|
||||
var components = ((CVRPointer) target).GetComponentsInParent<BaseCloth>();
|
||||
if (components.Length > 0)
|
||||
{
|
||||
EditorGUILayout.HelpBox(
|
||||
"A MagicaCloth component was detected on this Object or its parent. This can lead to pointers to not work as intended.",
|
||||
MessageType.Error
|
||||
);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRPointerEditor.cs.meta
Executable file
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRPointerEditor.cs.meta
Executable file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: aa2e8ef2abbd4a1a88e6ffd894337994
|
||||
timeCreated: 1630866666
|
309
Assets/ABI.CCK/Scripts/Editor/CCK_CVRSpawnableEditor.cs
Executable file
309
Assets/ABI.CCK/Scripts/Editor/CCK_CVRSpawnableEditor.cs
Executable file
|
@ -0,0 +1,309 @@
|
|||
using System.Collections.Generic;
|
||||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using AnimatorControllerParameterType = UnityEngine.AnimatorControllerParameterType;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(ABI.CCK.Components.CVRSpawnable), true)]
|
||||
public class CCK_CVRSpawnableEditor : UnityEditor.Editor
|
||||
{
|
||||
private CVRSpawnable _spawnable;
|
||||
private ReorderableList reorderableList;
|
||||
private ReorderableList subSyncList;
|
||||
private CVRSpawnableValue entity;
|
||||
private CVRSpawnableSubSync subSyncEntity;
|
||||
|
||||
private float SubSyncCosts = 0f;
|
||||
private bool outOfBoundsError = false;
|
||||
|
||||
private void InitializeList()
|
||||
{
|
||||
if (!_spawnable.useAdditionalValues) return;
|
||||
|
||||
reorderableList = new ReorderableList(_spawnable.syncValues, typeof(CVRAdvancedSettingsEntry), true, true, true, true);
|
||||
reorderableList.drawHeaderCallback = OnDrawHeader;
|
||||
reorderableList.drawElementCallback = OnDrawElement;
|
||||
reorderableList.elementHeightCallback = OnHeightElement;
|
||||
reorderableList.onAddCallback = OnAdd;
|
||||
reorderableList.onChangedCallback = OnChanged;
|
||||
}
|
||||
|
||||
private void InitializeSubSyncList()
|
||||
{
|
||||
if (!_spawnable.useAdditionalValues) return;
|
||||
|
||||
subSyncList = new ReorderableList(_spawnable.subSyncs, typeof(CVRSpawnableSubSync), false, true, true, true);
|
||||
subSyncList.drawHeaderCallback = OnDrawHeaderSubSync;
|
||||
subSyncList.drawElementCallback = OnDrawElementSubSync;
|
||||
subSyncList.elementHeightCallback = OnHeightElementSubSync;
|
||||
subSyncList.onAddCallback = OnAddSubSync;
|
||||
subSyncList.onChangedCallback = OnChangedSubSync;
|
||||
}
|
||||
|
||||
private void OnDrawHeaderSubSync(Rect rect)
|
||||
{
|
||||
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
GUI.Label(_rect, "Sub Sync Transforms");
|
||||
}
|
||||
|
||||
private void OnDrawElementSubSync(Rect rect, int index, bool isactive, bool isfocused)
|
||||
{
|
||||
if (index > _spawnable.subSyncs.Count) return;
|
||||
subSyncEntity = _spawnable.subSyncs[index];
|
||||
|
||||
rect.y += 2;
|
||||
Rect _rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Transform");
|
||||
_rect.x += 120;
|
||||
_rect.width = rect.width - 120;
|
||||
subSyncEntity.transform = (Transform) EditorGUI.ObjectField(_rect, subSyncEntity.transform, typeof(Transform));
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Synced Properties");
|
||||
_rect.x += 120;
|
||||
_rect.width = rect.width - 120;
|
||||
subSyncEntity.syncedValues = (CVRSpawnableSubSync.SyncFlags) EditorGUI.EnumFlagsField(_rect, subSyncEntity.syncedValues);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Sync Precision");
|
||||
_rect.x += 120;
|
||||
_rect.width = rect.width - 120;
|
||||
subSyncEntity.precision = (CVRSpawnableSubSync.SyncPrecision) EditorGUI.EnumPopup(_rect, subSyncEntity.precision);
|
||||
|
||||
if (subSyncEntity.precision == CVRSpawnableSubSync.SyncPrecision.Full) return;
|
||||
|
||||
if (subSyncEntity.transform != null &&
|
||||
(Mathf.Abs(subSyncEntity.transform.localPosition.x) > subSyncEntity.syncBoundary ||
|
||||
Mathf.Abs(subSyncEntity.transform.localPosition.y) > subSyncEntity.syncBoundary ||
|
||||
Mathf.Abs(subSyncEntity.transform.localPosition.z) > subSyncEntity.syncBoundary))
|
||||
{
|
||||
outOfBoundsError = true;
|
||||
}
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Sync Boundary");
|
||||
_rect.x += 120;
|
||||
_rect.width = rect.width - 120;
|
||||
subSyncEntity.syncBoundary = EditorGUI.FloatField(_rect, subSyncEntity.syncBoundary);
|
||||
}
|
||||
|
||||
private float OnHeightElementSubSync(int index)
|
||||
{
|
||||
if (_spawnable.subSyncs[index].precision == CVRSpawnableSubSync.SyncPrecision.Full) return EditorGUIUtility.singleLineHeight * 3.75f;
|
||||
return EditorGUIUtility.singleLineHeight * 5f;
|
||||
}
|
||||
|
||||
private void OnAddSubSync(ReorderableList list)
|
||||
{
|
||||
if (_spawnable.subSyncs.Count < 40)
|
||||
{
|
||||
_spawnable.subSyncs.Add(new CVRSpawnableSubSync());
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnChangedSubSync(ReorderableList list)
|
||||
{
|
||||
//EditorUtility.SetDirty(target);
|
||||
}
|
||||
|
||||
private void OnChanged(ReorderableList list)
|
||||
{
|
||||
//EditorUtility.SetDirty(target);
|
||||
}
|
||||
|
||||
private void OnAdd(ReorderableList list)
|
||||
{
|
||||
if (_spawnable.syncValues.Count < 40)
|
||||
{
|
||||
_spawnable.syncValues.Add(new CVRSpawnableValue());
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
private float OnHeightElement(int index)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight * 7.5f;
|
||||
}
|
||||
|
||||
private void OnDrawElement(Rect rect, int index, bool isactive, bool isfocused)
|
||||
{
|
||||
if (index > _spawnable.syncValues.Count) return;
|
||||
entity = _spawnable.syncValues[index];
|
||||
|
||||
rect.y += 2;
|
||||
Rect _rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Name");
|
||||
_rect.x += 120;
|
||||
_rect.width = rect.width - 120;
|
||||
entity.name = EditorGUI.TextField(_rect, entity.name);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Start Value");
|
||||
_rect.x += 120;
|
||||
_rect.width = rect.width - 120;
|
||||
entity.startValue = EditorGUI.FloatField(_rect, entity.startValue);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Update Type");
|
||||
_rect.x += 120;
|
||||
_rect.width = rect.width - 120;
|
||||
entity.updatedBy = (CVRSpawnableValue.UpdatedBy) EditorGUI.EnumPopup(_rect, entity.updatedBy);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Update Method");
|
||||
_rect.x += 120;
|
||||
_rect.width = rect.width - 120;
|
||||
entity.updateMethod = (CVRSpawnableValue.UpdateMethod) EditorGUI.EnumPopup(_rect, entity.updateMethod);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Connected Animator");
|
||||
_rect.x += 120;
|
||||
_rect.width = rect.width - 120;
|
||||
entity.animator = (Animator) EditorGUI.ObjectField(_rect, entity.animator, typeof(Animator));
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Animator Parameter");
|
||||
_rect.x += 120;
|
||||
_rect.width = rect.width - 120;
|
||||
|
||||
var parameters = new List<string>();
|
||||
parameters.Add("-none-");
|
||||
var parameterIndex = 0;
|
||||
if (entity.animator != null)
|
||||
{
|
||||
if (entity.animator.runtimeAnimatorController != null)
|
||||
{
|
||||
foreach (var parameter in ((UnityEditor.Animations.AnimatorController) entity.animator.runtimeAnimatorController).parameters)
|
||||
{
|
||||
if (parameter.type == AnimatorControllerParameterType.Float)
|
||||
{
|
||||
parameters.Add(parameter.name);
|
||||
}
|
||||
}
|
||||
|
||||
parameterIndex = parameters.FindIndex(match => match == entity.animatorParameterName);
|
||||
}
|
||||
}
|
||||
|
||||
if (parameterIndex < 0) parameterIndex = 0;
|
||||
|
||||
parameterIndex = EditorGUI.Popup(_rect, parameterIndex, parameters.ToArray());
|
||||
entity.animatorParameterName = parameters[parameterIndex];
|
||||
}
|
||||
|
||||
private void OnDrawHeader(Rect rect)
|
||||
{
|
||||
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
GUI.Label(_rect, "Values");
|
||||
}
|
||||
|
||||
public void UpdateSubSyncCosts()
|
||||
{
|
||||
SubSyncCosts = 0f;
|
||||
|
||||
foreach (var subSync in _spawnable.subSyncs)
|
||||
{
|
||||
if (subSync.syncedValues.HasFlag(CVRSpawnableSubSync.SyncFlags.TransformX))
|
||||
SubSyncCosts += (int) subSync.precision / 4f;
|
||||
if (subSync.syncedValues.HasFlag(CVRSpawnableSubSync.SyncFlags.TransformY))
|
||||
SubSyncCosts += (int) subSync.precision / 4f;
|
||||
if (subSync.syncedValues.HasFlag(CVRSpawnableSubSync.SyncFlags.TransformZ))
|
||||
SubSyncCosts += (int) subSync.precision / 4f;
|
||||
if (subSync.syncedValues.HasFlag(CVRSpawnableSubSync.SyncFlags.RotationX))
|
||||
SubSyncCosts += (int) subSync.precision / 4f;
|
||||
if (subSync.syncedValues.HasFlag(CVRSpawnableSubSync.SyncFlags.RotationY))
|
||||
SubSyncCosts += (int) subSync.precision / 4f;
|
||||
if (subSync.syncedValues.HasFlag(CVRSpawnableSubSync.SyncFlags.RotationZ))
|
||||
SubSyncCosts += (int) subSync.precision / 4f;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (_spawnable == null) _spawnable = (CVRSpawnable) target;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
_spawnable.spawnHeight = EditorGUILayout.FloatField("Spawn Height", _spawnable.spawnHeight);
|
||||
|
||||
_spawnable.propPrivacy = (CVRSpawnable.PropPrivacy) EditorGUILayout.EnumPopup("Prop Usage", _spawnable.propPrivacy);
|
||||
|
||||
GUILayout.BeginVertical("HelpBox");
|
||||
|
||||
GUILayout.BeginHorizontal ();
|
||||
_spawnable.useAdditionalValues = EditorGUILayout.Toggle (_spawnable.useAdditionalValues, GUILayout.Width(16));
|
||||
EditorGUILayout.LabelField ("Enable Sync Values", GUILayout.Width(250));
|
||||
GUILayout.EndHorizontal ();
|
||||
|
||||
if (_spawnable.useAdditionalValues)
|
||||
{
|
||||
UpdateSubSyncCosts();
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.BeginVertical("GroupBox");
|
||||
|
||||
var SyncCost = _spawnable.syncValues.Count + SubSyncCosts;
|
||||
|
||||
Rect _rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight);
|
||||
EditorGUI.ProgressBar(_rect, SyncCost / 40f, Mathf.CeilToInt(SyncCost) + " of 40 Synced Parameter Slots used");
|
||||
EditorGUILayout.Space();
|
||||
|
||||
if (SubSyncCosts > 0f)
|
||||
{
|
||||
EditorGUILayout.HelpBox(SubSyncCosts.ToString("F2")+" Values are used for Sub Sync Transforms", MessageType.Info);
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
if (reorderableList == null) InitializeList();
|
||||
reorderableList.displayAdd = SyncCost <= 39f;
|
||||
reorderableList.DoLayoutList();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
outOfBoundsError = false;
|
||||
if (subSyncList == null) InitializeSubSyncList();
|
||||
subSyncList.displayAdd = SyncCost <= 39f;
|
||||
subSyncList.DoLayoutList();
|
||||
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
if (outOfBoundsError)
|
||||
{
|
||||
EditorGUILayout.HelpBox("A Sub Sync Transform is out of bounds by default. This object will snap to its bounds, when it is being synced.", MessageType.Error);
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorUtility.SetDirty(_spawnable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/ABI.CCK/Scripts/Editor/CCK_CVRSpawnableEditor.cs.meta
Executable file
11
Assets/ABI.CCK/Scripts/Editor/CCK_CVRSpawnableEditor.cs.meta
Executable file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0ca17d4301024feca46190e9e0dae76e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
345
Assets/ABI.CCK/Scripts/Editor/CCK_CVRSpawnableTriggerEditor.cs
Executable file
345
Assets/ABI.CCK/Scripts/Editor/CCK_CVRSpawnableTriggerEditor.cs
Executable file
|
@ -0,0 +1,345 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using AnimatorController = UnityEditor.Animations.AnimatorController;
|
||||
using AnimatorControllerParameterType = UnityEngine.AnimatorControllerParameterType;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(CVRSpawnableTrigger))]
|
||||
public class CCK_CVRSpawnableTriggerEditor : UnityEditor.Editor
|
||||
{
|
||||
private CVRSpawnableTrigger trigger;
|
||||
private CVRSpawnableTriggerTask enterEntity;
|
||||
private CVRSpawnableTriggerTask exitEntity;
|
||||
private CVRSpawnableTriggerTaskStay stayEntity;
|
||||
private ReorderableList _onEnterList;
|
||||
private ReorderableList _onExitList;
|
||||
private ReorderableList _onStayList;
|
||||
private List<string> spawnableParameters;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
trigger = (CVRSpawnableTrigger) target;
|
||||
var spawnable = trigger.GetComponentInParent<CVRSpawnable>();
|
||||
|
||||
if (spawnable == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("No CVRSpawnable was detected for this Trigger.", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
spawnableParameters = new List<string>();
|
||||
spawnableParameters.Add("-none-");
|
||||
|
||||
if (!spawnable.useAdditionalValues)
|
||||
{
|
||||
EditorGUILayout.HelpBox("The detected Spawnable does not use additional Values.", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var syncValue in spawnable.syncValues)
|
||||
{
|
||||
spawnableParameters.Add(syncValue.name);
|
||||
}
|
||||
}
|
||||
|
||||
var triggers = trigger.GetComponents<CVRSpawnableTrigger>();
|
||||
|
||||
if (triggers.Length > 1)
|
||||
{
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ADVAVTR_TRIGGER_MULTIPLE_TRIGGER_HELPBOX"), MessageType.Error);
|
||||
}
|
||||
|
||||
trigger.areaSize = EditorGUILayout.Vector3Field("Area Size", trigger.areaSize);
|
||||
|
||||
trigger.areaOffset = EditorGUILayout.Vector3Field("Area Offset", trigger.areaOffset);
|
||||
|
||||
if (!trigger.useAdvancedTrigger)
|
||||
{
|
||||
trigger.settingIndex = EditorGUILayout.Popup("Parameter", trigger.settingIndex + 1, spawnableParameters.ToArray()) - 1;
|
||||
|
||||
trigger.settingValue = EditorGUILayout.FloatField("Setting Value", trigger.settingValue);
|
||||
|
||||
trigger.useAdvancedTrigger = EditorGUILayout.Toggle("Enabled Advanced Mode", trigger.useAdvancedTrigger);
|
||||
}
|
||||
else
|
||||
{
|
||||
trigger.useAdvancedTrigger = EditorGUILayout.Toggle("Enabled Advanced Mode", trigger.useAdvancedTrigger);
|
||||
|
||||
var list = serializedObject.FindProperty("allowedTypes");
|
||||
EditorGUILayout.PropertyField(list, new GUIContent("Allowed Types"), true);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ADVAVTR_TRIGGER_ALLOWED_TYPES_HELPBOX"), MessageType.Info);
|
||||
|
||||
trigger.allowParticleInteraction = EditorGUILayout.Toggle("Enabled Particle Interaction", trigger.allowParticleInteraction);
|
||||
|
||||
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ADVAVTR_TRIGGER_PARTICLE_HELPBOX"), MessageType.Info);
|
||||
|
||||
if (_onEnterList == null)
|
||||
{
|
||||
_onEnterList = new ReorderableList(trigger.enterTasks, typeof(CVRSpawnableTriggerTask),
|
||||
false, true, true, true);
|
||||
_onEnterList.drawHeaderCallback = OnDrawHeaderEnter;
|
||||
_onEnterList.drawElementCallback = OnDrawElementEnter;
|
||||
_onEnterList.elementHeightCallback = OnHeightElementEnter;
|
||||
_onEnterList.onAddCallback = OnAddEnter;
|
||||
_onEnterList.onChangedCallback = OnChangedEnter;
|
||||
}
|
||||
|
||||
_onEnterList.DoLayoutList();
|
||||
|
||||
if (_onExitList == null)
|
||||
{
|
||||
_onExitList = new ReorderableList(trigger.exitTasks, typeof(CVRSpawnableTriggerTask),
|
||||
false, true, true, true);
|
||||
_onExitList.drawHeaderCallback = OnDrawHeaderExit;
|
||||
_onExitList.drawElementCallback = OnDrawElementExit;
|
||||
_onExitList.elementHeightCallback = OnHeightElementExit;
|
||||
_onExitList.onAddCallback = OnAddExit;
|
||||
_onExitList.onChangedCallback = OnChangedExit;
|
||||
}
|
||||
|
||||
_onExitList.DoLayoutList();
|
||||
|
||||
if (_onStayList == null)
|
||||
{
|
||||
_onStayList = new ReorderableList(trigger.stayTasks, typeof(CVRSpawnableTriggerTaskStay),
|
||||
false, true, true, true);
|
||||
_onStayList.drawHeaderCallback = OnDrawHeaderStay;
|
||||
_onStayList.drawElementCallback = OnDrawElementStay;
|
||||
_onStayList.elementHeightCallback = OnHeightElementStay;
|
||||
_onStayList.onAddCallback = OnAddStay;
|
||||
_onStayList.onChangedCallback = OnChangedStay;
|
||||
}
|
||||
|
||||
_onStayList.DoLayoutList();
|
||||
|
||||
if (trigger.stayTasks.Count > 0)
|
||||
{
|
||||
trigger.sampleDirection = (CVRSpawnableTrigger.SampleDirection)
|
||||
EditorGUILayout.EnumPopup("Sample Direction", trigger.sampleDirection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDrawHeaderEnter(Rect rect)
|
||||
{
|
||||
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
GUI.Label(_rect, "On Enter Trigger");
|
||||
}
|
||||
|
||||
private void OnDrawElementEnter(Rect rect, int index, bool isactive, bool isfocused)
|
||||
{
|
||||
if (index > trigger.enterTasks.Count) return;
|
||||
enterEntity = trigger.enterTasks[index];
|
||||
|
||||
Rect _rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Parameter");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
|
||||
enterEntity.settingIndex = EditorGUI.Popup(_rect, enterEntity.settingIndex + 1, spawnableParameters.ToArray()) - 1;
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Setting Value");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
enterEntity.settingValue = EditorGUI.FloatField(_rect, enterEntity.settingValue);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Delay");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
enterEntity.delay = EditorGUI.FloatField(_rect, enterEntity.delay);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Hold Time");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
enterEntity.holdTime = EditorGUI.FloatField(_rect, enterEntity.holdTime);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Update Method");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
enterEntity.updateMethod = (CVRSpawnableTriggerTask.UpdateMethod) EditorGUI.EnumPopup(_rect, enterEntity.updateMethod);
|
||||
}
|
||||
|
||||
private float OnHeightElementEnter(int index)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight * 6.25f;
|
||||
}
|
||||
|
||||
private void OnAddEnter(ReorderableList list)
|
||||
{
|
||||
trigger.enterTasks.Add(new CVRSpawnableTriggerTask());
|
||||
Repaint();
|
||||
}
|
||||
|
||||
private void OnChangedEnter(ReorderableList list)
|
||||
{
|
||||
//EditorUtility.SetDirty(target);
|
||||
}
|
||||
|
||||
private void OnDrawHeaderExit(Rect rect)
|
||||
{
|
||||
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
GUI.Label(_rect, "On Exit Trigger");
|
||||
}
|
||||
|
||||
private void OnDrawElementExit(Rect rect, int index, bool isactive, bool isfocused)
|
||||
{
|
||||
if (index > trigger.exitTasks.Count) return;
|
||||
exitEntity = trigger.exitTasks[index];
|
||||
|
||||
Rect _rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Parameter");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
|
||||
exitEntity.settingIndex = EditorGUI.Popup(_rect, exitEntity.settingIndex + 1, spawnableParameters.ToArray()) - 1;
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Setting Value");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
exitEntity.settingValue = EditorGUI.FloatField(_rect, exitEntity.settingValue);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Delay");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
exitEntity.delay = EditorGUI.FloatField(_rect, exitEntity.delay);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Update Method");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
exitEntity.updateMethod = (CVRSpawnableTriggerTask.UpdateMethod) EditorGUI.EnumPopup(_rect, exitEntity.updateMethod);
|
||||
}
|
||||
|
||||
private float OnHeightElementExit(int index)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight * 5f;
|
||||
}
|
||||
|
||||
private void OnAddExit(ReorderableList list)
|
||||
{
|
||||
trigger.exitTasks.Add(new CVRSpawnableTriggerTask());
|
||||
Repaint();
|
||||
}
|
||||
|
||||
private void OnChangedExit(ReorderableList list)
|
||||
{
|
||||
//EditorUtility.SetDirty(target);
|
||||
}
|
||||
|
||||
private void OnDrawHeaderStay(Rect rect)
|
||||
{
|
||||
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
GUI.Label(_rect, "On Stay Trigger");
|
||||
}
|
||||
|
||||
private void OnDrawElementStay(Rect rect, int index, bool isactive, bool isfocused)
|
||||
{
|
||||
if (index > trigger.stayTasks.Count) return;
|
||||
stayEntity = trigger.stayTasks[index];
|
||||
|
||||
Rect _rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Parameter");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
|
||||
stayEntity.settingIndex = EditorGUI.Popup(_rect, stayEntity.settingIndex + 1, spawnableParameters.ToArray()) - 1;
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Update Method");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
|
||||
stayEntity.updateMethod = (CVRSpawnableTriggerTaskStay.UpdateMethod) EditorGUI.EnumPopup(_rect, stayEntity.updateMethod);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
if (stayEntity.updateMethod == CVRSpawnableTriggerTaskStay.UpdateMethod.SetFromPosition)
|
||||
{
|
||||
EditorGUI.LabelField(_rect, "Min Value");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
stayEntity.minValue = EditorGUI.FloatField(_rect, stayEntity.minValue);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Max Value");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
stayEntity.maxValue = EditorGUI.FloatField(_rect, stayEntity.maxValue);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.LabelField(_rect, "Change per sec");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
stayEntity.minValue = EditorGUI.FloatField(_rect, stayEntity.minValue);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private float OnHeightElementStay(int index)
|
||||
{
|
||||
if (index > trigger.stayTasks.Count) return EditorGUIUtility.singleLineHeight * 3.75f;
|
||||
stayEntity = trigger.stayTasks[index];
|
||||
|
||||
if (stayEntity.updateMethod == CVRSpawnableTriggerTaskStay.UpdateMethod.SetFromPosition)
|
||||
return EditorGUIUtility.singleLineHeight * 5f;
|
||||
|
||||
return EditorGUIUtility.singleLineHeight * 3.75f;
|
||||
}
|
||||
|
||||
private void OnAddStay(ReorderableList list)
|
||||
{
|
||||
trigger.stayTasks.Add(new CVRSpawnableTriggerTaskStay());
|
||||
Repaint();
|
||||
}
|
||||
|
||||
private void OnChangedStay(ReorderableList list)
|
||||
{
|
||||
//EditorUtility.SetDirty(target);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRSpawnableTriggerEditor.cs.meta
Executable file
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRSpawnableTriggerEditor.cs.meta
Executable file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4dcff2475b474b429c3fe0ba380bbbea
|
||||
timeCreated: 1624750389
|
353
Assets/ABI.CCK/Scripts/Editor/CCK_CVRTexturePropertyParserEditor.cs
Executable file
353
Assets/ABI.CCK/Scripts/Editor/CCK_CVRTexturePropertyParserEditor.cs
Executable file
|
@ -0,0 +1,353 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(ABI.CCK.Components.CVRTexturePropertyParser), true)]
|
||||
public class CCK_CVRTexturePropertyParserEditor : UnityEditor.Editor
|
||||
{
|
||||
private CVRTexturePropertyParser _parser;
|
||||
private ReorderableList _list;
|
||||
|
||||
private CVRTexturePropertyParserTask _element;
|
||||
private static Dictionary<int, string[]> TypeAttributeList = new Dictionary<int, string[]>()
|
||||
{
|
||||
{3, new string[]{"X", "Y"}},
|
||||
{4, new string[]{"X", "Y", "Z"}},
|
||||
{5, new string[]{"X", "Y", "Z", "W"}},
|
||||
{6, new string[]{"R", "G", "B", "A"}}
|
||||
};
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (_parser == null) _parser = (CVRTexturePropertyParser) target;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
CVRTexturePropertyParser.TextureType textureType = (CVRTexturePropertyParser.TextureType) EditorGUILayout.EnumPopup("Texture Type", _parser.textureType);
|
||||
|
||||
RenderTexture texture = null;
|
||||
string globalTextureName = "";
|
||||
if (textureType == CVRTexturePropertyParser.TextureType.LocalTexture)
|
||||
{
|
||||
texture = (RenderTexture) EditorGUILayout.ObjectField("Texture", _parser.texture, typeof(RenderTexture));
|
||||
}
|
||||
else
|
||||
{
|
||||
globalTextureName = EditorGUILayout.TextField("Texture Name", _parser.globalTextureName);
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(target, "Changed CVRTexturePropertyParser");
|
||||
|
||||
_parser.textureType = textureType;
|
||||
if (textureType == CVRTexturePropertyParser.TextureType.LocalTexture)
|
||||
{
|
||||
_parser.texture = texture;
|
||||
}
|
||||
else
|
||||
{
|
||||
_parser.globalTextureName = globalTextureName;
|
||||
}
|
||||
}
|
||||
|
||||
if (_list == null) InitializeList();
|
||||
_list.DoLayoutList();
|
||||
}
|
||||
|
||||
private void InitializeList()
|
||||
{
|
||||
_list = new ReorderableList(_parser.tasks, typeof(CVRTexturePropertyParserTask), false, true, true, true);
|
||||
_list.drawElementCallback = DrawElement;
|
||||
_list.drawHeaderCallback = DrawHeader;
|
||||
_list.elementHeightCallback = ElementHeight;
|
||||
}
|
||||
|
||||
private void DrawElement(Rect rect, int index, bool isactive, bool isfocused)
|
||||
{
|
||||
if (index >= _parser.tasks.Count) return;
|
||||
_element = _parser.tasks[index];
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
Rect _rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
EditorGUI.LabelField(_rect, "X Position");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
int x = EditorGUI.IntField(_rect, _element.x);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
EditorGUI.LabelField(_rect, "Y Position");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
int y = EditorGUI.IntField(_rect, _element.y);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
EditorGUI.LabelField(_rect, "Color Channel");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
CVRTexturePropertyParserTask.Channel channel = (CVRTexturePropertyParserTask.Channel) EditorGUI.EnumPopup(_rect, _element.channel);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
EditorGUI.LabelField(_rect, "Min Value");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
float minValue = EditorGUI.FloatField(_rect, _element.minValue);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
EditorGUI.LabelField(_rect, "Max Value");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
float maxValue = EditorGUI.FloatField(_rect, _element.maxValue);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
EditorGUI.LabelField(_rect, "Target");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
GameObject target = (GameObject) EditorGUI.ObjectField(_rect, _element.target, typeof(GameObject));
|
||||
|
||||
if (target != _element.target) _element.component = null;
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
EditorGUI.LabelField(_rect, "Component");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
|
||||
//Get Component
|
||||
List<Component> componentList = new List<Component>();
|
||||
List<Type> componentListTypes = new List<Type>();
|
||||
List<string> componentListNames = new List<string>();
|
||||
int selectedIndex = 0;
|
||||
Component component = null;
|
||||
|
||||
if (_element.target == null)
|
||||
{
|
||||
EditorGUI.HelpBox(_rect, "Select a Target.", MessageType.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
Component[] rawComponents = target.GetComponents<Component>();
|
||||
|
||||
foreach (var rawComponent in rawComponents)
|
||||
{
|
||||
if (rawComponent != null && !componentListTypes.Contains(rawComponent.GetType()) &&
|
||||
rawComponent.GetType() != typeof(CVRTexturePropertyParser))
|
||||
{
|
||||
componentListTypes.Add(rawComponent.GetType());
|
||||
componentListNames.Add(rawComponent.GetType().Name);
|
||||
componentList.Add(rawComponent);
|
||||
}
|
||||
}
|
||||
|
||||
selectedIndex = componentList.FindIndex(match => match == _element.component);
|
||||
|
||||
selectedIndex = EditorGUI.Popup(_rect, selectedIndex, componentListNames.ToArray());
|
||||
if (selectedIndex >= 0 && selectedIndex < componentListTypes.Count)
|
||||
{
|
||||
component = componentList[selectedIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
component = null;
|
||||
}
|
||||
}
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
EditorGUI.LabelField(_rect, "Property");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
|
||||
//Get Component Property
|
||||
string propertyName = "";
|
||||
int propertyType = 0;
|
||||
int targetIndex = 0;
|
||||
|
||||
if (_element.component == null)
|
||||
{
|
||||
EditorGUI.HelpBox(_rect, "Select a Component to proceed.", MessageType.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Default;
|
||||
FieldInfo[] finfos = componentListTypes[selectedIndex].GetFields(flags);
|
||||
PropertyInfo[] pinfos = componentListTypes[selectedIndex].GetProperties(flags);
|
||||
List<string> fieldListNames = new List<string>();
|
||||
List<string> fieldListDisplayNames = new List<string>();
|
||||
List<int> fieldTypes = new List<int>();
|
||||
selectedIndex = 0;
|
||||
|
||||
foreach (var finfo in finfos)
|
||||
{
|
||||
if (finfo.IsPublic)
|
||||
{
|
||||
if (finfo.FieldType == typeof(float))
|
||||
{
|
||||
fieldListNames.Add(finfo.Name);
|
||||
fieldListDisplayNames.Add(finfo.Name + " (float)");
|
||||
fieldTypes.Add(0);
|
||||
}
|
||||
else if (finfo.FieldType == typeof(int))
|
||||
{
|
||||
fieldListNames.Add(finfo.Name);
|
||||
fieldListDisplayNames.Add(finfo.Name + " (int)");
|
||||
fieldTypes.Add(1);
|
||||
}
|
||||
else if (finfo.FieldType == typeof(bool))
|
||||
{
|
||||
fieldListNames.Add(finfo.Name);
|
||||
fieldListDisplayNames.Add(finfo.Name + " (bool)");
|
||||
fieldTypes.Add(2);
|
||||
}
|
||||
else if (finfo.FieldType == typeof(Vector2))
|
||||
{
|
||||
fieldListNames.Add(finfo.Name);
|
||||
fieldListDisplayNames.Add(finfo.Name + " (Vector2)");
|
||||
fieldTypes.Add(3);
|
||||
}
|
||||
else if (finfo.FieldType == typeof(Vector3))
|
||||
{
|
||||
fieldListNames.Add(finfo.Name);
|
||||
fieldListDisplayNames.Add(finfo.Name + " (Vector3)");
|
||||
fieldTypes.Add(4);
|
||||
}
|
||||
else if (finfo.FieldType == typeof(Vector4))
|
||||
{
|
||||
fieldListNames.Add(finfo.Name);
|
||||
fieldListDisplayNames.Add(finfo.Name + " (Vector4)");
|
||||
fieldTypes.Add(5);
|
||||
}
|
||||
else if (finfo.FieldType == typeof(Color))
|
||||
{
|
||||
fieldListNames.Add(finfo.Name);
|
||||
fieldListDisplayNames.Add(finfo.Name + " (Color)");
|
||||
fieldTypes.Add(6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var pinfo in pinfos)
|
||||
{
|
||||
if (pinfo.CanWrite)
|
||||
{
|
||||
if (pinfo.PropertyType == typeof(float))
|
||||
{
|
||||
fieldListNames.Add(pinfo.Name);
|
||||
fieldListDisplayNames.Add(pinfo.Name + " (float)");
|
||||
fieldTypes.Add(0);
|
||||
}
|
||||
else if (pinfo.PropertyType == typeof(int))
|
||||
{
|
||||
fieldListNames.Add(pinfo.Name);
|
||||
fieldListDisplayNames.Add(pinfo.Name + " (int)");
|
||||
fieldTypes.Add(1);
|
||||
}
|
||||
else if (pinfo.PropertyType == typeof(bool))
|
||||
{
|
||||
fieldListNames.Add(pinfo.Name);
|
||||
fieldListDisplayNames.Add(pinfo.Name + " (bool)");
|
||||
fieldTypes.Add(2);
|
||||
}
|
||||
else if (pinfo.PropertyType == typeof(Vector2))
|
||||
{
|
||||
fieldListNames.Add(pinfo.Name);
|
||||
fieldListDisplayNames.Add(pinfo.Name + " (Vector2)");
|
||||
fieldTypes.Add(3);
|
||||
}
|
||||
else if (pinfo.PropertyType == typeof(Vector3))
|
||||
{
|
||||
fieldListNames.Add(pinfo.Name);
|
||||
fieldListDisplayNames.Add(pinfo.Name + " (Vector3)");
|
||||
fieldTypes.Add(4);
|
||||
}
|
||||
else if (pinfo.PropertyType == typeof(Vector4))
|
||||
{
|
||||
fieldListNames.Add(pinfo.Name);
|
||||
fieldListDisplayNames.Add(pinfo.Name + " (Vector4)");
|
||||
fieldTypes.Add(5);
|
||||
}
|
||||
else if (pinfo.PropertyType == typeof(Color))
|
||||
{
|
||||
fieldListNames.Add(pinfo.Name);
|
||||
fieldListDisplayNames.Add(pinfo.Name + " (Color)");
|
||||
fieldTypes.Add(6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
selectedIndex = fieldListNames.FindIndex(match => match == _element.propertyName);
|
||||
|
||||
selectedIndex = EditorGUI.Popup(_rect, selectedIndex, fieldListDisplayNames.ToArray());
|
||||
if (selectedIndex >= 0 && selectedIndex < fieldListNames.Count)
|
||||
{
|
||||
propertyName = fieldListNames[selectedIndex];
|
||||
propertyType = fieldTypes[selectedIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
propertyName = "";
|
||||
propertyType = 0;
|
||||
}
|
||||
|
||||
if (propertyType >= 3)
|
||||
{
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
EditorGUI.LabelField(_rect, "Target Attribute");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
|
||||
targetIndex = EditorGUI.Popup(_rect, _element.targetIndex, TypeAttributeList[propertyType]);
|
||||
}
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(_parser, "Changed CVRTexturePropertyParser Task");
|
||||
|
||||
_element.x = x;
|
||||
_element.y = y;
|
||||
_element.channel = channel;
|
||||
_element.minValue = minValue;
|
||||
_element.maxValue = maxValue;
|
||||
_element.target = target;
|
||||
_element.component = component;
|
||||
_element.propertyName = propertyName;
|
||||
_element.typeIndex = propertyType;
|
||||
_element.targetIndex = targetIndex;
|
||||
}
|
||||
}
|
||||
|
||||
private float ElementHeight(int index)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight * (_parser.tasks[index].typeIndex >= 3 ? 11.75f : 10.5f);
|
||||
}
|
||||
|
||||
private void DrawHeader(Rect rect)
|
||||
{
|
||||
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
GUI.Label(_rect, "Tasks");
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRTexturePropertyParserEditor.cs.meta
Executable file
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRTexturePropertyParserEditor.cs.meta
Executable file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5d55003c047243968442f020280c3fc3
|
||||
timeCreated: 1646244492
|
21
Assets/ABI.CCK/Scripts/Editor/CCK_CVRToggleStateTriggerEditor.cs
Executable file
21
Assets/ABI.CCK/Scripts/Editor/CCK_CVRToggleStateTriggerEditor.cs
Executable file
|
@ -0,0 +1,21 @@
|
|||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(CVRToggleStateTrigger))]
|
||||
public class CCK_CVRToggleStateTriggerEditor : UnityEditor.Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
var triggers = ((CVRToggleStateTrigger) target).GetComponents<CVRToggleStateTrigger>();
|
||||
|
||||
if (triggers.Length > 1)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Having multiple Triggers on the same GameObject will lead to unpredictable behavior!", MessageType.Error);
|
||||
}
|
||||
|
||||
base.OnInspectorGUI();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/ABI.CCK/Scripts/Editor/CCK_CVRToggleStateTriggerEditor.cs.meta
Executable file
11
Assets/ABI.CCK/Scripts/Editor/CCK_CVRToggleStateTriggerEditor.cs.meta
Executable file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1e3cda82ec114396b1c548b185085268
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
168
Assets/ABI.CCK/Scripts/Editor/CCK_CVRTranslatableEditor.cs
Executable file
168
Assets/ABI.CCK/Scripts/Editor/CCK_CVRTranslatableEditor.cs
Executable file
|
@ -0,0 +1,168 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ABI.CCK.Components;
|
||||
using TMPro;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(ABI.CCK.Components.CVRTranslatable))]
|
||||
public class CCK_CVRTranslatableEditor : UnityEditor.Editor
|
||||
{
|
||||
private CVRTranslatable _translatable;
|
||||
|
||||
private ReorderableList reorderableList;
|
||||
private CVRTranslatable.ObjectTranslatable_t entity;
|
||||
|
||||
private void InitializeList()
|
||||
{
|
||||
if (_translatable == null) return;
|
||||
|
||||
reorderableList = new ReorderableList(_translatable.Translatables, typeof(CVRTranslatable.ObjectTranslatable_t),
|
||||
true, true, true, true);
|
||||
reorderableList.drawHeaderCallback = OnDrawHeader;
|
||||
reorderableList.drawElementCallback = OnDrawElement;
|
||||
reorderableList.elementHeightCallback = OnHeightElement;
|
||||
reorderableList.onAddCallback = OnAdd;
|
||||
reorderableList.onChangedCallback = OnChanged;
|
||||
}
|
||||
|
||||
private void OnDrawElement(Rect rect, int index, bool isactive, bool isfocused)
|
||||
{
|
||||
if (index > _translatable.Translatables.Count) return;
|
||||
entity = _translatable.Translatables[index];
|
||||
rect.y += 2;
|
||||
rect.x += 12;
|
||||
rect.width -= 12;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
Rect _rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Type");
|
||||
_rect.x += 120;
|
||||
_rect.width = rect.width - 120;
|
||||
|
||||
entity.Type = (CVRTranslatable.TranslatableType) EditorGUI.EnumPopup(_rect, entity.Type);
|
||||
|
||||
if (entity.Type != CVRTranslatable.TranslatableType.GameObject)
|
||||
{
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Component");
|
||||
_rect.x += 120;
|
||||
_rect.width = rect.width - 120;
|
||||
|
||||
switch (entity.Type)
|
||||
{
|
||||
case CVRTranslatable.TranslatableType.Text:
|
||||
entity.Text = (Text) EditorGUI.ObjectField(_rect, entity.Text, typeof(Text), true);
|
||||
break;
|
||||
#if CCK_ADDIN_TRANSLATABLE_TMP
|
||||
case CVRTranslatable.TranslatableType.TextMeshPro:
|
||||
entity.TmpText =
|
||||
(TMP_Text) EditorGUI.ObjectField(_rect, entity.TmpText, typeof(TMP_Text), true);
|
||||
break;
|
||||
#endif
|
||||
case CVRTranslatable.TranslatableType.AudioClip:
|
||||
entity.Source =
|
||||
(AudioSource) EditorGUI.ObjectField(_rect, entity.Source, typeof(AudioSource), true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Fallback Language");
|
||||
_rect.x += 120;
|
||||
_rect.width = rect.width - 120;
|
||||
|
||||
var usedLanguages = new List<string>();
|
||||
var usedLanguagesNames = new List<string>();
|
||||
foreach (var translation in entity.Translations)
|
||||
{
|
||||
if (!usedLanguages.Contains(translation.Language))
|
||||
{
|
||||
var selectedUsedIndex = CVRTranslatable.Languages.Keys.ToList().FindIndex(match => match == translation.Language);
|
||||
usedLanguages.Add(translation.Language);
|
||||
usedLanguagesNames.Add(CVRTranslatable.Languages.Values.ToList()[selectedUsedIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
var selectedIndex = usedLanguages.FindIndex(match => match == entity.FallbackLanguage);
|
||||
|
||||
selectedIndex = EditorGUI.Popup(_rect, selectedIndex, usedLanguagesNames.ToArray());
|
||||
|
||||
if (selectedIndex >= 0)
|
||||
{
|
||||
entity.FallbackLanguage = usedLanguages.ToArray()[selectedIndex];
|
||||
}
|
||||
else if (usedLanguages.Count > 0)
|
||||
{
|
||||
entity.FallbackLanguage = usedLanguages[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.FallbackLanguage = "en";
|
||||
}
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 120, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
entity.GetList().DoList(new Rect(rect.x, rect.y, rect.width, 20f));
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorUtility.SetDirty(_translatable);
|
||||
Undo.RegisterCreatedObjectUndo (_translatable, "Changed Translatable");
|
||||
}
|
||||
}
|
||||
|
||||
private float OnHeightElement(int index)
|
||||
{
|
||||
if (index > _translatable.Translatables.Count) return EditorGUIUtility.singleLineHeight * 1f;
|
||||
entity = _translatable.Translatables[index];
|
||||
|
||||
/*if (entity.Type == CVRTranslatable.TranslatableType.GameObject)
|
||||
{
|
||||
return (entity.Translations.Count == 0 ? 1 : entity.Translations.Count * 2f + 5.25f) * 1.25f * EditorGUIUtility.singleLineHeight;
|
||||
}*/
|
||||
|
||||
return ((entity.Translations.Count == 0 ? 1 : entity.Translations.Count *
|
||||
(entity.Type == CVRTranslatable.TranslatableType.AudioClip || entity.Type == CVRTranslatable.TranslatableType.GameObject?2f:4f)) + 5.25f ) * 1.25f *
|
||||
EditorGUIUtility.singleLineHeight;
|
||||
}
|
||||
|
||||
private void OnChanged(ReorderableList list)
|
||||
{
|
||||
EditorUtility.SetDirty(_translatable);
|
||||
}
|
||||
|
||||
private void OnAdd(ReorderableList list)
|
||||
{
|
||||
_translatable.Translatables.Add(new CVRTranslatable.ObjectTranslatable_t());
|
||||
Repaint();
|
||||
}
|
||||
|
||||
private void OnDrawHeader(Rect rect)
|
||||
{
|
||||
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
GUI.Label(_rect, "Translatables");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (_translatable == null) _translatable = (CVRTranslatable) target;
|
||||
|
||||
if (reorderableList == null) InitializeList();
|
||||
|
||||
reorderableList.DoLayoutList();
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRTranslatableEditor.cs.meta
Executable file
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRTranslatableEditor.cs.meta
Executable file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d77d020521ad4e49bb2fe2208d6e5d0f
|
||||
timeCreated: 1623092626
|
529
Assets/ABI.CCK/Scripts/Editor/CCK_CVRWorldEditor.cs
Executable file
529
Assets/ABI.CCK/Scripts/Editor/CCK_CVRWorldEditor.cs
Executable file
|
@ -0,0 +1,529 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ABI.CCK.Components;
|
||||
#if CCK_ADDIN_HIGHLIGHT_PLUS
|
||||
using HighlightPlus;
|
||||
#endif
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(ABI.CCK.Components.CVRWorld)), CanEditMultipleObjects]
|
||||
public class CCK_CVRWorldEditor : UnityEditor.Editor
|
||||
{
|
||||
private CVRWorld _world;
|
||||
|
||||
private ReorderableList CategoryList = null;
|
||||
private CVRObjectCatalogCategory objectCatalogCategory = null;
|
||||
private List<string> popupListName = new List<string>();
|
||||
private List<string> popupListID = new List<string>();
|
||||
|
||||
private ReorderableList objectCatalogList = null;
|
||||
private CVRObjectCatalogEntry objectCatalogEntry = null;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (_world == null) _world = (CVRWorld) target;
|
||||
|
||||
EditorGUILayout.LabelField("World settings");
|
||||
|
||||
var list = serializedObject.FindProperty("spawns");
|
||||
EditorGUILayout.PropertyField(list, new GUIContent("Spawns"), true);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
_world.spawnRule = (CVRWorld.SpawnRule) EditorGUILayout.EnumPopup("Spawn Rule", _world.spawnRule);
|
||||
|
||||
_world.referenceCamera = (GameObject) EditorGUILayout.ObjectField("Reference Camera", _world.referenceCamera, typeof(GameObject), true);
|
||||
|
||||
_world.respawnHeightY = EditorGUILayout.IntField("Respawn Height Y", _world.respawnHeightY);
|
||||
|
||||
_world.objectRespawnBehaviour = (CVRWorld.RespawnBehaviour) EditorGUILayout.EnumPopup("Object Respawn Behaviour", _world.objectRespawnBehaviour);
|
||||
|
||||
EditorGUILayout.LabelField("Optional settings");
|
||||
|
||||
list = serializedObject.FindProperty("warpPoints");
|
||||
EditorGUILayout.PropertyField(list, new GUIContent("Warp Points"), true);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
|
||||
GUILayout.BeginVertical("HelpBox");
|
||||
GUILayout.BeginHorizontal ();
|
||||
_world.useAdvancedSettings = EditorGUILayout.Toggle (_world.useAdvancedSettings, GUILayout.Width(16));
|
||||
EditorGUILayout.LabelField ("Use Advanced Settings", GUILayout.Width(250));
|
||||
GUILayout.EndHorizontal ();
|
||||
|
||||
if (_world.useAdvancedSettings)
|
||||
{
|
||||
GUILayout.BeginHorizontal ();
|
||||
GUILayout.BeginVertical ("GroupBox");
|
||||
|
||||
EditorGUILayout.LabelField("World Rules");
|
||||
|
||||
_world.allowSpawnables = EditorGUILayout.Toggle("Allow Spawnables", _world.allowSpawnables);
|
||||
|
||||
_world.allowPortals = EditorGUILayout.Toggle("Allow Portals", _world.allowPortals);
|
||||
|
||||
_world.allowFlying = EditorGUILayout.Toggle("Allow Flying", _world.allowFlying);
|
||||
|
||||
_world.showNamePlates = EditorGUILayout.Toggle("Show Nameplates", _world.showNamePlates);
|
||||
|
||||
_world.enableBuilder = EditorGUILayout.Toggle("Enable Builder", _world.enableBuilder);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.LabelField("Movement Parameters");
|
||||
|
||||
EditorGUILayout.HelpBox("Changing these Values can lead to an undesirable experience.", MessageType.Warning);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
_world.baseMovementSpeed = EditorGUILayout.FloatField("Base Movement Speed", _world.baseMovementSpeed);
|
||||
|
||||
_world.sprintMultiplier = EditorGUILayout.FloatField("Sprint Multiplier", _world.sprintMultiplier);
|
||||
|
||||
_world.strafeMultiplier = EditorGUILayout.FloatField("Strafe Multiplier", _world.strafeMultiplier);
|
||||
|
||||
_world.crouchMultiplier = EditorGUILayout.FloatField("Crouch Multiplier", _world.crouchMultiplier);
|
||||
|
||||
_world.proneMultiplier = EditorGUILayout.FloatField("Prone Multiplier", _world.proneMultiplier);
|
||||
|
||||
_world.flyMultiplier = EditorGUILayout.FloatField("Fly Multiplier", _world.flyMultiplier);
|
||||
|
||||
_world.inAirMovementMultiplier = EditorGUILayout.FloatField("In Air Movement Multiplier", _world.inAirMovementMultiplier);
|
||||
|
||||
_world.gravity = EditorGUILayout.FloatField("Gravity", _world.gravity);
|
||||
|
||||
_world.jumpHeight = EditorGUILayout.FloatField("Jump Height", _world.jumpHeight);
|
||||
|
||||
_world.fov = EditorGUILayout.Slider("Fov", _world.fov, 60f, 120f);
|
||||
|
||||
_world.enableZoom = EditorGUILayout.Toggle("Enable Zoom", _world.enableZoom);
|
||||
|
||||
#if CCK_ADDIN_HIGHLIGHT_PLUS
|
||||
_world.highlightProfile = (HighlightProfile) EditorGUILayout.ObjectField("Highlighting Profile", _world.highlightProfile,
|
||||
typeof(HighlightProfile), true);
|
||||
#endif
|
||||
|
||||
GUILayout.EndVertical ();
|
||||
GUILayout.EndHorizontal ();
|
||||
}
|
||||
|
||||
GUILayout.EndVertical ();
|
||||
|
||||
GUILayout.BeginVertical("HelpBox");
|
||||
GUILayout.BeginHorizontal ();
|
||||
EditorGUILayout.LabelField ("Object Catalog");
|
||||
GUILayout.EndHorizontal ();
|
||||
GUILayout.BeginHorizontal ();
|
||||
GUILayout.BeginVertical ("GroupBox");
|
||||
|
||||
InitializeCategoryList();
|
||||
CategoryList.DoLayoutList();
|
||||
popupListName.Clear();
|
||||
popupListID.Clear();
|
||||
foreach (var category in _world.objectCatalogCategories)
|
||||
{
|
||||
if (string.IsNullOrEmpty(category.id)) category.id = "w~" + System.Guid.NewGuid().ToString();
|
||||
popupListName.Add(string.IsNullOrEmpty(category.name) ? "-" : category.name);
|
||||
popupListID.Add(category.id);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
InitializeObjectCatalogList();
|
||||
objectCatalogList.DoLayoutList();
|
||||
|
||||
GUILayout.EndVertical ();
|
||||
GUILayout.EndHorizontal ();
|
||||
GUILayout.EndVertical ();
|
||||
}
|
||||
|
||||
private void InitializeCategoryList()
|
||||
{
|
||||
if (CategoryList != null) return;
|
||||
|
||||
CategoryList = new ReorderableList(_world.objectCatalogCategories, typeof(CVRObjectCatalogCategory),
|
||||
false, true, true, true);
|
||||
CategoryList.drawHeaderCallback = OnDrawHeaderCategory;
|
||||
CategoryList.drawElementCallback = OnDrawElementCategory;
|
||||
CategoryList.elementHeightCallback = OnHeightElementCategory;
|
||||
CategoryList.onChangedCallback = OnChangedCategory;
|
||||
}
|
||||
|
||||
private void OnDrawHeaderCategory(Rect rect)
|
||||
{
|
||||
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
GUI.Label(_rect, "Categories");
|
||||
}
|
||||
|
||||
private void OnDrawElementCategory(Rect rect, int index, bool isactive, bool isfocused)
|
||||
{
|
||||
if (index > _world.objectCatalogCategories.Count) return;
|
||||
objectCatalogCategory = _world.objectCatalogCategories[index];
|
||||
|
||||
Rect _rect = new Rect(rect.x + 50, rect.y, 50, EditorGUIUtility.singleLineHeight);
|
||||
Rect initialRect = rect;
|
||||
|
||||
EditorGUI.LabelField(_rect, "Name");
|
||||
_rect.x += 50;
|
||||
_rect.width = rect.width - 50 - 50;
|
||||
|
||||
objectCatalogCategory.name = EditorGUI.TextField(_rect, objectCatalogCategory.name);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x + 50, rect.y, 50, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Image");
|
||||
_rect.x += 50;
|
||||
_rect.width = rect.width - 50 - 50;
|
||||
|
||||
objectCatalogCategory.image = (Texture2D) EditorGUI.ObjectField(_rect, objectCatalogCategory.image, typeof(Texture2D));
|
||||
|
||||
if (objectCatalogCategory.image != null)
|
||||
{
|
||||
GUI.DrawTexture(new Rect(initialRect.x, initialRect.y, 42, 42), objectCatalogCategory.image);
|
||||
}
|
||||
}
|
||||
|
||||
private float OnHeightElementCategory(int index)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight * 2.5f;
|
||||
}
|
||||
|
||||
private void OnChangedCategory(ReorderableList list)
|
||||
{
|
||||
EditorUtility.SetDirty(target);
|
||||
}
|
||||
|
||||
private void InitializeObjectCatalogList()
|
||||
{
|
||||
if (objectCatalogList != null) return;
|
||||
|
||||
objectCatalogList = new ReorderableList(_world.objectCatalogEntries, typeof(CVRObjectCatalogEntry),
|
||||
true, true, true, true);
|
||||
objectCatalogList.drawHeaderCallback = OnDrawHeaderEntry;
|
||||
objectCatalogList.drawElementCallback = OnDrawElementEntry;
|
||||
objectCatalogList.elementHeightCallback = OnHeightElementEntry;
|
||||
objectCatalogList.onChangedCallback = OnChangedEntry;
|
||||
}
|
||||
|
||||
private void OnDrawHeaderEntry(Rect rect)
|
||||
{
|
||||
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
GUI.Label(_rect, "Objects");
|
||||
}
|
||||
|
||||
private void OnDrawElementEntry(Rect rect, int index, bool isactive, bool isfocused)
|
||||
{
|
||||
if (index > _world.objectCatalogEntries.Count) return;
|
||||
objectCatalogEntry = _world.objectCatalogEntries[index];
|
||||
|
||||
while (objectCatalogEntry.guid == "")
|
||||
{
|
||||
var guid = "w~" + System.Guid.NewGuid().ToString();
|
||||
var guidValid = true;
|
||||
|
||||
foreach (var entry in _world.objectCatalogEntries)
|
||||
{
|
||||
if (entry.guid == guid) guidValid = false;
|
||||
}
|
||||
|
||||
if (!guidValid) continue;
|
||||
objectCatalogEntry.guid = guid;
|
||||
}
|
||||
|
||||
Rect _rect = new Rect(rect.x + 100, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
Rect initialRect = rect;
|
||||
|
||||
EditorGUI.LabelField(_rect, "Name");
|
||||
_rect.x += 60;
|
||||
_rect.width = rect.width - 160;
|
||||
|
||||
objectCatalogEntry.name = EditorGUI.TextField(_rect, objectCatalogEntry.name);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x + 100, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Prefab");
|
||||
_rect.x += 60;
|
||||
_rect.width = rect.width - 160;
|
||||
|
||||
objectCatalogEntry.prefab = (GameObject) EditorGUI.ObjectField(_rect, objectCatalogEntry.prefab, typeof(GameObject));
|
||||
|
||||
if (objectCatalogEntry.prefab != null)
|
||||
{
|
||||
var spawnable = objectCatalogEntry.prefab.GetComponent<CVRSpawnable>();
|
||||
var builder = objectCatalogEntry.prefab.GetComponent<CVRBuilderSpawnable>();
|
||||
|
||||
if (spawnable == null && builder == null) objectCatalogEntry.prefab = null;
|
||||
}
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x + 100, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Category");
|
||||
_rect.x += 60;
|
||||
_rect.width = rect.width - 160;
|
||||
|
||||
var catIndex = popupListID.IndexOf(objectCatalogEntry.categoryId);
|
||||
catIndex = EditorGUI.Popup(_rect, catIndex, popupListName.ToArray());
|
||||
if (catIndex >= 0) objectCatalogEntry.categoryId = popupListID[catIndex];
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x + 100, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Preview");
|
||||
_rect.x += 60;
|
||||
_rect.width = rect.width - 160;
|
||||
|
||||
objectCatalogEntry.preview = (Texture2D) EditorGUI.ObjectField(_rect, objectCatalogEntry.preview, typeof(Texture2D));
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
if (GUI.Button(_rect, "Generate Preview"))
|
||||
{
|
||||
GeneratePreviewImage(objectCatalogEntry);
|
||||
}
|
||||
|
||||
if (objectCatalogEntry.preview != null)
|
||||
{
|
||||
GUI.DrawTexture(new Rect(initialRect.x, initialRect.y, 88, 88), objectCatalogEntry.preview);
|
||||
}
|
||||
}
|
||||
|
||||
private void GeneratePreviewImage(CVRObjectCatalogEntry objectCatalogEntry)
|
||||
{
|
||||
if (objectCatalogEntry.prefab == null) return;
|
||||
|
||||
var path = "Assets/ABI.CCK/Resources/WorldObjectCatalog";
|
||||
var objectPosition = Vector3.down * 1000f;
|
||||
var rt = new RenderTexture(256, 256, 32);
|
||||
|
||||
if (!AssetDatabase.IsValidFolder(path))
|
||||
AssetDatabase.CreateFolder("Assets/ABI.CCK/Resources", "WorldObjectCatalog");
|
||||
|
||||
var obj = Instantiate(objectCatalogEntry.prefab, objectPosition, Quaternion.identity);
|
||||
|
||||
var renderers = obj.GetComponentsInChildren<Renderer>();
|
||||
Bounds b = new Bounds(Vector3.zero, Vector3.zero);
|
||||
|
||||
foreach (var renderer in renderers)
|
||||
{
|
||||
if (b.size.y == 0f)
|
||||
{
|
||||
b = renderer.bounds;
|
||||
}
|
||||
else
|
||||
{
|
||||
b.Encapsulate(renderer.bounds);
|
||||
}
|
||||
}
|
||||
|
||||
var transforms = obj.GetComponentsInChildren<Transform>();
|
||||
foreach (var transform in transforms)
|
||||
{
|
||||
transform.gameObject.layer = 12;
|
||||
}
|
||||
|
||||
var cam = new GameObject("Preview Capture", new[] {typeof(Camera), typeof(Light)}).GetComponent<Camera>();
|
||||
var light = cam.gameObject.GetComponent<Light>();
|
||||
light.type = LightType.Directional;
|
||||
light.cullingMask = 1 << 12;
|
||||
cam.aspect = 1f;
|
||||
cam.targetTexture = rt;
|
||||
cam.clearFlags = CameraClearFlags.Color;
|
||||
cam.backgroundColor = Color.black;
|
||||
cam.cullingMask = 1 << 12;
|
||||
|
||||
cam.transform.position = objectPosition + new Vector3(0f, b.extents.y, b.extents.y * 2f);
|
||||
cam.transform.eulerAngles = new Vector3(0f, 180f, 0f);
|
||||
Texture2D screenShot1 = new Texture2D(256, 256, TextureFormat.RGB24, false);
|
||||
cam.Render();
|
||||
RenderTexture.active = rt;
|
||||
screenShot1.ReadPixels(new Rect(0, 0, 256, 256), 0, 0);
|
||||
AssetDatabase.CreateAsset(screenShot1, path + "/ObjectCatalog_temp_1.asset");
|
||||
AssetDatabase.ImportAsset(path + "/ObjectCatalog_temp_1.asset", ImportAssetOptions.ForceUpdate);
|
||||
RenderTexture.active = null;
|
||||
|
||||
cam.transform.position = objectPosition + new Vector3(b.extents.y * 1.41f, b.extents.y, b.extents.y * 1.41f);
|
||||
cam.transform.eulerAngles = new Vector3(0f, 225f, 0f);
|
||||
Texture2D screenShot2 = new Texture2D(256, 256, TextureFormat.RGB24, false);
|
||||
cam.Render();
|
||||
RenderTexture.active = rt;
|
||||
screenShot2.ReadPixels(new Rect(0, 0, 256, 256), 0, 0);
|
||||
AssetDatabase.CreateAsset(screenShot2, path + "/ObjectCatalog_temp_2.asset");
|
||||
AssetDatabase.ImportAsset(path + "/ObjectCatalog_temp_2.asset", ImportAssetOptions.ForceUpdate);
|
||||
RenderTexture.active = null;
|
||||
|
||||
cam.transform.position = objectPosition + new Vector3(b.extents.y * 2f, b.extents.y, 0f);
|
||||
cam.transform.eulerAngles = new Vector3(0f, 270f, 0f);
|
||||
Texture2D screenShot3 = new Texture2D(256, 256, TextureFormat.RGB24, false);
|
||||
cam.Render();
|
||||
RenderTexture.active = rt;
|
||||
screenShot3.ReadPixels(new Rect(0, 0, 256, 256), 0, 0);
|
||||
AssetDatabase.CreateAsset(screenShot3, path + "/ObjectCatalog_temp_3.asset");
|
||||
AssetDatabase.ImportAsset(path + "/ObjectCatalog_temp_3.asset", ImportAssetOptions.ForceUpdate);
|
||||
RenderTexture.active = null;
|
||||
|
||||
cam.transform.position = objectPosition + new Vector3(b.extents.y * 1.41f, b.extents.y, b.extents.y * -1.41f);
|
||||
cam.transform.eulerAngles = new Vector3(0f, 315f, 0f);
|
||||
Texture2D screenShot4 = new Texture2D(256, 256, TextureFormat.RGB24, false);
|
||||
cam.Render();
|
||||
RenderTexture.active = rt;
|
||||
screenShot4.ReadPixels(new Rect(0, 0, 256, 256), 0, 0);
|
||||
AssetDatabase.CreateAsset(screenShot4, path + "/ObjectCatalog_temp_4.asset");
|
||||
AssetDatabase.ImportAsset(path + "/ObjectCatalog_temp_4.asset", ImportAssetOptions.ForceUpdate);
|
||||
RenderTexture.active = null;
|
||||
|
||||
cam.transform.position = objectPosition + new Vector3(0f, b.extents.y, b.extents.y * -2f);
|
||||
cam.transform.eulerAngles = new Vector3(0f, 0f, 0f);
|
||||
Texture2D screenShot5 = new Texture2D(256, 256, TextureFormat.RGB24, false);
|
||||
cam.Render();
|
||||
RenderTexture.active = rt;
|
||||
screenShot5.ReadPixels(new Rect(0, 0, 256, 256), 0, 0);
|
||||
AssetDatabase.CreateAsset(screenShot5, path + "/ObjectCatalog_temp_5.asset");
|
||||
AssetDatabase.ImportAsset(path + "/ObjectCatalog_temp_5.asset", ImportAssetOptions.ForceUpdate);
|
||||
RenderTexture.active = null;
|
||||
|
||||
cam.transform.position = objectPosition + new Vector3(b.extents.y * -1.41f, b.extents.y, b.extents.y * -1.41f);
|
||||
cam.transform.eulerAngles = new Vector3(0f, 45f, 0f);
|
||||
Texture2D screenShot6 = new Texture2D(256, 256, TextureFormat.RGB24, false);
|
||||
cam.Render();
|
||||
RenderTexture.active = rt;
|
||||
screenShot6.ReadPixels(new Rect(0, 0, 256, 256), 0, 0);
|
||||
AssetDatabase.CreateAsset(screenShot6, path + "/ObjectCatalog_temp_6.asset");
|
||||
AssetDatabase.ImportAsset(path + "/ObjectCatalog_temp_6.asset", ImportAssetOptions.ForceUpdate);
|
||||
RenderTexture.active = null;
|
||||
|
||||
cam.transform.position = objectPosition + new Vector3(b.extents.y * -2f, b.extents.y, 0f);
|
||||
cam.transform.eulerAngles = new Vector3(0f, 90f, 0f);
|
||||
Texture2D screenShot7 = new Texture2D(256, 256, TextureFormat.RGB24, false);
|
||||
cam.Render();
|
||||
RenderTexture.active = rt;
|
||||
screenShot7.ReadPixels(new Rect(0, 0, 256, 256), 0, 0);
|
||||
AssetDatabase.CreateAsset(screenShot7, path + "/ObjectCatalog_temp_7.asset");
|
||||
AssetDatabase.ImportAsset(path + "/ObjectCatalog_temp_7.asset", ImportAssetOptions.ForceUpdate);
|
||||
RenderTexture.active = null;
|
||||
|
||||
cam.transform.position = objectPosition + new Vector3(b.extents.y * -1.41f, b.extents.y, b.extents.y * 1.41f);
|
||||
cam.transform.eulerAngles = new Vector3(0f, 135f, 0f);
|
||||
Texture2D screenShot8 = new Texture2D(256, 256, TextureFormat.RGB24, false);
|
||||
cam.Render();
|
||||
RenderTexture.active = rt;
|
||||
screenShot8.ReadPixels(new Rect(0, 0, 256, 256), 0, 0);
|
||||
AssetDatabase.CreateAsset(screenShot8, path + "/ObjectCatalog_temp_8.asset");
|
||||
AssetDatabase.ImportAsset(path + "/ObjectCatalog_temp_8.asset", ImportAssetOptions.ForceUpdate);
|
||||
RenderTexture.active = null;
|
||||
|
||||
DestroyImmediate(obj);
|
||||
DestroyImmediate(cam.gameObject);
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
WorldObjectCatalogPreviewSelector window = (WorldObjectCatalogPreviewSelector) EditorWindow.GetWindow (
|
||||
typeof(WorldObjectCatalogPreviewSelector),
|
||||
true,
|
||||
"Select Catalog Object Preview"
|
||||
);
|
||||
|
||||
window.objectCatalogEntry = objectCatalogEntry;
|
||||
window.previewOption1 = screenShot1;
|
||||
window.previewOption2 = screenShot2;
|
||||
window.previewOption3 = screenShot3;
|
||||
window.previewOption4 = screenShot4;
|
||||
window.previewOption5 = screenShot5;
|
||||
window.previewOption6 = screenShot6;
|
||||
window.previewOption7 = screenShot7;
|
||||
window.previewOption8 = screenShot8;
|
||||
|
||||
var scale = WorldObjectCatalogPreviewSelector.previewWindowScale;
|
||||
|
||||
window.minSize = new Vector2(1152 * scale, 576 * scale);
|
||||
window.maxSize = new Vector2(1152 * scale, 576 * scale);
|
||||
|
||||
window.Show();
|
||||
}
|
||||
|
||||
private float OnHeightElementEntry(int index)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight * 6.25f;
|
||||
}
|
||||
|
||||
private void OnChangedEntry(ReorderableList list)
|
||||
{
|
||||
EditorUtility.SetDirty(target);
|
||||
}
|
||||
}
|
||||
|
||||
public class WorldObjectCatalogPreviewSelector : EditorWindow
|
||||
{
|
||||
public static float previewWindowScale = 0.75f;
|
||||
|
||||
public CVRObjectCatalogEntry objectCatalogEntry = null;
|
||||
public Texture2D previewOption1 = null;
|
||||
public Texture2D previewOption2 = null;
|
||||
public Texture2D previewOption3 = null;
|
||||
public Texture2D previewOption4 = null;
|
||||
public Texture2D previewOption5 = null;
|
||||
public Texture2D previewOption6 = null;
|
||||
public Texture2D previewOption7 = null;
|
||||
public Texture2D previewOption8 = null;
|
||||
|
||||
private string path = "Assets/ABI.CCK/Resources/WorldObjectCatalog";
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if (GUI.Button(new Rect(16 * previewWindowScale, 16 * previewWindowScale, 256 * previewWindowScale, 256 * previewWindowScale), previewOption1))
|
||||
{
|
||||
SelectPreviewImage(objectCatalogEntry, previewOption1);
|
||||
}
|
||||
if (GUI.Button(new Rect(304 * previewWindowScale, 16 * previewWindowScale, 256 * previewWindowScale, 256 * previewWindowScale), previewOption2))
|
||||
{
|
||||
SelectPreviewImage(objectCatalogEntry, previewOption2);
|
||||
}
|
||||
if (GUI.Button(new Rect(592 * previewWindowScale, 16 * previewWindowScale, 256 * previewWindowScale, 256 * previewWindowScale), previewOption3))
|
||||
{
|
||||
SelectPreviewImage(objectCatalogEntry, previewOption3);
|
||||
}
|
||||
if (GUI.Button(new Rect(880 * previewWindowScale, 16 * previewWindowScale, 256 * previewWindowScale, 256 * previewWindowScale), previewOption4))
|
||||
{
|
||||
SelectPreviewImage(objectCatalogEntry, previewOption4);
|
||||
}
|
||||
if (GUI.Button(new Rect(16 * previewWindowScale, 304 * previewWindowScale, 256 * previewWindowScale, 256 * previewWindowScale), previewOption5))
|
||||
{
|
||||
SelectPreviewImage(objectCatalogEntry, previewOption5);
|
||||
}
|
||||
if (GUI.Button(new Rect(304 * previewWindowScale, 304 * previewWindowScale, 256 * previewWindowScale, 256 * previewWindowScale), previewOption6))
|
||||
{
|
||||
SelectPreviewImage(objectCatalogEntry, previewOption6);
|
||||
}
|
||||
if (GUI.Button(new Rect(592 * previewWindowScale, 304 * previewWindowScale, 256 * previewWindowScale, 256 * previewWindowScale), previewOption7))
|
||||
{
|
||||
SelectPreviewImage(objectCatalogEntry, previewOption7);
|
||||
}
|
||||
if (GUI.Button(new Rect(880 * previewWindowScale, 304 * previewWindowScale, 256 * previewWindowScale, 256 * previewWindowScale), previewOption8))
|
||||
{
|
||||
SelectPreviewImage(objectCatalogEntry, previewOption8);
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectPreviewImage(CVRObjectCatalogEntry objectCatalogEntry, Texture2D selected)
|
||||
{
|
||||
byte[] bytes = selected.EncodeToPNG();
|
||||
var filename = path + "/ObjectCatalog_" + objectCatalogEntry.name + "_" + objectCatalogEntry.guid + "_preview.png";
|
||||
System.IO.File.WriteAllBytes(filename, bytes);
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
Texture2D createdTexture = AssetDatabase.LoadAssetAtPath<Texture2D>(filename);
|
||||
objectCatalogEntry.preview = createdTexture;
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRWorldEditor.cs.meta
Executable file
3
Assets/ABI.CCK/Scripts/Editor/CCK_CVRWorldEditor.cs.meta
Executable file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ce0787065da84f58b3b090f2a6bac03c
|
||||
timeCreated: 1627582871
|
15
Assets/ABI.CCK/Scripts/Editor/CCK_CVR_ActionEditor.cs
Executable file
15
Assets/ABI.CCK/Scripts/Editor/CCK_CVR_ActionEditor.cs
Executable file
|
@ -0,0 +1,15 @@
|
|||
using UnityEditor;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(ABI.CCK.Components.CVRAction))]
|
||||
public class CCK_CVR_ActionEditor : UnityEditor.Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
EditorGUILayout.HelpBox("This component is not yet ready to use!", MessageType.Error);
|
||||
|
||||
base.DrawDefaultInspector();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/ABI.CCK/Scripts/Editor/CCK_CVR_ActionEditor.cs.meta
Executable file
11
Assets/ABI.CCK/Scripts/Editor/CCK_CVR_ActionEditor.cs.meta
Executable file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9ab23ae3c6944eceb5b57b10e793ccc6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
15
Assets/ABI.CCK/Scripts/Editor/CCK_CVR_TimelineSyncEditor.cs
Executable file
15
Assets/ABI.CCK/Scripts/Editor/CCK_CVR_TimelineSyncEditor.cs
Executable file
|
@ -0,0 +1,15 @@
|
|||
using UnityEditor;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(ABI.CCK.Components.CVRTimelineSync))]
|
||||
public class CCK_CVR_TimelineSyncEditor : UnityEditor.Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
EditorGUILayout.HelpBox("This component is not yet ready to use!", MessageType.Error);
|
||||
|
||||
base.DrawDefaultInspector();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/ABI.CCK/Scripts/Editor/CCK_CVR_TimelineSyncEditor.cs.meta
Executable file
11
Assets/ABI.CCK/Scripts/Editor/CCK_CVR_TimelineSyncEditor.cs.meta
Executable file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e25b5a5d468e4e6084701674b84b6ad0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
246
Assets/ABI.CCK/Scripts/Editor/CCK_CVR_VideoPlayerEditor.cs
Executable file
246
Assets/ABI.CCK/Scripts/Editor/CCK_CVR_VideoPlayerEditor.cs
Executable file
|
@ -0,0 +1,246 @@
|
|||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
[CustomEditor(typeof(CVRVideoPlayer))]
|
||||
public class CCK_CVR_VideoPlayerEditor : Editor
|
||||
{
|
||||
private ReorderableList _reorderableList;
|
||||
private CVRVideoPlayer _player;
|
||||
private static bool _showGeneral = true;
|
||||
private static bool _showAudio = true;
|
||||
private static bool _showPlaylists = true;
|
||||
private static bool _showEvents = true;
|
||||
|
||||
private const string TypeLabel = "Playlists";
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (_player == null) _player = (CVRVideoPlayer)target;
|
||||
|
||||
_reorderableList = new ReorderableList(_player.entities, typeof(CVRVideoPlayerPlaylist), true, true, true, true);
|
||||
_reorderableList.drawHeaderCallback = OnDrawHeader;
|
||||
_reorderableList.drawElementCallback = OnDrawElement;
|
||||
_reorderableList.elementHeightCallback = OnHeightElement;
|
||||
_reorderableList.onAddCallback = OnAdd;
|
||||
_reorderableList.onChangedCallback = OnChanged;
|
||||
}
|
||||
|
||||
private float OnHeightElement(int index)
|
||||
{
|
||||
var height = 0f;
|
||||
|
||||
if (!_player.entities[index].isCollapsed) return EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
|
||||
height += EditorGUIUtility.singleLineHeight * (3f + 2.5f);
|
||||
|
||||
if (_player.entities[index].playlistVideos.Count == 0) height += 1.25f * EditorGUIUtility.singleLineHeight;
|
||||
|
||||
foreach (var entry in _player.entities[index].playlistVideos)
|
||||
{
|
||||
if (entry == null)
|
||||
{
|
||||
height += 1.25f * EditorGUIUtility.singleLineHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
height += (entry.isCollapsed ? 7.5f : 1.25f) * EditorGUIUtility.singleLineHeight;
|
||||
}
|
||||
}
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
private void OnDrawHeader(Rect rect)
|
||||
{
|
||||
Rect rectA = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
GUI.Label(rectA, TypeLabel);
|
||||
}
|
||||
|
||||
private void OnDrawElement(Rect rect, int index, bool isActive, bool isFocused)
|
||||
{
|
||||
if (index > _player.entities.Count) return;
|
||||
|
||||
rect.y += 2;
|
||||
rect.x += 12;
|
||||
rect.width -= 12;
|
||||
Rect rectA = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
bool collapse = EditorGUI.Foldout(rectA, _player.entities[index].isCollapsed, "Playlist Title", true);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(target, "Playlist Expand");
|
||||
_player.entities[index].isCollapsed = collapse;
|
||||
}
|
||||
|
||||
rectA.x += 80;
|
||||
rectA.width = rect.width - 80;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
string playlistTitle = EditorGUI.TextField(rectA, _player.entities[index].playlistTitle);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(target, "Playlist Title");
|
||||
_player.entities[index].playlistTitle = playlistTitle;
|
||||
}
|
||||
|
||||
if (!_player.entities[index].isCollapsed) return;
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
rectA = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(rectA, "Thumbnail Url");
|
||||
rectA.x += 80;
|
||||
rectA.width = rect.width - 80;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
string playlistThumbnailUrl = EditorGUI.TextField(rectA, _player.entities[index].playlistThumbnailUrl);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(target, "Playlist Thumbnail Url");
|
||||
_player.entities[index].playlistThumbnailUrl = playlistThumbnailUrl;
|
||||
}
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
//_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
var videoList = _player.entities[index].GetReorderableList(_player);
|
||||
videoList.DoList(new Rect(rect.x, rect.y, rect.width, 20f));
|
||||
}
|
||||
|
||||
private void OnAdd(ReorderableList list)
|
||||
{
|
||||
Undo.RecordObject(target, "Add Playlist Entry");
|
||||
_player.entities.Add(null);
|
||||
}
|
||||
|
||||
private void OnChanged(ReorderableList list)
|
||||
{
|
||||
Undo.RecordObject(target, "Playlist List changed");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
#region General settings
|
||||
|
||||
_showGeneral = EditorGUILayout.BeginFoldoutHeaderGroup(_showGeneral, "General");
|
||||
if (_showGeneral)
|
||||
{
|
||||
_player.syncEnabled = EditorGUILayout.Toggle("Network Sync", _player.syncEnabled);
|
||||
_player.autoplay = EditorGUILayout.Toggle("Play On Awake", _player.autoplay);
|
||||
_player.interactiveUI = EditorGUILayout.Toggle("Use Interactive Library UI", _player.interactiveUI);
|
||||
_player.videoPlayerUIPosition = (Transform)EditorGUILayout.ObjectField("UI Position/Parent", _player.videoPlayerUIPosition, typeof(Transform), true);
|
||||
_player.localPlaybackSpeed = EditorGUILayout.Slider("Playback Speed", _player.localPlaybackSpeed, 0.5f, 2.0f);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.Space();
|
||||
|
||||
_player.ProjectionTexture = (RenderTexture)EditorGUILayout.ObjectField("Projection Texture", _player.ProjectionTexture, typeof(RenderTexture), true);
|
||||
EditorGUILayout.Space();
|
||||
|
||||
if (_player.ProjectionTexture == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("The video player output texture is empty, please fill it or no video will be drawn.", MessageType.Warning);
|
||||
if (GUILayout.Button("Create Sample Render Texture"))
|
||||
{
|
||||
RenderTexture tex = new RenderTexture(1920, 1080, 24);
|
||||
if (!AssetDatabase.IsValidFolder("Assets/ABI.Generated"))
|
||||
AssetDatabase.CreateFolder("Assets", "ABI.Generated");
|
||||
if (!AssetDatabase.IsValidFolder("Assets/ABI.Generated/VideoPlayer"))
|
||||
AssetDatabase.CreateFolder("Assets/ABI.Generated", "VideoPlayer");
|
||||
if (!AssetDatabase.IsValidFolder("Assets/ABI.Generated/VideoPlayer/RenderTextures"))
|
||||
AssetDatabase.CreateFolder("Assets/ABI.Generated/VideoPlayer", "RenderTextures");
|
||||
AssetDatabase.CreateAsset(tex,
|
||||
"Assets/ABI.Generated/VideoPlayer/RenderTextures/" + _player.gameObject.GetInstanceID() +
|
||||
".renderTexture");
|
||||
_player.ProjectionTexture = tex;
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Audio settings
|
||||
|
||||
_showAudio = EditorGUILayout.BeginFoldoutHeaderGroup(_showAudio, "Audio");
|
||||
|
||||
if (_showAudio)
|
||||
{
|
||||
_player.playbackVolume = EditorGUILayout.Slider("Playback Volume", _player.playbackVolume, 0.0f, 1.0f);
|
||||
_player.audioPlaybackMode = (CVRVideoPlayer.AudioMode)EditorGUILayout.EnumPopup("Audio Playback Mode ", _player.audioPlaybackMode);
|
||||
_player.customAudioSource = (AudioSource)EditorGUILayout.ObjectField("Custom Audio Source", _player.customAudioSource, typeof(AudioSource), true);
|
||||
|
||||
var list = serializedObject.FindProperty("roomScaleAudioSources");
|
||||
EditorGUILayout.PropertyField(list, new GUIContent("Room Scale Audio Sources"), true);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Playlists
|
||||
|
||||
_showPlaylists = EditorGUILayout.BeginFoldoutHeaderGroup(_showPlaylists, "Playlists");
|
||||
|
||||
if (_showPlaylists)
|
||||
{
|
||||
EditorGUILayout.LabelField(new GUIContent("Play On Awake Object", "Default video to play on start/awake"), new GUIContent(_player.playOnAwakeObject?.videoTitle));
|
||||
if (GUILayout.Button("Remove Play on Awake Object")) _player.playOnAwakeObject = null;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.Space();
|
||||
|
||||
_reorderableList.DoLayoutList();
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
_showEvents = EditorGUILayout.BeginFoldoutHeaderGroup(_showEvents, "Events");
|
||||
|
||||
if (_showEvents)
|
||||
{
|
||||
serializedObject.Update();
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("startedPlayback"), true);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
serializedObject.Update();
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("finishedPlayback"), true);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
serializedObject.Update();
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("pausedPlayback"), true);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
serializedObject.Update();
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("setUrl"), true);
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
11
Assets/ABI.CCK/Scripts/Editor/CCK_CVR_VideoPlayerEditor.cs.meta
Executable file
11
Assets/ABI.CCK/Scripts/Editor/CCK_CVR_VideoPlayerEditor.cs.meta
Executable file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c6949d9993bf43cba4726fcbdbda90bb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
615
Assets/ABI.CCK/Scripts/Editor/CCK_FaceTrackingUtilities.cs
Executable file
615
Assets/ABI.CCK/Scripts/Editor/CCK_FaceTrackingUtilities.cs
Executable file
|
@ -0,0 +1,615 @@
|
|||
using System.Collections.Generic;
|
||||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
public class CCK_FaceTrackingUtilities : EditorWindow
|
||||
{
|
||||
public CVRAvatar Avatar;
|
||||
public CVRFaceTracking FaceTracking;
|
||||
public int Tab = 0;
|
||||
|
||||
private int[] _blendShapeIndexes = new int[37];
|
||||
|
||||
private bool _enablePreview = false;
|
||||
private Vector3 _jawPosition = new Vector4(0f, 0f, 0f);
|
||||
private float _apeShape = 0f;
|
||||
private float _mouthUpper = 0f;
|
||||
private float _mouthLower = 0f;
|
||||
private float _mouthPout = 0f;
|
||||
private float _mouthSmileLeft = 0f;
|
||||
private float _mouthSmileRight = 0f;
|
||||
private float _mouthSadLeft = 0f;
|
||||
private float _mouthSadRight = 0f;
|
||||
private float _mouthPuffLeft = 0f;
|
||||
private float _mouthPuffRight = 0f;
|
||||
private float _mouthSuck = 0f;
|
||||
|
||||
private List<string> _blendShapes = new List<string>();
|
||||
|
||||
private bool _enableJawGeneration = false;
|
||||
private int _jawBlendShapeIndex = -1;
|
||||
private float _jawMovementStrength = 0.05f;
|
||||
|
||||
private bool _enableLipGeneration = false;
|
||||
private int _lipBlendShapeIndex = -1;
|
||||
private float _lipMovementStrength = 0.05f;
|
||||
|
||||
private bool _enableSmileGeneration = false;
|
||||
private int _smileBlendShapeIndex = -1;
|
||||
|
||||
private bool _enableFrownGeneration = false;
|
||||
private int _frownBlendShapeIndex = -1;
|
||||
|
||||
private bool _enablePuffGeneration = false;
|
||||
private int _puffBlendShapeIndex = -1;
|
||||
|
||||
[MenuItem("Alpha Blend Interactive/Modules/Face Tracking Utilities")]
|
||||
private static void Init()
|
||||
{
|
||||
CCK_FaceTrackingUtilities window = (CCK_FaceTrackingUtilities)GetWindow(typeof(CCK_FaceTrackingUtilities), false, $"CCK :: Face Tracking Utilities");
|
||||
window.Show();
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
var avatar = (CVRAvatar) EditorGUILayout.ObjectField("Avatar", Avatar, typeof(CVRAvatar));
|
||||
|
||||
if (avatar != Avatar) FaceTracking = null;
|
||||
Avatar = avatar;
|
||||
|
||||
if (Avatar == null) return;
|
||||
|
||||
if (Avatar != null && FaceTracking == null) FaceTracking = Avatar.GetComponentInChildren<CVRFaceTracking>();
|
||||
|
||||
if (FaceTracking == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("No Face Tracking component detected on Avatar. Would you like to add one?", MessageType.Info);
|
||||
|
||||
if (GUILayout.Button("Add Face Tracking"))
|
||||
{
|
||||
if (Avatar.bodyMesh == null)
|
||||
{
|
||||
EditorUtility.DisplayDialog("Error", "Your Selected Avatar has no Face Mesh selected.", "OK");
|
||||
return;
|
||||
}
|
||||
|
||||
FaceTracking = Avatar.gameObject.AddComponent<CVRFaceTracking>();
|
||||
FaceTracking.FaceMesh = Avatar.bodyMesh;
|
||||
FaceTracking.GetBlendShapeNames();
|
||||
FaceTracking.FindVisemes();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Tab = GUILayout.Toolbar (Tab, new string[] {"Preview", "Blendshape Generator"});
|
||||
|
||||
switch (Tab)
|
||||
{
|
||||
case 0:
|
||||
ShowPreviewTab();
|
||||
break;
|
||||
case 1:
|
||||
ShowSetupTab();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowPreviewTab()
|
||||
{
|
||||
_enablePreview = EditorGUILayout.Toggle("Enable Preview", _enablePreview);
|
||||
|
||||
FaceTracking.BlendShapeStrength = EditorGUILayout.Slider("Blend Shape Weight", FaceTracking.BlendShapeStrength, 50f, 500f);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
_jawPosition.x = EditorGUILayout.Slider("Jaw Position Forward", _jawPosition.x, 0f, 1f);
|
||||
_jawPosition.y = EditorGUILayout.Slider("Jaw Position Open", _jawPosition.y, 0f, 1f);
|
||||
_jawPosition.z = EditorGUILayout.Slider("Jaw Position Left Right", _jawPosition.z, -1f, 1f);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
_apeShape = EditorGUILayout.Slider("Mouth Ape Shape", _apeShape, 0f, 1f);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
_mouthUpper = EditorGUILayout.Slider("Mouth Upper", _mouthUpper, -1f, 1f);
|
||||
_mouthLower = EditorGUILayout.Slider("Mouth Lower", _mouthLower, -1f, 1f);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
_mouthPout = EditorGUILayout.Slider("Mouth Pout", _mouthPout, 0f, 1f);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
_mouthSmileLeft = EditorGUILayout.Slider("Mouth Smile Left", _mouthSmileLeft, 0f, 1f);
|
||||
_mouthSmileRight = EditorGUILayout.Slider("Mouth Smile Right", _mouthSmileRight, 0f, 1f);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
_mouthSadLeft = EditorGUILayout.Slider("Mouth Sad Left", _mouthSadLeft, 0f, 1f);
|
||||
_mouthSadRight = EditorGUILayout.Slider("Mouth Sad Right", _mouthSadRight, 0f, 1f);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
_mouthPuffLeft = EditorGUILayout.Slider("Cheek Puff Left", _mouthPuffLeft, 0f, 1f);
|
||||
_mouthPuffRight = EditorGUILayout.Slider("Cheek Puff Right", _mouthPuffRight, 0f, 1f);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
_mouthSuck = EditorGUILayout.Slider("Cheek Suck", _mouthSuck, 0f, 1f);
|
||||
|
||||
if (FaceTracking != null && FaceTracking.FaceMesh != null)
|
||||
{
|
||||
var m = FaceTracking.FaceMesh.sharedMesh;
|
||||
if (m != null)
|
||||
{
|
||||
for (var i = 0; i < m.blendShapeCount; i++)
|
||||
{
|
||||
string s = m.GetBlendShapeName(i);
|
||||
for (var j = 0; j < FaceTracking.FaceBlendShapes.Length; j++)
|
||||
{
|
||||
if (s == FaceTracking.FaceBlendShapes[j])
|
||||
{
|
||||
_blendShapeIndexes[j] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (FaceTracking != null && FaceTracking.FaceMesh != null && _enablePreview)
|
||||
{
|
||||
var factor = FaceTracking.enableOverdriveBlendShapes ? 0.2f : 1f;
|
||||
|
||||
if (FaceTracking.FaceBlendShapes[2] != "-none-" && _blendShapeIndexes[2] <= FaceTracking.FaceMesh.sharedMesh.blendShapeCount)
|
||||
FaceTracking.FaceMesh.SetBlendShapeWeight(_blendShapeIndexes[2],
|
||||
Mathf.Clamp(_jawPosition.x, 0f, 1f) * FaceTracking.BlendShapeStrength * factor);
|
||||
|
||||
if (FaceTracking.FaceBlendShapes[3] != "-none-" && _blendShapeIndexes[3] <= FaceTracking.FaceMesh.sharedMesh.blendShapeCount)
|
||||
FaceTracking.FaceMesh.SetBlendShapeWeight(_blendShapeIndexes[3],
|
||||
Mathf.Clamp(_jawPosition.y, 0f, 1f) * FaceTracking.BlendShapeStrength * factor);
|
||||
|
||||
|
||||
if (FaceTracking.FaceBlendShapes[0] != "-none-" && _blendShapeIndexes[0] <= FaceTracking.FaceMesh.sharedMesh.blendShapeCount)
|
||||
FaceTracking.FaceMesh.SetBlendShapeWeight(_blendShapeIndexes[0],
|
||||
Mathf.Clamp(_jawPosition.z, 0f, 1f) * FaceTracking.BlendShapeStrength * factor);
|
||||
|
||||
if (FaceTracking.FaceBlendShapes[1] != "-none-" && _blendShapeIndexes[1] <= FaceTracking.FaceMesh.sharedMesh.blendShapeCount)
|
||||
FaceTracking.FaceMesh.SetBlendShapeWeight(_blendShapeIndexes[1],
|
||||
Mathf.Clamp(_jawPosition.z, -1f, 0f) * -1f * FaceTracking.BlendShapeStrength * factor);
|
||||
|
||||
if (FaceTracking.FaceBlendShapes[4] != "-none-" && _blendShapeIndexes[4] <= FaceTracking.FaceMesh.sharedMesh.blendShapeCount)
|
||||
FaceTracking.FaceMesh.SetBlendShapeWeight(_blendShapeIndexes[4],
|
||||
_apeShape * FaceTracking.BlendShapeStrength * factor);
|
||||
|
||||
if (FaceTracking.FaceBlendShapes[5] != "-none-" && _blendShapeIndexes[5] <= FaceTracking.FaceMesh.sharedMesh.blendShapeCount)
|
||||
FaceTracking.FaceMesh.SetBlendShapeWeight(_blendShapeIndexes[5],
|
||||
Mathf.Clamp(_mouthUpper, 0f, 1f) * FaceTracking.BlendShapeStrength * factor);
|
||||
|
||||
if (FaceTracking.FaceBlendShapes[6] != "-none-" && _blendShapeIndexes[6] <= FaceTracking.FaceMesh.sharedMesh.blendShapeCount)
|
||||
FaceTracking.FaceMesh.SetBlendShapeWeight(_blendShapeIndexes[6],
|
||||
Mathf.Clamp(_mouthUpper, -1f, 0f) * -1f * FaceTracking.BlendShapeStrength * factor);
|
||||
|
||||
if (FaceTracking.FaceBlendShapes[7] != "-none-" && _blendShapeIndexes[7] <= FaceTracking.FaceMesh.sharedMesh.blendShapeCount)
|
||||
FaceTracking.FaceMesh.SetBlendShapeWeight(_blendShapeIndexes[7],
|
||||
Mathf.Clamp(_mouthLower, 0f, 1f) * FaceTracking.BlendShapeStrength * factor);
|
||||
|
||||
if (FaceTracking.FaceBlendShapes[8] != "-none-" && _blendShapeIndexes[8] <= FaceTracking.FaceMesh.sharedMesh.blendShapeCount)
|
||||
FaceTracking.FaceMesh.SetBlendShapeWeight(_blendShapeIndexes[8],
|
||||
Mathf.Clamp(_mouthLower, -1f, 0f) * -1f * FaceTracking.BlendShapeStrength * factor);
|
||||
|
||||
if (FaceTracking.FaceBlendShapes[11] != "-none-" && _blendShapeIndexes[11] <= FaceTracking.FaceMesh.sharedMesh.blendShapeCount)
|
||||
FaceTracking.FaceMesh.SetBlendShapeWeight(_blendShapeIndexes[11],
|
||||
Mathf.Clamp(_mouthPout, 0f, 1f) * FaceTracking.BlendShapeStrength * factor);
|
||||
|
||||
if (FaceTracking.FaceBlendShapes[12] != "-none-" && _blendShapeIndexes[12] <= FaceTracking.FaceMesh.sharedMesh.blendShapeCount)
|
||||
FaceTracking.FaceMesh.SetBlendShapeWeight(_blendShapeIndexes[12],
|
||||
Mathf.Clamp(_mouthSmileRight, 0f, 1f) * FaceTracking.BlendShapeStrength * factor);
|
||||
|
||||
if (FaceTracking.FaceBlendShapes[13] != "-none-" && _blendShapeIndexes[13] <= FaceTracking.FaceMesh.sharedMesh.blendShapeCount)
|
||||
FaceTracking.FaceMesh.SetBlendShapeWeight(_blendShapeIndexes[13],
|
||||
Mathf.Clamp(_mouthSmileLeft, 0f, 1f) * FaceTracking.BlendShapeStrength * factor);
|
||||
|
||||
if (FaceTracking.FaceBlendShapes[14] != "-none-" && _blendShapeIndexes[14] <= FaceTracking.FaceMesh.sharedMesh.blendShapeCount)
|
||||
FaceTracking.FaceMesh.SetBlendShapeWeight(_blendShapeIndexes[14],
|
||||
Mathf.Clamp(_mouthSadRight, 0f, 1f) * FaceTracking.BlendShapeStrength * factor);
|
||||
|
||||
if (FaceTracking.FaceBlendShapes[15] != "-none-" && _blendShapeIndexes[15] <= FaceTracking.FaceMesh.sharedMesh.blendShapeCount)
|
||||
FaceTracking.FaceMesh.SetBlendShapeWeight(_blendShapeIndexes[15],
|
||||
Mathf.Clamp(_mouthSadLeft, 0f, 1f) * FaceTracking.BlendShapeStrength * factor);
|
||||
|
||||
if (FaceTracking.FaceBlendShapes[16] != "-none-" && _blendShapeIndexes[16] <= FaceTracking.FaceMesh.sharedMesh.blendShapeCount)
|
||||
FaceTracking.FaceMesh.SetBlendShapeWeight(_blendShapeIndexes[16],
|
||||
Mathf.Clamp(_mouthPuffRight, 0f, 1f) * FaceTracking.BlendShapeStrength * factor);
|
||||
|
||||
if (FaceTracking.FaceBlendShapes[17] != "-none-" && _blendShapeIndexes[17] <= FaceTracking.FaceMesh.sharedMesh.blendShapeCount)
|
||||
FaceTracking.FaceMesh.SetBlendShapeWeight(_blendShapeIndexes[17],
|
||||
Mathf.Clamp(_mouthPuffLeft, 0f, 1f) * FaceTracking.BlendShapeStrength * factor);
|
||||
|
||||
if (FaceTracking.FaceBlendShapes[18] != "-none-" && _blendShapeIndexes[18] <= FaceTracking.FaceMesh.sharedMesh.blendShapeCount)
|
||||
FaceTracking.FaceMesh.SetBlendShapeWeight(_blendShapeIndexes[18],
|
||||
Mathf.Clamp(_mouthSuck, 0f, 1f) * FaceTracking.BlendShapeStrength * factor);
|
||||
}
|
||||
else if (FaceTracking != null)
|
||||
{
|
||||
for (var j = 0; j < FaceTracking.FaceBlendShapes.Length; j++)
|
||||
{
|
||||
if (FaceTracking.FaceBlendShapes[j] != "-none-")
|
||||
{
|
||||
FaceTracking.FaceMesh.SetBlendShapeWeight(_blendShapeIndexes[j], 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowSetupTab()
|
||||
{
|
||||
if (FaceTracking != null && FaceTracking.FaceMesh != null)
|
||||
{
|
||||
var m = FaceTracking.FaceMesh.sharedMesh;
|
||||
if (m != null)
|
||||
{
|
||||
_blendShapes.Clear();
|
||||
_blendShapes.Add("-none-");
|
||||
for (var i = 0; i < m.blendShapeCount; i++)
|
||||
{
|
||||
_blendShapes.Add(m.GetBlendShapeName(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.HelpBox("The Generator uses your Avatars Voice Position to generate new Blendhapes. Please make sure it is in the middle of the mouth between the lips.", MessageType.Warning);
|
||||
|
||||
_enableJawGeneration = EditorGUILayout.Toggle("Generate Jaw Blendshapes", _enableJawGeneration);
|
||||
|
||||
if (_enableJawGeneration)
|
||||
{
|
||||
EditorGUILayout.HelpBox("You should use a Blendshape here that opens the mouth ond moves the jaw down. For example the AA Viseme.", MessageType.Info);
|
||||
_jawBlendShapeIndex = EditorGUILayout.Popup("Jaw Open Blendshape", _jawBlendShapeIndex + 1, _blendShapes.ToArray()) - 1;
|
||||
_jawMovementStrength = EditorGUILayout.FloatField("Jaw Movement Strength", _jawMovementStrength);
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
_enableLipGeneration = EditorGUILayout.Toggle("Generate Lip Blendshapes", _enableLipGeneration);
|
||||
|
||||
if (_enableLipGeneration)
|
||||
{
|
||||
EditorGUILayout.HelpBox("You should use a Blendshape here that moves only the Lips and a little bit of the surrounding face", MessageType.Info);
|
||||
_lipBlendShapeIndex = EditorGUILayout.Popup("Lips Blendshape", _lipBlendShapeIndex + 1, _blendShapes.ToArray()) - 1;
|
||||
_lipMovementStrength = EditorGUILayout.FloatField("Lip Movement Strength", _lipMovementStrength);
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
_enableSmileGeneration = EditorGUILayout.Toggle("Separate Smile Blendshape", _enableSmileGeneration);
|
||||
|
||||
if (_enableSmileGeneration)
|
||||
{
|
||||
EditorGUILayout.HelpBox("You should place a Blendshape that contains a smile expression. The Generator will separate the sides", MessageType.Info);
|
||||
_smileBlendShapeIndex = EditorGUILayout.Popup("Smile Blendshape", _smileBlendShapeIndex + 1, _blendShapes.ToArray()) - 1;
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
_enableFrownGeneration = EditorGUILayout.Toggle("Separate Frown Blendshape", _enableFrownGeneration);
|
||||
|
||||
if (_enableFrownGeneration)
|
||||
{
|
||||
EditorGUILayout.HelpBox("You should place a Blendshape that contains a frown expression. The Generator will separate the sides", MessageType.Info);
|
||||
_frownBlendShapeIndex = EditorGUILayout.Popup("Frown Blendshape", _frownBlendShapeIndex + 1, _blendShapes.ToArray()) - 1;
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
_enablePuffGeneration = EditorGUILayout.Toggle("Separate Puff Blendshape", _enablePuffGeneration);
|
||||
|
||||
if (_enablePuffGeneration)
|
||||
{
|
||||
EditorGUILayout.HelpBox("You should place a Blendshape here that Puffs both cheeks. The Generator will separate the sides", MessageType.Info);
|
||||
_puffBlendShapeIndex = EditorGUILayout.Popup("Puff Cheek Blendshape", _puffBlendShapeIndex + 1, _blendShapes.ToArray()) - 1;
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
|
||||
if (GUILayout.Button("Generate Blendshapes"))
|
||||
{
|
||||
GenerateBlendShapes();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void GenerateBlendShapes()
|
||||
{
|
||||
if (FaceTracking.OriginalMesh == null)
|
||||
{
|
||||
FaceTracking.OriginalMesh = FaceTracking.FaceMesh.sharedMesh;
|
||||
}
|
||||
|
||||
var mesh = FaceTracking.OriginalMesh;
|
||||
|
||||
//Mesh Creation
|
||||
Mesh m = mesh.Copy();
|
||||
|
||||
string pathToCurrentFolder = "Assets/FaceTracking.Generated";
|
||||
if (!AssetDatabase.IsValidFolder(pathToCurrentFolder)) AssetDatabase.CreateFolder("Assets", "FaceTracking.Generated");
|
||||
|
||||
var meshPath = pathToCurrentFolder + "/" + Avatar.transform.name + ".mesh";
|
||||
|
||||
AssetDatabase.CreateAsset(m, meshPath);
|
||||
|
||||
var worldPosition = Vector3.zero;
|
||||
|
||||
var minX = 0f;
|
||||
var maxX = 0f;
|
||||
var minY = 0f;
|
||||
var maxY = 0f;
|
||||
var minZ = 0f;
|
||||
var maxZ = 0f;
|
||||
|
||||
var leftWeight = 0f;
|
||||
var rightWeight = 0f;
|
||||
var upWeight = 0f;
|
||||
var downWeight = 0f;
|
||||
|
||||
Transform faceMeshTransform = FaceTracking.FaceMesh.transform;
|
||||
Matrix4x4 localToWorld = faceMeshTransform.localToWorldMatrix;
|
||||
Matrix4x4 worldToLocal = faceMeshTransform.worldToLocalMatrix;
|
||||
|
||||
//Jaw Blendshapes
|
||||
if (_enableJawGeneration && _jawBlendShapeIndex != -1)
|
||||
{
|
||||
Vector3[] deltaVerticesLeft = new Vector3[m.vertexCount];
|
||||
Vector3[] deltaVerticesRight = new Vector3[m.vertexCount];
|
||||
Vector3[] deltaVerticesOpen = new Vector3[m.vertexCount];
|
||||
Vector3[] deltaVerticesForward = new Vector3[m.vertexCount];
|
||||
Vector3[] deltaNormals = new Vector3[m.vertexCount];
|
||||
Vector3[] deltaTangents = new Vector3[m.vertexCount];
|
||||
m.GetBlendShapeFrameVertices(_jawBlendShapeIndex, 0, deltaVerticesLeft, deltaNormals, deltaTangents);
|
||||
m.GetBlendShapeFrameVertices(_jawBlendShapeIndex, 0, deltaVerticesRight, deltaNormals, deltaTangents);
|
||||
m.GetBlendShapeFrameVertices(_jawBlendShapeIndex, 0, deltaVerticesOpen, deltaNormals, deltaTangents);
|
||||
m.GetBlendShapeFrameVertices(_jawBlendShapeIndex, 0, deltaVerticesForward, deltaNormals, deltaTangents);
|
||||
|
||||
for (int i = 0; i < m.vertexCount; i++)
|
||||
{
|
||||
if (deltaVerticesLeft[i] == Vector3.zero) continue;
|
||||
|
||||
worldPosition = GetPointRelativeToAvatarVoicePosition(localToWorld, m.vertices[i]);
|
||||
if (worldPosition.y > maxY) maxY = worldPosition.y;
|
||||
if (worldPosition.y < minY) minY = worldPosition.y;
|
||||
}
|
||||
|
||||
for (int i = 0; i < m.vertexCount; i++)
|
||||
{
|
||||
if (deltaVerticesLeft[i] == Vector3.zero) continue;
|
||||
|
||||
worldPosition = GetPointRelativeToAvatarVoicePosition(localToWorld, m.vertices[i]);
|
||||
upWeight = Mathf.Clamp01(Mathf.InverseLerp(minY / 4f, 0, worldPosition.y));
|
||||
downWeight = 1f - upWeight;
|
||||
|
||||
deltaVerticesForward[i] = (deltaVerticesForward[i] + localToWorld.MultiplyPoint3x4(Vector3.forward) * _jawMovementStrength * 0.00001f) * downWeight;
|
||||
deltaVerticesForward[i].Scale(faceMeshTransform.InverseTransformDirection(Vector3.forward));
|
||||
deltaVerticesLeft[i] = (deltaVerticesLeft[i] + localToWorld.MultiplyPoint3x4(Vector3.left) * _jawMovementStrength * 0.00001f) * downWeight;
|
||||
deltaVerticesLeft[i].Scale(faceMeshTransform.InverseTransformDirection(Vector3.right));
|
||||
deltaVerticesRight[i] = (deltaVerticesRight[i] + localToWorld.MultiplyPoint3x4(Vector3.right) * _jawMovementStrength * 0.00001f) * downWeight;
|
||||
deltaVerticesRight[i].Scale(faceMeshTransform.InverseTransformDirection(Vector3.right));
|
||||
}
|
||||
|
||||
m.AddBlendShapeFrame("Jaw_Right_generated", 100f, deltaVerticesRight, null, null);
|
||||
m.AddBlendShapeFrame("Jaw_Left_generated", 100f, deltaVerticesLeft, null, null);
|
||||
m.AddBlendShapeFrame("Jaw_Forward_generated", 100f, deltaVerticesForward, null, null);
|
||||
m.AddBlendShapeFrame("Jaw_Open_generated", 100f, deltaVerticesOpen, null, null);
|
||||
}
|
||||
|
||||
//Lip Blendshapes
|
||||
if (_enableLipGeneration && _lipBlendShapeIndex != -1)
|
||||
{
|
||||
Vector3[] deltaVerticesUpLeft = new Vector3[m.vertexCount];
|
||||
Vector3[] deltaVerticesUpRight = new Vector3[m.vertexCount];
|
||||
Vector3[] deltaVerticesDownLeft = new Vector3[m.vertexCount];
|
||||
Vector3[] deltaVerticesDownRight = new Vector3[m.vertexCount];
|
||||
Vector3[] deltaNormals = new Vector3[m.vertexCount];
|
||||
Vector3[] deltaTangents = new Vector3[m.vertexCount];
|
||||
m.GetBlendShapeFrameVertices(_lipBlendShapeIndex, 0, deltaVerticesUpLeft, deltaNormals, deltaTangents);
|
||||
m.GetBlendShapeFrameVertices(_lipBlendShapeIndex, 0, deltaVerticesUpRight, deltaNormals, deltaTangents);
|
||||
m.GetBlendShapeFrameVertices(_lipBlendShapeIndex, 0, deltaVerticesDownLeft, deltaNormals, deltaTangents);
|
||||
m.GetBlendShapeFrameVertices(_lipBlendShapeIndex, 0, deltaVerticesDownRight, deltaNormals, deltaTangents);
|
||||
|
||||
for (int i = 0; i < m.vertexCount; i++)
|
||||
{
|
||||
if (deltaVerticesUpLeft[i] == Vector3.zero) continue;
|
||||
|
||||
worldPosition = GetPointRelativeToAvatarVoicePosition(localToWorld, m.vertices[i]);
|
||||
if (worldPosition.x > maxX) maxX = worldPosition.x;
|
||||
if (worldPosition.x < minX) minX = worldPosition.x;
|
||||
if (worldPosition.y > maxY) maxY = worldPosition.y;
|
||||
if (worldPosition.y < minY) minY = worldPosition.y;
|
||||
}
|
||||
|
||||
for (int i = 0; i < m.vertexCount; i++)
|
||||
{
|
||||
if (deltaVerticesUpLeft[i] == Vector3.zero) continue;
|
||||
|
||||
worldPosition = GetPointRelativeToAvatarVoicePosition(localToWorld, m.vertices[i]);
|
||||
upWeight = Mathf.Clamp01(Mathf.InverseLerp(0, 0.0001f, worldPosition.y));
|
||||
downWeight = 1f - upWeight;
|
||||
rightWeight = Mathf.Clamp01(Mathf.InverseLerp(minX / 4f, maxX / 4f, worldPosition.x));
|
||||
leftWeight = 1f - rightWeight;
|
||||
|
||||
deltaVerticesUpLeft[i] = (localToWorld.MultiplyPoint3x4(Vector3.left) * _lipMovementStrength * 0.00001f) * upWeight;
|
||||
deltaVerticesUpRight[i] = (localToWorld.MultiplyPoint3x4(Vector3.right) * _lipMovementStrength * 0.00001f) * upWeight;
|
||||
deltaVerticesDownLeft[i] = (localToWorld.MultiplyPoint3x4(Vector3.left) * _lipMovementStrength * 0.00001f) * downWeight;
|
||||
deltaVerticesDownRight[i] = (localToWorld.MultiplyPoint3x4(Vector3.right) * _lipMovementStrength * 0.00001f) * downWeight;
|
||||
}
|
||||
|
||||
m.AddBlendShapeFrame("Mouth_Upper_Right_generated", 100f, deltaVerticesUpRight, null, null);
|
||||
m.AddBlendShapeFrame("Mouth_Upper_Left_generated", 100f, deltaVerticesUpLeft, null, null);
|
||||
m.AddBlendShapeFrame("Mouth_Lower_Right_generated", 100f, deltaVerticesDownRight, null, null);
|
||||
m.AddBlendShapeFrame("Mouth_Lower_Left_generated", 100f, deltaVerticesDownLeft, null, null);
|
||||
}
|
||||
|
||||
//Smile Blendshapes
|
||||
if (_enableSmileGeneration && _smileBlendShapeIndex != -1)
|
||||
{
|
||||
Vector3[] deltaVerticesLeft = new Vector3[m.vertexCount];
|
||||
Vector3[] deltaVerticesRight = new Vector3[m.vertexCount];
|
||||
Vector3[] deltaNormals = new Vector3[m.vertexCount];
|
||||
Vector3[] deltaTangents = new Vector3[m.vertexCount];
|
||||
m.GetBlendShapeFrameVertices(_smileBlendShapeIndex, 0, deltaVerticesLeft, deltaNormals, deltaTangents);
|
||||
m.GetBlendShapeFrameVertices(_smileBlendShapeIndex, 0, deltaVerticesRight, deltaNormals, deltaTangents);
|
||||
|
||||
for (int i = 0; i < m.vertexCount; i++)
|
||||
{
|
||||
if (deltaVerticesLeft[i] == Vector3.zero) continue;
|
||||
|
||||
worldPosition = GetPointRelativeToAvatarVoicePosition(localToWorld, m.vertices[i]);
|
||||
if (worldPosition.x > maxX) maxX = worldPosition.x;
|
||||
if (worldPosition.x < minX) minX = worldPosition.x;
|
||||
}
|
||||
|
||||
for (int i = 0; i < m.vertexCount; i++)
|
||||
{
|
||||
worldPosition = GetPointRelativeToAvatarVoicePosition(localToWorld, m.vertices[i]);
|
||||
rightWeight = Mathf.Clamp01(Mathf.InverseLerp(minX / 4f, maxX / 4f, worldPosition.x));
|
||||
leftWeight = 1f - rightWeight;
|
||||
|
||||
deltaVerticesLeft[i] = deltaVerticesLeft[i] * leftWeight;
|
||||
deltaVerticesRight[i] = deltaVerticesRight[i] * rightWeight;
|
||||
}
|
||||
|
||||
m.AddBlendShapeFrame("Mouth_Smile_Left_generated", 100f, deltaVerticesLeft, null, null);
|
||||
m.AddBlendShapeFrame("Mouth_Smile_Right_generated", 100f, deltaVerticesRight, null, null);
|
||||
}
|
||||
|
||||
//Frown Blendshapes
|
||||
if (_enableFrownGeneration && _frownBlendShapeIndex != -1)
|
||||
{
|
||||
Vector3[] deltaVerticesLeft = new Vector3[m.vertexCount];
|
||||
Vector3[] deltaVerticesRight = new Vector3[m.vertexCount];
|
||||
Vector3[] deltaNormals = new Vector3[m.vertexCount];
|
||||
Vector3[] deltaTangents = new Vector3[m.vertexCount];
|
||||
m.GetBlendShapeFrameVertices(_frownBlendShapeIndex, 0, deltaVerticesLeft, deltaNormals, deltaTangents);
|
||||
m.GetBlendShapeFrameVertices(_frownBlendShapeIndex, 0, deltaVerticesRight, deltaNormals, deltaTangents);
|
||||
|
||||
for (int i = 0; i < m.vertexCount; i++)
|
||||
{
|
||||
if (deltaVerticesLeft[i] == Vector3.zero) continue;
|
||||
|
||||
worldPosition = GetPointRelativeToAvatarVoicePosition(localToWorld, m.vertices[i]);
|
||||
if (worldPosition.x > maxX) maxX = worldPosition.x;
|
||||
if (worldPosition.x < minX) minX = worldPosition.x;
|
||||
}
|
||||
|
||||
for (int i = 0; i < m.vertexCount; i++)
|
||||
{
|
||||
worldPosition = GetPointRelativeToAvatarVoicePosition(localToWorld, m.vertices[i]);
|
||||
rightWeight = Mathf.Clamp01(Mathf.InverseLerp(minX / 4f, maxX / 4f, worldPosition.x));
|
||||
leftWeight = 1f - rightWeight;
|
||||
|
||||
deltaVerticesLeft[i] = deltaVerticesLeft[i] * leftWeight;
|
||||
deltaVerticesRight[i] = deltaVerticesRight[i] * rightWeight;
|
||||
}
|
||||
|
||||
m.AddBlendShapeFrame("Mouth_Sad_Left_generated", 100f, deltaVerticesLeft, null, null);
|
||||
m.AddBlendShapeFrame("Mouth_Sad_Right_generated", 100f, deltaVerticesRight, null, null);
|
||||
}
|
||||
|
||||
//Puff Blendshapes
|
||||
if (_enablePuffGeneration && _puffBlendShapeIndex != -1)
|
||||
{
|
||||
Vector3[] deltaVerticesLeft = new Vector3[m.vertexCount];
|
||||
Vector3[] deltaVerticesRight = new Vector3[m.vertexCount];
|
||||
Vector3[] deltaNormals = new Vector3[m.vertexCount];
|
||||
Vector3[] deltaTangents = new Vector3[m.vertexCount];
|
||||
m.GetBlendShapeFrameVertices(_puffBlendShapeIndex, 0, deltaVerticesLeft, deltaNormals, deltaTangents);
|
||||
m.GetBlendShapeFrameVertices(_puffBlendShapeIndex, 0, deltaVerticesRight, deltaNormals, deltaTangents);
|
||||
|
||||
for (int i = 0; i < m.vertexCount; i++)
|
||||
{
|
||||
if (deltaVerticesLeft[i] == Vector3.zero) continue;
|
||||
|
||||
worldPosition = GetPointRelativeToAvatarVoicePosition(localToWorld, m.vertices[i]);
|
||||
if (worldPosition.x > maxX) maxX = worldPosition.x;
|
||||
if (worldPosition.x < minX) minX = worldPosition.x;
|
||||
}
|
||||
|
||||
for (int i = 0; i < m.vertexCount; i++)
|
||||
{
|
||||
worldPosition = GetPointRelativeToAvatarVoicePosition(localToWorld, m.vertices[i]);
|
||||
rightWeight = Mathf.Clamp01(Mathf.InverseLerp(minX / 4f, maxX / 4f, worldPosition.x));
|
||||
leftWeight = 1f - rightWeight;
|
||||
|
||||
deltaVerticesLeft[i] = deltaVerticesLeft[i] * leftWeight;
|
||||
deltaVerticesRight[i] = deltaVerticesRight[i] * rightWeight;
|
||||
}
|
||||
|
||||
m.AddBlendShapeFrame("Cheek_Puff_Left_generated", 100f, deltaVerticesLeft, null, null);
|
||||
m.AddBlendShapeFrame("Cheek_Puff_Right_generated", 100f, deltaVerticesRight, null, null);
|
||||
}
|
||||
|
||||
m.RecalculateNormals();
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
FaceTracking.FaceMesh.sharedMesh = m;
|
||||
FaceTracking.GetBlendShapeNames();
|
||||
FaceTracking.FindVisemes();
|
||||
}
|
||||
|
||||
private Vector3 GetPointRelativeToAvatarVoicePosition(Matrix4x4 matrix, Vector3 VertexPosition)
|
||||
{
|
||||
VertexPosition.Scale(Avatar.transform.localScale);
|
||||
return matrix.MultiplyPoint3x4(VertexPosition) - Avatar.transform.TransformPoint(Avatar.voicePosition);
|
||||
}
|
||||
}
|
||||
|
||||
public static class MeshExtensions
|
||||
{
|
||||
public static Mesh Copy(this Mesh MeshHolder)
|
||||
{
|
||||
var newMesh = new Mesh();
|
||||
|
||||
newMesh = new Mesh();
|
||||
newMesh.vertices = MeshHolder.vertices;
|
||||
newMesh.normals = MeshHolder.normals;
|
||||
newMesh.uv = MeshHolder.uv;
|
||||
newMesh.uv2 = MeshHolder.uv2;
|
||||
newMesh.uv3 = MeshHolder.uv3;
|
||||
newMesh.uv4 = MeshHolder.uv4;
|
||||
newMesh.uv5 = MeshHolder.uv5;
|
||||
newMesh.uv6 = MeshHolder.uv6;
|
||||
newMesh.uv7 = MeshHolder.uv7;
|
||||
newMesh.uv8 = MeshHolder.uv8;
|
||||
newMesh.colors = MeshHolder.colors;
|
||||
newMesh.tangents = MeshHolder.tangents;
|
||||
newMesh.triangles = MeshHolder.triangles;
|
||||
newMesh.bindposes = MeshHolder.bindposes;
|
||||
newMesh.boneWeights = MeshHolder.boneWeights;
|
||||
newMesh.bounds = MeshHolder.bounds;
|
||||
for (int shape = 0; shape < MeshHolder.blendShapeCount; shape++)
|
||||
{
|
||||
int frameCount = MeshHolder.GetBlendShapeFrameCount(shape);
|
||||
for (int frame = 0; frame < frameCount; frame++)
|
||||
{
|
||||
string shapeName = MeshHolder.GetBlendShapeName(shape);
|
||||
float frameWeight = MeshHolder.GetBlendShapeFrameWeight(shape, frame);
|
||||
|
||||
Vector3[] dVertices = new Vector3[MeshHolder.vertexCount];
|
||||
Vector3[] dNormals = new Vector3[MeshHolder.vertexCount];
|
||||
Vector3[] dTangents = new Vector3[MeshHolder.vertexCount];
|
||||
MeshHolder.GetBlendShapeFrameVertices(shape, frame, dVertices, dNormals, dTangents);
|
||||
newMesh.AddBlendShapeFrame(shapeName, frameWeight, dVertices, dNormals, dTangents);
|
||||
}
|
||||
}
|
||||
|
||||
newMesh.subMeshCount = MeshHolder.subMeshCount;
|
||||
|
||||
for (int submesh = 0; submesh < MeshHolder.subMeshCount; submesh++)
|
||||
{
|
||||
newMesh.SetSubMesh(submesh, MeshHolder.GetSubMesh(submesh));
|
||||
}
|
||||
|
||||
return newMesh;
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/ABI.CCK/Scripts/Editor/CCK_FaceTrackingUtilities.cs.meta
Executable file
3
Assets/ABI.CCK/Scripts/Editor/CCK_FaceTrackingUtilities.cs.meta
Executable file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3ad0f636a0bf4c44b038bb0a5c5e69a0
|
||||
timeCreated: 1622593306
|
94
Assets/ABI.CCK/Scripts/Editor/CCK_Init.cs
Executable file
94
Assets/ABI.CCK/Scripts/Editor/CCK_Init.cs
Executable file
|
@ -0,0 +1,94 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
#pragma warning disable
|
||||
|
||||
[InitializeOnLoad]
|
||||
public class CCK_Init
|
||||
{
|
||||
static CCK_Init()
|
||||
{
|
||||
|
||||
void SetTag(SerializedProperty tags, string name, int index)
|
||||
{
|
||||
SerializedProperty sp = tags.GetArrayElementAtIndex(index);
|
||||
if (sp != null) sp.stringValue = name;
|
||||
}
|
||||
|
||||
void SetLayer(SerializedProperty layers, string name, int index)
|
||||
{
|
||||
SerializedProperty sp = layers.GetArrayElementAtIndex(index);
|
||||
if (sp != null) sp.stringValue = name;
|
||||
}
|
||||
|
||||
string cckSymbol = "CVR_CCK_EXISTS";
|
||||
string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
|
||||
if (!defines.Contains(cckSymbol))
|
||||
{
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, (defines + ";" + cckSymbol));
|
||||
Debug.Log("[CCK:Init] Added CVR_CCK_EXISTS Scripting Symbol.");
|
||||
}
|
||||
|
||||
if (LayerMask.LayerToName(10) != "PlayerNetwork" || LayerMask.LayerToName(15) != "CVRReserved4" || LayerMask.LayerToName(17) != "CVRPickup")
|
||||
{
|
||||
Debug.Log("[CCK:Init] TagManager asset has to be recreated. Now recreating.");
|
||||
|
||||
SerializedObject tagManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]);
|
||||
|
||||
SerializedProperty tagProperty = tagManager.FindProperty("tags");
|
||||
|
||||
var tagList = new (int, string)[]
|
||||
{
|
||||
(0, "CCKEditorUI_Uploader"),
|
||||
(1, "CCKSerializable"),
|
||||
(2, "CCKLambda"),
|
||||
(3, "CCKNetwork_System"),
|
||||
(4, "CCKNetwork_Routine"),
|
||||
(5, "ThisIsGarbage")
|
||||
};
|
||||
|
||||
foreach (var tag in tagList) SetTag(tagProperty, tag.Item2, tag.Item1);
|
||||
|
||||
SerializedProperty layerProperty = tagManager.FindProperty("layers");
|
||||
|
||||
var layerList = new (int, string)[]
|
||||
{
|
||||
(8, "PlayerLocal"),
|
||||
(9, "PlayerClone"),
|
||||
(10, "PlayerNetwork"),
|
||||
(11, "MirrorReflection"),
|
||||
(12, "CVRReserved1"),
|
||||
(13, "CVRReserved2"),
|
||||
(14, "CVRReserved3"),
|
||||
(15, "CVRReserved4"),
|
||||
(16, "PostProcessing"),
|
||||
(17, "CVRPickup"),
|
||||
(18, "CVRInteractable")
|
||||
};
|
||||
|
||||
foreach (var layer in layerList) SetLayer(layerProperty, layer.Item2, layer.Item1);
|
||||
|
||||
tagManager.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
if (!PlayerSettings.virtualRealitySupported)
|
||||
{
|
||||
Debug.Log("[CCK:Init] XR and render settings have to be changed. Now changing.");
|
||||
EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows64);
|
||||
PlayerSettings.colorSpace = UnityEngine.ColorSpace.Linear;
|
||||
|
||||
PlayerSettings.apiCompatibilityLevel = ApiCompatibilityLevel.NET_4_6;
|
||||
|
||||
PlayerSettings.virtualRealitySupported = true;
|
||||
PlayerSettings.SetVirtualRealitySDKs(BuildTargetGroup.Standalone, new string[] { "None", "Oculus", "OpenVR", "MockHMD" });
|
||||
PlayerSettings.stereoRenderingPath = StereoRenderingPath.SinglePass;
|
||||
}
|
||||
|
||||
if (LayerMask.LayerToName(10) == "PlayerNetwork" && LayerMask.LayerToName(17) == "CVRPickup" && LayerMask.LayerToName(15) == "CVRReserved4" && PlayerSettings.virtualRealitySupported )
|
||||
{
|
||||
Debug.Log("[CCK:Init] Verified TagManager and ProjectSettings. No need to readjust.");
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/ABI.CCK/Scripts/Editor/CCK_Init.cs.meta
Executable file
11
Assets/ABI.CCK/Scripts/Editor/CCK_Init.cs.meta
Executable file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 81db3bbe621f01443ab7a3b446f9d851
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
18
Assets/ABI.CCK/Scripts/Editor/CCK_ObjectSyncEditor.cs
Executable file
18
Assets/ABI.CCK/Scripts/Editor/CCK_ObjectSyncEditor.cs
Executable file
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
|
||||
[CustomEditor(typeof(ABI.CCK.Components.CVRObjectSync))]
|
||||
public class CCK_ObjectSyncEditor : UnityEditor.Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
EditorGUILayout.HelpBox("This component will have this objects position and rotation synced over network.", MessageType.Info);
|
||||
|
||||
//EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
}
|
11
Assets/ABI.CCK/Scripts/Editor/CCK_ObjectSyncEditor.cs.meta
Executable file
11
Assets/ABI.CCK/Scripts/Editor/CCK_ObjectSyncEditor.cs.meta
Executable file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bf75b10b883c030499eef7b95f7f8674
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
93
Assets/ABI.CCK/Scripts/Editor/CCK_Tools.cs
Executable file
93
Assets/ABI.CCK/Scripts/Editor/CCK_Tools.cs
Executable file
|
@ -0,0 +1,93 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Xml.Linq;
|
||||
using System.Xml.XPath;
|
||||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Animations;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
public class CCK_Tools
|
||||
{
|
||||
|
||||
public enum SearchType
|
||||
{
|
||||
Scene = 1,
|
||||
Selection = 2
|
||||
}
|
||||
|
||||
public static int CleanMissingScripts (SearchType searchType, bool remove, GameObject givenObject)
|
||||
{
|
||||
List<GameObject> allFoundObjects = new List<GameObject>();
|
||||
GameObject[] rootObjects;
|
||||
|
||||
if (searchType == SearchType.Scene)
|
||||
{
|
||||
rootObjects = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects();
|
||||
}
|
||||
else
|
||||
{
|
||||
rootObjects = new GameObject[1];
|
||||
rootObjects[0] = givenObject;
|
||||
}
|
||||
|
||||
foreach (var item in rootObjects)
|
||||
{
|
||||
allFoundObjects.AddRange(item.GetComponentsInChildren<Transform>(true).Select(go => go.gameObject).ToArray());
|
||||
}
|
||||
|
||||
int scriptCount = 0;
|
||||
int goCount = 0;
|
||||
foreach (var go in allFoundObjects)
|
||||
{
|
||||
int count = GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(go);
|
||||
if (count > 0)
|
||||
{
|
||||
if (remove)
|
||||
{
|
||||
Undo.RegisterCompleteObjectUndo(go, "Remove missing scripts");
|
||||
GameObjectUtility.RemoveMonoBehavioursWithMissingScript(go);
|
||||
}
|
||||
scriptCount += count;
|
||||
goCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (remove)
|
||||
{
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene());
|
||||
}
|
||||
|
||||
if (remove) Debug.Log($"[CCK:Tools] Found and removed {scriptCount} missing scripts from {goCount} GameObjects");
|
||||
|
||||
return scriptCount;
|
||||
}
|
||||
|
||||
[MenuItem("Assets/Create/CVR Override Controller")]
|
||||
private static void CreateCVROverrideController()
|
||||
{
|
||||
var path = AssetDatabase.GetAssetPath(Selection.activeObject) + "/New Override Controller.overrideController";
|
||||
string[] guids = AssetDatabase.FindAssets("AvatarAnimator t:animatorController", null);
|
||||
|
||||
if (guids.Length < 1)
|
||||
{
|
||||
Debug.LogError("No Animator controller with the name \"AvatarAnimator\" was found. Please make sure that you CCK is installed properly.");
|
||||
return;
|
||||
}
|
||||
var overrideController = new AnimatorOverrideController();
|
||||
overrideController.runtimeAnimatorController = AssetDatabase.LoadAssetAtPath<AnimatorController>(AssetDatabase.GUIDToAssetPath(guids[0]));
|
||||
|
||||
AssetDatabase.CreateAsset (overrideController, path);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
Assets/ABI.CCK/Scripts/Editor/CCK_Tools.cs.meta
Executable file
11
Assets/ABI.CCK/Scripts/Editor/CCK_Tools.cs.meta
Executable file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 129e14ac20be5574bbd61c36906281a8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
103
Assets/ABI.CCK/Scripts/Editor/CVRDistanceLodEditor.cs
Executable file
103
Assets/ABI.CCK/Scripts/Editor/CVRDistanceLodEditor.cs
Executable file
|
@ -0,0 +1,103 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(ABI.CCK.Components.CVRDistanceLod), true)]
|
||||
public class CVRDistanceLodEditor : UnityEditor.Editor
|
||||
{
|
||||
private CVRDistanceLod _lod;
|
||||
|
||||
private ReorderableList reorderableList;
|
||||
|
||||
private CVRDistanceLodGroup entity;
|
||||
|
||||
private void InitializeList()
|
||||
{
|
||||
reorderableList = new ReorderableList(_lod.Groups, typeof(CVRDistanceLodGroup),
|
||||
false, true, true, true);
|
||||
reorderableList.drawHeaderCallback = OnDrawHeader;
|
||||
reorderableList.drawElementCallback = OnDrawElement;
|
||||
reorderableList.elementHeightCallback = OnHeightElement;
|
||||
reorderableList.onAddCallback = OnAdd;
|
||||
reorderableList.onChangedCallback = OnChanged;
|
||||
}
|
||||
|
||||
private void OnChanged(ReorderableList list)
|
||||
{
|
||||
//EditorUtility.SetDirty(target);
|
||||
}
|
||||
|
||||
private void OnAdd(ReorderableList list)
|
||||
{
|
||||
_lod.Groups.Add(new CVRDistanceLodGroup());
|
||||
Repaint();
|
||||
}
|
||||
|
||||
private float OnHeightElement(int index)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight * 3 * 1.25f;
|
||||
}
|
||||
|
||||
private void OnDrawElement(Rect rect, int index, bool isactive, bool isfocused)
|
||||
{
|
||||
if (index > _lod.Groups.Count) return;
|
||||
entity = _lod.Groups[index];
|
||||
|
||||
rect.y += 2;
|
||||
rect.x += 12;
|
||||
rect.width -= 12;
|
||||
Rect _rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Game Object");
|
||||
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
|
||||
entity.GameObject = (GameObject) EditorGUI.ObjectField(_rect, entity.GameObject, typeof(GameObject), true);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Min Distance");
|
||||
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
|
||||
entity.MinDistance = EditorGUI.FloatField(_rect, entity.MinDistance);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Max Distance");
|
||||
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
|
||||
entity.MaxDistance = EditorGUI.FloatField(_rect, entity.MaxDistance);
|
||||
}
|
||||
|
||||
private void OnDrawHeader(Rect rect)
|
||||
{
|
||||
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
GUI.Label(_rect, "Groups");
|
||||
}
|
||||
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (_lod == null) _lod = (CVRDistanceLod) target;
|
||||
|
||||
_lod.distance3D = EditorGUILayout.Toggle("3D Distance", _lod.distance3D);
|
||||
|
||||
if (reorderableList == null) InitializeList();
|
||||
reorderableList.DoLayoutList();
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/ABI.CCK/Scripts/Editor/CVRDistanceLodEditor.cs.meta
Executable file
3
Assets/ABI.CCK/Scripts/Editor/CVRDistanceLodEditor.cs.meta
Executable file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e8ae37e2eb38411daaa5786e09de0128
|
||||
timeCreated: 1621047850
|
98
Assets/ABI.CCK/Scripts/Editor/CVRHapticAreaChestEditor.cs
Executable file
98
Assets/ABI.CCK/Scripts/Editor/CVRHapticAreaChestEditor.cs
Executable file
|
@ -0,0 +1,98 @@
|
|||
using System;
|
||||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
#pragma warning disable
|
||||
|
||||
[CustomEditor(typeof(CVRHapticAreaChest))]
|
||||
public class CVRHapticAreaChestEditor : UnityEditor.Editor
|
||||
{
|
||||
private CVRHapticAreaChest _hapticsChest;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_hapticsChest = (CVRHapticAreaChest) target;
|
||||
}
|
||||
|
||||
private void OnSceneGUI()
|
||||
{
|
||||
if (_hapticsChest.gameObject.activeInHierarchy)
|
||||
{
|
||||
Event e = Event.current;
|
||||
int controlId = GUIUtility.GetControlID(GetHashCode(), FocusType.Passive);
|
||||
|
||||
var wasMouseDown = false;
|
||||
var preventControls = false;
|
||||
|
||||
if (Event.current.type == EventType.MouseUp && Event.current.button == 0)
|
||||
{
|
||||
preventControls = true;
|
||||
}
|
||||
|
||||
if(Event.current.type == EventType.MouseDown && Event.current.button == 0) {
|
||||
preventControls = true;
|
||||
}
|
||||
|
||||
if (Event.current.button == 0)
|
||||
{
|
||||
preventControls = true;
|
||||
}
|
||||
|
||||
var hapticsTransform = _hapticsChest.transform;
|
||||
var scale = hapticsTransform.localScale;
|
||||
var inverseScale = new Vector3(1 / scale.x, 1 / scale.y, 1 / scale.z);
|
||||
|
||||
var i = 0;
|
||||
var selected = false;
|
||||
foreach (var point in _hapticsChest.HapticPoints40)
|
||||
{
|
||||
var localPoint = point;
|
||||
localPoint.Scale(_hapticsChest.chestAreaSize * 0.5f);
|
||||
|
||||
if (i == _hapticsChest.selectedPoint)
|
||||
{
|
||||
Handles.color = Color.cyan;
|
||||
|
||||
Vector3 pos = hapticsTransform.TransformPoint(Vector3.Scale(_hapticsChest.HapticPoints40[i], inverseScale));
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
Vector3 pointPosition = Handles.PositionHandle(pos, _hapticsChest.transform.rotation);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(_hapticsChest, "CVR Haptic Chest Point Change");
|
||||
var newLocalPoint = _hapticsChest.transform.InverseTransformPoint(pointPosition);
|
||||
newLocalPoint.Scale(_hapticsChest.transform.lossyScale);
|
||||
Debug.Log(newLocalPoint);
|
||||
//_hapticsChest.HapticPoints40[i].z = newLocalPoint.z;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Handles.color = Color.yellow;
|
||||
}
|
||||
|
||||
/*if (Handles.Button(_hapticsChest.transform.TransformPoint(localPoint), _hapticsChest.transform.rotation, 0.01f, 0.01f,
|
||||
Handles.CubeHandleCap))
|
||||
{
|
||||
if (_hapticsChest.selectedPoint == i)
|
||||
{
|
||||
_hapticsChest.selectedPoint = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_hapticsChest.selectedPoint = i;
|
||||
}
|
||||
selected = true;
|
||||
}*/
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if (e.type == EventType.Layout && preventControls && selected)
|
||||
{
|
||||
HandleUtility.AddDefaultControl(controlId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/ABI.CCK/Scripts/Editor/CVRHapticAreaChestEditor.cs.meta
Executable file
11
Assets/ABI.CCK/Scripts/Editor/CVRHapticAreaChestEditor.cs.meta
Executable file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 001de8f7e84b47b985bc4a7b01553f74
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
191
Assets/ABI.CCK/Scripts/Editor/CVRMaterialDriverEditor.cs
Executable file
191
Assets/ABI.CCK/Scripts/Editor/CVRMaterialDriverEditor.cs
Executable file
|
@ -0,0 +1,191 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using ABI.CCK.Components;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
[CustomEditor(typeof(ABI.CCK.Components.CVRMaterialDriver))]
|
||||
public class CVRMaterialDriverEditor : UnityEditor.Editor
|
||||
{
|
||||
private CVRMaterialDriver _driver;
|
||||
|
||||
private ReorderableList reorderableList;
|
||||
|
||||
private CVRMaterialDriverTask entity;
|
||||
|
||||
private void InitializeList()
|
||||
{
|
||||
reorderableList = new ReorderableList(_driver.tasks, typeof(CVRMaterialDriverTask),
|
||||
true, true, true, true);
|
||||
reorderableList.drawHeaderCallback = OnDrawHeader;
|
||||
reorderableList.drawElementCallback = OnDrawElement;
|
||||
reorderableList.elementHeightCallback = OnHeightElement;
|
||||
reorderableList.onAddCallback = OnAdd;
|
||||
reorderableList.onChangedCallback = OnChanged;
|
||||
}
|
||||
|
||||
private void OnChanged(ReorderableList list)
|
||||
{
|
||||
//EditorUtility.SetDirty(target);
|
||||
}
|
||||
|
||||
private void OnAdd(ReorderableList list)
|
||||
{
|
||||
if (_driver.tasks.Count >= 16) return;
|
||||
_driver.tasks.Add(new CVRMaterialDriverTask());
|
||||
Repaint();
|
||||
}
|
||||
|
||||
private float OnHeightElement(int index)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight * 3 * 1.25f;
|
||||
}
|
||||
|
||||
private void OnDrawElement(Rect rect, int index, bool isactive, bool isfocused)
|
||||
{
|
||||
if (index > _driver.tasks.Count) return;
|
||||
entity = _driver.tasks[index];
|
||||
|
||||
rect.y += 2;
|
||||
rect.x += 12;
|
||||
rect.width -= 12;
|
||||
Rect _rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Renderer");
|
||||
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
|
||||
entity.Renderer = (Renderer) EditorGUI.ObjectField(_rect, entity.Renderer, typeof(Renderer), true);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
var materialList = new Dictionary<int, string>();
|
||||
if (entity.Renderer != null)
|
||||
{
|
||||
for (var i = 0; i < entity.Renderer.sharedMaterials.Length; i++)
|
||||
{
|
||||
if (entity.Renderer.sharedMaterials[i] != null)
|
||||
{
|
||||
materialList.Add(i, entity.Renderer.sharedMaterials[i].name + "[" + i + "]");
|
||||
}
|
||||
else
|
||||
{
|
||||
materialList.Add(i, "None[" + i + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var materialNames = new string[materialList.Count];
|
||||
materialList.Values.CopyTo(materialNames, 0);
|
||||
var materialIndeces = new int[materialList.Count];
|
||||
materialList.Keys.CopyTo(materialIndeces, 0);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Material");
|
||||
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
|
||||
entity.Index = EditorGUI.Popup(_rect, entity.Index, materialNames);
|
||||
|
||||
rect.y += EditorGUIUtility.singleLineHeight * 1.25f;
|
||||
_rect = new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
var propertyList = new Dictionary<string, string>();
|
||||
var rendererFound = false;
|
||||
|
||||
if (entity.Renderer != null)
|
||||
{
|
||||
int i = entity.Index;
|
||||
var material = entity.Renderer.sharedMaterials[i];
|
||||
if (material != null)
|
||||
{
|
||||
var shader = material.shader;
|
||||
for (var j = 0; j < shader.GetPropertyCount(); j++)
|
||||
{
|
||||
if ((shader.GetPropertyType(j) == ShaderPropertyType.Float ||
|
||||
shader.GetPropertyType(j) == ShaderPropertyType.Range ||
|
||||
shader.GetPropertyType(j) == ShaderPropertyType.Vector ||
|
||||
shader.GetPropertyType(j) == ShaderPropertyType.Color))
|
||||
{
|
||||
var propertyKey = material.name + "[" + i + "]: " + shader.GetPropertyDescription(j) + "(" +
|
||||
shader.GetPropertyName(j) + ")";
|
||||
if (!propertyList.ContainsKey(propertyKey))
|
||||
{
|
||||
propertyList.Add(
|
||||
propertyKey,
|
||||
"REN[" + i + "]:" + shader.GetPropertyName(j)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rendererFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
var propertyNames = new string[propertyList.Count];
|
||||
propertyList.Values.CopyTo(propertyNames, 0);
|
||||
var propertyDescriptions = new string[propertyList.Count];
|
||||
propertyList.Keys.CopyTo(propertyDescriptions, 0);
|
||||
|
||||
EditorGUI.LabelField(_rect, "Property");
|
||||
_rect.x += 100;
|
||||
_rect.width = rect.width - 100;
|
||||
var propertyIndex = EditorGUI.Popup(_rect, Array.IndexOf(propertyNames, entity.RendererType + "["+ entity.Index +"]:" + entity.PropertyName), propertyDescriptions);
|
||||
|
||||
if (propertyIndex >= 0)
|
||||
{
|
||||
Regex rx = new Regex(@"^([A-Z]{3})\[(\d+)\]\:(.+)$");
|
||||
var match = rx.Match(propertyNames[propertyIndex]);
|
||||
|
||||
entity.RendererType = match.Groups[1].Value;
|
||||
entity.Index = Convert.ToInt32(match.Groups[2].Value);
|
||||
entity.PropertyName = match.Groups[3].Value;
|
||||
|
||||
var shader = entity.Renderer.sharedMaterials[entity.Index].shader;
|
||||
|
||||
switch (shader.GetPropertyType(shader.FindPropertyIndex(entity.PropertyName)))
|
||||
{
|
||||
case ShaderPropertyType.Float:
|
||||
case ShaderPropertyType.Range:
|
||||
entity.PropertyType = CVRMaterialDriverTask.Type.Float;
|
||||
break;
|
||||
case ShaderPropertyType.Vector:
|
||||
entity.PropertyType = CVRMaterialDriverTask.Type.Vector4;
|
||||
break;
|
||||
case ShaderPropertyType.Color:
|
||||
entity.PropertyType = CVRMaterialDriverTask.Type.Color;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDrawHeader(Rect rect)
|
||||
{
|
||||
Rect _rect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
|
||||
GUI.Label(_rect, "Materials");
|
||||
}
|
||||
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (_driver == null) _driver = (CVRMaterialDriver) target;
|
||||
|
||||
base.OnInspectorGUI();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
if (reorderableList == null) InitializeList();
|
||||
reorderableList.DoLayoutList();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
3
Assets/ABI.CCK/Scripts/Editor/CVRMaterialDriverEditor.cs.meta
Executable file
3
Assets/ABI.CCK/Scripts/Editor/CVRMaterialDriverEditor.cs.meta
Executable file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4c4250ecf70741a4af371d128b50158f
|
||||
timeCreated: 1620873035
|
28
Assets/ABI.CCK/Scripts/Editor/ReadOnlyDrawer.cs
Executable file
28
Assets/ABI.CCK/Scripts/Editor/ReadOnlyDrawer.cs
Executable file
|
@ -0,0 +1,28 @@
|
|||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This class contain custom drawer for ReadOnly attribute.
|
||||
/// </summary>
|
||||
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
|
||||
public class ReadOnlyDrawer : PropertyDrawer
|
||||
{
|
||||
/// <summary>
|
||||
/// Unity method for drawing GUI in Editor
|
||||
/// </summary>
|
||||
/// <param name="position">Position.</param>
|
||||
/// <param name="property">Property.</param>
|
||||
/// <param name="label">Label.</param>
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
// Saving previous GUI enabled value
|
||||
var previousGUIState = GUI.enabled;
|
||||
// Disabling edit for property
|
||||
GUI.enabled = false;
|
||||
// Drawing Property
|
||||
EditorGUI.PropertyField(position, property, label);
|
||||
// Setting old GUI enabled value
|
||||
GUI.enabled = previousGUIState;
|
||||
}
|
||||
}
|
3
Assets/ABI.CCK/Scripts/Editor/ReadOnlyDrawer.cs.meta
Executable file
3
Assets/ABI.CCK/Scripts/Editor/ReadOnlyDrawer.cs.meta
Executable file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9e9b55e4a49846738a40daa8b2fff3ca
|
||||
timeCreated: 1646994870
|
Loading…
Add table
Add a link
Reference in a new issue