示例#1
0
    public void ReturnInventoryItem(IDItem item)
    {
        item.itemCopyForInventory.SetParent(null);
        item.itemCopyForInventory.SetParent(item.transform);
        item.itemCopyForInventory.localPosition = Vector3.zero;

        item.ShowOrHideInventoryCopy(false);
    }
示例#2
0
        public void TestContainerRooting()
        {
            var rootContainer = new IDContainer("RootContainer", true);
            var subContainer  = new IDContainer("SubContainer");
            var idItem        = new IDItem("Item1");

            subContainer.Add(idItem);

            Assert.AreEqual(false, idItem.IsRooted);

            rootContainer.Add(subContainer);
            Assert.AreEqual(true, idItem.IsRooted);
        }
示例#3
0
    public void PlaceItemToView(IDItem item)
    {
        item.itemCopyForInventory.SetParent(null);
        item.itemCopyForInventory.SetParent(itemViewerPosePosition);
        item.itemCopyForInventory.localPosition = Vector3.zero + item.itemCopyViewerOffsetPos;
        item.itemCopyForInventory.localRotation = Quaternion.identity * Quaternion.Euler(item.itemCopyViewerRotAdjustment);
        Vector3 newScale = item.itemCopyForInventory.localScale;

        newScale.Set(item.itemCopyViewerScale.x, item.itemCopyViewerScale.y, item.itemCopyViewerScale.z);
        item.itemCopyForInventory.localScale = newScale;

        item.ShowOrHideInventoryCopy(true);
    }
示例#4
0
        public void TestCollectionRooting()
        {
            var rootContainer = new IDContainer("RootContainer", true);
            var subContainer1 = new EditableIDList <IIDItem>("SubContainer1");
            var subContainer2 = new EditableIDList <IIDItem>("SubContainer2");
            var idItem        = new IDItem("Item1");

            subContainer1.Add(subContainer2);
            subContainer2.Add(idItem);

            Assert.AreEqual(false, idItem.IsRooted);

            rootContainer.Add(subContainer1);
            Assert.AreEqual(true, idItem.IsRooted);

            subContainer1.Remove(subContainer2);
            Assert.AreEqual(false, idItem.IsRooted);

            // Now check that events are fired not too often
            int eventFiredCount = 0;

            idItem.RootingChanged += delegate(object sender, RootingChangedEventArgs args)
            {
                eventFiredCount++;
                switch (args.Rooting)
                {
                case RootingAction.Rooted:
                    Assert.IsNotNull(idItem.Owner);
                    break;

                case RootingAction.ToBeUnrooted:
                    Assert.IsNotNull(idItem.Owner);
                    break;
                }
            };

            subContainer1.Add(subContainer2);    // This should trigger a Rooted event
            Assert.AreEqual(1, eventFiredCount, "Rooted event didn't occur.");
            subContainer2.Remove(idItem);        // This should trigger a ToBeUnrooted event
            Assert.AreEqual(2, eventFiredCount, "ToBeUnrooted event didn't occur.");
            subContainer1.Remove(subContainer2); // This shouldn't trigger anything
            Assert.AreEqual(2, eventFiredCount, "IdItem did not unsubcribe from event.");
            subContainer2.Add(idItem);           // This should also not trigger anything
            Assert.AreEqual(2, eventFiredCount, "RootingChanged event triggered even if not in object graph.");
            subContainer1.Add(subContainer2);    // Now this should finally trigger the RootingChanged event.
            Assert.AreEqual(3, eventFiredCount);
        }
示例#5
0
        public long GetNewId(string key)
        {
            IDItem idItem;
            // 获取idItem的实例,如果没有,用double check的方式创建实例
            if (!IDItems.TryGetValue(key, out idItem))
            {
                lock (_syncObj)
                {
                    if (!IDItems.TryGetValue(key, out idItem))
                    {
                        idItem = new IDItem(key, ContextFactory);
                        IDItems.Add(key, idItem);
                    }
                }
            }

            return idItem.GetNewId();
        }
示例#6
0
 public static IIDItem GetIDItem(this IDItem container, string relPath)
 {
     return(((IIDItem)container).GetIDItem(relPath));
 }
示例#7
0
    // Update is called once per frame
    void Update()
    {
        numOfItems = tedInventory.items.Count;
        GetTedInventory();

        if (isActive)
        {
            //numOfItems = tedInventory.items.Count;

            if (numOfItems > 0)
            {
                HighLightCurrentlyEquippedItem();

                curItem     = inventoryItems[curItemRow, curItemCol];
                curItemIcon = itemSlots[curItemRow, curItemCol];

                Debug.Log(curItem);

                if (curItem != prevItem && prevItem != null)
                {
                    tedInventory.ReturnInventoryItem(prevItem);
                }

                prevItem = curItem;

                itemSelectorBox.rectTransform.anchoredPosition = curItemIcon.rectTransform.anchoredPosition;

                currentInvItemNameTxt.enabled        = true;
                currentItemInvDescriptionTxt.enabled = true;

                currentInvItemNameTxt.text        = curItem.ObjActualName;
                currentItemInvDescriptionTxt.text = curItem.ObjDescription;

                inventoryItemCam.enabled        = true;
                currentInvItemInspector.enabled = true;
                itemInspectorFrame.enabled      = true;

                if (needToUpdateItemToView)
                {
                    tedInventory.PlaceItemToView(curItem);
                    needToUpdateItemToView = false;
                }

                RotateModel(curItem.itemCopyForInventory, modelRotationSpeed);
            }
            else
            {
                currentInvItemNameTxt.enabled        = true;
                currentItemInvDescriptionTxt.enabled = true;

                currentInvItemNameTxt.text        = "";
                currentItemInvDescriptionTxt.text = "";

                inventoryItemCam.enabled        = false;
                currentInvItemInspector.enabled = false;
                itemInspectorFrame.enabled      = false;
            }

            switch (InventoryState)
            {
            case InventoryMode.Selecting:

                itemActionSelectorBox.rectTransform.anchoredPosition = currentItemActionIcon.rectTransform.anchoredPosition;
                firstItemCombineBox.enabled = false;

                if (numOfItems > 0)
                {
                    itemSelectorBox.enabled = true;
                    FlashIcon(itemSelectorBox, itemSelectorFrameAlphaChange);
                }
                else
                {
                    itemSelectorBox.enabled = false;
                }

                break;

            case InventoryMode.SelectingCombinedItem:

                if (numOfItems > 1)
                {
                    itemSelectorBox.enabled     = true;
                    firstItemCombineBox.enabled = true;
                    FlashIcon(itemSelectorBox, itemActionSelectorFrameAlphaChange);
                    //itemActionSelectorBox.color = new Color(itemActionSelectorBox.color.r, itemActionSelectorBox.color.g, itemActionSelectorBox.color.b, iconAlphaMax);
                }

                break;

            case InventoryMode.Combining:



                break;
            }
        }
    }
