-Created block class -Turned objects in scene to prefabs -Moved Character movement out of update -Added keyboard controll class -Added some Utility classes -Fixed some foldersJosh_Dev_branch
@ -1,5 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: ece630d9a8c11c543956472c51dad691 | |||
guid: 38642f732c8d4de448bf987069f2b9e2 | |||
folderAsset: yes | |||
DefaultImporter: | |||
externalObjects: {} |
@ -0,0 +1,230 @@ | |||
using System.Collections; | |||
using System.Collections.Generic; | |||
using UnityEngine; | |||
using UnityEditor; | |||
using System; | |||
/// <summary> | |||
/// Editor Class used to search and replace objects with prefabs; | |||
/// </summary> | |||
public class MassReplacer : EditorWindow { | |||
#region Editor Settings | |||
//base settings | |||
private string FilterText; | |||
private ListItem[] FilteredList; | |||
private GameObject CopiedPrefab; | |||
//advanced settings | |||
private bool doCopyScale = true; | |||
private bool doCopyRot = true; | |||
private bool isCaseSensitive = false; | |||
#endregion Editor Settings | |||
#region Private Variables | |||
private Vector2 scrollPosition; | |||
private string prevFilterText; | |||
private bool showAdvancedSettings; | |||
#endregion Private Variables | |||
#region GUI Functions | |||
[MenuItem("Tools/Mass Replace %e")] | |||
static void createWindow() | |||
{ | |||
MassReplacer window = (MassReplacer)GetWindow(typeof(MassReplacer), true, "Replace", true); | |||
window.ReFilterList(window.FilterText); | |||
window.Repaint(); | |||
} | |||
void OnGUI() | |||
{ | |||
Event e = Event.current; | |||
//Base Settings | |||
EditorGUILayout.LabelField("Base Settings", EditorStyles.boldLabel); | |||
FilterText = EditorGUILayout.TextField((FilterText == null || FilterText == "") ? "Search..." : FilterText); //If textFiled is empty display "Searching..." else display search filter | |||
CopiedPrefab = (GameObject)EditorGUILayout.ObjectField(CopiedPrefab, typeof(GameObject), true); | |||
//Advanced Settings | |||
GUIStyle BoldFold = new GUIStyle(EditorStyles.foldout); BoldFold.font = EditorStyles.boldFont; //create foldoutstyle with bold text | |||
showAdvancedSettings = EditorGUILayout.Foldout(showAdvancedSettings, "Advanced Settings", BoldFold); | |||
if (showAdvancedSettings) { | |||
doCopyScale = EditorGUILayout.Toggle("Copy Scale", doCopyScale); | |||
doCopyRot = EditorGUILayout.Toggle("Copy Rotation", doCopyRot); | |||
isCaseSensitive = EditorGUILayout.Toggle("Case Sensitive Search", isCaseSensitive); | |||
} | |||
float advancedSettingHeight = 3 * ((showAdvancedSettings) ? 18 : 0); | |||
//Start of List | |||
GUILayout.Box("", GUILayout.Height(1), GUILayout.ExpandWidth(true)); | |||
Rect scrollRect = GUILayoutUtility.GetLastRect(); | |||
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(position.width), GUILayout.Height(position.height - (108 + advancedSettingHeight) )); | |||
scrollRect.height = position.height - (108 + advancedSettingHeight); | |||
//Each Item | |||
foreach (ListItem listItem in FilteredList) { | |||
GUILayout.BeginHorizontal(); | |||
listItem.isRepplaceable = GUILayout.Toggle(listItem.isRepplaceable, "", GUILayout.MaxWidth(10)); | |||
GUILayout.Label(listItem.gameObject.name); | |||
Rect tempRect = GUILayoutUtility.GetLastRect(); | |||
tempRect.position -= Vector2.down * (82 + advancedSettingHeight) + scrollPosition; | |||
if (tempRect.Overlaps(scrollRect)) | |||
listItem.rect = tempRect; | |||
GUILayout.EndHorizontal(); | |||
} | |||
GUILayout.EndScrollView(); //end list | |||
//Buttons at bottom of window | |||
GUILayout.BeginHorizontal(); | |||
GUI.enabled = (CopiedPrefab != null); | |||
if (GUILayout.Button("Replace")) { | |||
replaceFiltedList(); | |||
} | |||
GUI.enabled = true; | |||
if (GUILayout.Button("Cancel")) { | |||
} | |||
GUILayout.EndHorizontal(); // end buttons | |||
//Interaction | |||
//Check if filter is updated; | |||
if (prevFilterText != FilterText) { | |||
ReFilterList(FilterText); | |||
} | |||
//If clicked window check where clicked happened | |||
if (e.button == 0 && e.type == EventType.MouseDown) | |||
OnWindowClick(e.mousePosition); | |||
} | |||
/// <summary> | |||
/// Logic of when the window has been clicked | |||
/// </summary> | |||
/// <param name="mousePos">position of mouse when clicked</param> | |||
/// <returns></returns> | |||
private void OnWindowClick(Vector2 mousePos) | |||
{ | |||
//Loops through each asset to see if one has been clicked on | |||
foreach (ListItem listItem in FilteredList) { | |||
if (listItem.rect.Contains(mousePos)) { | |||
Debug.Log("clicked: " + listItem.gameObject.name); | |||
Selection.activeGameObject = listItem.gameObject; | |||
break; | |||
}//end if | |||
}//end foreach | |||
} | |||
#endregion GUI Functions | |||
#region Search Functions | |||
#region Helper Functions | |||
private void ReFilterList(string filter) | |||
{ | |||
if (filter == null) | |||
filter = ""; | |||
StringComparison caseComparer = (isCaseSensitive) ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; | |||
FilteredList = getFilteredList(filter, caseComparer); | |||
prevFilterText = filter; | |||
Repaint(); | |||
} | |||
#endregion Helper Fucntions | |||
#region Static Functions | |||
/// <summary> | |||
/// Returns an array of listItems of gameobjects in scene which contains a string | |||
/// </summary> | |||
/// <param name="filter">look for gameobjects containing this string</param> | |||
/// <returns></returns> | |||
private static ListItem[] getFilteredList(string filter, StringComparison caseComparer = StringComparison.OrdinalIgnoreCase) | |||
{ | |||
List<ListItem> retVal = new List<ListItem>(); | |||
object[] obj = FindObjectsOfType(typeof(GameObject)); | |||
foreach (object o in obj) { | |||
GameObject g = (GameObject)o; | |||
if (g.name.Contains(filter, caseComparer)) { | |||
ListItem newItem = new ListItem(g); | |||
retVal.Add(newItem); | |||
} | |||
} | |||
return retVal.ToArray(); | |||
} | |||
#endregion Static Functions | |||
#endregion Search Functions | |||
#region Replace Fucntions | |||
private void replaceFiltedList() | |||
{ | |||
foreach (ListItem listItem in FilteredList) { | |||
if (!listItem.isRepplaceable || listItem.gameObject.Equals(CopiedPrefab)) | |||
continue; | |||
GameObject replaceObject = (GameObject)PrefabUtility.InstantiatePrefab(CopiedPrefab); | |||
replaceObject.transform.parent = listItem.gameObject.transform.parent; | |||
replaceObject.transform.position = listItem.gameObject.transform.position; | |||
replaceObject.name = listItem.gameObject.name; | |||
if (doCopyRot) | |||
replaceObject.transform.rotation = listItem.gameObject.transform.rotation; | |||
if (doCopyScale) | |||
replaceObject.transform.localScale = listItem.gameObject.transform.localScale; | |||
Undo.RegisterCreatedObjectUndo(replaceObject, "Replaced Objects (" + FilterText + ")"); | |||
Undo.DestroyObjectImmediate(listItem.gameObject); | |||
} | |||
ReFilterList(FilterText); | |||
} | |||
#endregion Replace Fucntions | |||
class ListItem { | |||
public GameObject gameObject; | |||
public bool isRepplaceable; | |||
public Rect rect; | |||
public ListItem(GameObject gameObject) | |||
{ | |||
this.gameObject = gameObject; | |||
isRepplaceable = true; | |||
rect = new Rect(); | |||
} | |||
} | |||
} | |||
static class MassReplaceOverides { | |||
public static bool Contains(this string source, string toCheck, StringComparison comp) | |||
{ | |||
return source != null && toCheck != null && source.IndexOf(toCheck, comp) >= 0; | |||
} | |||
} |
@ -1,5 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: 59410bc2a512af44880241e461215082 | |||
guid: 31284179c34ec0a47be67dc331839e53 | |||
MonoImporter: | |||
externalObjects: {} | |||
serializedVersion: 2 |
@ -0,0 +1,3 @@ | |||
version https://git-lfs.github.com/spec/v1 | |||
oid sha256:6cd2eb3de9510a6319b174a92b11d1966b6f1bf6258b95c60b88af35c2666499 | |||
size 437 |
@ -1,8 +1,8 @@ | |||
fileFormatVersion: 2 | |||
guid: 78ebdcb036d362d4c8512be91f587a64 | |||
guid: 48f0ea7af28c10846b5b76ce70d06b60 | |||
NativeFormatImporter: | |||
externalObjects: {} | |||
mainObjectFileID: 2100000 | |||
mainObjectFileID: 11400000 | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -1,5 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: c97ced57d1c045e4083cf0b411027523 | |||
guid: 9432cd4a3bec3ba429cf77ce16ff21de | |||
NativeFormatImporter: | |||
externalObjects: {} | |||
mainObjectFileID: 2100000 |
@ -0,0 +1,8 @@ | |||
fileFormatVersion: 2 | |||
guid: 7a31528af3e5a6d4ba37a07c0ce64e91 | |||
folderAsset: yes | |||
DefaultImporter: | |||
externalObjects: {} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -0,0 +1,84 @@ | |||
// Made with Amplify Shader Editor | |||
// Available at the Unity Asset Store - http://u3d.as/y3X | |||
Shader "Custom/Checkers" | |||
{ | |||
Properties | |||
{ | |||
_Albedo("Albedo", Color) = (1,1,1,1) | |||
_Tint("Tint", Range( -1 , 1)) = 0 | |||
[HideInInspector] __dirty( "", Int ) = 1 | |||
} | |||
SubShader | |||
{ | |||
Tags{ "RenderType" = "Opaque" "Queue" = "Geometry+0" } | |||
Cull Back | |||
CGPROGRAM | |||
#pragma target 4.6 | |||
#pragma surface surf Standard keepalpha addshadow fullforwardshadows | |||
struct Input | |||
{ | |||
half filler; | |||
}; | |||
uniform float4 _Albedo; | |||
uniform float _Tint; | |||
void surf( Input i , inout SurfaceOutputStandard o ) | |||
{ | |||
float temp_output_33_0 = (0.0 + (_Tint - -1.0) * (1.0 - 0.0) / (1.0 - -1.0)); | |||
float4 appendResult29 = (float4(temp_output_33_0 , temp_output_33_0 , temp_output_33_0 , 1.0)); | |||
float4 blendOpSrc32 = _Albedo; | |||
float4 blendOpDest32 = appendResult29; | |||
float4 transform3 = mul(unity_ObjectToWorld,float4( 0,0,0,1 )); | |||
float4 lerpResult14 = lerp( _Albedo , ( saturate( (( blendOpDest32 > 0.5 ) ? ( 1.0 - ( 1.0 - 2.0 * ( blendOpDest32 - 0.5 ) ) * ( 1.0 - blendOpSrc32 ) ) : ( 2.0 * blendOpDest32 * blendOpSrc32 ) ) )) , ceil( frac( ( ( round( transform3.x ) + round( transform3.y ) + round( transform3.z ) ) / 2.0 ) ) )); | |||
o.Albedo = lerpResult14.xyz; | |||
o.Alpha = 1; | |||
} | |||
ENDCG | |||
} | |||
Fallback "Diffuse" | |||
CustomEditor "ASEMaterialInspector" | |||
} | |||
/*ASEBEGIN | |||
Version=16301 | |||
-1741;132;1617;696;2291.399;21.03448;1;True;True | |||
Node;AmplifyShaderEditor.ObjectToWorldTransfNode;3;-1903.136,544.4678;Float;False;1;0;FLOAT4;0,0,0,1;False;5;FLOAT4;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4 | |||
Node;AmplifyShaderEditor.RoundOpNode;25;-1452.05,648.6464;Float;False;1;0;FLOAT;0;False;1;FLOAT;0 | |||
Node;AmplifyShaderEditor.RoundOpNode;26;-1454.238,738.3569;Float;False;1;0;FLOAT;0;False;1;FLOAT;0 | |||
Node;AmplifyShaderEditor.RoundOpNode;24;-1452.05,553.4653;Float;False;1;0;FLOAT;0;False;1;FLOAT;0 | |||
Node;AmplifyShaderEditor.RangedFloatNode;10;-1089.315,786.6579;Float;False;Constant;_Two;Two;1;0;Create;True;0;0;False;0;2;0;0;0;0;1;FLOAT;0 | |||
Node;AmplifyShaderEditor.SimpleAddOpNode;7;-954.3315,524.3302;Float;False;3;3;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;1;FLOAT;0 | |||
Node;AmplifyShaderEditor.RangedFloatNode;27;-2178.944,260.724;Float;False;Property;_Tint;Tint;1;0;Create;True;0;0;False;0;0;0;-1;1;0;1;FLOAT;0 | |||
Node;AmplifyShaderEditor.SimpleDivideOpNode;9;-790.8982,541.6236;Float;False;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0 | |||
Node;AmplifyShaderEditor.TFHCRemapNode;33;-1886.399,258.9655;Float;False;5;0;FLOAT;0;False;1;FLOAT;-1;False;2;FLOAT;1;False;3;FLOAT;0;False;4;FLOAT;1;False;1;FLOAT;0 | |||
Node;AmplifyShaderEditor.FractNode;11;-660.9491,551.3666;Float;False;1;0;FLOAT;0;False;1;FLOAT;0 | |||
Node;AmplifyShaderEditor.ColorNode;1;-1611.683,-85.38494;Float;False;Property;_Albedo;Albedo;0;0;Create;True;0;0;False;0;1,1,1,1;0,0,0,0;True;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4 | |||
Node;AmplifyShaderEditor.DynamicAppendNode;29;-1546.767,229.1069;Float;False;FLOAT4;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;1;False;1;FLOAT4;0 | |||
Node;AmplifyShaderEditor.CeilOpNode;17;-506.1743,548.77;Float;False;1;0;FLOAT;0;False;1;FLOAT;0 | |||
Node;AmplifyShaderEditor.BlendOpsNode;32;-1150.732,187.9621;Float;False;Overlay;True;2;0;COLOR;0,0,0,0;False;1;FLOAT4;0,0,0,0;False;1;FLOAT4;0 | |||
Node;AmplifyShaderEditor.LerpOp;14;-512.2004,160.8983;Float;False;3;0;FLOAT4;0,0,0,0;False;1;FLOAT4;0,0,0,0;False;2;FLOAT;0;False;1;FLOAT4;0 | |||
Node;AmplifyShaderEditor.StandardSurfaceOutputNode;0;0,0;Float;False;True;6;Float;ASEMaterialInspector;0;0;Standard;Custom/Checkers;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;Back;0;False;-1;0;False;-1;False;0;False;-1;0;False;-1;False;0;Opaque;0.5;True;True;0;False;Opaque;;Geometry;All;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;0;False;-1;False;0;False;-1;255;False;-1;255;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;False;2;15;10;25;False;0.5;True;0;0;False;-1;0;False;-1;0;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;0;0,0,0,0;VertexOffset;True;False;Cylindrical;False;Relative;0;;-1;-1;-1;1;0;False;0;0;False;-1;-1;0;False;-1;0;0;0;False;0.1;False;-1;0;False;-1;16;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;2;FLOAT3;0,0,0;False;3;FLOAT;0;False;4;FLOAT;0;False;5;FLOAT;0;False;6;FLOAT3;0,0,0;False;7;FLOAT3;0,0,0;False;8;FLOAT;0;False;9;FLOAT;0;False;10;FLOAT;0;False;13;FLOAT3;0,0,0;False;11;FLOAT3;0,0,0;False;12;FLOAT3;0,0,0;False;14;FLOAT4;0,0,0,0;False;15;FLOAT3;0,0,0;False;0 | |||
WireConnection;25;0;3;2 | |||
WireConnection;26;0;3;3 | |||
WireConnection;24;0;3;1 | |||
WireConnection;7;0;24;0 | |||
WireConnection;7;1;25;0 | |||
WireConnection;7;2;26;0 | |||
WireConnection;9;0;7;0 | |||
WireConnection;9;1;10;0 | |||
WireConnection;33;0;27;0 | |||
WireConnection;11;0;9;0 | |||
WireConnection;29;0;33;0 | |||
WireConnection;29;1;33;0 | |||
WireConnection;29;2;33;0 | |||
WireConnection;17;0;11;0 | |||
WireConnection;32;0;1;0 | |||
WireConnection;32;1;29;0 | |||
WireConnection;14;0;1;0 | |||
WireConnection;14;1;32;0 | |||
WireConnection;14;2;17;0 | |||
WireConnection;0;0;14;0 | |||
ASEEND*/ | |||
//CHKSM=5CFACE81E59398461142413C2FF3AF7915B47B8C |
@ -0,0 +1,9 @@ | |||
fileFormatVersion: 2 | |||
guid: 419405570f32dd3418e2b05b3e7016d0 | |||
ShaderImporter: | |||
externalObjects: {} | |||
defaultTextures: [] | |||
nonModifiableTextures: [] | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -1,5 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: ca6cb8f5534ca26429bd3fb1ac52fde4 | |||
guid: ebc403a16f8803f4cb7b1fca470fa88d | |||
NativeFormatImporter: | |||
externalObjects: {} | |||
mainObjectFileID: 2100000 |
@ -1,77 +0,0 @@ | |||
%YAML 1.1 | |||
%TAG !u! tag:unity3d.com,2011: | |||
--- !u!21 &2100000 | |||
Material: | |||
serializedVersion: 6 | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
m_Name: Water_Obstacle | |||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} | |||
m_ShaderKeywords: | |||
m_LightmapFlags: 4 | |||
m_EnableInstancingVariants: 0 | |||
m_DoubleSidedGI: 0 | |||
m_CustomRenderQueue: -1 | |||
stringTagMap: {} | |||
disabledShaderPasses: [] | |||
m_SavedProperties: | |||
serializedVersion: 3 | |||
m_TexEnvs: | |||
- _BumpMap: | |||
m_Texture: {fileID: 0} | |||
m_Scale: {x: 1, y: 1} | |||
m_Offset: {x: 0, y: 0} | |||
- _DetailAlbedoMap: | |||
m_Texture: {fileID: 0} | |||
m_Scale: {x: 1, y: 1} | |||
m_Offset: {x: 0, y: 0} | |||
- _DetailMask: | |||
m_Texture: {fileID: 0} | |||
m_Scale: {x: 1, y: 1} | |||
m_Offset: {x: 0, y: 0} | |||
- _DetailNormalMap: | |||
m_Texture: {fileID: 0} | |||
m_Scale: {x: 1, y: 1} | |||
m_Offset: {x: 0, y: 0} | |||
- _EmissionMap: | |||
m_Texture: {fileID: 0} | |||
m_Scale: {x: 1, y: 1} | |||
m_Offset: {x: 0, y: 0} | |||
- _MainTex: | |||
m_Texture: {fileID: 0} | |||
m_Scale: {x: 1, y: 1} | |||
m_Offset: {x: 0, y: 0} | |||
- _MetallicGlossMap: | |||
m_Texture: {fileID: 0} | |||
m_Scale: {x: 1, y: 1} | |||
m_Offset: {x: 0, y: 0} | |||
- _OcclusionMap: | |||
m_Texture: {fileID: 0} | |||
m_Scale: {x: 1, y: 1} | |||
m_Offset: {x: 0, y: 0} | |||
- _ParallaxMap: | |||
m_Texture: {fileID: 0} | |||
m_Scale: {x: 1, y: 1} | |||
m_Offset: {x: 0, y: 0} | |||
m_Floats: | |||
- _BumpScale: 1 | |||
- _Cutoff: 0.5 | |||
- _DetailNormalMapScale: 1 | |||
- _DstBlend: 0 | |||
- _GlossMapScale: 1 | |||
- _Glossiness: 0.5 | |||
- _GlossyReflections: 1 | |||
- _Metallic: 0 | |||
- _Mode: 0 | |||
- _OcclusionStrength: 1 | |||
- _Parallax: 0.02 | |||
- _SmoothnessTextureChannel: 0 | |||
- _SpecularHighlights: 1 | |||
- _SrcBlend: 1 | |||
- _UVSec: 0 | |||
- _ZWrite: 1 | |||
m_Colors: | |||
- _Color: {r: 0, g: 1, b: 0.97520113, a: 1} | |||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} |
@ -1,5 +1,5 @@ | |||
fileFormatVersion: 2 | |||
guid: 646f348902cc6ca418957e91ad5ca9f6 | |||
guid: 4bd3cca6524bf894d9d57144c266e0ab | |||
NativeFormatImporter: | |||
externalObjects: {} | |||
mainObjectFileID: 2100000 |
@ -0,0 +1,107 @@ | |||
%YAML 1.1 | |||
%TAG !u! tag:unity3d.com,2011: | |||
--- !u!1 &850440798328794619 | |||
GameObject: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
serializedVersion: 6 | |||
m_Component: | |||
- component: {fileID: 850440798328794615} | |||
- component: {fileID: 850440798328794614} | |||
- component: {fileID: 850440798328794617} | |||
- component: {fileID: 850440798328794616} | |||
- component: {fileID: 5839339466837427850} | |||
m_Layer: 0 | |||
m_Name: Floor | |||
m_TagString: Untagged | |||
m_Icon: {fileID: 0} | |||
m_NavMeshLayer: 0 | |||
m_StaticEditorFlags: 0 | |||
m_IsActive: 1 | |||
--- !u!4 &850440798328794615 | |||
Transform: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
m_GameObject: {fileID: 850440798328794619} | |||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} | |||
m_LocalPosition: {x: 5, y: 0, z: -2} | |||
m_LocalScale: {x: 1, y: 1, z: 1} | |||
m_Children: [] | |||
m_Father: {fileID: 0} | |||
m_RootOrder: 0 | |||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | |||
--- !u!33 &850440798328794614 | |||
MeshFilter: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
m_GameObject: {fileID: 850440798328794619} | |||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} | |||
--- !u!23 &850440798328794617 | |||
MeshRenderer: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
m_GameObject: {fileID: 850440798328794619} | |||
m_Enabled: 1 | |||
m_CastShadows: 1 | |||
m_ReceiveShadows: 1 | |||
m_DynamicOccludee: 1 | |||
m_MotionVectors: 1 | |||
m_LightProbeUsage: 1 | |||
m_ReflectionProbeUsage: 1 | |||
m_RenderingLayerMask: 1 | |||
m_RendererPriority: 0 | |||
m_Materials: | |||
- {fileID: 2100000, guid: 9432cd4a3bec3ba429cf77ce16ff21de, type: 2} | |||
m_StaticBatchInfo: | |||
firstSubMesh: 0 | |||
subMeshCount: 0 | |||
m_StaticBatchRoot: {fileID: 0} | |||
m_ProbeAnchor: {fileID: 0} | |||
m_LightProbeVolumeOverride: {fileID: 0} | |||
m_ScaleInLightmap: 1 | |||
m_PreserveUVs: 0 | |||
m_IgnoreNormalsForChartDetection: 0 | |||
m_ImportantGI: 0 | |||
m_StitchLightmapSeams: 0 | |||
m_SelectedEditorRenderState: 3 | |||
m_MinimumChartSize: 4 | |||
m_AutoUVMaxDistance: 0.5 | |||
m_AutoUVMaxAngle: 89 | |||
m_LightmapParameters: {fileID: 0} | |||
m_SortingLayerID: 0 | |||
m_SortingLayer: 0 | |||
m_SortingOrder: 0 | |||
--- !u!65 &850440798328794616 | |||
BoxCollider: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
m_GameObject: {fileID: 850440798328794619} | |||
m_Material: {fileID: 0} | |||
m_IsTrigger: 0 | |||
m_Enabled: 1 | |||
serializedVersion: 2 | |||
m_Size: {x: 1, y: 1, z: 1} | |||
m_Center: {x: 0, y: 0, z: 0} | |||
--- !u!114 &5839339466837427850 | |||
MonoBehaviour: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
m_GameObject: {fileID: 850440798328794619} | |||
m_Enabled: 1 | |||
m_EditorHideFlags: 0 | |||
m_Script: {fileID: 11500000, guid: 1a69d64be9f9e8543b4278d7f139f6f1, type: 3} | |||
m_Name: | |||
m_EditorClassIdentifier: | |||
VisualHeight: 1 |
@ -0,0 +1,7 @@ | |||
fileFormatVersion: 2 | |||
guid: bf82e6870e62966448210c1718aa3fb3 | |||
PrefabImporter: | |||
externalObjects: {} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -0,0 +1,161 @@ | |||
%YAML 1.1 | |||
%TAG !u! tag:unity3d.com,2011: | |||
--- !u!1 &4279579644699983385 | |||
GameObject: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
serializedVersion: 6 | |||
m_Component: | |||
- component: {fileID: 3849649800983057758} | |||
- component: {fileID: 1925304773042429509} | |||
- component: {fileID: 6418332130559562760} | |||
- component: {fileID: 9109582599275685986} | |||
m_Layer: 0 | |||
m_Name: Visual | |||
m_TagString: Untagged | |||
m_Icon: {fileID: 0} | |||
m_NavMeshLayer: 0 | |||
m_StaticEditorFlags: 0 | |||
m_IsActive: 1 | |||
--- !u!4 &3849649800983057758 | |||
Transform: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
m_GameObject: {fileID: 4279579644699983385} | |||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} | |||
m_LocalPosition: {x: 0, y: -0.25, z: 0} | |||
m_LocalScale: {x: 1, y: 0.5, z: 1} | |||
m_Children: [] | |||
m_Father: {fileID: 5857971677613878141} | |||
m_RootOrder: 0 | |||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | |||
--- !u!33 &1925304773042429509 | |||
MeshFilter: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
m_GameObject: {fileID: 4279579644699983385} | |||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} | |||
--- !u!23 &6418332130559562760 | |||
MeshRenderer: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
m_GameObject: {fileID: 4279579644699983385} | |||
m_Enabled: 1 | |||
m_CastShadows: 1 | |||
m_ReceiveShadows: 1 | |||
m_DynamicOccludee: 1 | |||
m_MotionVectors: 1 | |||
m_LightProbeUsage: 1 | |||
m_ReflectionProbeUsage: 1 | |||
m_RenderingLayerMask: 1 | |||
m_RendererPriority: 0 | |||
m_Materials: | |||
- {fileID: 2100000, guid: 4bd3cca6524bf894d9d57144c266e0ab, type: 2} | |||
m_StaticBatchInfo: | |||
firstSubMesh: 0 | |||
subMeshCount: 0 | |||
m_StaticBatchRoot: {fileID: 0} | |||
m_ProbeAnchor: {fileID: 0} | |||
m_LightProbeVolumeOverride: {fileID: 0} | |||
m_ScaleInLightmap: 1 | |||
m_PreserveUVs: 0 | |||
m_IgnoreNormalsForChartDetection: 0 | |||
m_ImportantGI: 0 | |||
m_StitchLightmapSeams: 0 | |||
m_SelectedEditorRenderState: 3 | |||
m_MinimumChartSize: 4 | |||
m_AutoUVMaxDistance: 0.5 | |||
m_AutoUVMaxAngle: 89 | |||
m_LightmapParameters: {fileID: 0} | |||
m_SortingLayerID: 0 | |||
m_SortingLayer: 0 | |||
m_SortingOrder: 0 | |||
--- !u!65 &9109582599275685986 | |||
BoxCollider: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
m_GameObject: {fileID: 4279579644699983385} | |||
m_Material: {fileID: 0} | |||
m_IsTrigger: 0 | |||
m_Enabled: 1 | |||
serializedVersion: 2 | |||
m_Size: {x: 1, y: 1, z: 1} | |||
m_Center: {x: 0, y: 0, z: 0} | |||
--- !u!1 &5857971677613878113 | |||
GameObject: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
serializedVersion: 6 | |||
m_Component: | |||
- component: {fileID: 5857971677613878141} | |||
- component: {fileID: 5857971677613878114} | |||
- component: {fileID: 5857971677613878112} | |||
- component: {fileID: 172200333729527278} | |||
m_Layer: 0 | |||
m_Name: Stump | |||
m_TagString: Untagged | |||
m_Icon: {fileID: 0} | |||
m_NavMeshLayer: 0 | |||
m_StaticEditorFlags: 0 | |||
m_IsActive: 1 | |||
--- !u!4 &5857971677613878141 | |||
Transform: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
m_GameObject: {fileID: 5857971677613878113} | |||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} | |||
m_LocalPosition: {x: 3, y: 0.5, z: -2} | |||
m_LocalScale: {x: 1, y: 1, z: 1} | |||
m_Children: | |||
- {fileID: 3849649800983057758} | |||
m_Father: {fileID: 0} | |||
m_RootOrder: 0 | |||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | |||
--- !u!33 &5857971677613878114 | |||
MeshFilter: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
m_GameObject: {fileID: 5857971677613878113} | |||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} | |||
--- !u!65 &5857971677613878112 | |||
BoxCollider: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
m_GameObject: {fileID: 5857971677613878113} | |||
m_Material: {fileID: 0} | |||
m_IsTrigger: 0 | |||
m_Enabled: 1 | |||
serializedVersion: 2 | |||
m_Size: {x: 1, y: 1, z: 1} | |||
m_Center: {x: 0, y: 0, z: 0} | |||
--- !u!114 &172200333729527278 | |||
MonoBehaviour: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
m_GameObject: {fileID: 5857971677613878113} | |||
m_Enabled: 1 | |||
m_EditorHideFlags: 0 | |||
m_Script: {fileID: 11500000, guid: 1a69d64be9f9e8543b4278d7f139f6f1, type: 3} | |||
m_Name: | |||
m_EditorClassIdentifier: | |||
VisualHeight: 0.5 |
@ -0,0 +1,7 @@ | |||
fileFormatVersion: 2 | |||
guid: 294b606c3a106394bbb96600703a5a0a | |||
PrefabImporter: | |||
externalObjects: {} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -0,0 +1,108 @@ | |||
%YAML 1.1 | |||
%TAG !u! tag:unity3d.com,2011: | |||
--- !u!1 &9118974935492818487 | |||
GameObject: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
serializedVersion: 6 | |||
m_Component: | |||
- component: {fileID: 9118974935492818475} | |||
- component: {fileID: 9118974935492818474} | |||
- component: {fileID: 9118974935492818485} | |||
- component: {fileID: 9118974935492818484} | |||
- component: {fileID: 7668614157595083013} | |||
m_Layer: 0 | |||
m_Name: Water | |||
m_TagString: Untagged | |||
m_Icon: {fileID: 0} | |||
m_NavMeshLayer: 0 | |||
m_StaticEditorFlags: 0 | |||
m_IsActive: 1 | |||
--- !u!4 &9118974935492818475 | |||
Transform: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
m_GameObject: {fileID: 9118974935492818487} | |||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} | |||
m_LocalPosition: {x: 6, y: 0, z: -2} | |||
m_LocalScale: {x: 1, y: 1, z: 1} | |||
m_Children: [] | |||
m_Father: {fileID: 0} | |||
m_RootOrder: 0 | |||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | |||
--- !u!33 &9118974935492818474 | |||
MeshFilter: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
m_GameObject: {fileID: 9118974935492818487} | |||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} | |||
--- !u!23 &9118974935492818485 | |||
MeshRenderer: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
m_GameObject: {fileID: 9118974935492818487} | |||
m_Enabled: 1 | |||
m_CastShadows: 1 | |||
m_ReceiveShadows: 1 | |||
m_DynamicOccludee: 1 | |||
m_MotionVectors: 1 | |||
m_LightProbeUsage: 1 | |||
m_ReflectionProbeUsage: 1 | |||
m_RenderingLayerMask: 1 | |||
m_RendererPriority: 0 | |||
m_Materials: | |||
- {fileID: 2100000, guid: ebc403a16f8803f4cb7b1fca470fa88d, type: 2} | |||
m_StaticBatchInfo: | |||
firstSubMesh: 0 | |||
subMeshCount: 0 | |||
m_StaticBatchRoot: {fileID: 0} | |||
m_ProbeAnchor: {fileID: 0} | |||
m_LightProbeVolumeOverride: {fileID: 0} | |||
m_ScaleInLightmap: 1 | |||
m_PreserveUVs: 0 | |||
m_IgnoreNormalsForChartDetection: 0 | |||
m_ImportantGI: 0 | |||
m_StitchLightmapSeams: 0 | |||
m_SelectedEditorRenderState: 3 | |||
m_MinimumChartSize: 4 | |||
m_AutoUVMaxDistance: 0.5 | |||
m_AutoUVMaxAngle: 89 | |||
m_LightmapParameters: {fileID: 0} | |||
m_SortingLayerID: 0 | |||
m_SortingLayer: 0 | |||
m_SortingOrder: 0 | |||
--- !u!65 &9118974935492818484 | |||
BoxCollider: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
m_GameObject: {fileID: 9118974935492818487} | |||
m_Material: {fileID: 0} | |||
m_IsTrigger: 0 | |||
m_Enabled: 1 | |||
serializedVersion: 2 | |||
m_Size: {x: 1, y: 1, z: 1} | |||
m_Center: {x: 0, y: 0, z: 0} | |||
--- !u!114 &7668614157595083013 | |||
MonoBehaviour: | |||
m_ObjectHideFlags: 0 | |||
m_CorrespondingSourceObject: {fileID: 0} | |||
m_PrefabInstance: {fileID: 0} | |||
m_PrefabAsset: {fileID: 0} | |||
m_GameObject: {fileID: 9118974935492818487} | |||
m_Enabled: 1 | |||
m_EditorHideFlags: 0 | |||
m_Script: {fileID: 11500000, guid: 1a69d64be9f9e8543b4278d7f139f6f1, type: 3} | |||
m_Name: | |||
m_EditorClassIdentifier: | |||
VisualHeight: 1 | |||
_isWalkable: 0 |
@ -0,0 +1,7 @@ | |||
fileFormatVersion: 2 | |||
guid: 948d960b31fbccb4e83f20ef530bba85 | |||
PrefabImporter: | |||
externalObjects: {} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -0,0 +1,102 @@ | |||
using System.Collections; | |||
using System.Collections.Generic; | |||
using UnityEngine; | |||
using System.Linq; | |||
/// <summary> | |||
/// Class which defines blocks around the level | |||
/// </summary> | |||
[RequireComponent(typeof(BoxCollider))] | |||
public class Block : MonoBehaviour | |||
{ | |||
#region Inspector Fields | |||
[SerializeField] | |||
[Tooltip("Offset from the top of the block from which a character should stand")] | |||
private Vector3 VisualOffset = Vector3.zero; | |||
[SerializeField] | |||
[Tooltip("Can this type of block be walked on")] | |||
private bool _isWalkable = true; | |||
#endregion InspectorFields | |||
#region ReadOnly Properties | |||
/// <summary> | |||
/// Blocks position in global space | |||
/// </summary> | |||
public Vector3 position { get { return transform.position; } } | |||
/// <summary> | |||
/// Position character should stand in global space | |||
/// </summary> | |||
public Vector3 VisualPosition { get { return position + VisualOffset + Vector3.up * 0.5f; } } | |||
#endregion ReadOnly Properties | |||
#region Public Functions | |||
/// <summary> | |||
/// Is a block valid to walk on | |||
/// </summary> | |||
/// <param name="layerMask">Layers to check for when checking for blocks above</param> | |||
/// <returns></returns> | |||
public bool isWalkable(LayerMask layerMask) | |||
{ | |||
//checks if there is no block above this one and that this is tagged as walkable | |||
return (_isWalkable && !isBlockAtPosition(position + Vector3.up, 1, layerMask)); | |||
} | |||
#endregion Public Functions | |||
#region Static Functions | |||
/// <summary> | |||
/// Checks if there is a block at supplied position | |||
/// </summary> | |||
/// <param name="position">position to check at</param> | |||
/// <param name="Scale">Scale of block. (should be 1)</param> | |||
/// <param name="layerMask">Layers to check on</param> | |||
/// <param name="hit">Block hit</param> | |||
/// <returns>if a block is at position</returns> | |||
public static bool isBlockAtPosition(Vector3 position, float Scale, LayerMask layerMask, out Block hit) | |||
{ | |||
//Turn scale into halfextent and shrink a bit so it doesn't hit bordering blocks | |||
Vector3 halfExtent = Vector3.one * ((Scale - 0.1f) / 2); | |||
//Get every collider which is at position | |||
Collider[] cols = Physics.OverlapBox(position, halfExtent, Quaternion.identity, layerMask); | |||
//Filter colliders for only GameObjects with an Block component | |||
Block[] blocks = cols.Where(p => p.GetComponent<Block>() != null).Select(p => p.GetComponent<Block>()).ToArray(); | |||
//Draw cube, for visuals | |||
DebugExtensions.DrawCube(position, halfExtent, Color.cyan, 1, false); | |||
//if didn't hit anyblocks return false | |||
if (blocks.Length == 0) | |||
{ | |||
hit = null; | |||
return false; | |||
} | |||
else | |||
{ | |||
//else get the closest block to disered position, (in case we hit mulitple blocks) | |||
hit = Utility.minBy(blocks, p => Vector3.Distance(p.transform.position, position)); | |||
return true; | |||
} | |||
} | |||
/// <summary> | |||
/// Checks if there is a block at supplied position | |||
/// </summary> | |||
/// <param name="position">position to check at</param> | |||
/// <param name="Scale">Scale of block. (should be 1)</param> | |||
/// <param name="layerMask">Layers to check on</param> | |||
/// <returns>if a block is at position</returns> | |||
public static bool isBlockAtPosition(Vector3 position, float scale, LayerMask layerMask) | |||
{ | |||
//Return Overloaded function above | |||
Block hit; | |||
return (isBlockAtPosition(position, scale, layerMask, out hit)); | |||
} | |||
#endregion | |||
} |
@ -0,0 +1,11 @@ | |||
fileFormatVersion: 2 | |||
guid: 1a69d64be9f9e8543b4278d7f139f6f1 | |||
MonoImporter: | |||
externalObjects: {} | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -0,0 +1,149 @@ | |||
using System.Collections; | |||
using System.Collections.Generic; | |||
using UnityEngine; | |||
public class Character : MonoBehaviour | |||
{ | |||
#region Inspector Fields | |||
[SerializeField] | |||
[Tooltip("Will move to this block at start, else will try and find a block below")] | |||
private Block CurrentBlock; | |||
[SerializeField] | |||
[Tooltip("Layers to ignore when checking for blocks")] | |||
private LayerMask Ignore; | |||
#endregion Inspector Fields | |||
#region Unity Functions | |||
private void Awake() | |||
{ | |||
//If no starting block find one below it | |||
if (CurrentBlock == null) | |||
Block.isBlockAtPosition(transform.position + Vector3.down/2, 1, ~Ignore, out CurrentBlock); | |||
//move to starting block | |||
transform.position = CurrentBlock.VisualPosition; | |||
} | |||
#endregion Unity Functions | |||
#region Class Implementation | |||
/// <summary> | |||
/// Moves one block in specefied direction, Can walk off obstacles | |||
/// </summary> | |||
/// <param name="direction">direction to walk</param> | |||
/// <remarks>Technically is same as JumpLong(1) but kept seperate to avoid confusion</remarks> | |||
public void Move(Direction direction) | |||
{ | |||
//setting up variables | |||
Vector3 position = CurrentBlock.position + direction.ToVector(transform); // position wanted | |||
Block hit; //output of block detection | |||
Block moveTo = CurrentBlock; //block we'll actually move to | |||
//if move is obstucted no where to move | |||
if (Block.isBlockAtPosition(position + Vector3.up, 1, ~Ignore)) | |||
return; | |||
//If block at Position is walkable set it to moveTo | |||
if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) | |||
moveTo = hit; | |||
//else if block down one is walkable | |||
else if (Block.isBlockAtPosition(position + Vector3.down, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) | |||
moveTo = hit; | |||
//set current block && move | |||
CurrentBlock = moveTo; | |||
transform.position = CurrentBlock.VisualPosition; | |||
} | |||
/// <summary> | |||
/// Rotates to point in specific direction based on current direction | |||
/// </summary> | |||
/// <param name="direction">Local direction to point</param> | |||
public void Rotate(Direction direction) | |||
{ | |||
transform.forward = direction.ToVector(transform); | |||
} | |||
/// <summary> | |||
/// Jumps in specefied direction, picks between Long Jump and Jumping up | |||
/// </summary> | |||
/// <param name="direction">Direction to Jump</param> | |||
public void Jump(Direction direction) | |||
{ | |||
//if there is a block infront JumpUp else LongJump | |||
if (Block.isBlockAtPosition(CurrentBlock.position + direction.ToVector(transform) + Vector3.up, 1, ~Ignore)) | |||
JumpUp(direction); | |||
else | |||
JumpLong(direction); | |||
} | |||
#endregion Class Implementation | |||
#region Private Functions | |||
/// <summary> | |||
/// Jumps up obstacle of specific height. Jumps as high as possible | |||
/// </summary> | |||
/// <param name="direction">Direction of obstacle</param> | |||
/// <param name="height">max height</param> | |||
private void JumpUp(Direction direction,int height = 1) | |||
{ | |||
//setting up variables | |||
Vector3 position; // position wanted | |||
Block hit; //output of block detection | |||
Block moveTo = CurrentBlock; //block we'll actually move to | |||
//Check blocks in going up then move to the heighest walkable one | |||
for (int i = 0; i <= height; i++) | |||
{ | |||
//next position up the tower | |||
position = CurrentBlock.position + direction.ToVector(transform) + (Vector3.up * i); | |||
//if block is walkable set it to last known position | |||
if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) | |||
moveTo = hit; | |||
} | |||
//set current block && move | |||
CurrentBlock = moveTo; | |||
transform.position = CurrentBlock.VisualPosition; | |||
} | |||
/// <summary> | |||
/// Long jumps forward a specified distance. Can Jump gaps. Stops at obstruction | |||
/// </summary> | |||
/// <param name="direction">Direction to Jump</param> | |||
/// <param name="Distance">Max distance</param> | |||
private void JumpLong(Direction direction, int Distance = 2) | |||
{ | |||
//setting up variables | |||
Vector3 position; // position wanted | |||
Block hit; //output of block detection | |||
Block moveTo = CurrentBlock; //block we'll actually move to | |||
//Check blocks in front until we hit an obstruction or went the distance | |||
for (int i = 1; i <= Distance; i++) | |||
{ | |||
//Next position to MoveTo | |||
position = CurrentBlock.position + (direction.ToVector(transform) * i); | |||
//if jump is obstructed, stop and go to last known block | |||
if (Block.isBlockAtPosition(position + Vector3.up, 1, ~Ignore)) | |||
break; | |||
//If block at Position is walkable set it to last known position | |||
if (Block.isBlockAtPosition(position, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) | |||
moveTo = hit; | |||
//else if block down one is walkable | |||
else if (Block.isBlockAtPosition(position + Vector3.down, 1, ~Ignore, out hit) && hit.isWalkable(~Ignore)) | |||
moveTo = hit; | |||
}//end for | |||
//Set Current Block and move | |||
CurrentBlock = moveTo; | |||
transform.position = CurrentBlock.VisualPosition; | |||
} | |||
#endregion Private Functions | |||
} |
@ -0,0 +1,50 @@ | |||
using System.Collections; | |||
using System.Collections.Generic; | |||
using UnityEngine; | |||
/// <summary> | |||
/// Debug class for controlling a character with keyboard input | |||
/// </summary> | |||
public class KeyboardInput : MonoBehaviour | |||
{ | |||
#region Inspector Fields | |||
[SerializeField] | |||
[Tooltip("Character to move")] | |||
private Character character; | |||
#endregion Unity Functions | |||
#region Unity Functions | |||
// Update is called once per frame | |||
void Update() | |||
{ | |||
if (character == null) | |||
return; | |||
if (Input.GetKeyDown(KeyCode.LeftArrow)) | |||
{ | |||
character.Rotate(Direction.Left); | |||
} | |||
if (Input.GetKeyDown(KeyCode.RightArrow)) | |||
{ | |||
character.Rotate(Direction.Right); | |||
} | |||
if (Input.GetKeyDown(KeyCode.UpArrow)) | |||
{ | |||
character.Move(Direction.Forward); | |||
} | |||
if (Input.GetKeyDown(KeyCode.Space)) | |||
{ | |||
character.Jump(Direction.Forward); | |||
} | |||
} | |||
//if character is empty check on object for it | |||
private void OnValidate() | |||
{ | |||
if (character == null) | |||
character = GetComponent<Character>(); | |||
} | |||
#endregion Unity Functions | |||
} |
@ -0,0 +1,11 @@ | |||
fileFormatVersion: 2 | |||
guid: 5b3919f20216e804e94750d37d069b8e | |||
MonoImporter: | |||
externalObjects: {} | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -0,0 +1,71 @@ | |||
using System.Collections; | |||
using System.Collections.Generic; | |||
using UnityEngine; | |||
/// <summary> | |||
/// Class which reads a a list of logic blocks and applies to a character | |||
/// </summary> | |||
public class BlockReader : MonoBehaviour | |||
{ | |||
#region Inspector Variables | |||
[SerializeField] | |||
[Tooltip("Character to be controllered by the Logic Chain")] | |||
protected Character character; | |||
[SerializeField] | |||
[Tooltip("List of LogicBlocks which will affected this character")] | |||
protected List<LogicBlock> LogicChain; | |||
#endregion Inspector Variables | |||
#region Read-only Variables | |||
/// <summary> | |||
/// returns true if all LogicBlocks in LogicChain have been completed | |||
/// </summary> | |||
public bool Finished { get { return currentBlockIndex >= LogicChain.Count; } } | |||
#endregion Read-only Variables | |||
#region Private Variables | |||
private int currentBlockIndex;//Block currently on | |||
#endregion Private Variables | |||
#region Class Implementation | |||
/// <summary> | |||
/// Resets Block reader; | |||
/// </summary> | |||
public void Reset() | |||
{ | |||
currentBlockIndex = 0; | |||
} | |||
/// <summary> | |||
/// Reads the current block in the logic chain | |||
/// </summary> | |||
/// <returns>Returns false if other readers should wait for this one to run again</returns> | |||
[ContextMenu("Do Read")] | |||
public bool Read() | |||
{ | |||
//return that this is done if no more blocks left in chain | |||
if (LogicChain.Count <= currentBlockIndex) | |||
return true; | |||
//get current Block | |||
LogicBlock currentBlock = LogicChain[currentBlockIndex]; | |||
//apply blocks to character | |||
currentBlock.Run(character); | |||
//if the block is finished reset it and move on to next one | |||
//(it might not be finished if it is a for loop or something) | |||
if (currentBlock.isFinished()) | |||
{ | |||
currentBlock.Reset(); | |||
currentBlockIndex++; | |||
} | |||
//Should other readers wait for this one | |||
return (currentBlock.isFinished() || !currentBlock.WaitUntilFinished); | |||
} | |||
#endregion | |||
} | |||
@ -0,0 +1,11 @@ | |||
fileFormatVersion: 2 | |||
guid: 5af5d8d7710c465468e79064046bb0e1 | |||
MonoImporter: | |||
externalObjects: {} | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -1,57 +0,0 @@ | |||
//Attach this script to your GameObject. This GameObject doesn’t need to have a Collider component | |||
//Set the Layer Mask field in the Inspector to the layer you would like to see collisions in (set to Everything if you are unsure). | |||
//Create a second Gameobject for testing collisions. Make sure your GameObject has a Collider component (if it doesn’t, click on | |||
//the Add Component button in the GameObject’s Inspector, and go to Physics>Box Collider). | |||
//Place it so it is overlapping your other GameObject. | |||
//Press Play to see the console output the name of your second GameObject | |||
//This script uses the OverlapBox that creates an invisible Box Collider that detects multiple collisions with other colliders. | |||
//The OverlapBox in this case is the same size and position as the GameObject you attach it to (acting as a replacement for the BoxCollider component). | |||
using System.Collections; | |||
using System.Collections.Generic; | |||
using UnityEngine; | |||
public class OverlapBoxExample : MonoBehaviour | |||
{ | |||
bool m_Started; | |||
public LayerMask m_LayerMask; | |||
public Collider[] hitColliders; | |||
void Start() | |||
{ | |||
//Use this to ensure that the Gizmos are being drawn when in Play Mode. | |||
m_Started = true; | |||
} | |||
void FixedUpdate() | |||
{ | |||
MyCollisions(); | |||
} | |||
void MyCollisions() | |||
{ | |||
//Use the OverlapBox to detect if there are any other colliders within this box area. | |||
//Use the GameObject's centre, half the size (as a radius) and rotation. This creates an invisible box around your GameObject. | |||
hitColliders = Physics.OverlapBox(gameObject.transform.position, transform.localScale / 2, Quaternion.identity, m_LayerMask); | |||
int i = 0; | |||
//Check when there is a new collider coming into contact with the box | |||
while (i < hitColliders.Length) | |||
{ | |||
//Output all of the collider names | |||
//Debug.Log("Hit : " + hitColliders[i].name + i); | |||
//Increase the number of Colliders in the array | |||
i++; | |||
} | |||
} | |||
//Draw the Box Overlap as a gizmo to show where it currently is testing. Click the Gizmos button to see this | |||
void OnDrawGizmos() | |||
{ | |||
Gizmos.color = Color.red; | |||
//Check that it is being run in Play Mode, so it doesn't try to draw this in Editor mode | |||
if (m_Started) | |||
//Draw a cube where the OverlapBox is (positioned where your GameObject is as well as a size) | |||
Gizmos.DrawWireCube(transform.position, transform.localScale); | |||
} | |||
} |
@ -0,0 +1,8 @@ | |||
fileFormatVersion: 2 | |||
guid: db95b4dbea436d94cae78279067b9588 | |||
folderAsset: yes | |||
DefaultImporter: | |||
externalObjects: {} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -0,0 +1,57 @@ | |||
using System.Collections; | |||
using System.Collections.Generic; | |||
using UnityEngine; | |||
/// <summary> | |||
/// Static class for adding More Debug funtions | |||
/// </summary> | |||
public static class DebugExtensions | |||
{ | |||
/// <summary> | |||
/// Draws wireframe cube in scene view | |||
/// </summary> | |||
/// <param name="Position">Centre of cube</param> | |||
/// <param name="Extent">extent of cube (half of size)</param> | |||
/// <param name="color">Color of lines</param> | |||
/// <param name="duration">Amount of time cube is displayed</param> | |||
/// <param name="depthTest">Should cube be obsured by otherobjects</param> | |||
public static void DrawCube(Vector3 Position, Vector3 Extent, Color color, float duration, bool depthTest = true) | |||
{ | |||
Vector3 min = Position - Extent; | |||
Vector3 max = Position + Extent; | |||
//Draw bottom Square | |||
Debug.DrawLine(new Vector3(min.x, min.y, min.z), new Vector3(min.x, min.y, max.z), color, duration, depthTest); | |||
Debug.DrawLine(new Vector3(min.x, min.y, max.z), new Vector3(max.x, min.y, max.z), color, duration, depthTest); | |||
Debug.DrawLine(new Vector3(max.x, min.y, max.z), new Vector3(max.x, min.y, min.z), color, duration, depthTest); | |||
Debug.DrawLine(new Vector3(max.x, min.y, min.z), new Vector3(min.x, min.y, min.z), color, duration, depthTest); | |||
//top square | |||
Debug.DrawLine(new Vector3(min.x, max.y, min.z), new Vector3(min.x, max.y, max.z), color, duration, depthTest); | |||
Debug.DrawLine(new Vector3(min.x, max.y, max.z), new Vector3(max.x, max.y, max.z), color, duration, depthTest); | |||
Debug.DrawLine(new Vector3(max.x, max.y, max.z), new Vector3(max.x, max.y, min.z), color, duration, depthTest); | |||
Debug.DrawLine(new Vector3(max.x, max.y, min.z), new Vector3(min.x, max.y, min.z), color, duration, depthTest); | |||
//connect top and bottom | |||
Debug.DrawLine(new Vector3(min.x, min.y, min.z), new Vector3(min.x, max.y, min.z), color, duration, depthTest); | |||
Debug.DrawLine(new Vector3(min.x, min.y, max.z), new Vector3(min.x, max.y, max.z), color, duration, depthTest); | |||
Debug.DrawLine(new Vector3(max.x, min.y, max.z), new Vector3(max.x, max.y, max.z), color, duration, depthTest); | |||
Debug.DrawLine(new Vector3(max.x, min.y, min.z), new Vector3(max.x, max.y, min.z), color, duration, depthTest); | |||
} | |||
/// <summary> | |||
/// Draws wireframe cube in scene view | |||
/// </summary> | |||
/// <param name="Position">Centre of cube</param> | |||
/// <param name="Extent">extent of cube (half of size)</param> | |||
/// <param name="color">Color of lines</param> | |||
/// <param name="duration">Amount of time cube is displayed</param> | |||
public static void DrawCube(Vector3 Position, float Extent, Color color, float duration) | |||
{ | |||
//Call overload funtion | |||
DrawCube(Position, Vector3.one * Extent, color, duration); | |||
} | |||
}//End DebugExtentions |
@ -0,0 +1,11 @@ | |||
fileFormatVersion: 2 | |||
guid: 20d15368599080b4f9886be4cc16eb31 | |||
MonoImporter: | |||
externalObjects: {} | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -0,0 +1,3 @@ | |||
//Use this file to Global enums in | |||
public enum Direction { Left, Right,Forward, Back} |
@ -0,0 +1,11 @@ | |||
fileFormatVersion: 2 | |||
guid: 4ec7f5e9af1413644b582845cf918f61 | |||
MonoImporter: | |||
externalObjects: {} | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -0,0 +1,58 @@ | |||
using System.Collections; | |||
using System.Collections.Generic; | |||
using UnityEngine; | |||
/// <summary> | |||
/// Class used to write extension methodes in | |||
/// </summary> | |||
public static class ExtensionMethods | |||
{ | |||
/// <summary> | |||
/// Converts provided Direction to Global Vector3 | |||
/// </summary> | |||
/// <param name="direction">Direction to convert</param> | |||
/// <returns>Global Vector3 direction</returns> | |||
public static Vector3 ToVector(this Direction direction) | |||
{ | |||
switch (direction) | |||
{ | |||
case Direction.Forward: | |||
return Vector3.forward; | |||
case Direction.Right: | |||
return Vector3.right; | |||
case Direction.Back: | |||
return Vector3.back; | |||
case Direction.Left: | |||
return Vector3.left; | |||
default: | |||
return Vector3.zero; | |||
} | |||
} | |||
/// <summary> | |||
/// Converts provided Direction to local Vector3 | |||
/// </summary> | |||
/// <param name="direction">Direction to convert</param> | |||
/// <param name="transform">Transform to use as directions local space</param> | |||
/// <returns>Local Vector3 direction</returns> | |||
public static Vector3 ToVector(this Direction direction, Transform transform) | |||
{ | |||
switch (direction) | |||
{ | |||
case Direction.Forward: | |||
return transform.forward; | |||
case Direction.Right: | |||
return transform.right; | |||
case Direction.Back: | |||
return -transform.forward; | |||
case Direction.Left: | |||
return -transform.right; | |||
default: | |||
return Vector3.zero; | |||
} | |||
} | |||
} | |||
@ -0,0 +1,11 @@ | |||
fileFormatVersion: 2 | |||
guid: 276b5d9d762adf142bb540f0e20764fb | |||
MonoImporter: | |||
externalObjects: {} | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -0,0 +1,38 @@ | |||
using System.Collections; | |||
using System.Collections.Generic; | |||
using UnityEngine; | |||
using System.Linq; | |||
using System; | |||
/// <summary> | |||
/// Utility Class used for common methodes which don't fit in a class | |||
/// </summary> | |||
public static class Utility | |||
{ | |||
/// <summary> | |||
/// Gets the smallest item in an array based on the provided function | |||
/// </summary> | |||
/// <typeparam name="T">Array type</typeparam> | |||
/// <param name="values">Array to find smallest item in</param> | |||
/// <param name="predicate">What to compare items with</param> | |||
/// <returns></returns> | |||
public static T minBy<T>(T[] values, Func<T,IComparable> predicate) | |||
{ | |||
//if empty return null | |||
if (values.Length == 0) | |||
return default; | |||
//Define smallest value as first | |||
T min = values[0]; | |||
//compare all other values | |||
for (int i = 1; i < values.Length; i++) | |||
if (predicate(values[i]).CompareTo(predicate(min)) < 0) | |||
min = values[i]; | |||
//return | |||
return min; | |||
} | |||
} |
@ -0,0 +1,11 @@ | |||
fileFormatVersion: 2 | |||
guid: 054334daf4057254fa61f2ed76a38a93 | |||
MonoImporter: | |||
externalObjects: {} | |||
serializedVersion: 2 | |||
defaultReferences: [] | |||
executionOrder: 0 | |||
icon: {instanceID: 0} | |||
userData: | |||
assetBundleName: | |||
assetBundleVariant: |
@ -1,58 +0,0 @@ | |||
using System.Collections; | |||
using System.Collections.Generic; | |||
using UnityEngine; | |||
public class Character: MonoBehaviour | |||
{ | |||
bool move = true; | |||
bool floorFound = false; | |||
Vector3 halfJump = new Vector3 (1.0f, 0.5f, 1.0f); | |||
void Update () | |||
{ | |||
if (Input.GetKeyDown (KeyCode.LeftArrow)) { | |||
transform.rotation = Quaternion.Euler (transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y - 90, transform.rotation.eulerAngles.z); | |||
} | |||
if (Input.GetKeyDown (KeyCode.RightArrow)) { | |||
transform.rotation = Quaternion.Euler (transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y + 90, transform.rotation.eulerAngles.z); | |||
} | |||
if (Input.GetKeyDown (KeyCode.UpArrow)) { | |||
OverlapBoxExample childScript = this.transform.GetChild (2).GetComponent < OverlapBoxExample > (); | |||
if(transform.position.y < 1.5){ | |||
foreach (Collider x in childScript.hitColliders) { | |||
if (x.name == "Wall" || x.name == "Stump" || x.name == "Water") { | |||
move = false; | |||
break; | |||
} | |||
} | |||
if (move == true ) { | |||
transform.position -= transform.forward; | |||
} | |||
}else{ | |||
transform.position -= transform.forward; | |||
transform.position -= Vector3.Scale(halfJump , transform.up); | |||
} | |||
} | |||
if (Input.GetKeyUp (KeyCode.UpArrow)) { | |||
move = true; | |||
} | |||
if (Input.GetKeyDown (KeyCode.Space)) { | |||
OverlapBoxExample childScript = this.transform.GetChild (2).GetComponent < OverlapBoxExample > (); | |||
foreach (Collider x in childScript.hitColliders) { | |||
//Debug.Log(x.name); | |||
if (x.name == "Stump" && transform.position.y < 1.5) { | |||
transform.position -= transform.forward; | |||
transform.position += Vector3.Scale(halfJump , transform.up); | |||
break; | |||
} else if (x.name == "Water") { | |||
transform.position -= transform.forward; | |||
transform.position += Vector3.Scale(halfJump , transform.up); | |||
transform.position -= transform.forward; | |||
transform.position -= Vector3.Scale(halfJump , transform.up); | |||
break; | |||
} | |||
} | |||
} | |||
} | |||
} |
@ -1 +1 @@ | |||
m_EditorVersion: 2018.3.4f1 | |||
m_EditorVersion: 2018.3.7f1 |