示例#1
0
 IEnumerator RebuildTreeRoutine()
 {
     while (manager == null)
     {
         yield return(new WaitForEndOfFrame());
     }
     manager.RebuildTree();
 }
示例#2
0
    // Use this for initialization
    void Start()
    {
        manager = FindObjectOfType <PhysicsGridManager>();
        if (manager == null)
        {
            Debug.LogError("No physics grid manager found in scene!");
        }
        else
        {
            Debug.Log("Gridmanager name = " + manager.name);
        }

        gridTransform      = transform;
        gridZonedTransform = GetComponent <ZonedTransform>();

        if (isRootGrid && transform.parent != null)
        {
            Debug.LogError("Root grid has a parent! This won't work!");
        }
        if (isRootGrid && proxy != null)
        {
            Debug.LogError("Root grid has a proxy! This won't work!");
        }
        if (isRootGrid && GetComponent <IdentityContainer>() != null)
        {
            Debug.LogError("Root grid has an identity container. Root grids should not be networked!");
        }
        manager.RebuildTree(); //will also trigger ScanForGrids

        if (isRootGrid == false)
        {
            if (proxy != null)
            {
                proxyZT = proxy.GetComponent <ZonedTransform>();
                if (proxy.GetComponent <IdentityContainer>() != null)
                {
                    hasGridID = true;
                    GridID    = proxy.GetComponent <IdentityContainer>().GetIdentity().GetObjectID();
                }
            }
            else if (gameObject.GetComponent <IdentityContainer>() != null)
            {
                hasGridID = true;
                GridID    = gameObject.GetComponent <IdentityContainer>().GetIdentity().GetObjectID();
            }
        }
        else
        {
            hasGridID = true;
            GridID    = (ushort)ReservedObjectIDs.RootGrid;
        }

        if (proxyZT != null)
        {
            proxyOffset = gridTransform.position - proxy.transform.position;
        }

        if (hasGridID == false)
        {
            Debug.LogWarning("Physics grid " + name + " has no grid ID. Will not be able to be serialized across network.");
        }
    }