public void GetNearest(Vector3 v, float force, int pieces)
    {
        List <Transform> l = new List <Transform>();

        if (Forms.Count == 0)
        {
            return;
        }
        l.AddRange(Forms.OrderBy(x => (x.position - v).magnitude));
        int maxN = 0;

        maxN += Mathf.Max(Forms.FindIndex(x => x == l[0]), maxN);

        ParticleMan.Emit(4, Random.Range(0, (int)(force / 10f)), v, Vector3.up);


        for (int i = 0; i < pieces && i < l.Count; i++)
        {
            if (l[i].GetComponent <Rigidbody>() != null)
            {
                continue;
            }
            l[i].parent = null;
            Forms.RemoveAt(0);
            RootSegment rs = l[i].gameObject.AddComponent <RootSegment>();
            rs.BreakForce    = BreakForce;
            rs.StartVelocity = (l[i].position - v).normalized * Mathf.Clamp(force, 0f, 1f);
        }

        Forms = new List <Transform>();
        Forms.AddRange(GetComponentsInChildren <Transform>());
        CalculateBodyStuff();
    }
Beispiel #2
0
        static Exception _TryParseList(string text, out IteratedSegmentSequence segments)
        {
            segments = null;
            string[]       items   = text.Split('/', '\\');
            List <Segment> results = new List <Segment>(items.Length);

            foreach (string s in items)
            {
                Segment sgt;
                if (s.Length == 0)
                {
                    // TODO Only apply at real root; enforce match segment as file or directory
                    sgt = new RootSegment();
                }
                else if (DEVICE.IsMatch(s))
                {
                    sgt = new DeviceSegment(DEVICE.Match(s).Groups["Name"].Value);
                }
                else if (s == "*")
                {
                    sgt = new AnyDirectorySegment();
                }
                else if (s == "**")
                {
                    sgt = new RecursiveSegment();

                    // TODO Support directory navigation
                }
                else if (s == "..")
                {
                    throw new NotImplementedException();
                }
                else if (s == ".")
                {
                    sgt = new CwdSegment();
                }
                else
                {
                    string segment = ExpandSegment(s);
                    if (segment == null)
                    {
                        return(SpecFailure.NotParsable("text", typeof(Glob)));
                    }

                    sgt = new MatchSegment(segment);
                }

                results.Add(sgt);
            }

            segments = new IteratedSegmentSequence(results.ToArray());
            return(null);
        }
Beispiel #3
0
        /// <summary>
        /// Add a subsegment
        /// </summary>
        /// <param name="subsegment">The subsegment to add</param>
        /// <exception cref="EntityNotAvailableException">Cannot add subsegment to a completed segment.</exception>
        public void AddSubsegment(Subsegment subsegment)
        {
            if (!IsInProgress)
            {
                throw new EntityNotAvailableException("Cannot add subsegment to a completed segment.");
            }

            lock (_lazySubsegments.Value)
            {
                _lazySubsegments.Value.Add(subsegment);
            }

            IncrementReferenceCounter();
            subsegment.Parent      = this;
            subsegment.RootSegment = RootSegment;
            RootSegment.IncrementSize();
        }
    //private List<Rigidbody> _bodies;

    // Use this for initialization
    void Start()
    {
        _forms = new List <Transform>();
        _forms.AddRange(Pieces.OrderBy(x => x.transform.position.y));

        for (int i = _forms.Count - 1; i > 0; i--)
        {
            //_forms[i].GetComponent<MeshRenderer>().material.color = new Color(Random.Range(.5f, .8f), Random.Range(.5f, .8f), Random.Range(.5f, .8f));
            _forms[i].parent = _forms[i - 1];
        }

        _forms[0].parent = null;
        RootSegment rs = _forms[0].gameObject.AddComponent <RootSegment>();

        rs.BreakForce = BreakForce;
        rs.Density    = Mass;
        _forms.RemoveAt(0);
        rs.Forms = _forms;
    }
Beispiel #5
0
        /// <summary>
        /// Get the corresponding target path for target directroy, depending of the given source directroy and mode
        /// </summary>
        /// <param name="copyMode">Mode to get the target path</param>
        /// <param name="sourceDirectory">Source directroy to get the target forc</param>
        /// <param name="projectSettings">Settings of the project</param>
        /// <returns>Full target name for the directroy to create</returns>
        public string GetTargetFullName(CopyItems.CopyMode copyMode, DirectoryInfo sourceDirectory, Settings.Settings projectSettings)
        {
            string RootSegment;
            string DriveNameSegment;
            string SourceSegment;

            switch (copyMode)
            {
            case CopyItems.CopyMode.Backup:
                RootSegment      = projectSettings.ControleBackup.Directory.Path;
                DriveNameSegment = projectSettings.ControleBackup.Directory.CreateDriveDirectroy ? sourceDirectory.Root.FullName.Remove(1, 2) : "";
                SourceSegment    = sourceDirectory.FullName.Remove(0, sourceDirectory.Root.FullName.Length);
                return(this.BuildTargetFullName(RootSegment, DriveNameSegment, SourceSegment));

            case CopyItems.CopyMode.Restore:
                DirectoryInfo Source = new DirectoryInfo(projectSettings.ControleRestore.Directory.Path);
                if (projectSettings.ControleRestore.Directory.CreateDriveDirectroy)
                {
                    RootSegment = sourceDirectory.FullName.Substring(Source.FullName.Length + 1);
                    return(OLKI.Toolbox.DirectoryAndFile.Path.Repair(RootSegment.Insert(1, @":\")));
                }
                else
                {
                    SourceSegment = "";
                    if (sourceDirectory.FullName.Length > Source.FullName.Length + 1)
                    {
                        SourceSegment = sourceDirectory.FullName.Substring(Source.FullName.Length + 1);
                    }
                    RootSegment  = projectSettings.ControleRestore.Directory.RestoreTargetPath;
                    RootSegment += @"\" + SourceSegment;
                    return(OLKI.Toolbox.DirectoryAndFile.Path.Repair(RootSegment));
                }

            default:
                break;
            }
            return(string.Empty);
        }
        static Exception _TryParseList(string text, out IteratedSegmentSequence segments)
        {
            segments = null;
            string[] items = text.Split('/', '\\');
            List<Segment> results = new List<Segment>(items.Length);

            foreach (string s in items) {
                Segment sgt;
                if (s.Length == 0) {
                    // TODO Only apply at real root; enforce match segment as file or directory
                    sgt = new RootSegment();

                } else if (DEVICE.IsMatch(s)) {
                    sgt = new DeviceSegment(DEVICE.Match(s).Groups["Name"].Value);

                } else if (s == "*") {
                    sgt = new AnyDirectorySegment();

                } else if (s == "**") {
                    sgt = new RecursiveSegment();

                    // TODO Support directory navigation
                } else if (s == "..") {
                    throw new NotImplementedException();

                } else if (s == ".") {
                    throw new NotImplementedException();

                } else {
                    string segment = ExpandSegment(s);
                    if (segment == null)
                        return Failure.NotParsable("text", typeof(Glob));

                    sgt = new MatchSegment(segment);
                }

                results.Add(sgt);
            }

            segments = new IteratedSegmentSequence(results.ToArray());
            return null;
        }