private void OnEnable() { part = target as MonoPart; if (part.RootPort.IsExists()) { rootPort = (MonoPort)part.RootPort; } else // 如果该部件没有根接口.. { Debug.Log("Adding root port"); // 尝试在其子对象中寻找根接口 rootPort = part.transform.Find("RootPort")?.GetComponent <MonoPort>(); // 如果没有.. if (rootPort == null) { // 新创建一个 rootPort = new GameObject("RootPort").AddComponent <BasicPort>(); rootPort.transform.parent = part.transform; rootPort.transform.localPosition = Vector3.zero; } // 将根部件加入到部件上 part.AddPort(rootPort, true); } }
public static void ReturnPart(MonoPart parts) { if (!Instance.spareParts.Contains(parts)) { Debug.LogWarning($"This part wasn't belong to the storage... How did you get it"); Instance.spareParts.Add(parts); } parts.transform.SetParent(GlobalObject.HidenObject.transform); parts.transform.position = Vector3.zero; parts.transform.rotation = Quaternion.identity; parts.transform.localScale = Vector3.one; }