Exemple #1
0
    public void StringShoot(Vector3 start, Vector3 end)
    {
        start = SnapPoint(start);
        end   = SnapPoint(end);
        Quaternion look       = Quaternion.LookRotation(end - start);
        StringUnit stringUnit = Instantiate(m_StringUnit, start, look).GetComponent <StringUnit>();

        stringUnit.AddTree(GetConnectingTree(start));
        stringUnit.AddTree(GetConnectingTree(end));
        stringUnit.Create(this, start, end, m_Cartridge);
        stringUnit.SetConnecter(GetConnecter(start, stringUnit.GetComponent <Collider>()), GetConnecter(end, stringUnit.GetComponent <Collider>()));
        m_Strings.Add(stringUnit);
        m_Cost += stringUnit.m_Cost;
        while (m_Cost > m_MaxCost)
        {
            StringUnit firstStringUnit = m_Strings[0];
            //m_Strings.RemoveAt(0);
            firstStringUnit.Delete();
        }
        if (/*(stringUnit.m_StartConnecter is Tree || stringUnit.m_EndConnecter is Tree && false) &&*/ stringUnit.m_Cost <= m_NetCostLimit)
        {
            List <Collider> colliders = new List <Collider>(Physics.OverlapSphere(start, m_Radius, layerMask.value));
            colliders.Remove(stringUnit.m_Collider);
            foreach (var item in colliders)
            {
                var SU = item.GetComponent <StringUnit>();
                if (SU == null)
                {
                    continue;
                }
                if (SU.m_SideNumber != m_SideNumber)
                {
                    continue;
                }
                if (SU.m_Cost > m_NetCostLimit)
                {
                    continue;
                }
                if (SU.m_PointA == start && SU.m_PointB == end || SU.m_PointA == end && SU.m_PointB == start)
                {
                    continue;
                }
                if (Vector3.Angle(end - start, SU.m_PointA - start) < m_NetAngleLimit)
                {
                    Net net = Instantiate(m_Net).GetComponent <Net>();
                    net.AddTree(GetConnectingTree(SU.m_PointA));
                    net.AddTree(GetConnectingTree(start));
                    net.AddTree(GetConnectingTree(end));
                    net.Create(this, SU.m_PointA, end, start);
                    net.SetConnecter(SU, stringUnit);
                }
                if (Vector3.Angle(end - start, SU.m_PointB - start) < m_NetAngleLimit)
                {
                    Net net = Instantiate(m_Net).GetComponent <Net>();
                    net.AddTree(GetConnectingTree(SU.m_PointB));
                    net.AddTree(GetConnectingTree(start));
                    net.AddTree(GetConnectingTree(end));
                    net.Create(this, SU.m_PointB, end, start);
                    net.SetConnecter(SU, stringUnit);
                }
            }
            colliders = new List <Collider>(Physics.OverlapSphere(end, m_Radius, layerMask.value));
            colliders.Remove(stringUnit.m_Collider);
            foreach (var item in colliders)
            {
                var SU = item.GetComponent <StringUnit>();
                if (SU == null)
                {
                    continue;
                }
                if (SU.m_SideNumber != m_SideNumber)
                {
                    continue;
                }
                if (SU.m_Cost > m_NetCostLimit)
                {
                    continue;
                }
                if (SU.m_PointA == start && SU.m_PointB == end || SU.m_PointA == end && SU.m_PointB == start)
                {
                    continue;
                }
                if (Vector3.Angle(start - end, SU.m_PointA - end) < m_NetAngleLimit)
                {
                    Net net = Instantiate(m_Net).GetComponent <Net>();
                    net.AddTree(GetConnectingTree(SU.m_PointA));
                    net.AddTree(GetConnectingTree(start));
                    net.AddTree(GetConnectingTree(end));
                    net.Create(this, SU.m_PointA, start, end);
                    net.SetConnecter(SU, stringUnit);
                }
                if (Vector3.Angle(start - end, SU.m_PointB - end) < m_NetAngleLimit)
                {
                    Net net = Instantiate(m_Net).GetComponent <Net>();
                    net.AddTree(GetConnectingTree(SU.m_PointB));
                    net.AddTree(GetConnectingTree(start));
                    net.AddTree(GetConnectingTree(end));
                    net.Create(this, SU.m_PointB, start, end);
                    net.SetConnecter(SU, stringUnit);
                }
            }
        }
    }