Esempio n. 1
0
        public static TargetLedger GetLedger(Component target, string memberName)
        {
            if (target == null)
            {
                return(null);
            }

            var ledger = target.GetComponent <CompoundStateLedger>();

            if (ledger == null)
            {
                ledger = target.AddComponent <CompoundStateLedger>();
            }

            var          token = new Token(target, memberName);
            TargetLedger result;

            if (ledger._table.TryGetValue(token, out result))
            {
                return(result);
            }

            result = TargetLedger.Create(ledger, target, memberName);
            ledger._table[new Token(target, memberName)] = result;
            return(result);
        }
Esempio n. 2
0
        private void Populate(Component component)
        {
            Vector2 p;
            Vector2 offset = Vector2.One * TileSize * .5f;

            for (int i = 0; i < this.cells.Length; i++)
            {
                Entity e;
                p = offset + new Vector2(i % this.size, i / this.size) * TileSize;
                if (this.cells[i] == WALL && this.CountNeighnors(this.cells, i, WALL) < 8)
                {
                    e = new Entity(p);
                    e.AddComponent(new OABB(offset));
                }
                else if (this.cells[i] > TREE)
                {
                    e = new Entity(p + new Vector2(0, 4));
                    e.InitiateCollision = false;
                    e.AddComponent(new Circle(4));
                }
                else
                {
                    continue;
                }
                e.InitiateCollision = false;
                e.UpdateBehaviour   = Entity.UpdateBehaviours.NeverUpdate;
                component.AddComponent(e);
            }
        }
Esempio n. 3
0
 public static Component SafeGetComponent(this Component component, Type componentType)
 {
     if (component.GetComponent(componentType) != null)
     {
         return(component.GetComponent(componentType));
     }
     return(component.AddComponent(componentType));
 }
Esempio n. 4
0
 public static T SafeGetComponent <T>(this Component component) where T : Component
 {
     if (component.GetComponent <T>() != null)
     {
         return(component.GetComponent <T>());
     }
     return(component.AddComponent <T>());
 }
 public static T SafeGetComponent <T>(this Component component) where T : Component
 {
     if ((UnityEngine.Object)component.GetComponent <T>() != (UnityEngine.Object)null)
     {
         return(component.GetComponent <T>());
     }
     return(component.AddComponent <T>());
 }
        public static T GetOrAddComponent <T>(this Component self) where T : Component
        {
            var result = self.GetComponent <T>();

            if (result == null)
            {
                result = self.AddComponent <T>();
            }

            return(result);
        }
Esempio n. 7
0
        public static T GetOrAddComponent <T>(this Component c) where T : Component
        {
            var r = c.GetComponent <T>();

            if (r != null)
            {
                return(r);
            }

            return(c.AddComponent <T>());
        }
Esempio n. 8
0
        static public Component FetchComponent(this Component item, Type type)
        {
            Component component = item.GetComponent(type);

            if (component.IsNull())
            {
                component = item.AddComponent(type);
            }

            return(component);
        }
Esempio n. 9
0
 public void LoadAsset(string prefabName, string destinationComponent)
 {
     if (_globalComponentTable.ContainsKey(destinationComponent))
     {
         Component          component = _globalComponentTable[destinationComponent];
         UnityEngine.Object @object   = Resources.Load(prefabName);
         if (@object != null)
         {
             GameObject gameObject = UnityEngine.Object.Instantiate(@object) as GameObject;
             gameObject.name = gameObject.name.Replace("(Clone)", "");
             string key = destinationComponent + "_" + gameObject.name;
             if (_globalComponentTable.ContainsKey(key))
             {
                 UnityEngine.Object.Destroy(gameObject);
                 return;
             }
             gameObject.transform.parent = component.transform;
             Component component2 = gameObject.GetComponent <Component>();
             if (component2 != null)
             {
                 component2.Initialise(component, isComponentInstance: false);
                 component.AddComponent(component2);
                 AddChildComponentsToGlobalTable(component2, destinationComponent);
             }
             VolumeMeter component3 = component.GetComponent <VolumeMeter>();
             if (component3 != null)
             {
                 component3.CollectAudioComponents();
             }
             DebugLog.Print("Asset [" + prefabName + "] loaded succesfuly");
         }
         else
         {
             DebugLog.Print("Asset [" + prefabName + "] name not found", DebugLevel.Error);
         }
     }
     else
     {
         DebugLog.Print("Target Component [" + destinationComponent + "] not found", DebugLevel.Error);
     }
 }
