Exemple #1
0
        private void Initialize()
        {
            mInactiveObjects.Clear();
            mUsedObjects.Clear();
            for (int i = 0; i < _validObjectsRoot.childCount; ++i)
            {
                mInactiveObjects.Add(_validObjectsRoot.GetChild(i).GetComponent <ValidObjectsScript>());
                mInactiveObjects[i].enabled = false;
            }
            mTotalObjects = _validObjectsRoot.childCount;
            mObjectsFound = 0;

            // Select objects and place into menu slots
            for (int i = 0; i < _menuSlots.Length; ++i)
            {
                ValidObjectsScript obj = GetNextObject();
                if (obj != null)
                {
                    _menuSlots[i].SetObject(obj);
                    int menuItemId = i;
                    _menuSlots[i].pOnMenuObjectRemoved += (HoGObjectMenuItem menuItem) =>
                    {
                        ValidObjectsScript newObj = GetNextObject();
                        if (newObj != null)
                        {
                            _menuSlots[menuItemId].SetObject(newObj);
                        }
                        mObjectsFound++;
                        UpdateStatus();
                        CheckGameOver();
                    };
                }
            }
            UpdateStatus();
        }
Exemple #2
0
        private ValidObjectsScript GetNextObject()
        {
            ValidObjectsScript outObj = null;

            if (mInactiveObjects.Count <= 0 || mCurrentIndex >= mInactiveObjects.Count)
            {
                return(null);
            }
            if (_randomize)
            {
                int rndIdx = Random.Range(0, mInactiveObjects.Count);
                outObj = mInactiveObjects[rndIdx];
                mUsedObjects.Add(outObj);
                mInactiveObjects.Remove(outObj);
            }
            else
            {
                if (mCurrentIndex < 0 || mCurrentIndex >= mInactiveObjects.Count)
                {
                    mCurrentIndex = 0;
                }
                outObj = mInactiveObjects[mCurrentIndex++];
            }
            return(outObj);
        }
 private void OnObjectFound()
 {
     // Maybe play some animation before.
     if (_iconImage != null)
     {
         _iconImage.sprite  = null;
         _iconImage.enabled = false;
     }
     if (_iconText != null)
     {
         _iconText.text = string.Empty;
     }
     mCurrentObject.pObjectFound -= OnObjectFound;
     mCurrentObject = null;
     if (mOnMenuObjectRemoved != null)
     {
         mOnMenuObjectRemoved(this);
     }
 }
 public void SetObject(ValidObjectsScript obj)
 {
     if (pHasObject)
     {
         throw new UnityException(gameObject.name + " menu already contains object!");
     }
     mCurrentObject = obj;
     mCurrentObject.pObjectFound += OnObjectFound;
     mCurrentObject.enabled       = true;
     if (_iconImage != null)
     {
         _iconImage.enabled = true;
         _iconImage.sprite  = mCurrentObject.pMenuIconSprite;
         Color c = _iconImage.color;
         c.a = (_iconImage.sprite == null) ? 0 : 1;
         _iconImage.color = c;
     }
     if (_iconText != null)
     {
         _iconText.text = obj.pName;
     }
 }