Ejemplo n.º 1
0
        private bool CreateCable(Node node)
        {
            var nativeCable = m_tree.GetCable(node.Uuid);

            if (nativeCable == null)
            {
                Debug.LogWarning("Unable to find native instance of cable: " + node.GameObject.name +
                                 " (UUID: " + node.Uuid.str() + ")");
                return(false);
            }

            var cable = node.GameObject.GetOrCreateComponent <Cable>();
            var route = cable.Route;

            route.Clear();

            cable.RestoreLocalDataFrom(nativeCable);
            cable.RouteAlgorithm = Cable.RouteType.Identity;

            var properties = CableProperties.Create <CableProperties>().RestoreLocalDataFrom(nativeCable.getCableProperties(),
                                                                                             nativeCable.getCablePlasticity());

            properties.name  = cable.name + "_properties";
            cable.Properties = properties = AddOrReplaceAsset(properties, node, AGXUnity.IO.AssetType.CableProperties);

            for (var it = nativeCable.getSegments().begin(); !it.EqualWith(nativeCable.getSegments().end()); it.inc())
            {
                var segment = it.get();
                route.Add(segment, attachment =>
                {
                    if (attachment == null || attachment.getRigidBody() == null)
                    {
                        return(FileInfo.PrefabInstance);
                    }
                    var rbNode = m_tree.GetNode(attachment.getRigidBody().getUuid());
                    if (rbNode == null)
                    {
                        Debug.LogWarning("Unable to find rigid body in cable attachment.");
                        return(FileInfo.PrefabInstance);
                    }
                    return(rbNode.GameObject);
                });
            }

            var materials = node.GetReferences(Node.NodeType.Material);

            if (materials.Length > 0)
            {
                cable.Material = materials[0].Asset as ShapeMaterial;
            }

            cable.GetComponent <CableRenderer>().InitializeRenderer();
            cable.GetComponent <CableRenderer>().Material = null;

            // Adding collision group from restored instance since the disabled pair
            // will be read from Space (cable.setEnableCollisions( foo, false ) will
            // work out of the box).
            var collisionGroups = cable.gameObject.GetOrCreateComponent <CollisionGroups>();

            collisionGroups.AddGroup(nativeCable.getUniqueId().ToString(), false);
            var referencedGroups = node.GetReferences(Node.NodeType.GroupId);

            foreach (var group in referencedGroups)
            {
                if (group.Object is string)
                {
                    collisionGroups.AddGroup(group.Object as string, false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        private Tuple <PropertyWrapper, CableProperties.Direction, object> OnPropertyGUI(CableProperties.Direction dir,
                                                                                         CableProperties properties,
                                                                                         GUISkin skin)
        {
            Tuple <PropertyWrapper, CableProperties.Direction, object> changed = null;
            var data = EditorData.Instance.GetData(properties, "CableProperty" + dir.ToString());

            if (GUI.Foldout(data, GUI.MakeLabel(dir.ToString()), skin))
            {
                using (new GUI.Indent(12)) {
                    GUI.Separator();

                    var wrappers = PropertyWrapper.FindProperties <CableProperty>(System.Reflection.BindingFlags.Instance |
                                                                                  System.Reflection.BindingFlags.Public);
                    foreach (var wrapper in wrappers)
                    {
                        if (wrapper.GetContainingType() == typeof(float) && InspectorEditor.ShouldBeShownInInspector(wrapper.Member))
                        {
                            var value = EditorGUILayout.FloatField(InspectorGUI.MakeLabel(wrapper.Member),
                                                                   wrapper.Get <float>(properties[dir]));
                            if (UnityEngine.GUI.changed)
                            {
                                changed = new Tuple <PropertyWrapper, CableProperties.Direction, object>(wrapper, dir, value);
                                UnityEngine.GUI.changed = false;
                            }
                        }
                    }
                }
            }
            return(changed);
        }