Пример #1
0
        public void Initialize(ServerAction response)
        {
            sceneConfig = sceneConfigList.configs [response.sceneConfigIndex];
            Dictionary <string, SimObj> simobjLookup = new Dictionary <string, SimObj> ();

            SimObj[] simObjects = GameObject.FindObjectsOfType(typeof(SimObj)) as SimObj[];

            for (int i = 0; i < simObjects.Length; i++)
            {
                SimObj so = simObjects [i];
                simobjLookup [so.UniqueID] = so;
                // only pick everything up if we have a list of receptacle/object pairs
                if (IsPickupable(so) && sceneConfig.receptacleObjectPairs.Length > 0)
                {
                    SimUtil.TakeItem(so);
                }
                if (IsOpenable(so))
                {
                    if (Array.IndexOf(sceneConfig.openReceptacles, so.UniqueID) >= 0)
                    {
                        openSimObj(so);
                    }
                    else
                    {
                        closeSimObj(so);
                    }
                }
            }
            foreach (ReceptacleObjectPair rop in sceneConfig.receptacleObjectPairs)
            {
                SimObj o = simobjLookup [rop.objectId];
                SimObj r = simobjLookup [rop.receptacleObjectId];
                SimUtil.AddItemToReceptaclePivot(o, r.Receptacle.Pivots [rop.pivot]);
            }

            InitializePositionRotation(response);
        }
        // empty target receptacle and put object into receptacle

        public void Replace(ServerAction response)
        {
            bool success = false;

            SimObj[] simObjs = SceneManager.Current.ObjectsInScene.ToArray();
            foreach (SimObj rso in simObjs)
            {
                if (response.receptacleObjectId == rso.UniqueID)
                {
                    foreach (SimObj so in SimUtil.GetItemsFromReceptacle(rso.Receptacle))
                    {
                        SimUtil.TakeItem(so);
                    }
                    foreach (SimObj so in simObjs)
                    {
                        if (so.UniqueID == response.objectId && SimUtil.AddItemToReceptaclePivot(so, rso.Receptacle.Pivots[response.pivot]))
                        {
                            success = true;
                        }
                    }
                }
            }
            actionFinished(success);
        }
Пример #3
0
        public void PutObject(ServerAction response)
        {
            bool success           = false;
            bool receptacleVisible = false;

            if (inventory.ContainsKey(response.objectId))
            {
                foreach (SimObj rso in VisibleSimObjs(response.forceVisible))
                {
                    if (rso.IsReceptacle && (rso.UniqueID == response.receptacleObjectId || rso.Type == response.ReceptableSimObjType()))
                    {
                        receptacleVisible = true;
                        SimObj so = removeObjectInventory(response.objectId);
                        if (!IsOpenable(rso) || IsOpen(rso))
                        {
                            Transform emptyPivot = null;
                            if (!SimUtil.GetFirstEmptyReceptaclePivot(rso.Receptacle, out emptyPivot))
                            {
                                errorCode = ServerActionErrorCode.ReceptacleFull;
                            }
                            else
                            {
                                if (response.forceVisible)
                                {
                                    SimUtil.AddItemToReceptaclePivot(so, emptyPivot);
                                    success = true;
                                }
                                else
                                {
                                    emptyPivot = null;
                                    if (!SimUtil.GetFirstEmptyVisibleReceptaclePivot(rso.Receptacle, m_Camera, out emptyPivot))
                                    {
                                        errorCode = ServerActionErrorCode.ReceptaclePivotNotVisible;
                                    }
                                    else
                                    {
                                        SimUtil.AddItemToReceptaclePivot(so, emptyPivot);
                                        success = true;
                                    }
                                }
                            }
                        }
                        else
                        {
                            errorCode = ServerActionErrorCode.ReceptacleNotOpen;
                        }



                        if (!success)
                        {
                            addObjectInventory(so);
                        }

                        break;
                    }
                }
            }
            else
            {
                errorCode = ServerActionErrorCode.ObjectNotInInventory;
            }

            if (success)
            {
                errorCode = ServerActionErrorCode.Undefined;
            }
            else
            {
                if (!receptacleVisible && errorCode == ServerActionErrorCode.Undefined)
                {
                    errorCode = ServerActionErrorCode.ReceptacleNotVisible;
                }
            }
            StartCoroutine(checkWaitAction(success));
        }