Commit 59187c5f authored by Markus Schlösser's avatar Markus Schlösser

SPAAAAAAAAAAAAAAAACE

parent 6ae5720a
fileFormatVersion: 2
guid: 51175eb0b90da024ebb0be4770a082c9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEditor.AnimatedValues;
using UnityEditorInternal;
using UnityEngine;
using Object = UnityEngine.Object;
[CustomEditor(typeof(Object), true, isFallback = true)]
[CanEditMultipleObjects]
public class CustomEditorBase : Editor {
private Dictionary<string, ReorderableListProperty> reorderableLists;
protected virtual void OnEnable() {
reorderableLists = new Dictionary<string, ReorderableListProperty>(10);
}
~CustomEditorBase() {
reorderableLists.Clear();
reorderableLists = null;
}
public override void OnInspectorGUI() {
EditorGUILayout.LabelField("Custom Editor", EditorStyles.centeredGreyMiniLabel);
Color cachedGuiColor = GUI.color;
serializedObject.Update();
SerializedProperty property = serializedObject.GetIterator();
if (property.NextVisible(true)) {
do {
GUI.color = cachedGuiColor;
HandleProperty(property);
} while (property.NextVisible(false));
}
serializedObject.ApplyModifiedProperties();
}
protected void HandleProperty(SerializedProperty property) {
//Debug.LogFormat("name: {0}, displayName: {1}, type: {2}, propertyType: {3}, path: {4}", property.name, property.displayName, property.type, property.propertyType, property.propertyPath);
bool isdefaultScriptProperty = property.name.Equals("m_Script") && property.type.Equals("PPtr<MonoScript>") && property.propertyType == SerializedPropertyType.ObjectReference && property.propertyPath.Equals("m_Script");
bool oldGuiEnabled = GUI.enabled;
if (isdefaultScriptProperty) {
GUI.enabled = false;
}
if (property.isArray && property.propertyType != SerializedPropertyType.String) {
HandleArray(property);
} else {
EditorGUILayout.PropertyField(property, property.isExpanded);
}
if (isdefaultScriptProperty) {
GUI.enabled = oldGuiEnabled;
}
}
protected void HandleArray(SerializedProperty property) {
var listData = GetReorderableList(property);
listData.IsExpanded.target = property.isExpanded;
if ((!listData.IsExpanded.value && !listData.IsExpanded.isAnimating) || (!listData.IsExpanded.value && listData.IsExpanded.isAnimating)) {
using (new EditorGUILayout.HorizontalScope()) {
property.isExpanded = EditorGUILayout.ToggleLeft($"{property.displayName}[]", property.isExpanded, EditorStyles.boldLabel);
EditorGUILayout.LabelField($"size: {property.arraySize}");
}
} else {
using (new EditorGUILayout.FadeGroupScope(listData.IsExpanded.faded)) {
listData.List.DoLayoutList();
}
}
}
protected object[] GetPropertyAttributes(SerializedProperty property) {
return GetPropertyAttributes<PropertyAttribute>(property);
}
protected static object[] GetPropertyAttributes<T>(SerializedProperty property) where T : Attribute {
const BindingFlags BindingFlags = BindingFlags.GetField
| BindingFlags.GetProperty
| BindingFlags.IgnoreCase
| BindingFlags.Instance
| BindingFlags.NonPublic
| BindingFlags.Public;
if (property.serializedObject.targetObject == null) return null;
var targetType = property.serializedObject.targetObject.GetType();
var field = targetType.GetField(property.name, BindingFlags);
return field != null ? field.GetCustomAttributes(typeof(T), true) : null;
}
private ReorderableListProperty GetReorderableList(SerializedProperty property) {
if (reorderableLists.TryGetValue(property.name, out ReorderableListProperty ret)) {
ret.Property = property;
return ret;
}
ret = new ReorderableListProperty(property);
reorderableLists.Add(property.name, ret);
return ret;
}
#region Inner-class ReorderableListProperty
private class ReorderableListProperty {
private SerializedProperty property;
public ReorderableListProperty(SerializedProperty property) {
IsExpanded = new AnimBool(property.isExpanded);
IsExpanded.speed = 1f;
this.property = property;
CreateList();
}
public AnimBool IsExpanded { get; }
/// <summary>
/// ref http://va.lent.in/unity-make-your-lists-functional-with-reorderablelist/
/// </summary>
public ReorderableList List { get; private set; }
public SerializedProperty Property {
get { return property; }
set {
property = value;
List.serializedProperty = property;
}
}
~ReorderableListProperty() {
property = null;
List = null;
}
private void CreateList() {
List = new ReorderableList(Property.serializedObject, Property, true, true, true, true);
List.drawHeaderCallback += rect => property.isExpanded = EditorGUI.ToggleLeft(rect, property.displayName, property.isExpanded, EditorStyles.boldLabel);
List.onCanRemoveCallback += list => List.count > 0;
List.drawElementCallback += DrawElement;
List.elementHeightCallback += idx => Mathf.Max(EditorGUIUtility.singleLineHeight, EditorGUI.GetPropertyHeight(property.GetArrayElementAtIndex(idx), GUIContent.none, true)) + 4.0f;
}
private void DrawElement(Rect rect, int index, bool active, bool focused) {
if (property.GetArrayElementAtIndex(index).propertyType == SerializedPropertyType.Generic) {
EditorGUI.LabelField(rect, property.GetArrayElementAtIndex(index).displayName);
}
//rect.height = 16;
rect.height = EditorGUI.GetPropertyHeight(property.GetArrayElementAtIndex(index), GUIContent.none, true);
rect.y += 1;
EditorGUI.PropertyField(rect, property.GetArrayElementAtIndex(index), GUIContent.none, true);
List.elementHeight = rect.height + 4.0f;
}
}
#endregion
}
fileFormatVersion: 2
guid: 138ccd21aa3888e4a8c47fa2d295c0be
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
{
"name": "Supergame.SpaceAttacker.Editor",
"references": [
"GUID:ee33549d2d76d294cb1d1550ff28e5a0"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": []
}
\ No newline at end of file
fileFormatVersion: 2
guid: 90871014c924fff45907c35b4a8cea40
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -47,6 +47,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
voxelRoot: {fileID: 1726221274844343498}
explosionForce: 200
hitPoints: 1
--- !u!54 &6047212517645363867
Rigidbody:
m_ObjectHideFlags: 0
......
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &2255568859996186776
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 5336066396422231871, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_Name
value: Large Attacker
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4732932245674216541, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: hitPoints
value: 2
objectReference: {fileID: 0}
- target: {fileID: 1726221274844343498, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalScale.x
value: 0.35
objectReference: {fileID: 0}
- target: {fileID: 1726221274844343498, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalScale.y
value: 0.35
objectReference: {fileID: 0}
- target: {fileID: 1726221274844343498, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalScale.z
value: 0.35
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2ed483c265b3a8445aefda1321fc7ad4, type: 3}
fileFormatVersion: 2
guid: 1df788dc006dd0545a35079f88c0cd28
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &881748159068035474
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 8119908504615950147}
m_Modifications:
- target: {fileID: 1412370920879691268, guid: 37b8379a4b3d3bd498f70a16564381e1,
type: 3}
propertyPath: m_Name
value: Eye (2)
objectReference: {fileID: 0}
- target: {fileID: 8294202188468026973, guid: 37b8379a4b3d3bd498f70a16564381e1,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8294202188468026973, guid: 37b8379a4b3d3bd498f70a16564381e1,
type: 3}
propertyPath: m_LocalPosition.y
value: 3
objectReference: {fileID: 0}
- target: {fileID: 8294202188468026973, guid: 37b8379a4b3d3bd498f70a16564381e1,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8294202188468026973, guid: 37b8379a4b3d3bd498f70a16564381e1,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8294202188468026973, guid: 37b8379a4b3d3bd498f70a16564381e1,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8294202188468026973, guid: 37b8379a4b3d3bd498f70a16564381e1,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8294202188468026973, guid: 37b8379a4b3d3bd498f70a16564381e1,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8294202188468026973, guid: 37b8379a4b3d3bd498f70a16564381e1,
type: 3}
propertyPath: m_RootOrder
value: 48
objectReference: {fileID: 0}
- target: {fileID: 8294202188468026973, guid: 37b8379a4b3d3bd498f70a16564381e1,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8294202188468026973, guid: 37b8379a4b3d3bd498f70a16564381e1,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8294202188468026973, guid: 37b8379a4b3d3bd498f70a16564381e1,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 37b8379a4b3d3bd498f70a16564381e1, type: 3}
--- !u!1001 &7447670486242114441
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 5336066396422231871, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_Name
value: Very Large Attacker
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6513588737743217509, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4732932245674216541, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: hitPoints
value: 4
objectReference: {fileID: 0}
- target: {fileID: 1726221274844343498, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalScale.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1726221274844343498, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalScale.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 1726221274844343498, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_LocalScale.z
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 2420802670151732750, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2ed483c265b3a8445aefda1321fc7ad4, type: 3}
--- !u!4 &8119908504615950147 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 1726221274844343498, guid: 2ed483c265b3a8445aefda1321fc7ad4,
type: 3}
m_PrefabInstance: {fileID: 7447670486242114441}
m_PrefabAsset: {fileID: 0}
fileFormatVersion: 2
guid: 90be04e546b1b8141b603d00143ea840
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -546,10 +546,12 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 80438334c5896c040b8c0d6308bce165, type: 3}
m_Name:
m_EditorClassIdentifier:
movementSpeed: 10
projectile: {fileID: 2304431709535212093, guid: 0dbad0fe3ac6ade48afbedab7a57d27c,
type: 3}
muzzle: {fileID: 7728957991079732447}
baseAttackSpeed: 4
bonusAttackSpeed: 0.25
movementSpeed: 10
--- !u!54 &4886276944394470301
Rigidbody:
m_ObjectHideFlags: 0
......
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class Attacker : MonoBehaviour {
[SerializeField] private Transform voxelRoot;
[SerializeField] private float explosionForce;
[SerializeField] private int hitPoints;
private int fragmentLayer;
private Rigidbody rb;
private List<GameObject> voxels;
private bool isDestroyed;
public bool IsAlive => hitPoints > 0;
private void Awake() {
fragmentLayer = LayerMask.NameToLayer("Space/Fragment");
......@@ -23,8 +24,10 @@ public class Attacker : MonoBehaviour {
}
private void OnCollisionEnter(Collision other) {
if (isDestroyed) return;
isDestroyed = true;
if (!IsAlive) return;
rb.velocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
if (other.gameObject.layer == LayerMask.NameToLayer("Space/Ground")) {
FindObjectOfType<GameManager>().EndGame();
......@@ -33,38 +36,42 @@ public class Attacker : MonoBehaviour {
Fragment(new Ray(other.GetContact(0).point, other.relativeVelocity));
}
private void Fragment(Ray pierce) {
GameObject leftObj = new GameObject("LeftFragment");
GameObject rightObj = new GameObject("RightFragment");
public void Fragment(Ray pierce) {
if (!IsAlive) return;
hitPoints -= 1;
leftObj.layer = fragmentLayer;
rightObj.layer = fragmentLayer;
List<GameObject> left = voxels.FindAll(x => Vector3.SignedAngle(x.transform.position - pierce.origin, pierce.direction, Vector3.forward) < 0);
List<GameObject> right = voxels.FindAll(x => Vector3.SignedAngle(x.transform.position - pierce.origin, pierce.direction, Vector3.forward) > 0);
leftObj.AddComponent<DesintegrateOnCollision>();
rightObj.AddComponent<DesintegrateOnCollision>();
var smallerFragment = left.Count < right.Count ? left : right;
var largerFragment = smallerFragment == left ? right : left;
Transform left = leftObj.transform;
Transform right = rightObj.transform;
CreateFragment(smallerFragment, pierce.origin);
voxels = voxels.Except(smallerFragment).ToList();
if (hitPoints <= 0) {
CreateFragment(largerFragment, pierce.origin);
left.parent = voxelRoot;
right.parent = voxelRoot;
Destroy(gameObject);
}
}
Rigidbody leftRb = left.gameObject.AddComponent<Rigidbody>();
Rigidbody rightRb = right.gameObject.AddComponent<Rigidbody>();
private void CreateFragment(IEnumerable<GameObject> parts, Vector3 impactPosition) {
GameObject root = new GameObject("Fragment", typeof(Fragment), typeof(Rigidbody)) {
layer = fragmentLayer
};
foreach (GameObject voxel in voxels) {
voxel.layer = fragmentLayer;
Transform rootTransform = root.transform;
rootTransform.parent = transform.parent;
Vector3 offset = voxel.transform.position - pierce.origin;
voxel.transform.parent = Vector3.SignedAngle(offset, pierce.direction, Vector3.f