示例#1
0
        /// <summary>
        /// Initializes this view with an item data.
        /// </summary>
        /// <param name="item">The item data</param>
        /// <param name="showQuantity">A flag that indicates if we should show quantities</param>
        public void Init(Item item, bool showQuantity = false)
        {
            if (item != null)
            {
                _data = item;

                _referenceData = ReferenceService.GetInstance().GetItem(this._data.itemId);
                if (_referenceData != null)
                {
                    ItemName.text        = _referenceData.name;
                    ItemDescription.text = _referenceData.description;
                    ItemIcon.sprite      = Resources.Load <Sprite>("Icon" + _referenceData.prefab);
                }

                if (_data.quantity >= 0)
                {
                    ItemQuantity.text = "+" + _data.quantity;
                }
                else
                {
                    ItemQuantity.text = _data.quantity.ToString();
                }

                ItemQuantity.gameObject.SetActive(showQuantity);
            }
            else
            {
                Debug.LogError("Invalid item data assigned to item prefab.");
            }
        }
示例#2
0
        /// <summary>
        ///     Sets up the setup milestones list.
        ///     Loads reference data and player data.
        /// </summary>
        void Awake()
        {
            // Initialize start up check list
            _startupCheckList = new List <string>
            {
                PLAYABLE_LOCATIONS_INITIALIZED,
                REFERENCE_DATA_INITIALIZED,
                PLAYER_DATA_INITIALIZED,
                MAP_INITIALIZED
            };

            // Load and initialize Reference Data
            StartCoroutine(ServerManager.GetReferenceData(data =>
            {
                ReferenceService.GetInstance().Init(data);
                _startupCheckList.Remove(REFERENCE_DATA_INITIALIZED);
                CheckStartConditions();
            }, OnError));

            // Load and initialize Player Data
            StartCoroutine(ServerManager.GetPlayerData(data =>
            {
                PlayerService.GetInstance().Init(data);
                _startupCheckList.Remove(PLAYER_DATA_INITIALIZED);
                CheckStartConditions();
            }, OnError));

            LoadOnStart = false;
        }
        public static ReferenceService GetInstance()
        {
            if (_instance == null)
            {
                _instance = new ReferenceService();
            }

            return(_instance);
        }
        /// <summary>
        ///     On Updates, adjust the position and CW, CCW rotations of the Rig.
        ///     The code also applies vertical motions if Up and Down buttons are continously pressed.
        /// </summary>
        void Update()
        {
            if (PlayerService.GetInstance().IsInitialized)
            {
                ReferenceItem refItem = ReferenceService.GetInstance()
                                        .GetItem(PlayerService.GetInstance().AvatarType);
                if (refItem != null && refItem.itemId != AvatarType && AvatarImage != null)
                {
                    Texture2D t = (Texture2D)Resources.Load("Icon" + refItem.prefab);
                    Sprite    s = Sprite.Create(t, AvatarImage.sprite.rect, AvatarImage.sprite.pivot);
                    AvatarImage.sprite = s;
                    AvatarType         = refItem.itemId;
                }
            }

            // Move the camera at a speed that is linearly dependent on the height of the camera above
            // the ground plane to make camera manual camera movement practicable. The movement speed
            // is clamped between 1% and 100% of the configured MovementSpeed.
            float forwardSpeed = Mathf.Clamp(
                Target.transform.position.y,
                MaximumForwardSpeed * 0.1f,
                MaximumForwardSpeed) * Time.deltaTime;


            if (InputDirection.magnitude != 0 && Target != null)
            {
                float rotationDirection = 1f;
                float angle             = Vector3.Angle(InputDirection, Vector3.right);

                if (angle > 90f)
                {
                    rotationDirection = -1f;
                }

                if (angle < 80f || angle > 100)
                {
                    // Rotate target around y axis
                    Target.transform.RotateAround(
                        Target.transform.position,
                        Vector3.up,
                        rotationDirection * MaximumRotationSpeed * InputDirection.magnitude *
                        Time.deltaTime);
                }
                else
                {
                    float dir = InputDirection.y >= 0 ? 1f : -1f;
                    Target.transform.position += Target.transform.forward * forwardSpeed * dir
                                                 * InputDirection.magnitude;
                }
            }
        }
示例#5
0
 public void Update()
 {
     if (PlayerService.GetInstance().IsInitialized)
     {
         ReferenceItem refItem = ReferenceService.GetInstance()
                                 .GetItem(PlayerService.GetInstance().AvatarType);
         if (refItem != null && refItem.itemId != AvatarType)
         {
             Material pinMaterial = (Material)Resources.Load("Material" + refItem.prefab);
             GetComponent <MeshRenderer>().sharedMaterial = pinMaterial;
             AvatarType = refItem.itemId;
         }
     }
 }
        /// <summary>
        /// Initializes the battle by passing the battle data received from the server,
        /// and a callback function to notify the caller when it ends.
        ///
        /// </summary>
        /// <param name="battleData">A battle data</param>
        /// <param name="OnBattleEnds">A callback</param>
        public void Init(BattleData battleData, Action <bool> OnBattleEnds)
        {
            this._onBattleEnds = OnBattleEnds;
            this._battleData   = battleData;

            _referenceService = ReferenceService.GetInstance();
            _playerService    = PlayerService.GetInstance();
            _uiManager        = GameObject.FindGameObjectWithTag("UIManager").GetComponent <UIManager>();

            Feedback.gameObject.SetActive(false);
            Feedback.text = "";

            InitNPC();
            InitAvatar();

            _npcCurrentState = BATTLE_STATES.READY_SET_GO;

            _isBattleOn = true;
        }
        /// <summary>
        ///     Starts respawn at the location identified by the given id, only if the location
        ///     definition indicates that this it is respawnable.
        ///     Note that this information will be overriden after the next server sync.
        /// </summary>
        /// <param name="locationId">The location id</param>
        /// <exception cref="Exception">Exception if id is invalid</exception>
        public void StartRespawn(string locationId)
        {
            if (string.IsNullOrEmpty(locationId))
            {
                throw new System.Exception("Invalid Location Id!");
            }

            // Init the spawn location respawn time and active flag (to mimic what the server will do)
            // Prevents constant syncs - the server is the final authority
            SpawnLocation location = GetInstance().GetSpawnLocation(locationId);
            ReferenceItem ri       = ReferenceService.GetInstance().GetItem(location.objectTypeId);

            if (location != null && ri != null && ri.respawnDuration != null)
            {
                location.active = false;
                TimeSpan ts = XmlConvert.ToTimeSpan(ri.respawnDuration);
                DateTime dt = DateTime.Now.Add(ts);
                location.respawnTime = dt.ToString("O");
                DataHasChanged       = true;
            }
        }
        /// <summary>
        ///     Sets up the setup milestones list.
        ///     Loads reference data and player data.
        /// </summary>
        void Awake()
        {
            _gameStarted = false;

            // Initialize start up check list
            _startupCheckList = new List <string>
            {
                REFERENCE_DATA_INITIALIZED,
                PLAYER_DATA_INITIALIZED,
                MAP_INITIALIZED
            };

            // Load and initialize Reference Data
            ReferenceService.GetInstance().Init(ServerManager.GetReferenceData());
            _startupCheckList.Remove(REFERENCE_DATA_INITIALIZED);

            // Load and initialize Player Data
            PlayerService.GetInstance().Init(ServerManager.GetPlayerData());
            _startupCheckList.Remove(PLAYER_DATA_INITIALIZED);

            LoadOnStart = false;

            //CheckStartConditions();
        }