Advertisement
Pro_Unit

SpawnedObject

Dec 13th, 2018
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. using UnityEngine;
  6. using UnityEngine.Events;
  7.  
  8.     public class SpawnedObject : TransformObject
  9.     {
  10.         Dictionary<Type, Component> ChashedComponents = new Dictionary<Type, Component> ();
  11.         public T Get<T> () where T : Component
  12.         {
  13.             var type = typeof (T);
  14.             if (!ChashedComponents.ContainsKey (type))
  15.                 ChashedComponents.Add (type, GetComponent<T> ());
  16.  
  17.             T result = ChashedComponents[type] as T;
  18.             return result;
  19.         }
  20.         public void ActionWith<T> (Action<T> ActionWhithComponent) where T : Component
  21.         {
  22.             ActionWhithComponent (Get<T> ());
  23.         }
  24.  
  25.         public UnityEvent OnSpawn;
  26.  
  27.         public UnityEvent OnDeSpawn;
  28.  
  29.         public Vector3 OffsetPosition;
  30.  
  31.         public void PushToPool ()
  32.         {
  33.             Pool.instance.Push (gameObject);
  34.         }
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement