private IEnumerator Co_Gather(TreeTrunk trunk)
    {
        Speaker.Speak();

        _isLoadPointSet = false;
        Animator.SetBool(_dragStateName, true);

        if (!RobotModel.Programs.Any(_ => _.Template.Type == ProgramType.Gather))
        {
            EndCoProgram();
            yield break;
        }

        _movable.LinearSpeed = basicSpeed;

        if (trunk == null || trunk.IsCarring)
        {
            EndCoProgram();
            yield break;
        }

        trunk.IsCarring = true;

        yield return(null);

        trunk.Carry(Joint);
        _trunk = trunk;

        var ark = WorldObjects.Instance.GetFirstItem <Ark>();

        _navAgent.nextPosition = transform.position;
        _navAgent.ResetPath();
        _navAgent.SetDestination(ark.transform.position);

        yield return(null);

        ResetTime();

        Animator.SetBool(_walkStateName, true);

        while (!trunk.IsRecycling && _navAgent.pathStatus != NavMeshPathStatus.PathInvalid)
        {
            var direction = _navAgent.desiredVelocity.normalized;
            Steer(new Vector2(direction.x, direction.z), true);
            _navAgent.velocity     = _movable.Velocity;
            _navAgent.nextPosition = transform.position;

            ComputeTime(Time.deltaTime, ProgramType.Gather);

            yield return(null);
        }

        EndCoProgram();
    }
Esempio n. 2
0
 private void DockLeaf(TreeTrunk trunk, TreeLeaf leaf, DockType dockType)
 {
     if (!closedLeafs.Contains(leaf))
     {
         Log.E("Err: Have Exist");
     }
     else
     {
         trunk.DockLeaf(leaf, dockType);
         closedLeafs.Remove(leaf);
         if (onDockLeaf != null)
         {
             onDockLeaf(leaf);
         }
     }
 }
Esempio n. 3
0
    private void Start()
    {
        _deadCondition = GetComponentInChildren <TreeTrunk>();

        if (_fallingRigidbody == null)
        {
            _fallingRigidbody = GetComponentInChildren <Rigidbody>();
        }

        if (_fallingRigidbody == null)
        {
            return;
        }

        // TODO: поиграться с центром масс для более реалистичного падения.
        //var centerOfMass = _fallingRigidbody.centerOfMass;
        //centerOfMass.z -= 1;
        //_fallingRigidbody.centerOfMass = centerOfMass;
    }
Esempio n. 4
0
    public void FindDragTarget()
    {
        if (burden != null)
        {
            burden.Drop();
            burden.RecycleAction -= OnBurdenRecycled;
            burden = null;
        }
        else
        {
            if (_interactive[0] != null)
            {
                var treeTrunk = _interactive[0].GetComponentInParent <TreeTrunk>();
                burden = treeTrunk;
                burden.RecycleAction += OnBurdenRecycled;
                burden.Carry(Joint);
            }
        }

        Drag = burden != null;
    }
    private void EndCoProgram()
    {
        Speaker.Speak();

        Animator.SetBool(_walkStateName, false);
        Animator.SetBool(_cutStateName, false);
        Animator.SetBool(_dragStateName, false);
        _inProgress = false;
        _target     = null;

        if (_trunk != null)
        {
            if (!_trunk.IsRecycling)
            {
                _trunk.Drop();
            }

            _trunk = null;
        }
        Joint.connectedBody = null;

        if (_nextProgram.HasValue)
        {
            _currentProgramType = _nextProgram;
            if (_nextTarget != null)
            {
                _target     = _nextTarget;
                _nextTarget = null;
            }
        }
        else
        {
            SelectNextProgram();
        }

        _nextProgram = null;
    }
Esempio n. 6
0
            public override void DeSerialize(XmlElement root)
            {
                base.DeSerialize(root);
                DeSerializeField(root, "SplitType", ref splitType);
                DeSerializeField(root, "SplitWidth", ref splitWidth);
                XmlNode ts = root.SelectSingleNode("Trunks");

                for (int i = 0; i < ts.ChildNodes.Count; i++)
                {
                    TreeTrunk trunk = new TreeTrunk();
                    trunk.parent = this;
                    trunk.DeSerialize(ts.ChildNodes[i] as XmlElement);
                    trunks.Add(trunk);
                }
                XmlNode ls = root.SelectSingleNode("Leafs");

                for (int i = 0; i < ls.ChildNodes.Count; i++)
                {
                    TreeLeaf leaf = tree.CreateOpenedLeaf(null);
                    leaf.parent = this;
                    leaf.DeSerialize(ls.ChildNodes[i] as XmlElement);
                    leafs.Add(leaf);
                }
            }
Esempio n. 7
0
            internal bool RemoveLeaf(TreeLeaf leaf)
            {
                if (hasChildTrunks)
                {
                    if (trunks[0].RemoveLeaf(leaf))
                    {
                        return(true);
                    }
                    return(trunks[1].RemoveLeaf(leaf));
                }
                else
                {
                    if (!leafs.Contains(leaf))
                    {
                        return(false);
                    }
                    leafs.Remove(leaf);
                    leaf.parent = null;
                    if (leafCount == 1)
                    {
                        if (!isRoot)
                        {
                            int       index   = 0;
                            TreeTrunk brother = default(TreeTrunk);
                            for (; index < parentTrunk.trunkCount; index++)
                            {
                                if (parentTrunk.trunks[index] != this)
                                {
                                    brother = parentTrunk.trunks[index];
                                    break;
                                }
                            }
                            if (brother != null && !brother.hasChildTrunks && brother.leafCount == 1)
                            {
                                parentTrunk.trunks.Clear();
                                switch (parentTrunk.splitType)
                                {
                                case SplitType.Vertical:
                                    if (index == 0)
                                    {
                                        parentTrunk.DockLeaf(brother.leafs[0], DockType.Left);
                                        parentTrunk.DockLeaf(leafs[0], DockType.Right);
                                    }
                                    else
                                    {
                                        parentTrunk.DockLeaf(brother.leafs[0], DockType.Right);
                                        parentTrunk.DockLeaf(leafs[0], DockType.Left);
                                    }
                                    break;

                                case SplitType.Horizontal:
                                    if (index == 0)
                                    {
                                        parentTrunk.DockLeaf(brother.leafs[0], DockType.Up);
                                        parentTrunk.DockLeaf(leafs[0], DockType.Down);
                                    }
                                    else
                                    {
                                        parentTrunk.DockLeaf(brother.leafs[0], DockType.Down);
                                        parentTrunk.DockLeaf(leafs[0], DockType.Up);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    else if (leafCount == 0)
                    {
                        if (!isRoot)
                        {
                            TreeTrunk brother = default(TreeTrunk);
                            for (int i = 0; i < parentTrunk.trunkCount; i++)
                            {
                                if (parentTrunk.trunks[i] != this)
                                {
                                    brother = parentTrunk.trunks[i];
                                }
                            }
                            parentTrunk.trunks.Clear();

                            if (brother != null)
                            {
                                if (brother.hasChildTrunks)
                                {
                                    parentTrunk.splitType = brother.splitType;
                                    for (int i = 0; i < brother.trunkCount; i++)
                                    {
                                        brother.trunks[i].parent = parentTrunk;
                                        parentTrunk.trunks.Add(brother.trunks[i]);
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < brother.leafCount; i++)
                                    {
                                        TreeLeaf tmpLeaf = brother.leafs[i];
                                        tmpLeaf.parent = null;
                                        switch (brother.splitType)
                                        {
                                        case SplitType.Vertical:
                                            if (i == 0)
                                            {
                                                parentTrunk.DockLeaf(tmpLeaf, DockType.Left);
                                            }
                                            else if (i == 1)
                                            {
                                                parentTrunk.DockLeaf(tmpLeaf, DockType.Right);
                                            }
                                            break;

                                        case SplitType.Horizontal:
                                            if (i == 0)
                                            {
                                                parentTrunk.DockLeaf(tmpLeaf, DockType.Up);
                                            }
                                            else if (i == 1)
                                            {
                                                parentTrunk.DockLeaf(tmpLeaf, DockType.Down);
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        //parent = null;
                    }
                    return(true);
                }
            }
Esempio n. 8
0
        private void DragWindow()
        {
            List <TreeLeaf> OpenLeafs = allLeafs.FindAll((leaf) => { return(!closedLeafs.Contains(leaf)); });
            Event           e         = Event.current;

            if (e.button != 0)
            {
                return;
            }
            if (!position.Contains(e.mousePosition))
            {
                return;
            }

            if (e.type == EventType.Repaint && dragleaf != null)
            {
                Styles.FlowWindow.Draw(new Rect(e.mousePosition, Vector2.one * 150), dragleaf.titleContent, false, false, false, false);
                Styles.SelectRect.Draw(selectionRect, false, false, false, false);
            }
            if (e.type == EventType.MouseDrag)
            {
                if (dragleaf == null)
                {
                    dragleaf = OpenLeafs.Find((leaf) => { return(leaf.IsOverTitle(e.mousePosition)); });
                }
                if (dragleaf == null)
                {
                    return;
                }
                var overLeaf = OpenLeafs.Find((leaf) => { return(leaf.IsOver(e.mousePosition)); });
                if (overLeaf == null)
                {
                    selectionRect = Rect.zero;
                    return;
                }
                Vector2 v   = e.mousePosition;
                Rect    r   = overLeaf.position;
                float   spH = r.height / 3;
                float   spW = r.width / 3;
                if (v.y < r.yMin + spH &&
                    v.x > r.xMin + spW &&
                    v.x < r.xMax - spW)
                {
                    selectionRect = new Rect(r.position, new Vector2(r.width, spH));
                    docktype      = DockType.Up;
                }
                else if (v.y > r.yMax - spH &&
                         v.x > r.xMin + spW &&
                         v.x < r.xMax - spW)
                {
                    selectionRect = new Rect(new Vector2(r.x, r.yMax - spH),
                                             new Vector2(r.width, spH));
                    docktype = DockType.Down;
                }
                else if (v.x > r.xMax - spW &&
                         v.y < r.yMax - spH &&
                         v.y > r.yMin + spH)
                {
                    selectionRect = new Rect(new Vector2(r.xMax - spW, r.y),
                                             new Vector2(spW, r.height));
                    docktype = DockType.Right;
                }
                else if (v.x < r.xMin + spW &&
                         v.y < r.yMax - spH &&
                         v.y > r.yMin + spH)
                {
                    selectionRect = new Rect(r.position, new Vector2(spW, r.height));
                    docktype      = DockType.Left;
                }
                else
                {
                    selectionRect = Rect.zero;
                }
                Repaint();
            }
            else if (e.type == EventType.MouseUp)
            {
                if (dragleaf != null)
                {
                    var overLeaf = OpenLeafs.Find((leaf) => { return(leaf.IsOver(e.mousePosition)); });
                    if (overLeaf != null && selectionRect != Rect.zero && overLeaf != dragleaf)
                    {
                        root.RemoveLeaf(dragleaf);
                        TreeTrunk node = overLeaf.parent as TreeTrunk;
                        node.DockLeaf(overLeaf, dragleaf, docktype);
                    }
                    dragleaf      = null;
                    selectionRect = Rect.zero;
                    Repaint();
                }
            }
        }
Esempio n. 9
0
 private void OnBurdenRecycled(TreeTrunk obj)
 {
     obj.RecycleAction -= OnBurdenRecycled;
     burden             = null;
     Drag = burden != null;
 }
Esempio n. 10
0
 private void RecyclingStarted(TreeTrunk obj, float ln)
 {
     Source.PlayOneShot(Clip);
     StartCoroutine(Recycle(obj.Wood, ln, obj.transform));
 }
Esempio n. 11
0
 public void LoadTrunk(TreeTrunk trunk)
 {
     trunk.IsLoaded = true;
 }