示例#1
0
    // Use this for initialization
    void Start()
    {
        thisTransform = transform;
        manager       = FindObjectOfType <PhysicsGridManager>();
        if (manager == null)
        {
            Debug.LogError("No grid manager found in scene");
        }
        if (transform.parent != null)
        {
            SetGrid(transform.parent.GetComponent <PhysicsGrid>(), true);
        }
        else
        {
            SetGrid(manager.GetGridByID((ushort)ReservedObjectIDs.RootGrid), true);
        }
        if (parentGrid == null)
        {
            Debug.Log("ZonedTransform does not have a parent grid, this should happen rarely");
        }
        debugRigidbody = GetComponent <Rigidbody>();

        IdentityContainer c = GetComponent <IdentityContainer>();

        if (c != null)
        {
            thisMNI = c.GetIdentity();
            hasIdentityContainer = true;
        }

        manager.TriggerRootScan();
    }
示例#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.");
        }
    }