<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kadir Çallıoğlu on Medium]]></title>
        <description><![CDATA[Stories by Kadir Çallıoğlu on Medium]]></description>
        <link>https://medium.com/@kadircalliogluu?source=rss-5b36a6207793------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*gzwQo4TfMj3gX1JC_SVKXw.jpeg</url>
            <title>Stories by Kadir Çallıoğlu on Medium</title>
            <link>https://medium.com/@kadircalliogluu?source=rss-5b36a6207793------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 14:01:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kadircalliogluu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Linear Regression from Scratch: An Overview with Regularization Techniques]]></title>
            <link>https://medium.com/@kadircalliogluu/linear-regression-from-scratch-an-overview-with-regularization-techniques-5ae106fca44f?source=rss-5b36a6207793------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ae106fca44f</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Kadir Çallıoğlu]]></dc:creator>
            <pubDate>Mon, 31 Mar 2025 18:43:35 GMT</pubDate>
            <atom:updated>2025-03-31T18:43:35.122Z</atom:updated>
            <content:encoded><![CDATA[<h3>Linear Regression from Scratch: An Overview with Regularization Technique</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_UodYEJEBORARFK1.jpeg" /></figure><p>In this project, we explore the fundamentals of linear regression by building a model from scratch — without relying on high-level machine learning libraries. Our goal is to understand the inner workings of linear regression, how gradient descent optimizes the model parameters, and how regularization techniques can dramatically improve performance, especially in noisy environments.</p><h4>Introduction</h4><p>Linear regression is a fundamental statistical method used to model the relationship between a dependent variable (y) and one or more independent variables (x). The basic form of the linear model is:</p><p>y = β₀ + β₁x₁ + β₂x₂ + … + βₙxₙ + ε</p><p>Where:</p><ul><li>y is the target variable</li><li>β₀ is the intercept</li><li>β₁, β₂, …, βₙ are the coefficients for the features</li><li>x₁, x₂, …, xₙ are the features</li><li>ε is the error term</li></ul><h4>Building a Basic Linear Regression Model</h4><p>We start by implementing linear regression from scratch using gradient descent. The objective is to minimize the Mean Squared Error (MSE):</p><p>J(θ) = (1/2m) Σ (yᵢ — ŷᵢ)²</p><p>With update rules for the parameters:</p><p>dw = (1/m) * Xᵀ * (y_pred — y)<br> db = (1/m) * Σ (y_pred — y)<br> w := w — α * dw<br> b := b — α * db</p><p>where <strong>α</strong> is the learning rate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*2-ZrbiVqVYF_PtAyy5gG1A.png" /></figure><h4>Advanced Model: Incorporating SGD and Regularization</h4><p>While our basic model provides a good foundation, it struggles in noisy scenarios. To address this, we extended the model using Stochastic Gradient Descent (SGD) along with regularization techniques: Ridge (L2) and Lasso (L1).</p><h4>Why Use SGD?</h4><p>SGD offers:</p><ul><li>Faster convergence on large datasets</li><li>Lower memory usage</li><li>Inherent noise helps escape local minima</li></ul><h4>Ridge Regression (L2 Regularization)</h4><p>Ridge Regression adds a penalty proportional to the square of the coefficients:</p><p>J(θ) = (1/2m) Σ (h_θ(xᵢ) — yᵢ)² + (λ/2m) Σ θⱼ²</p><p>This discourages large coefficient values, helping to reduce overfitting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*FaH9oScv1TCcKSqOxAO_Ig.png" /></figure><h4>Lasso Regression (L1 Regularization)</h4><p>Lasso Regression adds a penalty proportional to the absolute value of the coefficients:</p><p>J(θ) = (1/2m) Σ (h_θ(xᵢ) — yᵢ)² + (λ/m) Σ |θⱼ|</p><p>Lasso can force some coefficients to zero, effectively performing feature selection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*SQueMTYHeU4D2xAeqz_6MA.png" /></figure><h3>Experimental Results</h3><p>We tested our models using a dataset with a<strong> noise level of 7</strong>. The results were as follows:</p><ul><li>Normal Linear Regression: R² Score = 0.70</li><li>SGD with Ridge (L2) Regularization: R² Score = 0.9636</li><li>SGD with Lasso (L1) Regularization: R² Score = 0.9681</li></ul><p>These results clearly demonstrate that both SGD-based models with regularization outperform the basic linear regression model in noisy conditions. The slight edge of Lasso suggests that automatic feature selection can be particularly beneficial when dealing with noise and multicollinearity.</p><h3>Conclusion</h3><p>This project provided a comprehensive overview of linear regression — from basic implementation using gradient descent to advanced optimization with SGD and regularization techniques.</p><p>Key takeaways include:</p><ul><li>Regularization is crucial for preventing overfitting, especially in noisy datasets.</li><li>SGD allows efficient training on large datasets.</li><li>Lasso’s automatic feature selection can enhance performance in complex scenarios.</li></ul><p>For more details, check out the <a href="https://github.com/DARETNY/Linear_Reg_Overview/tree/main">GitHub repository.</a></p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ae106fca44f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Some Patterns(Part 1)]]></title>
            <link>https://medium.com/@kadircalliogluu/some-patterns-part-1-077e57a32734?source=rss-5b36a6207793------2</link>
            <guid isPermaLink="false">https://medium.com/p/077e57a32734</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Kadir Çallıoğlu]]></dc:creator>
            <pubDate>Mon, 23 Oct 2023 22:25:10 GMT</pubDate>
            <atom:updated>2023-10-23T22:25:10.058Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Buılder Pattern</strong></p><p>The Builder design pattern is a design pattern used to abstract the process of creating complex objects, hiding the intricacies of object creation. It employs a series of method calls to build an object step by step, setting its various parts and attributes. The Builder pattern aids in making the construction of objects more understandable, flexible, and easy to maintain.</p><p>The key components of the Builder design pattern include:</p><p><strong>1. Director</strong>: This is the class that manages the object creation process using the Builder pattern. The Director determines the sequence of steps to follow and how the object will be constructed.</p><p><strong>2. Builder:</strong> This is an interface used for creating an object. The Builder class defines the methods required to construct an object step by step.</p><p><strong>3. Concrete Builder:</strong> These are classes that implement the Builder interface and perform the actual steps needed to construct an object. Each Concrete Builder focuses on creating a specific type of object.</p><p><strong>4. Product</strong>: This represents the final object that has been constructed. The Product is built incrementally by the Builder and is ultimately presented to the user.</p><p>The Builder design pattern modularizes the object creation process, making the object’s structure more flexible and allowing the same Director to be used for creating different objects. It is particularly useful in scenarios where numerous objects need to be created with complex configurations.</p><p>Lets look at the code part now — &gt;</p><p>So as I explain before we need 4 part: In this example, we will try to create a car using the builder pattern.</p><pre> public interface ICarBuılder<br>    {<br>        Car GetCar();<br>        ICarBuılder SetModel();<br>        <br>        ICarBuılder Construct();<br>        ICarBuılder SetColor();<br>        ICarBuılder SetSpeed();<br>        ICarBuılder SetAcceleration();<br>    }</pre><pre> public class Car<br>    {<br>        #region Variables -&gt; You can use So or struct if you want<br><br>        public string Model { get; set; }<br>        public string Color { get; set; }<br>        public float Speed { get; set; }<br>        public float Acceleration { get; set; }<br><br>        #endregion<br><br>        public void ShowInfo()<br>        {<br>            Debug.Log($&quot;Model: {Model}, Color: {Color}, Speed: {Speed}, Acceleration: {Acceleration} &quot;);<br>        }<br>    }</pre><pre><br>{<br>    public class JeepModels : ICarBuılder<br>    {<br>        private Car _car;<br><br>        public Car GetCar()<br>        {<br>            return _car;<br>        }<br><br>        public ICarBuılder SetModel()<br>        {<br>            _car.Model = &quot;Jeep&quot;;<br>            return this;<br>        }<br><br>        public ICarBuılder Construct()<br>        {<br>            _car = new Car();<br>            return this;<br>        }<br><br>        public ICarBuılder SetColor()<br>        {<br>            _car.Color = &quot;White&quot;;<br>            return this;<br>        }<br><br>        public ICarBuılder SetSpeed()<br>        {<br>            _car.Speed = 100;<br>            return this;<br>        }<br><br>        public ICarBuılder SetAcceleration()<br>        {<br>            _car.Acceleration = 10;<br>            return this;<br>        }<br>        public ICarBuılder Setall()<br>        {<br>            SetAcceleration();<br>            SetColor();<br>            SetModel();<br>            SetSpeed();<br>            return this;<br>        }<br>    }<br>}</pre><p>As you see we implement <strong>IcarBuilder…</strong></p><pre> case ModelType.Sedan:<br>                    ICarBuılder sedanBuilder = new SedanModels();<br>                    Car sedanCar = sedanBuilder.Construct().SetModel().SetColor().SetSpeed().SetAcceleration().GetCar();<br>                    sedanCar.ShowInfo();<br><br>                    break;<br>                case ModelType.Jeep:<br>                    ICarBuılder jeepBuilder = new JeepModels();<br>                    Car jeepCar = jeepBuilder.Construct().SetModel().SetColor().GetCar();<br>                    jeepCar.ShowInfo(); <br>                    break;</pre><p>So in this case we created sedan car and jeep car, you can see our expectations from the sedan are as follows:</p><pre>SetModel().SetColor().SetSpeed().SetAcceleration()</pre><p>other expectations form the jeep are :</p><pre>SetModel().SetColor()</pre><p>In conclusion We will receive the conditions you specify for the sedan and jeep.</p><figure><img alt="(We took the values ​​0 for speed and accselarition because we did not specify this condition to be included.)" src="https://cdn-images-1.medium.com/max/1024/1*MXOJMKWh66ZjhX-yZvSxlw.png" /><figcaption>We took the values ​​0 for speed and acceleration because we did not specify this condition to be included.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GU6CbEfZb_4o9w5v9AJuDw.png" /><figcaption>We implement all of them.</figcaption></figure><p>Mediator Pattern</p><p>The Mediator design pattern is a behavioral design pattern used to manage communication between objects and reduce tight couplings. It encourages objects to communicate through a mediator object rather than directly with each other. The Mediator pattern reduces system complexity and eases maintenance by avoiding direct interactions between objects.</p><p>The primary purpose of the Mediator design pattern is to prevent tight couplings between objects and reduce system complexity. This pattern is particularly useful in large and complex systems.</p><p>In this case, we gonna look 2 different action one is going up other one is rotate around its own axis, we want to log when rotate start otherwise don&#39;t anything</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/0*gnacBjquW78-Efrh.jpeg" /></figure><p>so lets follow the chart</p><pre> public interface IMediator<br>    {<br>        void SetterMed(Colleague colleague);<br>    }</pre><pre>   public abstract class Colleague<br>    {<br>        protected readonly IMediator Mediator;<br><br>        protected Colleague(IMediator mediator)<br>        {<br>            Mediator = mediator;<br>        }<br><br>        public abstract void Dosomething();<br>    }</pre><p>As you can see we build the base</p><pre>public class Rotater : Colleague<br>    {<br>        private readonly Transform _target;<br><br>        public Rotater(IMediator mediator, Transform target) : base(mediator)<br>        {<br>            _target = target;<br>        }<br><br>        <br>        public override void Dosomething()<br>        {<br><br>            _target.RotateAround(Vector3.up, 45 * Time.deltaTime);<br><br>            Mediator.SetterMed(this);// we set the med 1 here<br>        }<br>    }</pre><pre> public class Jumper : Colleague<br>    {<br>        private readonly Transform _target;<br><br>        public Jumper(IMediator mediator, Transform target) : base(mediator)<br>        {<br>            _target = target;<br>        }<br><br>        public override void Dosomething()<br>        {<br>            _target.Translate(Vector3.up);<br><br>            Mediator.SetterMed(this); //we set the med 2 here<br>        }<br>    }</pre><p>lets create MedManager(“ConcreteMediator”)</p><pre> public class MedManager : IMediator<br>    {<br>        public Jumper Jumper1 { get; private set; }<br><br>        public Rotater Slider1 { get; set; }<br><br>        public void SetterMed(Colleague colleague)<br>        {<br>            switch (colleague)<br>            {<br>                case Jumper jumper:<br>                    Jumper1 = jumper;<br>                    break;<br>                case Rotater slider:<br>                    Slider1 = slider;<br>                    break;<br>            }<br>        }<br>    }</pre><p>So as you can see we create the chart now time to play 😵‍💫</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*attmNewGsbhu6ZST9l-33g.gif" /></figure><p>when we do the different action we can easily manipulate them in this video if we do these actions log(“Match ”)</p><p>Command Pattern</p><p>The Command design pattern is a behavioral design pattern that provides a structure where a command (an action) is represented as an object. This pattern abstracts the idea of an operation, including its parameters, into an object.</p><p>The Command design pattern is particularly useful in scenarios where you need to decouple an object that issues commands from the object that performs the action, or when you want to support undo/redo operations, or when you want to create a queue of requests.</p><p>So basically we need the Undo and Execute functions lets build the system</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kvaOrYOW7WZLbvs-m13RyA.png" /></figure><pre>public interface ICommand<br>    {<br>        void Execute();<br>        void Undo();<br>    }</pre><p>Now we need to stack(IEnumerable type) this operations</p><pre><br>{<br>    public class Commandİnvoker<br>    {<br>        private readonly Stack&lt;ICommand&gt; _commandStack = new();<br>        // we can use Queue<br>        <br>        public void ExecuteCommand(ICommand command)<br>        {<br>            command.Execute();<br>            _commandStack.Push(command);<br>            <br>        }<br><br>        public void UndoCommand()<br>        {<br>            if (_commandStack.Count&gt;0)<br>            {<br>                _commandStack.Pop().Undo();<br>            }<br>            <br>        }<br>    }<br>}</pre><pre><br>    internal class SpawnedObjectCommand : ICommand<br>    {<br>        private readonly Vector3 _position;<br>        private GameObject _spawnedObject;<br><br>        public SpawnedObjectCommand(Vector3 position, GameObject spawnedObject)<br>        {<br>            _position = position;<br>            _spawnedObject = spawnedObject;<br>        }<br><br>        public void Execute()<br>        {<br>            _spawnedObject = Object.Instantiate(_spawnedObject, _position, Quaternion.identity);<br><br>            Color materialColor = new Color(Random.value, Random.value, Random.value);<br>            if (_spawnedObject.TryGetComponent(out Renderer renderer))<br>            {<br>                renderer.material.color = materialColor;<br>            }<br>        }<br><br>        public void Undo()<br>        {<br>            if (!_spawnedObject.activeInHierarchy) return;<br>            Object.Destroy(_spawnedObject);<br>        }<br>    }<br></pre><p>So as you see we implement the main logic, now show time</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*S3nX03LAv4mf6-hiDXPJrg.gif" /></figure><p>Service Provider Pattern</p><p>The Service Provider design pattern is useful in Unity for providing access to specialized objects such as managers. This pattern facilitates centralized access to service objects (e.g., managers) and helps make your code more organized and maintainable.</p><p>The Service Provider design pattern in Unity is a way to centralize access to different services, such as managers, databases, resources, and more. It can help make your code more organized and maintainable while reducing dependencies between services.</p><p>If you have multiple managers in your project and you want to organize them more efficiently, the Service Provider design pattern is a structured approach to achieving this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/0*C1V3hlWgAMiwq-u0.jpg" /><figcaption>As you can see we need a base template</figcaption></figure><pre> public interface IProviderHandler<br>    {<br>    }</pre><pre> public static class ServiceProvider<br>    {<br>        private static readonly Dictionary&lt;Type, IProviderHandler&gt; Providers = new();<br><br><br>        private static T GetManager&lt;T&gt;() where T : class, IProviderHandler<br>        {<br>            if (Providers.ContainsKey(typeof(T)))<br>                return (T)Providers[typeof(T)];<br><br>            return null;<br>        }<br><br>        public static void Register&lt;T&gt;(T target) where T : class, IProviderHandler<br>        {<br>            Providers.Add(typeof(T), target);<br>        }<br><br>        // this is easy way to reach all manager whic are registered<br>        public static GameManager GetGameManager =&gt; GetManager&lt;GameManager&gt;();<br>        public static SoundManager GetSoundManager =&gt; GetManager&lt;SoundManager&gt;();<br>    }</pre><p>As you see, we use generic type class because we need easy access .In this case we have 2 managers(Sound,Game).</p><pre> public class GameManager : MonoBehaviour, IProviderHandler<br>    {<br>        private void Awake()<br>        {<br>            ServiceProvider.Register(this);<br>        }<br>    }</pre><pre>    public class SoundManager : MonoBehaviour, IProviderHandler<br>    {<br><br>        private void Awake()<br>        {<br>            ServiceProvider.Register(this);<br>        }<br><br>        public void PlaySound(string soundName)<br>        {<br>            Debug.Log($&quot;Playing sound:{soundName}&quot;);<br>        }<br>    }</pre><p>Now we set the provider in order to reach them easily…</p><pre>public class Player : MonoBehaviour<br>    {<br>        private void Start()<br>        {<br>            ServiceProvider.GetSoundManager.PlaySound(&quot;Soud data is here&quot;);<br>// easy access from all sources <br>        }<br>    }</pre><p>Strategy Pattern</p><p>Imagine a game development scenario. In your game, you have various weapons, each of which deals a different type of damage. For instance, let’s consider a classic first-person shooter game where different weapons (pistol, shotgun, sniper rifle) produce different damage types (fire, explosion, sniper). You can use the Strategy design pattern to handle this situation.</p><p>The Strategy design pattern makes it easy for different weapon types to produce different damage types. You can dynamically choose which damage type each weapon uses. This makes the game development process more modular and flexible. You can extend the system to include new weapon types or damage types without having to modify existing code — simply create a new damage strategy class and assign it to the weapon’s context.</p><p>So in this example we will consider with 2 different wepon, 2 different damage type</p><p>Lets create basement to implement our damage types</p><pre>public interface IDodamage<br>    {<br>        void DoDamage(ushort damage);<br>    }</pre><pre> public sealed class IceDamage : IDodamage<br>    {<br>        public void DoDamage(ushort damage)<br>        {<br>            Debug.Log(&quot;Freezinnnngggg&quot;);<br>        }<br>    }</pre><pre> public sealed class ToxicDamage : IDodamage<br>    {<br>        public void DoDamage(ushort damage)<br>        {<br>            <br>            // you can do something there like crit damage or extra damage vs...<br>            Debug.Log(&quot;AAAAAA&quot;);<br>        }<br>    }</pre><p>as ı mentioned, we created 2 different damage type now next step creat 2 different weapon</p><pre> public abstract class WeponsBase <br>    {<br>        private IDodamage _dodamage;<br>        private readonly ushort _damage;<br><br>        public ushort TryAttack()<br>        {<br>            _dodamage?.DoDamage(_damage);<br>            return _damage;<br>        }<br><br><br>        protected void SetDamagetype(IDodamage dodamage)<br>        {<br>            _dodamage = dodamage;<br>        }<br><br>        protected WeponsBase(IDodamage dodamage, ushort damage)<br>        {<br>            _dodamage = dodamage;<br>            _damage = damage;<br>        }<br>    }</pre><pre> public sealed class MeleGun : WeponsBase<br>    {<br>        public MeleGun(IDodamage dodamage, ushort damage) : base(dodamage, damage)<br>        {<br>            base.SetDamagetype(dodamage);<br>        }<br>    }</pre><pre>public sealed class RifleGun : WeponsBase<br>    {<br>        public RifleGun(IDodamage dodamage, ushort damage) : base(dodamage, damage)<br>        {<br>            base.SetDamagetype(dodamage);<br>        }<br>    }<br></pre><p>As you can see, we have set up the whole system.Next step playyyy but first choose a gun</p><pre>switch (chooseGun)<br>            {<br>                case ChooseGun.Rifle:<br>                    _rifleGun = new RifleGun(new IceDamage(), Health);<br>                    break;<br>                case ChooseGun.Mele:<br>                    _mele = new MeleGun(new ToxicDamage(), Health);<br>                    break;<br>                default:<br>                    throw new (&quot;Invalid Model Type&quot;);<br>            }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*LbHyx1hN-eV1TYz7oBqMxA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*LgbSVmSop3i3DJG-KN4S-g.png" /><figcaption>So as you see, we chose ice damage type to our rifle gun</figcaption></figure><p>Thank you for taking the time to read these articles. I hope that it has provided you with valuable insights and a better understanding of the topic. If you have any questions or need further information, please don’t hesitate to reach out to me.</p><p>You can access the project from this link-&gt;</p><p><a href="https://github.com/DARETNY/Patterns">Patterns</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=077e57a32734" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ZENJECT]]></title>
            <link>https://medium.com/@kadircalliogluu/zenject-19a663f49fe8?source=rss-5b36a6207793------2</link>
            <guid isPermaLink="false">https://medium.com/p/19a663f49fe8</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity3d]]></category>
            <dc:creator><![CDATA[Kadir Çallıoğlu]]></dc:creator>
            <pubDate>Mon, 21 Aug 2023 22:20:45 GMT</pubDate>
            <atom:updated>2023-08-22T05:18:30.199Z</atom:updated>
            <content:encoded><![CDATA[<h3>ZENJECT(BEGINNER)</h3><p><strong>What is the zenject</strong>?</p><p>Zenject is a lightweight highly performant dependency injection framework built specifically to target Unity 3D . It can be used to turn your application into a collection of loosely coupled parts with highly segmented responsibilities. Zenject can then glue the parts together in many different configurations to allow you to easily write, re-use, refactor and test your code in a scalable and extremely flexible way.</p><p>Zenject is a dependency injection framework designed for use with the Unity game engine. Dependency injection is a fundamental concept in modern software development that aims to make code cleaner, more flexible, and easier to test. In the context of Unity game development, Zenject serves as a powerful tool for implementing these principles, enhancing the management of game projects.</p><h4>Key Features of Zenject:</h4><p>Automatic Dependency Resolution: Zenject is capable of automatically resolving dependencies between components. This eliminates the need to manually set up the required dependencies for a component. Consequently, this leads to code that is less tightly coupled.</p><p>Modular Code: Zenject facilitates the division of projects into modules. Each module independently manages its dependencies, fostering a more modular project structure. This results in code that is more organized and manageable.</p><p>Component-Oriented: Zenject is tailored to Unity’s component-based structure. This enables seamless injection and management of Unity components such as MonoBehaviours and ScriptableObjects.</p><p>Installers: Zenject employs installers to define how dependencies should be injected and configured. Installers simplify the configuration of dependency injection in a project.</p><p>Testability: Zenject streamlines the creation of test scenarios and testable components. It supports the use of mock objects to test components in isolation.</p><p>Flexible Injection Methods: Zenject offers a variety of injection methods, including constructor injection, field injection, and method injection. This flexibility allows for adaptable approaches to suit your specific needs.</p><p><em>In particular, Zenject shines in larger and more complex Unity game projects by making the management of dependencies between components more efficient, resulting in cleaner and more maintainable code. This framework can enhance the game development process by improving project organization and overall quality.</em></p><p>How to ınstall zenject?</p><p>You can add it to your library as a package from the link I left below, download and use it.</p><blockquote><a href="https://assetstore.unity.com/packages/tools/utilities/extenject-dependency-injection-ioc-157735">https://assetstore.unity.com/packages/tools/utilities/extenject-dependency-injection-ioc-157735</a></blockquote><p>Let see in the ınspector-&gt;</p><p>When you download the pack Zenjct automatically pop out you can see in the image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*RUTQylRnhzPVGDk-FrucoQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*H3x3Ee5KwxxZAFwOLpcfQg.png" /></figure><p>What is the Installer?</p><p><strong>Installer in Zenject:</strong> An Installer is a design pattern used in the Zenject framework to inject and configure dependencies. Installers define how dependencies are injected into different components of your project and aid in making your project more modular. They help organize your project’s structure, configure dependency injection, and manage dependencies between different parts of your project.</p><p><strong>MonoInstaller: </strong>MonoInstaller is a specialized type of Installer designed specifically for Unity’s MonoBehaviours. MonoBehaviours are fundamental components in Unity’s component-based structure. MonoInstallers are used within Zenject to inject dependencies into MonoBehaviours and enable communication between these components and other parts of your project.</p><p><strong>Role of Installers:</strong></p><ul><li><strong>Dependency Definition:</strong> Installers define what dependencies a component requires. This helps determine how the injection process should be carried out.</li><li><strong>Configuration of Injection:</strong> Installers define how dependencies are injected and configured. This allows for managing dependencies according to your project’s needs.</li><li><strong>Promoting Modularity:</strong> Installers help organize your project into modules, promoting a more modular structure and cleaner, more understandable code.</li></ul><p><strong>Role of MonoInstallers:</strong></p><ul><li><strong>Dependency Injection for MonoBehaviours:</strong> MonoInstallers are used to inject and configure dependencies for MonoBehaviours. This enables MonoBehaviours to interact and collaborate with other components.</li><li><strong>Project-Specific Configuration: </strong>Each MonoInstaller can be customized to suit your project’s requirements. This enables you to define different injection and configuration settings for various parts of your project.</li></ul><p>Installers and MonoInstallers play a crucial role in utilizing the Zenject framework to create more organized, maintainable, and testable projects.</p><p>Lets make a some code to understand.</p><p>First we need to implement Installer-&gt;</p><pre>public class ZenjectTest : MonoInstaller<br>    {<br>        public override void InstallBindings()<br>        {<br>           Container.Bind&lt;CurrentJob&gt;().AsSingle(); //-&gt; its coming from basic classs<br>          <br>        }<br>    }</pre><p>Second we need to reference it on hierarchy -&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mf9njcB4x78cMig3n_0xXg.png" /></figure><p>Then lets make a script to implement normal class to MonoBehaviour class</p><pre> public class Progress : MonoBehaviour<br>    {<br>        [Inject] private CurrentJob _currentJob;<br>      <br><br>        <br>        /* private CurrentJob CurrentJob;<br>        //<br>        // private void Awake()            //todo: we dont need anymore<br>        // {<br>        //     CurrentJob = new CurrentJob();<br>         }*/<br><br>        private void Start()<br>        {<br>            <br>            _currentJob.JustDoIt();<br>        }</pre><p>So in the code you can see that we don’t need any more references to work our functions.</p><p>CurrentJob class-&gt;</p><pre> public class CurrentJob<br>    {<br>        public void JustDoIt()<br>        {<br>            Debug.Log($&quot;ı can do what ı want&quot;);<br>        }<br>    }</pre><p>To sum up,management in large projects, using Zenject in large and complex gaming projects makes the code more organized and sustainable despite the size and complexity of the project. This provides an easier foundation for managing the project and making new additions.</p><p>Reduction of Errors ,zenject minimizes errors by standardizing the injection of dependency. Errors where dependencies are identified are detected and corrected faster.</p><p>Thank you for reading, we will discuss the subject in more detail in my next article.</p><h3><strong><em>References</em></strong></h3><p><a href="https://github.com/modesttree/Zenject">Zenject</a></p><blockquote><a href="https://www.youtube.com/watch?v=JgBmAkkLFBI">https://www.youtube.com/watch?v=JgBmAkkLFBI</a></blockquote><p><a href="https://www.youtube.com/playlist?list=PLKERDLXpXl_jNJPY2czQcfPXW4BJaGZc_">ZenjectPlaylist</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19a663f49fe8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scriptable Objects Event]]></title>
            <link>https://medium.com/@kadircalliogluu/scriptable-objects-event-c71616bbfd75?source=rss-5b36a6207793------2</link>
            <guid isPermaLink="false">https://medium.com/p/c71616bbfd75</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Kadir Çallıoğlu]]></dc:creator>
            <pubDate>Tue, 18 Jul 2023 22:21:31 GMT</pubDate>
            <atom:updated>2023-07-18T22:21:31.906Z</atom:updated>
            <content:encoded><![CDATA[<p>Scriptable Objects are a special type that allows us to create and edit game objects independently of Game Objects in the Unity scene. However, Scriptable Objects are not only for storing data; they can also be used to manage in-game interactions through Events.</p><blockquote>In this case, we will learn about Scriptable Objects with managing and using them.</blockquote><p>So why we are we using this Scriptable Objects with events,developers can create modular and flexible systems in Unity. Scriptable Objects can hold and manage data, while Events can handle in-game interactions and communication. For example, a Scriptable Object can represent a player’s inventory, storing items and their quantities. Events can be used to notify the UI when the inventory is updated, allowing the UI to display the correct information.</p><p>Lets check our example scene:</p><figure><img alt="dsfdsfsdsdsd" src="https://cdn-images-1.medium.com/max/1024/1*v-yB-z0ncPcetmSkSdGUsg.png" /></figure><p>In this scenario, we have two objects: one is red, and the other is yellow. We want to implement a behavior where the red object moves downwards, while the yellow object moves upwards. But first we need to implement scriptable object to control our events.</p><pre>using System;<br>using System.Collections.Generic;<br>using UnityEngine;<br><br>namespace SoEvents<br>{<br>    [CreateAssetMenu(fileName = &quot;MOVE EVENT&quot;, menuName = &quot;GAME EVENT&quot;, order = 0)]<br>    public class GameEvent : ScriptableObject<br>    {<br>        private readonly List&lt;Action&gt; _events = new ();<br>        <br>        /// &lt;summary&gt;<br>        /// InvokeYourEvent<br>        /// &lt;/summary&gt;<br>        public void Raise()<br>        {<br>            for (var i = _events.Count - 1; i &gt;= 0; i--)<br>                _events[i].Invoke();<br>        }<br>        <br>        /// &lt;summary&gt;<br>        /// calThisMethod OnEnable<br>        /// &lt;/summary&gt;<br>        /// &lt;param name=&quot;pop&quot;&gt;&lt;/param&gt;<br>        public void Subs(Action pop) =&gt; _events.Add(pop);<br>        /// &lt;summary&gt;<br>        /// calThisMethod OnDisable<br>        /// &lt;/summary&gt;<br>        /// &lt;param name=&quot;pop&quot;&gt;&lt;/param&gt;<br>        public void NonSubs(Action pop) =&gt; _events.Remove(pop);<br><br><br>    }<br><br><br>}</pre><blockquote>In this script, the Scriptable Object named “GameEvent” can be used to trigger certain actions within the game. It provides functions to trigger events with methods named “<em>Raise</em>()”, “<em>Subs</em>(Action pop)” and “<em>NonSubs</em>(Action pop)” and to make other objects subscribe or unsubscribe to these events.</blockquote><ul><li><strong>_events </strong>List: This list is used to store methods of type Action. The Action type is a delegate with no parameters and no return value. That is, it is a type that can be called by any object and can represent a set of methods.</li><li><strong>Raise()</strong> method: This method triggers (invoke) all Actions in the _events list and makes the event happen. This allows the event’s listeners (subscribe) to detect the triggered event and take necessary actions.</li><li>Subs(Action pop) method: This method is used to add an Action to the _events list. This operation allows the objects listening to the event (subscribe) to follow the event and take the corresponding action when it is triggered.</li><li>NonSubs(Action pop) method: This method is used to remove an Action from the _events list. This operation ensures that objects that stop listening to the event (unsubscribe) stop following the event.</li></ul><p>So we basically create our event management, now lets implement somewhere</p><pre>using UnityEngine;<br><br>namespace SoEvents<br>{<br>    public class Eventcheck : MonoBehaviour<br>    {<br>        [Header(&quot;Scritable Events&quot;)]<br>        public GameEvent eventUp, eventdown;<br>        [Header(&quot;Game objects&quot;)]<br>        public Transform upTransform, downTransform;<br>        private void OnEnable()<br>        {<br>            eventUp.Subs(PopUp);<br>            eventdown.Subs(PopDown);<br>        }<br>        private void OnDisable()<br>        {<br>            eventUp.NonSubs(PopUp);<br>            eventdown.NonSubs(PopDown);<br>        }<br>        private void PopUp() =&gt; upTransform.Translate(Vector3.up);<br>        private void PopDown() =&gt; downTransform.Translate(Vector3.down);<br><br>    }<br>}</pre><ul><li><strong>eventUp and eventdown </strong>: These variables represent two Scriptable Objects of type GameEvent. These events will be listened by this object of the Eventcheck class and trigger the movement of the upTransform and downTransform objects when they occur.</li><li>OnEnable() and OnDisable(): These two methods are used to start and stop listening for events. PopUp and PopDown methods are removed from the eventUp and eventdown events in the OnEnable() method, and these methods are removed from these events in the OnDisable() method. The game object listens for these events when active and stops listening when inactive.</li><li>PopUp() and PopDown(): These two methods will run when the eventUp and eventdown events are triggered. In the PopUp() method, the upTransform object moves up, while in the PopDown() method, the downTransform object moves down. In this way, certain actions are performed by triggering events.</li></ul><p>To sum up,The Eventcheck class is a MonoBehaviour class that listens for Scriptable Object-based events, eventUp and eventdown, and moves the upTransform and downTransform objects when these events occur. In this way, interaction is established between game objects and movement is performed by triggering certain actions within the game.</p><p>Lets implements our scripts :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*qL-MH21iKRVgdCThVnp0IQ.png" /></figure><p>Nice now we need to raise our event in this scenario ı use button you can use whatever you want like that:</p><pre>using UnityEngine;<br>using UnityEngine.UI;<br><br>namespace SoEvents<br>{<br>    public class ButtonClikced : MonoBehaviour<br>    {<br>        public Eventcheck eventcheck;<br><br>        [SerializeField] private Button button;<br>        private void OnEnable() =&gt; button.onClick.AddListener(Buttonclicked);<br>        private void OnDisable() =&gt; button.onClick.RemoveListener(Buttonclicked);<br>        private void Buttonclicked()<br>        {<br>            eventcheck.eventUp.Raise();<br>            eventcheck.eventdown.Raise();<br>        }<br><br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*rwyM-PmhMYYtcQZPImmrBw.png" /></figure><h4>Congrats we got it all done now all we have to do is play our game</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Ff6jWi7aC5j4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Df6jWi7aC5j4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Ff6jWi7aC5j4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/50044f42190f4393100312ef06e2af83/href">https://medium.com/media/50044f42190f4393100312ef06e2af83/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c71616bbfd75" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>