update CCK to 3.10, fixing unity 2021 crash :)
This commit is contained in:
parent
48a978fa2a
commit
d11e0fb3a9
492 changed files with 2165204 additions and 437687 deletions
|
@ -0,0 +1,59 @@
|
|||
using UnityEditor;
|
||||
|
||||
namespace ABI.CCK.Components
|
||||
{
|
||||
[CustomEditor(typeof(CVRLuaClientBehaviour))]
|
||||
public partial class CCK_CVRLuaClientBehaviourEditor : Editor
|
||||
{
|
||||
#region Editor GUI Fields
|
||||
|
||||
private static bool _guiLuaAssetFoldout = true;
|
||||
private static bool _guiBoundObjectsFoldout = true;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Variables
|
||||
|
||||
private CVRBaseLuaBehaviour _baseLuaBehaviour;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Serialized Properties
|
||||
private SerializedProperty m_LocalOnly;
|
||||
private SerializedProperty m_LuaAsset;
|
||||
private SerializedProperty m_BoundObjects;
|
||||
|
||||
#endregion
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
if (target == null) return;
|
||||
_baseLuaBehaviour = (CVRLuaClientBehaviour)target;
|
||||
|
||||
m_LocalOnly = serializedObject.FindProperty(nameof(CVRLuaClientBehaviour.localOnly));
|
||||
m_LuaAsset = serializedObject.FindProperty(nameof(CVRLuaClientBehaviour.asset));
|
||||
m_BoundObjects = serializedObject.FindProperty(nameof(CVRLuaClientBehaviour.boundObjects));
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (_baseLuaBehaviour == null)
|
||||
return;
|
||||
|
||||
EditorGUILayout.HelpBox(
|
||||
"Lua is an open-source language that you can use to easily add new scripted behaviours to objects in props, avatars, and worlds.",
|
||||
MessageType.Info);
|
||||
|
||||
EditorGUILayout.HelpBox(
|
||||
"To test scripting in-game you need to use our Scripting Nightly branch. Instruction on how to opt in can be found in our discord server.",
|
||||
MessageType.Warning);
|
||||
|
||||
serializedObject.Update();
|
||||
|
||||
Draw_LuaAsset();
|
||||
Draw_BoundObjects();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5efc2461fe2c34a4995284eab5c86e21
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,94 @@
|
|||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using static ABI.CCK.Scripts.Editor.SharedComponentGUI;
|
||||
|
||||
namespace ABI.CCK.Components
|
||||
{
|
||||
public partial class CCK_CVRLuaClientBehaviourEditor
|
||||
{
|
||||
private ReorderableList _boundObjectList;
|
||||
|
||||
private void Draw_BoundObjects()
|
||||
{
|
||||
using (new FoldoutScope(ref _guiBoundObjectsFoldout, "Bound Objects", s_BoldFoldoutStyle))
|
||||
{
|
||||
if (!_guiBoundObjectsFoldout) return;
|
||||
DrawBoundObjects();
|
||||
}
|
||||
}
|
||||
|
||||
#region Drawing Methods
|
||||
|
||||
private void DrawBoundObjects()
|
||||
{
|
||||
_boundObjectList ??= new ReorderableList(serializedObject, m_BoundObjects, true, true, false, false)
|
||||
{
|
||||
footerHeight = 0f,
|
||||
elementHeight = EditorGUIUtility.singleLineHeight + 4f,
|
||||
drawHeaderCallback = rect =>
|
||||
{
|
||||
EditorGUI.LabelField(new Rect(rect.x, rect.y, rect.width * 0.5f, rect.height), "Object Names");
|
||||
EditorGUI.LabelField(
|
||||
new Rect(rect.x + rect.width * 0.5f, rect.y, rect.width * 0.5f, rect.height),
|
||||
"Object Values");
|
||||
},
|
||||
drawElementCallback = (rect, index, _, _) =>
|
||||
{
|
||||
Rect _rect = new (rect.x, rect.y + 2, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
SerializedProperty element = _boundObjectList.serializedProperty.GetArrayElementAtIndex(index);
|
||||
|
||||
var halfWidth = _rect.width * 0.5f;
|
||||
EditorGUI.PropertyField(
|
||||
new Rect(_rect.x, _rect.y, halfWidth - 5f, EditorGUIUtility.singleLineHeight),
|
||||
element.FindPropertyRelative(nameof(CVRBaseLuaBehaviour.BoundObject.name)), GUIContent.none);
|
||||
EditorGUI.PropertyField(
|
||||
new Rect(_rect.x + halfWidth, _rect.y, halfWidth, EditorGUIUtility.singleLineHeight),
|
||||
element.FindPropertyRelative(nameof(CVRBaseLuaBehaviour.BoundObject.boundThing)), GUIContent.none);
|
||||
}
|
||||
};;
|
||||
|
||||
EditorGUILayout.HelpBox(
|
||||
"Bound Objects are a way to tell your script about other objects in the scene, and will be accessible via the BoundObjects global (read-only). Careful: Duplicate names will be overwritten by the last duplicate.",
|
||||
MessageType.Info);
|
||||
|
||||
Separator();
|
||||
|
||||
DrawBoundObjectButtons();
|
||||
_boundObjectList.DoLayoutList();
|
||||
}
|
||||
|
||||
private void DrawBoundObjectButtons()
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
// Add Button
|
||||
if (GUILayout.Button("Add Bound Object"))
|
||||
{
|
||||
m_BoundObjects.InsertArrayElementAtIndex(m_BoundObjects.arraySize);
|
||||
SerializedProperty newElement =
|
||||
m_BoundObjects.GetArrayElementAtIndex(m_BoundObjects.arraySize - 1);
|
||||
newElement.FindPropertyRelative(nameof(CVRBaseLuaBehaviour.BoundObject.name)).stringValue = "";
|
||||
newElement.FindPropertyRelative(nameof(CVRBaseLuaBehaviour.BoundObject.boundThing)).objectReferenceValue = null;
|
||||
_boundObjectList.index = m_BoundObjects.arraySize - 1;
|
||||
}
|
||||
|
||||
// Remove Button
|
||||
EditorGUI.BeginDisabledGroup(m_BoundObjects.arraySize == 0 || _boundObjectList.index < 0);
|
||||
if (GUILayout.Button("Remove Bound Object"))
|
||||
{
|
||||
var removeIndex = _boundObjectList.index;
|
||||
if (removeIndex >= 0 && removeIndex < m_BoundObjects.arraySize)
|
||||
{
|
||||
m_BoundObjects.DeleteArrayElementAtIndex(removeIndex);
|
||||
_boundObjectList.index--;
|
||||
}
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 53e02df5678c8bd4695568fa966d3a37
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,113 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using ABI.CCK.Components.ScriptableObjects;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using static ABI.CCK.Scripts.Editor.SharedComponentGUI;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace ABI.CCK.Components
|
||||
{
|
||||
public partial class CCK_CVRLuaClientBehaviourEditor
|
||||
{
|
||||
private Vector2 _scrollPosition;
|
||||
|
||||
private void Draw_LuaAsset()
|
||||
{
|
||||
using (new FoldoutScope(ref _guiLuaAssetFoldout, "Lua Script", s_BoldFoldoutStyle))
|
||||
{
|
||||
if (!_guiLuaAssetFoldout) return;
|
||||
using (new EditorGUI.IndentLevelScope())
|
||||
DrawLuaAsset();
|
||||
}
|
||||
}
|
||||
|
||||
#region Drawing Methods
|
||||
|
||||
private void DrawLuaAsset()
|
||||
{
|
||||
if (!DrawScriptAsset())
|
||||
return;
|
||||
|
||||
Separator();
|
||||
DrawScriptPreview();
|
||||
}
|
||||
|
||||
private bool DrawScriptAsset()
|
||||
{
|
||||
DrawLocalOnly();
|
||||
|
||||
Object luaAsset = EditorGUILayout.ObjectField("Script Asset:", m_LuaAsset.objectReferenceValue, typeof(CVRLuaScript),
|
||||
allowSceneObjects: true, null);
|
||||
|
||||
if (luaAsset is CVRLuaScript luaScript
|
||||
&& m_LuaAsset.objectReferenceValue != luaScript)
|
||||
{
|
||||
string assetPath = AssetDatabase.GetAssetPath(luaScript);
|
||||
if (!string.IsNullOrEmpty(assetPath) && assetPath.EndsWith(".lua", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_baseLuaBehaviour.asset = luaScript;
|
||||
m_LuaAsset.objectReferenceValue = luaScript; // set via serialized property to support undo
|
||||
}
|
||||
}
|
||||
using (new EditorGUI.DisabledScope(true))
|
||||
EditorGUILayout.LabelField("Script Path:", _baseLuaBehaviour.ScriptPath);
|
||||
|
||||
if (m_LuaAsset.objectReferenceValue != null)
|
||||
return true;
|
||||
|
||||
EditorGUILayout.HelpBox(
|
||||
"No linked file. Please drag your LUA file from your project to the field above.",
|
||||
MessageType.Error);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void DrawLocalOnly()
|
||||
{
|
||||
if (_baseLuaBehaviour.GetComponentInParent<CVRAvatar>() != null)
|
||||
{
|
||||
EditorGUILayout.PropertyField(m_LocalOnly, new GUIContent("Run only for Avatar's Wearer"));
|
||||
if (!m_LocalOnly.boolValue)
|
||||
EditorGUILayout.HelpBox("This script will run on every player's machine. When unsure keep it enabled.", MessageType.Warning);
|
||||
}
|
||||
else if (_baseLuaBehaviour.GetComponentInParent<CVRSpawnable>() != null)
|
||||
{
|
||||
EditorGUILayout.PropertyField(m_LocalOnly, new GUIContent("Run only for Prop's Spawner"));
|
||||
if (!m_LocalOnly.boolValue)
|
||||
EditorGUILayout.HelpBox("This script will run on every player's machine. When unsure keep it enabled.", MessageType.Info);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawScriptPreview()
|
||||
{
|
||||
const float lineHeight = 24;
|
||||
int lineCount = CountLines(_baseLuaBehaviour.ScriptText);
|
||||
float scrollViewHeight = Mathf.Min(lineCount * lineHeight, 200);
|
||||
|
||||
_scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, false, false,
|
||||
GUILayout.Width(EditorGUIUtility.currentViewWidth - 30), GUILayout.Height(scrollViewHeight));
|
||||
|
||||
using (new EditorGUI.DisabledScope(true))
|
||||
{
|
||||
using (new SetIndentLevelScope(0))
|
||||
EditorGUILayout.TextArea(_baseLuaBehaviour.ScriptText, GUILayout.ExpandHeight(true));
|
||||
}
|
||||
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private static int CountLines(string text)
|
||||
{
|
||||
return string.IsNullOrEmpty(text)
|
||||
? 0
|
||||
: 1 + text.Count(c => c == '\n');
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e38ea6ae063fa384fb87bff48c26d590
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue