Beispiel #1
0
        public static FieldObjectEntity createBlank(FieldObjectID id)
        {
            var exist = Rank.None;

            //debugLogFirldObjectID(id);

            foreach (Rank rank in Enum.GetValues(typeof(Rank)))
            {
                //debugLogRank(rank);
                if (rank == Rank.None)
                {
                    continue;
                }

                if (!base_resources.ContainsKey(rank))
                {
                    throw new Exception("rank Not found in base_resources" + Enum.GetName(typeof(Rank), rank));
                }

                if (base_resources[rank].ContainsKey(id))
                {
                    exist = rank;
                }
            }

            if (exist == Rank.None)
            {
                throw new Exception("Key not found in FieldObjectEntity base resouces.");
            }

            var resource = base_resources[exist][id];

            var entity = new FieldObjectEntity {
                id   = entity_id,
                type = resource.type,
                size = resource.size,
                //prefab_path = resource.prefab_path,
                prefab_id      = resource.prefab_id,
                inventory_size = resource.inventory_size,
            };

            var go_base = prefabs[entity.prefab_id];

            entity.game_object = Object.Instantiate(go_base);
            var foc = entity.game_object.GetComponent <FieldObjectController>();

            if (foc != null)
            {
                foc.id = entity_id;
            }
            entity.game_object.SetActive(false);

            entity_id += 1;
            return(entity);
        }
        public static FieldObjectID getRandomObjectID(Array array)
        {
            FieldObjectID id = FieldObjectID.None;

            do
            {
                id = (FieldObjectID)array.GetValue((new Random()).Next(array.Length));
            } while (id == FieldObjectID.None);

            return(id);
        }
        public static void FieldObjectIDDebugLog(FieldObjectID id)
        {
            switch (id)
            {
            case FieldObjectID.None: Debug.Log("FieldObjectIDDebugLog: None"); break;

            case FieldObjectID.Torch: Debug.Log("FieldObjectIDDebugLog: Torch"); break;

            case FieldObjectID.TreasureBox: Debug.Log("FieldObjectIDDebugLog: TreasureBox"); break;

            default: Debug.Log("FieldObjectIDDebugLog: default"); break;
            }
        }
Beispiel #4
0
        public static FieldObjectEntity createEntity(Rank rank, FieldObjectID id)
        {
            if (!base_resources.ContainsKey(rank) || !base_resources[rank].ContainsKey(id))
            {
                throw new KeyNotFoundException();
            }

            var entity = base_resources[rank][id].clone();

            entity.id = entity_id;

            entity_id += 1;
            return(entity);
        }
        public static FieldObjectEntity createEntity(FieldObjectID id)
        {
            //FieldObjectEntity entity = (FieldObjectEntity)ObjectPoolService.takeOut(Type.Props, id);
            //FieldObjectEntity entity = FieldObjectEntityFactory.createBlank(id);

            /*
             * FieldObjectEntity entity = (FieldObjectEntity)ObjectPoolService.takeOut(Type.Props, id);
             * if (entity == null) { entity = FieldObjectEntityFactory.createBlank(id); }
             */
            FieldObjectEntity entity = FieldObjectEntityFactory.createBlank(id);

            FieldObjectEntityFactory.setupInventory(entity);
            FieldObjectEntityFactory.setupRandomPosition(entity);

/*
 *          if (r == null) {
 *              ObjectPoolService.ret(Type.Props, entity.type, entity);
 *          }
 */
            entity_list.Add(entity.id, entity);
            return(entity);
        }