From c12f4497fd7972964fe992c64c9d4c2d04e5a876 Mon Sep 17 00:00:00 2001 From: Samuel Date: Fri, 14 Aug 2015 12:22:10 -0400 Subject: [PATCH 1/2] - Updated Unity Layers - Refactoring rename Class TagManager to TagLayerManager - Added Layer Property in class Unit.cs - Updated method InitializeDefaultTagAndLayer in class ZombieSquad and VampireSquad - Layers now are instancied at run time if the user ommit to specify a layer by default the human layer is set to any gameObject that have an Unit.cs script attached to it's component. Idem for ZombieSquad and VampireSquad --- Assets/Scenes/sam_squad.unity | 62 +++++++++++++++++-- Assets/Scripts/Squad.cs | 4 +- Assets/Scripts/TagLayerManager.cs | 19 ++++++ ...anager.cs.meta => TagLayerManager.cs.meta} | 0 Assets/Scripts/TagManager.cs | 14 ----- Assets/Scripts/Unit.cs | 15 +++-- Assets/Scripts/VampireSquad.cs | 17 +++-- Assets/Scripts/ZombieSquad.cs | 15 +++-- ProjectSettings/DynamicsManager.asset | 2 +- ProjectSettings/ProjectVersion.txt | 2 +- ProjectSettings/QualitySettings.asset | 19 +----- ProjectSettings/TagManager.asset | 6 +- 12 files changed, 115 insertions(+), 60 deletions(-) create mode 100644 Assets/Scripts/TagLayerManager.cs rename Assets/Scripts/{TagManager.cs.meta => TagLayerManager.cs.meta} (100%) delete mode 100644 Assets/Scripts/TagManager.cs diff --git a/Assets/Scenes/sam_squad.unity b/Assets/Scenes/sam_squad.unity index 5860c2d..52fc804 100644 --- a/Assets/Scenes/sam_squad.unity +++ b/Assets/Scenes/sam_squad.unity @@ -138,6 +138,10 @@ Prefab: propertyPath: m_Materials.Array.data[0] value: objectReference: {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} + - target: {fileID: 5460952, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_IsKinematic + value: 0 + objectReference: {fileID: 0} m_RemovedComponents: - {fileID: 11449880, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} m_ParentPrefab: {fileID: 100100000, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} @@ -298,7 +302,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 2 + m_RootOrder: 3 --- !u!1 &550371263 GameObject: m_ObjectHideFlags: 0 @@ -358,7 +362,57 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 3 + m_RootOrder: 4 +--- !u!1001 &1070827265 +Prefab: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 421072, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_LocalPosition.x + value: 7.80999994 + objectReference: {fileID: 0} + - target: {fileID: 421072, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_LocalPosition.y + value: 5 + objectReference: {fileID: 0} + - target: {fileID: 421072, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 421072, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 421072, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 421072, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 421072, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 421072, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_RootOrder + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 11449880, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: defaultHp + value: 10050 + objectReference: {fileID: 0} + - target: {fileID: 159974, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + propertyPath: m_Name + value: Vampire (1) + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 100100000, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} + m_IsPrefabParent: 0 --- !u!1 &1191318663 stripped GameObject: m_PrefabParentObject: {fileID: 159974, guid: 55aad163f90cc4e40b686a69ba29569d, type: 2} @@ -533,7 +587,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 4 + m_RootOrder: 5 --- !u!1 &1740025638 GameObject: m_ObjectHideFlags: 0 @@ -606,4 +660,4 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 7 + m_RootOrder: 8 diff --git a/Assets/Scripts/Squad.cs b/Assets/Scripts/Squad.cs index 5a772b8..bd4b071 100644 --- a/Assets/Scripts/Squad.cs +++ b/Assets/Scripts/Squad.cs @@ -184,7 +184,7 @@ public class Squad : Unit humanUnit.Tag = Tag; // AddSoldier((VampireSquad) humanUnit) ) (VampireSquad or ZombieSquad) - if (Tag.Equals(TagManager.VampirePlayer)) + if (Tag.Equals(TagLayerManager.VampirePlayer)) { // add the vampire to the soldier list AddSoldier((VampireSquad) humanUnit); @@ -232,7 +232,7 @@ public class Squad : Unit //unit.Hp -= Attack; // we remove some hp of the unit that was targettedEnemySquad.ReceiveDamage(ComputeAttackDamage()); - Debug.Log("Attacked the ennemy : " + targettedEnemySquad.Tag); + Debug.Log("Attacked the enemy : " + targettedEnemySquad.Tag); } /// diff --git a/Assets/Scripts/TagLayerManager.cs b/Assets/Scripts/TagLayerManager.cs new file mode 100644 index 0000000..23f08b5 --- /dev/null +++ b/Assets/Scripts/TagLayerManager.cs @@ -0,0 +1,19 @@ +using System; +using UnityEngine; +using System.Collections; +using System.Linq; + +public class TagLayerManager : MonoBehaviour +{ + // Use this for initialization + private static readonly string[] availableTags = UnityEditorInternal.InternalEditorUtility.tags; + private static readonly string[] availableLayers = UnityEditorInternal.InternalEditorUtility.layers; + // TODO FIND A WAY TO ADD EXCEPTION ERROR IF THE USER OMMIT TO ADD TAGS!!! + public static string Human = availableTags[7]; + public static string VampirePlayer = availableTags[8]; + public static string ZombiePlayer = availableTags[9]; + // TODO remove hard coding layers + public static int HumanLayerIndex = 8; + public static int VampireLayerIndex = 9; + public static int ZombieLayerIndex = 10; +} diff --git a/Assets/Scripts/TagManager.cs.meta b/Assets/Scripts/TagLayerManager.cs.meta similarity index 100% rename from Assets/Scripts/TagManager.cs.meta rename to Assets/Scripts/TagLayerManager.cs.meta diff --git a/Assets/Scripts/TagManager.cs b/Assets/Scripts/TagManager.cs deleted file mode 100644 index 9ea639d..0000000 --- a/Assets/Scripts/TagManager.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using UnityEngine; -using System.Collections; -using System.Linq; - -public class TagManager : MonoBehaviour -{ - // Use this for initialization - private static readonly String[] availableTags = UnityEditorInternal.InternalEditorUtility.tags; - // TODO FIND A WAY TO ADD EXCEPTION ERROR IF THE USER OMMIT TO ADD TAGS!!! - public static String Human = availableTags[7]; - public static String VampirePlayer = availableTags[8]; - public static String ZombiePlayer = availableTags[9]; -} diff --git a/Assets/Scripts/Unit.cs b/Assets/Scripts/Unit.cs index 0d15744..b110e3e 100644 --- a/Assets/Scripts/Unit.cs +++ b/Assets/Scripts/Unit.cs @@ -14,12 +14,11 @@ public class Unit : MonoBehaviour void Start () { IsCaptured = false; - // initialize default hp Hp = defaultHp; - // initialize default attack Attack = defaultAttack; - // initialize default team // initialize default specie + Tag = TagLayerManager.Human; + Layer = TagLayerManager.HumanLayerIndex; IsDead = false; } @@ -72,16 +71,20 @@ public class Unit : MonoBehaviour } public int Attack { get; set; } - //public bool isAlly { get; set; } - //public bool isHuman { get; set; } public bool IsDead { get; set; } - public String Tag + public string Tag { get { return this.gameObject.tag; } set { gameObject.tag = value; } } + public int Layer + { + get { return this.gameObject.layer; } + set { gameObject.layer = value; } + } + #endregion } diff --git a/Assets/Scripts/VampireSquad.cs b/Assets/Scripts/VampireSquad.cs index bf67dc3..30a48dc 100644 --- a/Assets/Scripts/VampireSquad.cs +++ b/Assets/Scripts/VampireSquad.cs @@ -11,7 +11,7 @@ public class VampireSquad : Squad void Start () { InitializeSquad(); - InitializeDefaultTag(); + InitializeDefaultTagAndLayer(); // initialize default hp //Hp = defaultHp; // initialize default attack @@ -31,22 +31,27 @@ public class VampireSquad : Squad } } - private void InitializeDefaultTag() + private void InitializeDefaultTagAndLayer() { try { - this.Tag = TagManager.VampirePlayer; // set the tag to player 1 + this.Tag = TagLayerManager.VampirePlayer; // set the tag to player 1 + this.Layer = TagLayerManager.VampireLayerIndex; } catch (IndexOutOfRangeException ex) { Debug.LogError( "Please set a vampire Tag, check the Tag & layers in the inspector!\n" + ex ); } - // set the tag of the gameObject to vampire + // set the tag and the layer of the gameObject to vampire if (this.gameObject.tag != Tag) { this.gameObject.tag = Tag; - } + } + if (this.gameObject.layer != Layer) + { + this.gameObject.layer = Layer; + } } /*void CaptureHuman(Unit unit) @@ -78,7 +83,7 @@ public class VampireSquad : Squad if (this.Tag == unitComponent.Tag) return; - if (unitComponent.Tag.Equals(TagManager.Human)) + if (unitComponent.Tag.Equals(TagLayerManager.Human)) { if (unitComponent.IsCaptured) { diff --git a/Assets/Scripts/ZombieSquad.cs b/Assets/Scripts/ZombieSquad.cs index c9e7741..f405fb3 100644 --- a/Assets/Scripts/ZombieSquad.cs +++ b/Assets/Scripts/ZombieSquad.cs @@ -11,7 +11,7 @@ public class ZombieSquad : Squad void Start() { InitializeSquad(); - InitializeDefaultTag(); + InitializeDefaultTagAndLayer(); // initialize default hp //Hp = defaultHp; // initialize default attack @@ -31,22 +31,27 @@ public class ZombieSquad : Squad } } - private void InitializeDefaultTag() + private void InitializeDefaultTagAndLayer() { try { - this.Tag = TagManager.ZombiePlayer; // set the tag to player 1 + this.Tag = TagLayerManager.ZombiePlayer; // set the tag to player 1 + this.Layer = TagLayerManager.ZombieLayerIndex; } catch (IndexOutOfRangeException ex) { Debug.LogError("Please set a vampire Tag, check the Tag & layers in the inspector!\n" + ex); } - // set the tag of the gameObject to zombie + // set the tag and the layer of the gameObject to vampire if (this.gameObject.tag != Tag) { this.gameObject.tag = Tag; } + if (this.gameObject.layer != Layer) + { + this.gameObject.layer = Layer; + } } /*void CaptureHuman(Unit unit) @@ -77,7 +82,7 @@ public class ZombieSquad : Squad if (this.Tag == unitComponent.Tag) return; - if (unitComponent.Tag.Equals(TagManager.Human)) + if (unitComponent.Tag.Equals(TagLayerManager.Human)) { CaptureHuman(unitComponent); } diff --git a/ProjectSettings/DynamicsManager.asset b/ProjectSettings/DynamicsManager.asset index dd3756e..4eec957 100644 --- a/ProjectSettings/DynamicsManager.asset +++ b/ProjectSettings/DynamicsManager.asset @@ -11,4 +11,4 @@ PhysicsManager: m_SolverIterationCount: 6 m_RaycastsHitTriggers: 1 m_EnableAdaptiveForce: 0 - m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff + m_LayerCollisionMatrix: fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffffdfffffffbffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index b0ac510..2a285eb 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 5.0.0f4 +m_EditorVersion: 5.1.0f3 m_StandardAssetsVersion: 0 diff --git a/ProjectSettings/QualitySettings.asset b/ProjectSettings/QualitySettings.asset index 60b0053..856ed7a 100644 --- a/ProjectSettings/QualitySettings.asset +++ b/ProjectSettings/QualitySettings.asset @@ -144,21 +144,4 @@ QualitySettings: maximumLODLevel: 0 particleRaycastBudget: 4096 excludedTargetPlatforms: [] - m_PerPlatformDefaultQuality: - Android: 2 - BlackBerry: 2 - GLES Emulation: 5 - PS3: 5 - PS4: 5 - PSM: 5 - PSP2: 5 - Samsung TV: 2 - Standalone: 5 - Tizen: 2 - WP8: 5 - Web: 5 - WebGL: 3 - Windows Store Apps: 5 - XBOX360: 5 - XboxOne: 5 - iPhone: 2 + m_PerPlatformDefaultQuality: {} diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 18271ed..2848044 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -16,9 +16,9 @@ TagManager: - UI - - - - - - - - + - Human + - VampirePlayer + - ZombiePlayer - - - From 260a6c9941737bf4b238e4a8ef685be11eb8e641 Mon Sep 17 00:00:00 2001 From: Samuel Date: Fri, 14 Aug 2015 12:57:47 -0400 Subject: [PATCH 2/2] - Updated Capture function and AbandonUnit function. --- Assets/Scripts/Squad.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Assets/Scripts/Squad.cs b/Assets/Scripts/Squad.cs index bd4b071..1f3a4c4 100644 --- a/Assets/Scripts/Squad.cs +++ b/Assets/Scripts/Squad.cs @@ -134,6 +134,12 @@ public class Squad : Unit { // retreive the human at the specified index var humanUnit = _humans.ElementAt(i); + // reassign the human attributes + humanUnit.Tag = TagLayerManager.Human; + humanUnit.Layer = TagLayerManager.HumanLayerIndex; + humanUnit.gameObject.GetComponent().useGravity = true; + humanUnit.IsCaptured = false; + // add the human to the abandonned Unit list AddAbandonnedHuman(humanUnit); // remove the human from the humandUnit that was added to the abandonned unit list @@ -219,6 +225,7 @@ public class Squad : Unit //Debug.Log(String.Format("Human parent before colision :{0}", unit.transform.name)); unit.IsCaptured = true; unit.transform.parent = this.transform; + unit.transform.gameObject.GetComponent().useGravity = false; unit.transform.localPosition = new Vector3(0, 0, 0); //Debug.Log(String.Format("Human parent before colision :{0}", unit.transform.parent.name)); AddHuman(unit);