Weapos Rejiggered

Modified weapon scripts to eliminate specialized projectile behavior - allows charged weapons to have projectiles and modify weapon stats when charged
Added machine gun weapon & VFX
Moved third party code to Plugins folder to improve compile times
This commit is contained in:
Reinier Vens 2021-01-31 03:52:32 +00:00
commit dbc522a224
2105 changed files with 7033 additions and 1141 deletions

View file

@ -0,0 +1,118 @@
using UnityEngine;
using UnityEditor;
using System.Reflection;
using System.Collections;
using System;
using System.Collections.Generic;
namespace NaughtyAttributes.Editor
{
[PropertyDrawer(typeof(DropdownAttribute))]
public class DropdownPropertyDrawer : PropertyDrawer
{
public override void DrawProperty(SerializedProperty property)
{
DropdownAttribute dropdownAttribute = PropertyUtility.GetAttributes<DropdownAttribute>(property)[0];
UnityEngine.Object target = PropertyUtility.GetTargetObject(property);
FieldInfo fieldInfo = target.GetType().GetField(property.name,
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
FieldInfo valuesFieldInfo = target.GetType().GetField(dropdownAttribute.ValuesFieldName,
BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
if (valuesFieldInfo == null)
{
this.DrawWarningBox(string.Format("{0} cannot find a values field with name \"{1}\"", dropdownAttribute.GetType().Name, dropdownAttribute.ValuesFieldName));
EditorGUILayout.PropertyField(property, true);
}
else if (fieldInfo.FieldType == valuesFieldInfo.FieldType.GetElementType())
{
// Selected value
object selectedValue = fieldInfo.GetValue(target);
// Values and display options
IList valuesList = (IList)valuesFieldInfo.GetValue(target);
object[] values = new object[valuesList.Count];
string[] displayOptions = new string[valuesList.Count];
for (int i = 0; i < values.Length; i++)
{
object value = valuesList[i];
values[i] = value;
displayOptions[i] = value.ToString();
}
// Selected value index
int selectedValueIndex = Array.IndexOf(values, selectedValue);
if (selectedValueIndex < 0)
{
selectedValueIndex = 0;
}
// Draw the dropdown
this.DrawDropdown(target, fieldInfo, property.displayName, selectedValueIndex, values, displayOptions);
}
else if (valuesFieldInfo.GetValue(target) is IDropdownList)
{
// Current value
object selectedValue = fieldInfo.GetValue(target);
// Current value index, values and display options
IDropdownList dropdown = (IDropdownList)valuesFieldInfo.GetValue(target);
IEnumerator<KeyValuePair<string, object>> dropdownEnumerator = dropdown.GetEnumerator();
int index = -1;
int selectedValueIndex = -1;
List<object> values = new List<object>();
List<string> displayOptions = new List<string>();
while (dropdownEnumerator.MoveNext())
{
index++;
KeyValuePair<string, object> current = dropdownEnumerator.Current;
if (current.Value.Equals(selectedValue))
{
selectedValueIndex = index;
}
values.Add(current.Value);
displayOptions.Add(current.Key);
}
if (selectedValueIndex < 0)
{
selectedValueIndex = 0;
}
// Draw the dropdown
this.DrawDropdown(target, fieldInfo, property.displayName, selectedValueIndex, values.ToArray(), displayOptions.ToArray());
}
else
{
this.DrawWarningBox(typeof(DropdownAttribute).Name + " works only when the type of the field is equal to the element type of the array");
EditorGUILayout.PropertyField(property, true);
}
}
private void DrawDropdown(UnityEngine.Object target, FieldInfo fieldInfo, string label, int selectedValueIndex, object[] values, string[] displayOptions)
{
EditorGUI.BeginChangeCheck();
int newIndex = EditorGUILayout.Popup(label, selectedValueIndex, displayOptions);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(target, "Dropdown");
fieldInfo.SetValue(target, values[newIndex]);
}
}
private void DrawWarningBox(string message)
{
EditorGUILayout.HelpBox(message, MessageType.Warning);
Debug.LogWarning(message);
}
}
}

View file

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 19d935f1205a5804c80c51c3ad95a271
timeCreated: 1508753698
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,75 @@
using UnityEngine;
using UnityEditor;
namespace NaughtyAttributes.Editor
{
[PropertyDrawer(typeof(MinMaxSliderAttribute))]
public class MinMaxSliderPropertyDrawer : PropertyDrawer
{
public override void DrawProperty(SerializedProperty property)
{
MinMaxSliderAttribute minMaxSliderAttribute = PropertyUtility.GetAttributes<MinMaxSliderAttribute>(property)[0];
if (property.propertyType == SerializedPropertyType.Vector2)
{
Rect controlRect = EditorGUILayout.GetControlRect();
float labelWidth = EditorGUIUtility.labelWidth;
float floatFieldWidth = EditorGUIUtility.fieldWidth;
float sliderWidth = controlRect.width - labelWidth - 2f * floatFieldWidth;
float sliderPadding = 5f;
Rect labelRect = new Rect(
controlRect.x,
controlRect.y,
labelWidth,
controlRect.height);
Rect sliderRect = new Rect(
controlRect.x + labelWidth + floatFieldWidth + sliderPadding,
controlRect.y,
sliderWidth - 2f * sliderPadding,
controlRect.height);
Rect minFloatFieldRect = new Rect(
controlRect.x + labelWidth,
controlRect.y,
floatFieldWidth,
controlRect.height);
Rect maxFloatFieldRect = new Rect(
controlRect.x + labelWidth + floatFieldWidth + sliderWidth,
controlRect.y,
floatFieldWidth,
controlRect.height);
// Draw the label
EditorGUI.LabelField(labelRect, property.displayName);
// Draw the slider
EditorGUI.BeginChangeCheck();
Vector2 sliderValue = property.vector2Value;
EditorGUI.MinMaxSlider(sliderRect, ref sliderValue.x, ref sliderValue.y, minMaxSliderAttribute.MinValue, minMaxSliderAttribute.MaxValue);
sliderValue.x = EditorGUI.FloatField(minFloatFieldRect, sliderValue.x);
sliderValue.x = Mathf.Clamp(sliderValue.x, minMaxSliderAttribute.MinValue, Mathf.Min(minMaxSliderAttribute.MaxValue, sliderValue.y));
sliderValue.y = EditorGUI.FloatField(maxFloatFieldRect, sliderValue.y);
sliderValue.y = Mathf.Clamp(sliderValue.y, Mathf.Max(minMaxSliderAttribute.MinValue, sliderValue.x), minMaxSliderAttribute.MaxValue);
if (EditorGUI.EndChangeCheck())
{
property.vector2Value = sliderValue;
}
}
else
{
string warning = minMaxSliderAttribute.GetType().Name + " can be used only on Vector2 fields";
EditorGUILayout.HelpBox(warning, MessageType.Warning);
Debug.LogWarning(warning, PropertyUtility.GetTargetObject(property));
EditorGUILayout.PropertyField(property, true);
}
}
}
}

View file

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 27011af81554b5b4489b155f09275475
timeCreated: 1508427131
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,14 @@
using UnityEditor;
namespace NaughtyAttributes.Editor
{
public abstract class PropertyDrawer
{
public abstract void DrawProperty(SerializedProperty property);
public virtual void ClearCache()
{
}
}
}

View file

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

View file

@ -0,0 +1,16 @@
using UnityEditor;
using UnityEngine;
namespace NaughtyAttributes.Editor
{
[PropertyDrawer(typeof(ReadOnlyAttribute))]
public class ReadOnlyPropertyDrawer : PropertyDrawer
{
public override void DrawProperty(SerializedProperty property)
{
GUI.enabled = false;
EditorGUILayout.PropertyField(property, true);
GUI.enabled = true;
}
}
}

View file

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

View file

@ -0,0 +1,55 @@
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
using System.Collections.Generic;
namespace NaughtyAttributes.Editor
{
[PropertyDrawer(typeof(ReorderableListAttribute))]
public class ReorderableListPropertyDrawer : PropertyDrawer
{
private Dictionary<string, ReorderableList> reorderableListsByPropertyName = new Dictionary<string, ReorderableList>();
public override void DrawProperty(SerializedProperty property)
{
if (property.isArray)
{
if (!this.reorderableListsByPropertyName.ContainsKey(property.name))
{
ReorderableList reorderableList = new ReorderableList(property.serializedObject, property, true, true, true, true)
{
drawHeaderCallback = (Rect rect) =>
{
EditorGUI.LabelField(rect, string.Format("{0}: {1}", property.displayName, property.arraySize), EditorStyles.label);
},
drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
{
var element = property.GetArrayElementAtIndex(index);
rect.y += 2f;
EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), element);
}
};
this.reorderableListsByPropertyName[property.name] = reorderableList;
}
this.reorderableListsByPropertyName[property.name].DoLayoutList();
}
else
{
string warning = typeof(ReorderableListAttribute).Name + " can be used only on arrays or lists";
EditorGUILayout.HelpBox(warning, MessageType.Warning);
Debug.LogWarning(warning, PropertyUtility.GetTargetObject(property));
EditorGUILayout.PropertyField(property, true);
}
}
public override void ClearCache()
{
this.reorderableListsByPropertyName.Clear();
}
}
}

