Exemplo n.º 1
0
        public static void Modify(MeshQuery query)
        {
            Collider[] hitColliders = Physics.OverlapSphere(query.Epicenter, query.Radius);
            foreach (var hitCollider in hitColliders)
            {
                var meshIndexBehavior = hitCollider.gameObject.GetComponent <MeshIndexBehaviour>();
                if (meshIndexBehavior == null)
                {
                    continue;
                }

                var mesh = hitCollider.gameObject.GetComponent <MeshFilter>().mesh;
                query.Vertices = mesh.vertices;

                var meshQueryResult = meshIndexBehavior.Index.Modify(query);

                if (meshQueryResult.IsDestroyed)
                {
                    var collider = hitCollider;
                    ObservableUnity
                    .FromCoroutine(() => SplitMesh(collider.gameObject))
                    .Subscribe();
                }
                else if (meshQueryResult.IsModified)
                {
                    mesh.vertices = meshQueryResult.Vertices;
                    meshIndexBehavior.IsMeshModified = true;
                }

                Debug.Log(String.Format("MeshIndex:{0} modified:{1} scanned tris:{2}, forceDir:{3}",
                                        hitCollider.name, meshQueryResult.ModifiedVertices, meshQueryResult.ScannedTriangles, query.ForceDirection));
            }
        }
Exemplo n.º 2
0
 public static IObservable <WWW> PostWWW(string url, byte[] postData, Hash headers, IProgress <float> progress = null)
 {
     return(ObservableUnity.FromCoroutine <WWW>((observer, cancellation) => Fetch(new WWW(url, postData, headers), observer, progress, cancellation)));
 }
Exemplo n.º 3
0
 public static IObservable <WWW> PostWWW(string url, WWWForm content, IProgress <float> progress = null)
 {
     return(ObservableUnity.FromCoroutine <WWW>((observer, cancellation) => Fetch(new WWW(url, content), observer, progress, cancellation)));
 }
Exemplo n.º 4
0
        public static IObservable <byte[]> PostAndGetBytes(string url, WWWForm content, Hash headers, IProgress <float> progress = null)
        {
            var contentHeaders = content.headers;

            return(ObservableUnity.FromCoroutine <byte[]>((observer, cancellation) => FetchBytes(new WWW(url, content.data, MergeHash(contentHeaders, headers)), observer, progress, cancellation)));
        }
Exemplo n.º 5
0
 public static IObservable <byte[]> PostAndGetBytes(string url, byte[] postData, IProgress <float> progress = null)
 {
     return(ObservableUnity.FromCoroutine <byte[]>((observer, cancellation) => FetchBytes(new WWW(url, postData), observer, progress, cancellation)));
 }
Exemplo n.º 6
0
 public static IObservable <WWW> GetWWW(string url, Hash headers = null, IProgress <float> progress = null)
 {
     return(ObservableUnity.FromCoroutine <WWW>((observer, cancellation) => Fetch(new WWW(url, null, (headers ?? new Hash())), observer, progress, cancellation)));
 }
Exemplo n.º 7
0
 public static IObservable <AssetBundle> LoadFromCacheOrDownload(string url, Hash128 hash128, uint crc, IProgress <float> progress = null)
 {
     return(ObservableUnity.FromCoroutine <AssetBundle>((observer, cancellation) => FetchAssetBundle(WWW.LoadFromCacheOrDownload(url, hash128, crc), observer, progress, cancellation)));
 }
Exemplo n.º 8
0
        /// <summary>
        /// Publish target property when value is changed. If source is destroyed/destructed, publish OnCompleted.
        /// </summary>
        /// <param name="fastDestroyCheck">If true and target is UnityObject, use destroyed check by additional component. It is faster check for lifecycle but needs initial cost.</param>
        public static IObservable <TProperty> ObserveEveryValueChanged <TSource, TProperty>(this TSource source, Func <TSource, TProperty> propertySelector, FrameCountType frameCountType, IEqualityComparer <TProperty> comparer, bool fastDestroyCheck)
            where TSource : class
        {
            if (source == null)
            {
                return(Observable.Empty <TProperty>());
            }
            if (comparer == null)
            {
                comparer = UnityEqualityComparer.GetDefault <TProperty>();
            }

            var unityObject   = source as UnityEngine.Object;
            var isUnityObject = source is UnityEngine.Object;

            if (isUnityObject && unityObject == null)
            {
                return(Observable.Empty <TProperty>());
            }

            // MicroCoroutine does not publish value immediately, so publish value on subscribe.
            if (isUnityObject)
            {
                return(ObservableUnity.FromMicroCoroutine <TProperty>((observer, cancellationToken) =>
                {
                    if (unityObject != null)
                    {
                        var firstValue = default(TProperty);
                        try
                        {
                            firstValue = propertySelector((TSource)(object)unityObject);
                        }
                        catch (Exception ex)
                        {
                            observer.OnError(ex);
                            return EmptyEnumerator();
                        }

                        observer.OnNext(firstValue);
                        return PublishUnityObjectValueChanged(unityObject, firstValue, propertySelector, comparer, observer, cancellationToken, fastDestroyCheck);
                    }
                    else
                    {
                        observer.OnCompleted();
                        return EmptyEnumerator();
                    }
                }, frameCountType));
            }
            else
            {
                var reference = new WeakReference(source);
                source = null;

                return(ObservableUnity.FromMicroCoroutine <TProperty>((observer, cancellationToken) =>
                {
                    var target = reference.Target;
                    if (target != null)
                    {
                        var firstValue = default(TProperty);
                        try
                        {
                            firstValue = propertySelector((TSource)target);
                        }
                        catch (Exception ex)
                        {
                            observer.OnError(ex);
                            return EmptyEnumerator();
                        }
                        finally
                        {
                            target = null;
                        }

                        observer.OnNext(firstValue);
                        return PublishPocoValueChanged(reference, firstValue, propertySelector, comparer, observer, cancellationToken);
                    }
                    else
                    {
                        observer.OnCompleted();
                        return EmptyEnumerator();
                    }
                }, frameCountType));
            }
        }