Ejemplo n.º 1
0
        public void CopyTo(GameObject obj)
        {
            TreeChopablePart c = obj.AddComponent <TreeChopablePart>();

            c.abovePart = abovePart;
            Outline oc = obj.AddComponent <Outline>();
        }
Ejemplo n.º 2
0
        void Chop(GameObject obj, TreeChopablePart tcc)
        {
            if ((DateTime.Now - lastChop).TotalSeconds < 1)
            {
                return;
            }

            lastChop = DateTime.Now;

            var res = API.tmp(obj, GetTemplate());

            if (res != null)
            {
                res.DestroyObject();
                res.PolySeparatePositive();
                List <GameObject> robjs = res.PositiveResults.ConvertAll(
                    rm => rm
                    .CopyParent()
                    .CopyMaterial()
                    .WithCollider(true)
                    .Instantiate()
                    );
                if (robjs.Count > 1)
                {
                    tcc.abovePart.GetComponent <Rigidbody>().isKinematic = false;
                    GameObject above = null;
                    float      maxY  = float.NegativeInfinity;
                    foreach (GameObject robj in robjs)
                    {
                        float y = robj.GetComponent <Collider>().bounds.center.y;
                        if (y > maxY)
                        {
                            above = robj;
                            maxY  = y;
                        }
                    }
                    above.GetComponent <MeshCollider>().convex = true;
                    above.transform.SetParent(tcc.abovePart.transform);
                }
                else
                {
                    foreach (GameObject robj in robjs)
                    {
                        tcc.CopyTo(robj);
                    }
                }
            }
            else
            {
                Debug.Log("fail");
            }
        }