View file

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 6d5a6c66de03d1d4882f0c83b0e5f8f2
timeCreated: 1508402303
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,34 @@
using UnityEngine;
using UnityEditor;
namespace NaughtyAttributes.Editor
{
[PropertyDrawer(typeof(ResizableTextAreaAttribute))]
public class ResizableTextAreaPropertyDrawer : PropertyDrawer
{
public override void DrawProperty(SerializedProperty property)
{
if (property.propertyType == SerializedPropertyType.String)
{
EditorGUILayout.LabelField(property.displayName);
EditorGUI.BeginChangeCheck();
string textAreaValue = EditorGUILayout.TextArea(property.stringValue, GUILayout.MinHeight(EditorGUIUtility.singleLineHeight * 3f));
if (EditorGUI.EndChangeCheck())
{
property.stringValue = textAreaValue;
}
}
else
{
string warning = PropertyUtility.GetAttributes<ResizableTextAreaAttribute>(property)[0].GetType().Name + " can only be used on string fields";
EditorGUILayout.HelpBox(warning, MessageType.Warning);
Debug.LogWarning(warning, PropertyUtility.GetTargetObject(property));
EditorGUILayout.PropertyField(property, true);
}
}
}
}

View file

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 57848d4e847a8d445a53095abdbbb274
timeCreated: 1508583167
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,44 @@
using UnityEngine;
using UnityEditor;
namespace NaughtyAttributes.Editor
{
[PropertyDrawer(typeof(ShowAssetPreviewAttribute))]
public class ShowAssetPreviewPropertyDrawer : PropertyDrawer
{
public override void DrawProperty(SerializedProperty property)
{
EditorGUILayout.PropertyField(property, true);
if (property.propertyType == SerializedPropertyType.ObjectReference)
{
if (property.objectReferenceValue != null)
{
Texture2D previewTexture = AssetPreview.GetAssetPreview(property.objectReferenceValue);
if (previewTexture != null)
{
ShowAssetPreviewAttribute showAssetPreviewAttribute = PropertyUtility.GetAttributes<ShowAssetPreviewAttribute>(property)[0];
int width = Mathf.Clamp(showAssetPreviewAttribute.Width, 0, previewTexture.width);
int height = Mathf.Clamp(showAssetPreviewAttribute.Height, 0, previewTexture.height);
GUILayout.Label(previewTexture, GUILayout.MaxWidth(width), GUILayout.MaxHeight(height));
}
else
{
this.DrawWarningBox(property.name + " doesn't have an asset preview", property);
}
}
}
else
{
this.DrawWarningBox(property.name + " doesn't have an asset preview", property);
}
}
private void DrawWarningBox(string warningText, SerializedProperty property)
{
EditorGUILayout.HelpBox(warningText, MessageType.Warning);
Debug.LogWarning(warningText, PropertyUtility.GetTargetObject(property));
}
}
}

View file

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 6c461f4d7edd955419e5e6ce2c874599
timeCreated: 1509089502
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,31 @@
using UnityEngine;
using UnityEditor;
namespace NaughtyAttributes.Editor
{
[PropertyDrawer(typeof(SliderAttribute))]
public class SliderPropertyDrawer : PropertyDrawer
{
public override void DrawProperty(SerializedProperty property)
{
SliderAttribute sliderAttribute = PropertyUtility.GetAttributes<SliderAttribute>(property)[0];
if (property.propertyType == SerializedPropertyType.Integer)
{
EditorGUILayout.IntSlider(property, (int)sliderAttribute.MinValue, (int)sliderAttribute.MaxValue);
}
else if (property.propertyType == SerializedPropertyType.Float)
{
EditorGUILayout.Slider(property, sliderAttribute.MinValue, sliderAttribute.MaxValue);
}
else
{
string warning = sliderAttribute.GetType().Name + " can be used only on int or float fields";
EditorGUILayout.HelpBox(warning, MessageType.Warning);
Debug.LogWarning(warning, PropertyUtility.GetTargetObject(property));
EditorGUILayout.PropertyField(property, true);
}
}
}
}

View file

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