Exemplo n.º 1
0
        public GameObject Show(ViewType viewType, ViewData data = null)
        {
            TypedView typedView = null;

            if (typedViewInstances.ContainsKey(viewType))
            {
                var instance = typedViewInstances[viewType];
                instance.Setup(data);
                typedView = instance;
            }
            else
            {
                var prefab = typedViewPrefabs.GetPrefab(viewType);
                if (prefab != null)
                {
                    GameObject instance = GameObject.Instantiate <GameObject>(prefab);
                    typedView = instance.GetComponentInChildren <TypedView>();
                    if (typedView != null)
                    {
                        typedViewInstances[viewType] = typedView;
                        instance.transform.SetParent(GetCanvasTransform(typedView.CanvasType), false);
                        if (data != null && data.ViewDepth.HasValue)
                        {
                            typedView.SetViewDepth(data.ViewDepth.Value);
                        }
                        SortByDepth(typedView.CanvasType);
                        typedView.AnimIn();
                        typedView.Setup(data);
                        GameEvents.OnViewShowed(viewType);
                    }
                    else
                    {
                        throw new UnityException($"Not found TypedView on view => {viewType}");
                    }
                }
                else
                {
                    throw new UnityException($"Prefab for view type => {viewType} not founded");
                }
            }

            OpenedStack.Push(CurrentOpen);
            CurrentOpen = viewType;
            return(typedView?.gameObject ?? null);
        }
Exemplo n.º 2
0
        public GameObject Show(string name, ViewData data = null)
        {
            NamedView namedView = null;

            if (namedViewInstances.ContainsKey(name))
            {
                var instance = namedViewInstances[name];
                instance.Setup(data);
                namedView = instance;
            }
            else
            {
                var prefab = namedViewPrefabs.GetPrefab(name);
                if (prefab != null)
                {
                    GameObject instance = GameObject.Instantiate <GameObject>(prefab);
                    namedView = instance.GetComponentInChildren <NamedView>();
                    if (namedView != null)
                    {
                        namedViewInstances[name] = namedView;
                        instance.transform.SetParent(GetCanvasTransform(namedView.CanvasType), false);
                        if (data != null && data.ViewDepth.HasValue)
                        {
                            namedView.SetViewDepth(data.ViewDepth.Value);
                        }
                        SortByDepth(namedView.CanvasType);
                        namedView.AnimIn();
                        namedView.Setup(data);
                    }
                    else
                    {
                        throw new UnityException($"Not found NamedView on view => {name}");
                    }
                }
                else
                {
                    throw new UnityException($"Prefab for view name => {name} not founded");
                }
            }
            return(namedView?.gameObject ?? null);
        }
Exemplo n.º 3
0
        public Task <bool> CreateRole([NotNull] CreateRoleOption option)
        {
            if (option == null)
            {
                throw new ArgumentNullException(nameof(option));
            }

            option.Name = option.Name?.Trim() ?? throw new ArgumentNullException(nameof(option.Name));
            if (option.Name.Length < 3)
            {
                throw new ArgumentOutOfRangeException(nameof(option.Name));
            }

            Entity role;

            switch (option.Race)
            {
            case Race.Human:
            {
                role = PrefabRepository.GetPrefab("human.init").Clone();
            }

            break;

            default:

                throw new ArgumentOutOfRangeException();
            }

            Mapper.Map(option, role.Get <UnitComponent>());
            role.Name = option.Name;
            role.Get <PositionComponent>().Pos = Config.Cfg.SpawnPoint;
            EntityRepository.SaveEntity(role);
            Roles.Add(role);

            Logger.Info($"New role {option.Name} has been added");

            return(Task.FromResult(true));
        }