Beispiel #1
0
    public void SetMaster(ISetMultitoolMaster Imaster)
    {
        var InAPC = (Imaster as Component)?.gameObject.GetComponent <APC>();

        if (RelatedAPC != null)
        {
            RemoveFromAPC();
        }
        RelatedAPC = InAPC;
        RelatedAPC.AddDevice(this);
    }
Beispiel #2
0
        private void ConnectToClosestAPC(APCPoweredDevice device)
        {
            var apcs = FindObjectsOfType <APC>();

            if (apcs.Length == 0)
            {
                return;
            }

            APC   bestTarget      = null;
            float closestDistance = Mathf.Infinity;
            var   devicePosition  = device.gameObject.transform.position;

            foreach (var potentialTarget in apcs)
            {
                var   directionToTarget = potentialTarget.gameObject.transform.position - devicePosition;
                float dSqrToTarget      = directionToTarget.sqrMagnitude;

                if (dSqrToTarget >= closestDistance)
                {
                    continue;
                }
                closestDistance = dSqrToTarget;
                bestTarget      = potentialTarget;
            }

            if (bestTarget == null || bestTarget == device.RelatedAPC)
            {
                return;
            }

            //If connected to apc before remove us
            if (device.RelatedAPC != null)
            {
                EditorUtility.SetDirty(device.RelatedAPC);
                device.RelatedAPC.RemoveDevice(device);
            }

            device.RelatedAPC = bestTarget;

            EditorUtility.SetDirty(device);
            EditorUtility.SetDirty(device.RelatedAPC);
            bestTarget.AddDevice(device);
            EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
        }