示例#8
0
    //
    // CONTROLS/INPUT
    //

    public void PressX()
    {
        if (InventoryState == InventoryMode.Selecting)
        {
            if (tedInventory.items.Count > 0)
            {
                if (currentItemActionIcon == equipButton)
                {
                    // Equip item if possible, or unequip
                    if (!curItem.isInHand)
                    {
                        if (curItem.canBeInHand)
                        {
                            if (currentlyEquippedItem != null)
                            {
                                currentlyEquippedItem.UnequipItem();
                            }
                            curItem.EquipItem();
                            currentlyEquippedItem = curItem;
                            //itemInHandHighlighter.enabled = true;
                            //itemInHandHighlighter.rectTransform.anchoredPosition = itemSlots[curItemRow, curItemCol].rectTransform.anchoredPosition;
                        }
                    }
                    else if (curItem.isInHand)
                    {
                        curItem.UnequipItem();
                        currentlyEquippedItem = null;
                        //itemInHandHighlighter.enabled = false;
                    }
                }
                else if (currentItemActionIcon == combineItemButton)
                {
                    if (curItem.makesCombinationItem && (numOfItems > 1))
                    {
                        curFirstCombinationItem = curItem;
                        firstItemCombineBox.rectTransform.anchoredPosition = curItemIcon.rectTransform.anchoredPosition;
                        int[] nextRowAndCol = GetRowAndColumnOfNextItem();
                        curItemRow = nextRowAndCol[0];
                        curItemCol = nextRowAndCol[1];

                        InventoryState = InventoryMode.SelectingCombinedItem;

                        needToUpdateItemToView = true;
                    }
                }
            }
        }
        else if (InventoryState == InventoryMode.SelectingCombinedItem)
        {
            IDItem firstItem = null, secondItem = null, combinedItem = null;

            if (curFirstCombinationItem.canCombineToMakeTheseItems.Count > 0)
            {
                foreach (IDItem item in curFirstCombinationItem.canCombineToMakeTheseItems)
                {
                    if (item.isCombinedItem && item.consistsOfTheseItems.Contains(curItem))
                    {
                        combinedItem = item;
                        firstItem    = curFirstCombinationItem;
                        secondItem   = curItem;
                    }
                }

                if (firstItem && secondItem && combinedItem)
                {
                    tedInventory.items.Remove(firstItem);
                    tedInventory.items.Remove(secondItem);
                    tedInventory.items.Add(combinedItem);
                    numOfItems--;

                    curItem = tedInventory.items[numOfItems - 2];
                    int[] nextRowAndCol = GetRowAndColumnOfNextItem();
                    curItemRow = nextRowAndCol[0];
                    curItemCol = nextRowAndCol[1];

                    InventoryState = InventoryMode.Selecting;

                    needToUpdateItemToView = true;
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        numOfItems = tedInventory.items.Count;
        GetTedInventory();

        if (deskScreenActivated)
        {
            switch (DeskScreenTabState)
            {
            case DeskScreenTabMode.ProjectTab:

                ShowProjectWindows(true);
                FlashIcon(projListSelectorBar, projBulletPointSelectorFrameAlphaChange);

                break;

            case DeskScreenTabMode.InventoryTab:

                ShowInventoryWindows(true);

                //numOfItems = tedInventory.items.Count;

                if (numOfItems > 0)
                {
                    HighLightCurrentlyEquippedItem();

                    curItem     = inventoryItems[curItemRow, curItemCol];
                    curItemIcon = itemSlots[curItemRow, curItemCol];

                    if (curItem != prevItem && prevItem != null)
                    {
                        tedInventory.ReturnInventoryItem(prevItem);
                    }

                    prevItem = curItem;

                    itemSelectorBox.rectTransform.anchoredPosition = curItemIcon.rectTransform.anchoredPosition;

                    currentInvItemNameTxt.enabled        = true;
                    currentItemInvDescriptionTxt.enabled = true;

                    currentInvItemNameTxt.text        = curItem.ObjActualName;
                    currentItemInvDescriptionTxt.text = curItem.ObjDescription;

                    inventoryItemCam.enabled        = true;
                    currentInvItemInspector.enabled = true;

                    if (needToUpdateItemToView)
                    {
                        tedInventory.PlaceItemToView(curItem);
                        needToUpdateItemToView = false;
                    }

                    RotateModel(curItem.itemCopyForInventory, hostModelRotationSpeed);
                }
                else
                {
                    currentInvItemNameTxt.enabled        = true;
                    currentItemInvDescriptionTxt.enabled = true;

                    currentInvItemNameTxt.text        = "";
                    currentItemInvDescriptionTxt.text = "";

                    inventoryItemCam.enabled        = false;
                    currentInvItemInspector.enabled = false;
                }

                switch (InventoryState)
                {
                case InventoryMode.Selecting:

                    itemActionSelectorBox.rectTransform.anchoredPosition = currentItemActionIcon.rectTransform.anchoredPosition;
                    firstItemCombineBox.enabled = false;

                    if (numOfItems > 0)
                    {
                        itemSelectorBox.enabled = true;
                        //FlashIcon(itemActionSelectorBox, itemActionSelectorFrameAlphaChange);
                        FlashIcon(itemSelectorBox, itemSelectorFrameAlphaChange);
                    }
                    else
                    {
                        itemSelectorBox.enabled = false;
                    }

                    break;

                case InventoryMode.SelectingCombinedItem:

                    if (numOfItems > 1)
                    {
                        itemSelectorBox.enabled     = true;
                        firstItemCombineBox.enabled = true;
                        FlashIcon(itemSelectorBox, itemActionSelectorFrameAlphaChange);
                        //itemActionSelectorBox.color = new Color(itemActionSelectorBox.color.r, itemActionSelectorBox.color.g, itemActionSelectorBox.color.b, iconAlphaMax);
                    }

                    break;

                case InventoryMode.Combining:



                    break;
                }

                break;

            case DeskScreenTabMode.StatusTab:

                ShowStatusWindows(true);
                RotateModel(hostModel, hostModelRotationSpeed);
                RotateModel(eyeModel, eyeModelRotationSpeed);

                string headerColorHex  = ColorUtility.ToHtmlStringRGBA(statusTextHeaderColor);
                string resultsColorHex = ColorUtility.ToHtmlStringRGBA(statusTextResultsColor);

                hostStatusTxt.text = "<color=#" + headerColorHex + ">" + hostNameHeader + "</color>  <color=#" + resultsColorHex + ">" + curHostNameString + "</color>\n\n" +
                                     "<color=#" + headerColorHex + ">" + hostHeightHeader + "</color>  <color=#" + resultsColorHex + ">" + curHostHeightString + "</color>\n\n" +
                                     "<color=#" + headerColorHex + ">" + hostHealthHeader + "</color>  <color=#" + resultsColorHex + ">" + curHostHealthString + "</color>\n\n" +
                                     "<color=#" + headerColorHex + ">" + hostEffectsHeader + "</color>  <color=#" + resultsColorHex + ">" + curHostEffectsString + "</color>";
                eyeStatusTxt.text = "<color=#" + resultsColorHex + ">" + curEyeNameString + "</color>  <color=#" + headerColorHex + ">" + eyeNameHeader + "</color>\n\n" +
                                    "<color=#" + resultsColorHex + ">" + curEyeEffectsString + "</color>  <color=#" + headerColorHex + ">" + eyeEffectsHeader + "</color>";

                //hostStatusHeaderTxt.text = hostNameHeader + "\n\n" + hostHeightHeader + "\n\n" + hostHealthHeader + "\n\n" + hostEffectsHeader;
                //hostStatusTxt.text = curHostNameString + "\n\n" + curHostHeightString + "\n\n" + curHostHealthString + "\n\n" + curHostEffectsString;

                //eyeStatusHeaderTxt.text = eyeNameHeader + "\n\n" + eyeEffectsHeader;
                //eyeStatusTxt.text = curEyeNameString + "\n\n" + curEyeEffectsString;

                if ((Time.time - hostNameUnravelFrameRefTime > hostNameCharUnravelTime) && (hostNameCharIndex < hostNameTitleSpecies.ToCharArray().Length))
                {
                    if (justDisplayedRandomHostNameChar)
                    {
                        curHostNameString = curHostNameString.Remove(curHostNameString.Length - 1, 1);
                    }

                    bool displayRandomChar = (Random.Range(0.0f, 1.0f) < chanceToDisplayRandomChar);

                    if (displayRandomChar)
                    {
                        curHostNameString = curHostNameString + statusTextRandomCharString.ToCharArray()[Random.Range(0, statusTextRandomCharString.ToCharArray().Length)];
                        justDisplayedRandomHostNameChar = true;
                    }
                    else
                    {
                        curHostNameString = curHostNameString + hostNameTitleSpecies.ToCharArray()[hostNameCharIndex];
                        justDisplayedRandomHostNameChar = false;
                        hostNameCharIndex++;
                    }

                    //if (Random.Range(0.0f, 1.0f) < chanceToResetString) {
                    //    curHostNameString = "";
                    //    hostNameCharIndex = 0;
                    //}

                    hostNameUnravelFrameRefTime = Time.time;
                }
                if ((Time.time - hostHeightUnravelFrameRefTime > hostHeightCharUnravelTime) && (hostHeightCharIndex < hostHeightWeightBloodType.ToCharArray().Length))
                {
                    if (justDisplayedRandomHostHeightChar)
                    {
                        curHostHeightString = curHostHeightString.Remove(curHostHeightString.Length - 1, 1);
                    }

                    bool displayRandomChar = (Random.Range(0.0f, 1.0f) < chanceToDisplayRandomChar);

                    if (displayRandomChar)
                    {
                        curHostHeightString = curHostHeightString + statusTextRandomCharString.ToCharArray()[Random.Range(0, statusTextRandomCharString.ToCharArray().Length)];
                        justDisplayedRandomHostHeightChar = true;
                    }
                    else
                    {
                        curHostHeightString = curHostHeightString + hostHeightWeightBloodType.ToCharArray()[hostHeightCharIndex];
                        justDisplayedRandomHostHeightChar = false;
                        hostHeightCharIndex++;
                    }

                    //if (Random.Range(0.0f, 1.0f) < chanceToResetString) {
                    //    curHostHeightString = "";
                    //    hostHeightCharIndex = 0;
                    //}

                    hostHeightUnravelFrameRefTime = Time.time;
                }
                if ((Time.time - hostHealthUnravelFrameRefTime > hostHealthCharUnravelTime) && (hostHealthCharIndex < hostHealthSapLevelConnectionStrength.ToCharArray().Length))
                {
                    if (justDisplayedRandomHostHealthChar)
                    {
                        curHostHealthString = curHostHealthString.Remove(curHostHealthString.Length - 1, 1);
                    }

                    bool displayRandomChar = (Random.Range(0.0f, 1.0f) < chanceToDisplayRandomChar);

                    if (displayRandomChar)
                    {
                        curHostHealthString = curHostHealthString + statusTextRandomCharString.ToCharArray()[Random.Range(0, statusTextRandomCharString.ToCharArray().Length - 1)];
                        justDisplayedRandomHostHealthChar = true;
                    }
                    else
                    {
                        curHostHealthString = curHostHealthString + hostHealthSapLevelConnectionStrength.ToCharArray()[hostHealthCharIndex];
                        justDisplayedRandomHostHealthChar = false;
                        hostHealthCharIndex++;
                    }

                    //if (Random.Range(0.0f, 1.0f) < chanceToResetString) {
                    //    curHostHealthString = "";
                    //    hostHealthCharIndex = 0;
                    //}

                    hostHealthUnravelFrameRefTime = Time.time;
                }

                if ((Time.time - hostEffectsUnravelFrameRefTime > hostEffectsCharUnravelTime) && (hostEffectsCharIndex < hostExtraEffects.ToCharArray().Length))
                {
                    if (justDisplayedRandomHostEffectsChar)
                    {
                        curHostEffectsString = curHostEffectsString.Remove(curHostEffectsString.Length - 1, 1);
                    }

                    bool displayRandomChar = (Random.Range(0.0f, 1.0f) < chanceToDisplayRandomChar);

                    if (displayRandomChar)
                    {
                        curHostEffectsString = curHostEffectsString + statusTextRandomCharString.ToCharArray()[Random.Range(0, statusTextRandomCharString.ToCharArray().Length - 1)];
                        justDisplayedRandomHostEffectsChar = true;
                    }
                    else
                    {
                        curHostEffectsString = curHostEffectsString + hostExtraEffects.ToCharArray()[hostEffectsCharIndex];
                        justDisplayedRandomHostEffectsChar = false;
                        hostEffectsCharIndex++;
                    }

                    //if (Random.Range(0.0f, 1.0f) < chanceToResetString) {
                    //    curHostEffectsString = "";
                    //    hostEffectsCharIndex = 0;
                    //}

                    hostEffectsUnravelFrameRefTime = Time.time;
                }
                if ((Time.time - eyeNameUnravelFrameRefTime > eyeNameCharUnravelTime) && (eyeNameCharIndex > -1))
                {
                    if (justDisplayedRandomEyeNameChar)
                    {
                        curEyeNameString = curEyeNameString.Remove(0, 1);
                    }

                    bool displayRandomChar = (Random.Range(0.0f, 1.0f) < chanceToDisplayRandomChar);

                    if (displayRandomChar)
                    {
                        curEyeNameString = statusTextRandomCharString.ToCharArray()[Random.Range(0, statusTextRandomCharString.ToCharArray().Length - 1)] + curEyeNameString;
                        justDisplayedRandomEyeNameChar = true;
                    }
                    else
                    {
                        curEyeNameString = eyeNameVersionConnection.ToCharArray()[eyeNameCharIndex] + curEyeNameString;
                        justDisplayedRandomEyeNameChar = false;
                        eyeNameCharIndex--;
                    }

                    //if (Random.Range(0.0f, 1.0f) < chanceToResetString) {
                    //    curEyeNameString = "";
                    //    eyeNameCharIndex = eyeNameVersionConnection.ToCharArray().Length - 1;
                    //}

                    eyeNameUnravelFrameRefTime = Time.time;
                }
                if ((Time.time - eyeEffectsUnravelFrameRefTime > eyeEffectsCharUnravelTime) && (eyeEffectsCharIndex > -1))
                {
                    if (justDisplayedRandomEyeEffectsChar)
                    {
                        curEyeEffectsString = curEyeEffectsString.Remove(0, 1);
                    }

                    bool displayRandomChar = (Random.Range(0.0f, 1.0f) < chanceToDisplayRandomChar);

                    if (displayRandomChar)
                    {
                        curEyeEffectsString = statusTextRandomCharString.ToCharArray()[Random.Range(0, statusTextRandomCharString.ToCharArray().Length - 1)] + curEyeEffectsString;
                        justDisplayedRandomEyeEffectsChar = true;
                    }
                    else
                    {
                        curEyeEffectsString = eyeExtraEffects.ToCharArray()[eyeEffectsCharIndex] + curEyeEffectsString;
                        justDisplayedRandomEyeEffectsChar = false;
                        eyeEffectsCharIndex--;
                    }

                    //if (Random.Range(0.0f, 1.0f) < chanceToResetString) {
                    //    curEyeEffectsString = "";
                    //    eyeEffectsCharIndex = eyeExtraEffects.ToCharArray().Length - 1;
                    //}

                    eyeEffectsUnravelFrameRefTime = Time.time;
                }

                break;
            }
        }
    }
示例#10
0
 public void AddItemToInventory(IDItem newItem)
 {
     newItem.AssignOwnerAndHide(this.transform);
     items.Add(newItem);
 }