private void Instance_ObjectCreated(SyncObjectBinding obj)
        {
            if (_identifiers.Contains(obj.identifier)) // skipping duplicates
            {
                return;
            }

            var md = obj.GetComponent <Metadata>();

            if (md == null) // skipping objects with no Metadata
            {
                return;
            }

            if (md.GetParameter(_key) == _value)
            {
                if (_minHeight > 0 && md.parameters.dictionary.ContainsKey("Height"))
                {
                    var height = float.Parse(md.GetParameter("Height")) * 0.001f;
                    if (height < _minHeight)
                    {
                        return;
                    }
                }

                _identifiers.Add(obj.identifier);
                _addedObjects[obj] = Instantiate(prefab, obj.transform.position, obj.transform.rotation * Quaternion.Euler(0, Random.Range(-_rotationY_randomness, _rotationY_randomness), 0), transform);

                if (_matchHeight && md.parameters.dictionary.ContainsKey("Height"))
                {
                    var height = float.Parse(md.GetParameter("Height")) * 0.001f;
                    _addedObjects[obj].transform.localScale = Vector3.one * (height / prefabBounds.size.y);
                }
            }
        }
Esempio n. 2
0
        private void Instance_ObjectCreated(SyncObjectBinding obj)
        {
            if (_identifiers.Contains(obj.identifier)) // skipping duplicates
            {
                return;
            }

            var md = obj.GetComponent <Metadata>();

            if (md == null) // skipping objects with no Metadata
            {
                return;
            }

            if (matchType == MATCH_TYPE.All && md.MatchAllCriterias(criterias) ||
                matchType == MATCH_TYPE.Any && md.MatchAnyCriterias(criterias))
            {
                _identifiers.Add(obj.identifier);
                _addedObjects[obj] = Instantiate(prefab, obj.transform.position, obj.transform.rotation, transform);
                if (_matchHeight && md.parameters.dictionary.ContainsKey("Height"))
                {
                    var height = float.Parse(md.GetParameter("Height")) * 0.001f;
                    _addedObjects[obj].transform.localScale = Vector3.one * (height / prefabBounds.size.y);
                }
            }
        }
        private void Instance_ObjectCreated(SyncObjectBinding obj)
        {
            if (_modifiedObjects.ContainsKey(obj.identifier)) // skipping duplicates
            {
                return;
            }

            var md = obj.GetComponent <Metadata>();

            if (md == null) // skipping objects with no Metadata
            {
                return;
            }

            for (int set = 0; set < objectReplacementSets.Length; set++)
            {
                // bypass if no replacement set
                if (objectReplacementSets[set].replacements.Length == 0)
                {
                    continue;
                }

                // for all replacements in set
                for (int r = 0; r < objectReplacementSets[set].replacements.Length; r++)
                {
                    // bypass if no gameobject assigned
                    if (!objectReplacementSets[set].replacements[r].gameObject)
                    {
                        continue;
                    }

                    if (md.MatchAllCriterias(objectReplacementSets[set].replacements[r].criterias))
                    {
                        _modifiedObjects.Add(obj.identifier, obj);

                        _prefabReferences.Add(obj.gameObject, objectReplacementSets[set].replacements[r].gameObject);

                        if (!_disabledRenderersTable.ContainsKey(obj.gameObject))
                        {
                            _disabledRenderersTable.Add(obj.gameObject, objectReplacementSets[set].replacements[r].disableOriginal);
                        }
                        else
                        {
                            _disabledRenderersTable[obj.gameObject] &= objectReplacementSets[set].replacements[r].disableOriginal;
                        }

                        float scaleFactor = (objectReplacementSets[set].replacements[r].matchHeight && md.parameters.dictionary.ContainsKey("Height")) ?
                                            float.Parse(md.GetParameter("Height")) * 0.001f / _bounds[objectReplacementSets[set].replacements[r].gameObject].size.y :
                                            1.0f;

                        _scaleFactors[obj.gameObject] = scaleFactor;

                        SpawnChild(obj.transform, _prefabReferences[obj.gameObject], _disabledRenderersTable[obj.gameObject], scaleFactor);
                    }
                }
            }
        }
Esempio n. 4
0
        private void Instance_ObjectCreated(SyncObjectBinding obj)
        {
            if (_identifiers.Contains(obj.identifier)) // skipping duplicates
            {
                return;
            }

            var md = obj.GetComponent <Metadata>();

            if (md == null) // skipping objects with no Metadata
            {
                return;
            }

            if (md.parameters.dictionary.ContainsKey(_assetBundleURL) && md.parameters.dictionary.ContainsKey(_assetBundleName))
            {
                var url  = md.GetParameter(_assetBundleURL);
                var name = md.GetParameter(_assetBundleName);
                if (url == string.Empty || name == string.Empty)
                {
                    return;
                }

                AssetBundleTarget target = new AssetBundleTarget(url, name);
                if (_prefabLibrary.ContainsKey(target))
                {
                    _identifiers.Add(obj.identifier);
                    _addedObjects[obj] = Instantiate(_prefabLibrary[target], obj.transform.position, obj.transform.rotation, transform);
                }
                else
                {
                    var assetBundle = AssetBundle.LoadFromFile(System.IO.Path.Combine(Application.streamingAssetsPath, url));
                    if (assetBundle == null)
                    {
                        Debug.LogWarning(string.Format("Failed to load AssetBundle from {0}!", url));
                        return;
                    }
                    var prefab = assetBundle.LoadAsset <GameObject>(name);
                    _prefabLibrary.Add(target, prefab);
                    _identifiers.Add(obj.identifier);
                    _addedObjects[obj] = Instantiate(prefab, obj.transform.position, obj.transform.rotation, transform);
                    assetBundle.Unload(false);
                }
            }
        }