├── .gitignore ├── Assets ├── Fundamentals.unity ├── Fundamentals.unity.meta ├── Scripts.meta └── Scripts │ ├── Animal.cs │ ├── Animal.cs.meta │ ├── Cat.cs │ ├── Cat.cs.meta │ ├── IControllable.cs │ ├── IControllable.cs.meta │ ├── InputController.cs │ ├── InputController.cs.meta │ ├── Kangaroo.cs │ ├── Kangaroo.cs.meta │ ├── Panda.cs │ ├── Panda.cs.meta │ ├── Parrot.cs │ └── Parrot.cs.meta ├── LICENSE.txt └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # This .gitignore file should be placed at the root of your Unity project directory 2 | # 3 | # Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore 4 | # 5 | /[Ll]ibrary/ 6 | /[Tt]emp/ 7 | /[Oo]bj/ 8 | /[Bb]uild/ 9 | /[Bb]uilds/ 10 | /[Ll]ogs/ 11 | /[Mm]emoryCaptures/ 12 | 13 | # Asset meta data should only be ignored when the corresponding asset is also ignored 14 | !/[Aa]ssets/**/*.meta 15 | 16 | # Uncomment this line if you wish to ignore the asset store tools plugin 17 | # /[Aa]ssets/AssetStoreTools* 18 | 19 | # Autogenerated Jetbrains Rider plugin 20 | [Aa]ssets/Plugins/Editor/JetBrains* 21 | 22 | # Visual Studio cache directory 23 | .vs/ 24 | 25 | # Gradle cache directory 26 | .gradle/ 27 | 28 | # Autogenerated VS/MD/Consulo solution and project files 29 | ExportedObj/ 30 | .consulo/ 31 | *.csproj 32 | *.unityproj 33 | *.sln 34 | *.suo 35 | *.tmp 36 | *.user 37 | *.userprefs 38 | *.pidb 39 | *.booproj 40 | *.svd 41 | *.pdb 42 | *.mdb 43 | *.opendb 44 | *.VC.db 45 | 46 | # Unity3D generated meta files 47 | *.pidb.meta 48 | *.pdb.meta 49 | *.mdb.meta 50 | 51 | # Unity3D generated file on crash reports 52 | sysinfo.txt 53 | 54 | # Builds 55 | *.apk 56 | *.unitypackage 57 | 58 | # Crashlytics generated file 59 | crashlytics-build.properties 60 | 61 | -------------------------------------------------------------------------------- /Assets/Fundamentals.unity: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!29 &1 4 | OcclusionCullingSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_OcclusionBakeSettings: 8 | smallestOccluder: 5 9 | smallestHole: 0.25 10 | backfaceThreshold: 100 11 | m_SceneGUID: 00000000000000000000000000000000 12 | m_OcclusionCullingData: {fileID: 0} 13 | --- !u!104 &2 14 | RenderSettings: 15 | m_ObjectHideFlags: 0 16 | serializedVersion: 9 17 | m_Fog: 0 18 | m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} 19 | m_FogMode: 3 20 | m_FogDensity: 0.01 21 | m_LinearFogStart: 0 22 | m_LinearFogEnd: 300 23 | m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} 24 | m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} 25 | m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} 26 | m_AmbientIntensity: 1 27 | m_AmbientMode: 3 28 | m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} 29 | m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} 30 | m_HaloStrength: 0.5 31 | m_FlareStrength: 1 32 | m_FlareFadeSpeed: 3 33 | m_HaloTexture: {fileID: 0} 34 | m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} 35 | m_DefaultReflectionMode: 1 36 | m_DefaultReflectionResolution: 128 37 | m_ReflectionBounces: 1 38 | m_ReflectionIntensity: 1 39 | m_CustomReflection: {fileID: 0} 40 | m_Sun: {fileID: 0} 41 | m_IndirectSpecularColor: {r: 0.37311953, g: 0.38074014, b: 0.3587274, a: 1} 42 | m_UseRadianceAmbientProbe: 0 43 | --- !u!157 &3 44 | LightmapSettings: 45 | m_ObjectHideFlags: 0 46 | serializedVersion: 11 47 | m_GIWorkflowMode: 1 48 | m_GISettings: 49 | serializedVersion: 2 50 | m_BounceScale: 1 51 | m_IndirectOutputScale: 1 52 | m_AlbedoBoost: 1 53 | m_EnvironmentLightingMode: 0 54 | m_EnableBakedLightmaps: 0 55 | m_EnableRealtimeLightmaps: 0 56 | m_LightmapEditorSettings: 57 | serializedVersion: 12 58 | m_Resolution: 2 59 | m_BakeResolution: 40 60 | m_AtlasSize: 1024 61 | m_AO: 0 62 | m_AOMaxDistance: 1 63 | m_CompAOExponent: 1 64 | m_CompAOExponentDirect: 0 65 | m_ExtractAmbientOcclusion: 0 66 | m_Padding: 2 67 | m_LightmapParameters: {fileID: 0} 68 | m_LightmapsBakeMode: 1 69 | m_TextureCompression: 1 70 | m_FinalGather: 0 71 | m_FinalGatherFiltering: 1 72 | m_FinalGatherRayCount: 256 73 | m_ReflectionCompression: 2 74 | m_MixedBakeMode: 2 75 | m_BakeBackend: 1 76 | m_PVRSampling: 1 77 | m_PVRDirectSampleCount: 32 78 | m_PVRSampleCount: 500 79 | m_PVRBounces: 2 80 | m_PVREnvironmentSampleCount: 500 81 | m_PVREnvironmentReferencePointCount: 2048 82 | m_PVRFilteringMode: 2 83 | m_PVRDenoiserTypeDirect: 0 84 | m_PVRDenoiserTypeIndirect: 0 85 | m_PVRDenoiserTypeAO: 0 86 | m_PVRFilterTypeDirect: 0 87 | m_PVRFilterTypeIndirect: 0 88 | m_PVRFilterTypeAO: 0 89 | m_PVREnvironmentMIS: 0 90 | m_PVRCulling: 1 91 | m_PVRFilteringGaussRadiusDirect: 1 92 | m_PVRFilteringGaussRadiusIndirect: 5 93 | m_PVRFilteringGaussRadiusAO: 2 94 | m_PVRFilteringAtrousPositionSigmaDirect: 0.5 95 | m_PVRFilteringAtrousPositionSigmaIndirect: 2 96 | m_PVRFilteringAtrousPositionSigmaAO: 1 97 | m_ExportTrainingData: 0 98 | m_TrainingDataDestination: TrainingData 99 | m_LightProbeSampleCountMultiplier: 4 100 | m_LightingDataAsset: {fileID: 0} 101 | m_UseShadowmask: 1 102 | --- !u!196 &4 103 | NavMeshSettings: 104 | serializedVersion: 2 105 | m_ObjectHideFlags: 0 106 | m_BuildSettings: 107 | serializedVersion: 2 108 | agentTypeID: 0 109 | agentRadius: 0.5 110 | agentHeight: 2 111 | agentSlope: 45 112 | agentClimb: 0.4 113 | ledgeDropHeight: 0 114 | maxJumpAcrossDistance: 0 115 | minRegionArea: 2 116 | manualCellSize: 0 117 | cellSize: 0.16666667 118 | manualTileSize: 0 119 | tileSize: 256 120 | accuratePlacement: 0 121 | debug: 122 | m_Flags: 0 123 | m_NavMeshData: {fileID: 0} 124 | --- !u!1 &232524562 125 | GameObject: 126 | m_ObjectHideFlags: 0 127 | m_CorrespondingSourceObject: {fileID: 0} 128 | m_PrefabInstance: {fileID: 0} 129 | m_PrefabAsset: {fileID: 0} 130 | serializedVersion: 6 131 | m_Component: 132 | - component: {fileID: 232524567} 133 | - component: {fileID: 232524563} 134 | m_Layer: 0 135 | m_Name: Animal 136 | m_TagString: Untagged 137 | m_Icon: {fileID: 0} 138 | m_NavMeshLayer: 0 139 | m_StaticEditorFlags: 0 140 | m_IsActive: 1 141 | --- !u!114 &232524563 142 | MonoBehaviour: 143 | m_ObjectHideFlags: 0 144 | m_CorrespondingSourceObject: {fileID: 0} 145 | m_PrefabInstance: {fileID: 0} 146 | m_PrefabAsset: {fileID: 0} 147 | m_GameObject: {fileID: 232524562} 148 | m_Enabled: 1 149 | m_EditorHideFlags: 0 150 | m_Script: {fileID: 11500000, guid: b7f489cd5529a144596d63f84e4a6145, type: 3} 151 | m_Name: 152 | m_EditorClassIdentifier: 153 | stamina: 100 154 | --- !u!4 &232524567 155 | Transform: 156 | m_ObjectHideFlags: 0 157 | m_CorrespondingSourceObject: {fileID: 0} 158 | m_PrefabInstance: {fileID: 0} 159 | m_PrefabAsset: {fileID: 0} 160 | m_GameObject: {fileID: 232524562} 161 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 162 | m_LocalPosition: {x: 0, y: 0, z: 0} 163 | m_LocalScale: {x: 1, y: 1, z: 1} 164 | m_Children: [] 165 | m_Father: {fileID: 0} 166 | m_RootOrder: 1 167 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 168 | --- !u!1 &423387871 169 | GameObject: 170 | m_ObjectHideFlags: 0 171 | m_CorrespondingSourceObject: {fileID: 0} 172 | m_PrefabInstance: {fileID: 0} 173 | m_PrefabAsset: {fileID: 0} 174 | serializedVersion: 6 175 | m_Component: 176 | - component: {fileID: 423387876} 177 | - component: {fileID: 423387872} 178 | m_Layer: 0 179 | m_Name: InputController 180 | m_TagString: Untagged 181 | m_Icon: {fileID: 0} 182 | m_NavMeshLayer: 0 183 | m_StaticEditorFlags: 0 184 | m_IsActive: 1 185 | --- !u!114 &423387872 186 | MonoBehaviour: 187 | m_ObjectHideFlags: 0 188 | m_CorrespondingSourceObject: {fileID: 0} 189 | m_PrefabInstance: {fileID: 0} 190 | m_PrefabAsset: {fileID: 0} 191 | m_GameObject: {fileID: 423387871} 192 | m_Enabled: 1 193 | m_EditorHideFlags: 0 194 | m_Script: {fileID: 11500000, guid: a243bd5d4a9008f4ba30b599f0f2955e, type: 3} 195 | m_Name: 196 | m_EditorClassIdentifier: 197 | go: {fileID: 232524562} 198 | --- !u!4 &423387876 199 | Transform: 200 | m_ObjectHideFlags: 0 201 | m_CorrespondingSourceObject: {fileID: 0} 202 | m_PrefabInstance: {fileID: 0} 203 | m_PrefabAsset: {fileID: 0} 204 | m_GameObject: {fileID: 423387871} 205 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 206 | m_LocalPosition: {x: 0, y: 0, z: 0} 207 | m_LocalScale: {x: 1, y: 1, z: 1} 208 | m_Children: [] 209 | m_Father: {fileID: 0} 210 | m_RootOrder: 0 211 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 212 | -------------------------------------------------------------------------------- /Assets/Fundamentals.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bc02759f512fef542907c5e8d4006c2c 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Assets/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 28690915cc6c8cf4a88bb0a34e9234da 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scripts/Animal.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; // Unity's Main Library for MonoBehaviour 2 | 3 | public abstract class Animal : MonoBehaviour, IControllable // Base Class / Abstraction 4 | { 5 | private void Walk() // Encapsulation 6 | { 7 | Debug.Log("Walking"); // Encapsulated Action 8 | } 9 | 10 | public virtual void Move() // Virtual Method / Polymorphism 11 | { 12 | Walk(); // Calling Private Method 13 | } 14 | } -------------------------------------------------------------------------------- /Assets/Scripts/Animal.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 10f56c90ca832d34b8652aeb30ba8eea 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/Cat.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; // Unity's Main Library for MonoBehaviour 2 | 3 | public class Cat : Animal // Derived Class / Inheritance 4 | { 5 | public override void Move() // Polymorphism 6 | { 7 | base.Move(); // Calling Base Class Method 8 | Debug.Log("Moew"); // Added Actions 9 | } 10 | } -------------------------------------------------------------------------------- /Assets/Scripts/Cat.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 716350747f7db474ea24a35cf107340e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/IControllable.cs: -------------------------------------------------------------------------------- 1 | public interface IControllable // Interface 2 | { 3 | void Move(); // Method for Character's Base Class 4 | } -------------------------------------------------------------------------------- /Assets/Scripts/IControllable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 385f8fc8021660d4d9a60c4e10691633 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/InputController.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; // Unity's Main Library for MonoBehaviour 2 | 3 | public class InputController : MonoBehaviour // Unity's Base Class 4 | { 5 | [SerializeField] // Serialize the Variable for Inspector 6 | private GameObject go; // GameObject of Component IControllable 7 | private IControllable controllable; // Component IControllable 8 | 9 | private void Start() // Unity's Event Function / Update Once 10 | { 11 | controllable = go.GetComponent(); // Gets Component IControllable from GameObject 12 | } 13 | 14 | private void Update() // Unity's Event Function / Updates Every Frame 15 | { 16 | if (Input.GetMouseButtonDown(0)) controllable.Move(); // Waiting for Player Mouse Left Click 17 | } 18 | } -------------------------------------------------------------------------------- /Assets/Scripts/InputController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a243bd5d4a9008f4ba30b599f0f2955e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/Kangaroo.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; // Unity's Main Library for MonoBehaviour 2 | 3 | public class Kangaroo : Animal // Derived Class / Inheritance 4 | { 5 | private void Jump() // Encapsulation 6 | { 7 | Debug.Log("Jumping"); // Encapsulated Action 8 | } 9 | 10 | public override void Move() // Polymorphism 11 | { 12 | Jump(); // Overrided Actions 13 | } 14 | } -------------------------------------------------------------------------------- /Assets/Scripts/Kangaroo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 51be1e05de795d84587904f3326e44b1 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/Panda.cs: -------------------------------------------------------------------------------- 1 | public class Panda : Animal // Derived Class / Inheritance 2 | { 3 | // Some Code for Panda 4 | } -------------------------------------------------------------------------------- /Assets/Scripts/Panda.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 59913052f28f63d4c8131e137fc9898a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Assets/Scripts/Parrot.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; // Unity's Main Library for MonoBehaviour 2 | 3 | public class Parrot : Animal // Derived Class / Inheritance 4 | { 5 | [SerializeField] // Serialize the Variable for Inspector 6 | private float stamina = 100; // Private Variable for Stamina 7 | 8 | private void Fly() // Encapsulation 9 | { 10 | Debug.Log("Flying"); // Encapsulated Action 11 | } 12 | 13 | public override void Move() // Polymorphism 14 | { 15 | if (stamina > 50) Fly(); // Checks Stamina before calling Fly() Method 16 | else base.Move(); // Calls Move() Method instead 17 | 18 | stamina -= 10; // Reducing Stamina 19 | if (stamina < 1) stamina = 0; // Keeps Stamina 0 20 | } 21 | 22 | private void Update() // Unity's Event Function / Updates Every Frame 23 | { 24 | if (stamina < 100) stamina += Time.deltaTime * 10f; // Adds Stamina over time 25 | } 26 | } -------------------------------------------------------------------------------- /Assets/Scripts/Parrot.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b7f489cd5529a144596d63f84e4a6145 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) [year] [fullname] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OOP in Unity 2 | 3 | Object-oriented programming concepts: 4 | 5 | ## encapsulation, 6 | ## abstraction, 7 | ## inheritance, 8 | ## polymorphism 9 | 10 | in Unity Engine 11 | --------------------------------------------------------------------------------