Esempio n. 10
0
 public void LoadAsset(GameObject component, string destinationComponent)
 {
     if (_globalComponentTable.ContainsKey(destinationComponent))
     {
         Component component2 = _globalComponentTable[destinationComponent];
         if (component != null)
         {
             component.name = component.name.Replace("(Clone)", "");
             string key = destinationComponent + "_" + component.name;
             if (_globalComponentTable.ContainsKey(key))
             {
                 UnityEngine.Object.DestroyImmediate(component);
                 return;
             }
             component.transform.parent = component2.transform;
             Component component3 = component.GetComponent <Component>();
             if (component3 != null)
             {
                 component3.Initialise(component2, isComponentInstance: false);
                 component2.AddComponent(component3);
                 AddChildComponentsToGlobalTable(component3, destinationComponent);
                 VolumeMeter component4 = component2.GetComponent <VolumeMeter>();
                 if (component4 != null)
                 {
                     component4.CollectAudioComponents();
                 }
             }
             DebugLog.Print("Asset [" + component.name + "] loaded succesfuly");
         }
         else
         {
             DebugLog.Print("Asset [" + component.name + "] name not found", DebugLevel.Error);
         }
     }
     else
     {
         DebugLog.Print("Target Component [" + destinationComponent + "] not found", DebugLevel.Error);
     }
 }
 public override BuildingBuilder BuildHouse(int x, int y)
 {
     Component.AddComponent(MapFactory.CreateHouse(Component.Title), x, y);
     return(this);
 }
 public override SquareBuilder BuildOakTree(int x, int y)
 {
     Component.AddComponent(MapFactory.CreateTree(Trees.Oak), x, y);
     return(this);
 }
 public override DistrictBuilder BuildRoad(IMapComponent component)
 {
     Component.AddComponent(component, 0, 0);
     return(this);
 }
Esempio n. 14
0
 /// <summary>
 ///     Gets a component attached to the given component's game object.
 ///     If one isn't found, a new one is attached and returned.
 /// </summary>
 /// <param name="component">Component.</param>
 /// <returns>Previously or newly attached component.</returns>
 public static T GetOrAddComponent <T>(this Component component) where T : Component =>
 component.GetComponent <T>() ?? component.AddComponent <T>();
Esempio n. 15
0
 static public T AddComponent <T>(this Component item) where T : Component
 {
     return(item.AddComponent(typeof(T)).Convert <T>());
 }
Esempio n. 16
0
 public override CityBuilder BuildDistrict(IMapComponent component)
 {
     Component.AddComponent(component, 0, 0);
     return(this);
 }
Esempio n. 17
0
        /// <summary>
        /// Gets a component attached to the given component's game object.
        /// If one isn't found, a new one is attached and returned.
        /// </summary>
        /// <param name="component">Component.</param>
        /// <returns>Previously or newly attached component.</returns>
        public static T GetOrAddComponent <T> (this Component component) where T : Component
        {
            var newOrExistingComponent = component.GetComponent <T>() ?? component.AddComponent <T>();

            return(newOrExistingComponent);
        }
Esempio n. 18
0
        /// <summary>
        /// Get component or add if not exist
        /// </summary>
        public static T GetOrAddComponent <T>(this Component component) where T : Component
        {
            T result = component.GetComponent <T>();

            return(result == null?component.AddComponent <T>() : result);
        }
Esempio n. 19
0
        /// <summary>
        /// Get component or add if not exist
        /// </summary>
        public static Component GetOrAddComponent(this Component component, Type componentType)
        {
            Component result = component.GetComponent(componentType);

            return(result == null?component.AddComponent(componentType) : result);
        }
Esempio n. 20
0
        public bool RegisterGroupComponent(GroupComponent groupComponent, string targetGroupComponentPath, bool createProxy = true)
        {
            if (!_allowExternalGroupComponents)
            {
                DebugLog.Print("External GroupComponent registration is disabled");
                return(false);
            }
            bool      result          = false;
            Component componentByName = GetComponentByName(targetGroupComponentPath);

            if (groupComponent != null)
            {
                groupComponent.Initialise(componentByName, isComponentInstance: false);
                if (componentByName != null)
                {
                    componentByName.AddComponent(groupComponent);
                }
                else
                {
                    _components.Add(groupComponent);
                }
                if (createProxy)
                {
                    GameObject gameObject = new GameObject();
                    gameObject.hideFlags = HideFlags.DontSave;
                    GroupComponentProxy groupComponentProxy = gameObject.AddComponent <GroupComponentProxy>();
                    groupComponentProxy._groupComponent = groupComponent;
                    groupComponentProxy.name            = groupComponent.name + "_Proxy";
                    if (componentByName != null)
                    {
                        groupComponentProxy.transform.parent = componentByName.transform;
                    }
                    else
                    {
                        groupComponentProxy.transform.parent = base.gameObject.transform;
                    }
                    _groupComponentProxies.Add(groupComponentProxy);
                }
                else if (componentByName != null)
                {
                    groupComponent.transform.parent = componentByName.transform;
                }
                else
                {
                    groupComponent.transform.parent = base.gameObject.transform;
                }
                if (componentByName != null)
                {
                    VolumeMeter component = componentByName.GetComponent <VolumeMeter>();
                    if (component != null)
                    {
                        component.CollectAudioComponents();
                    }
                }
                DebugLog.Print("GroupComponent [" + groupComponent.name + "] registred succesfuly");
                result = true;
            }
            else
            {
                DebugLog.Print("GroupComponent [" + groupComponent.name + "] failed to register", DebugLevel.Error);
            }
            return(result);
        }
Esempio n. 21
0
 /// <summary>
 /// Gets a component attached to the given component's GameObject.
 /// If one isn't found, a new one is attached and returned.
 /// </summary>
 /// <param name="component">Component.</param>
 /// <returns>Previously or newly attached component.</returns>
 public static T GetOrAddComponent <T>(this Component component) where T : Component
 {
     return(component.GetComponent <T>() ?? component.AddComponent <T>());
 }
Esempio n. 22
0
 public override RoadBuilder BuildTurnRight(int x, int y)
 {
     Component.AddComponent(MapFactory.CreateRoad(Roads.TurnRight), x, y);
     return(this);
 }