public Model(string path) { Parts = new List <ModelPart>(); FilePath = path; using (var stream = new FileStream(path, FileMode.Open)) { CheckHeader(stream); Type = BitConverter.ToInt32(stream.ReadBytes(4)); Template = new ModelTemplate(stream); stream.ReadBytes(10); MountPoints = new MountPoints(stream); Lights = new Lights(stream); stream.ReadBytes(64); stream.ReadBytes(488); UnknownVal1 = BitConverter.ToInt16(stream.ReadBytes(2)); UnknownVal2 = BitConverter.ToInt16(stream.ReadBytes(2)); UnknownVal3 = BitConverter.ToInt16(stream.ReadBytes(2)); UnknownVal4 = BitConverter.ToInt16(stream.ReadBytes(2)); UnknownVal5 = BitConverter.ToInt16(stream.ReadBytes(4)); if (Type != 0) { throw new NotSupportedException("Not supported mesh format"); } Parts = GetParts(stream).ToList(); PartsTree = GetPartsTree(Parts); } }
private void OnMouseUp() { // Grab the closest point that doesn't belong to this object MountPoint lClosestMountPoint = MountPoints.GetClosestMountPoint(mMountPoints); if (lClosestMountPoint != null) { // Grab the closest point from this object to the just-found point Vector3 lTestPosition = lClosestMountPoint._Anchor.transform.position; MountPoint lThisMountPoint = mMountPoints.GetClosestMountPoint(lTestPosition); if (lThisMountPoint != null) { // Disconnect any existing parent for (int i = 0; i < mMountPoints.Points.Count; i++) { mMountPoints.Points[i].ChildTo(null); } // Check if we're in snap distance float lDistance = Vector3.Distance(lTestPosition, lThisMountPoint._Anchor.transform.position); if (lDistance < mSnapDistance) { // Connect this new one lThisMountPoint.ChildTo(lClosestMountPoint); } } } }
/// <summary> /// Builds the list of bones to tie the mount point to /// </summary> private void LoadBoneNames() { mBoneNames.Clear(); for (int i = 0; i < MountPoints.UnityBones.Length; i++) { mBoneNames.Add(MountPoints.GetHumanBodyBoneName((HumanBodyBones)i)); } mBoneNames.Add("Custom"); }
/// <summary> /// Remounts the mount point. /// </summary> /// <param name="mountPoint">the mount point</param> /// <param name="readOnly">if set to <c>true</c> the mount poine will be set to read-only.</param> /// <exception cref="IOException">Throws if the mount point does not exist.</exception> public void RemountMountPoint(String mountPoint, bool readOnly) { if (MountPoints.ContainsKey(mountPoint)) { MountPoint mnt = MountPoints[mountPoint]; RemountMountPoint(mnt, readOnly); } else { throw new IOException("Invalid mount point"); } }
/// <summary> /// Once the objects are instanciated, awake is called before start. Use it /// to setup references to other objects /// </summary> protected void Awake() { if (BasicInventory.UnityBones == null) { BasicInventory.UnityBones = System.Enum.GetNames(typeof(HumanBodyBones)); for (int i = 0; i < BasicInventory.UnityBones.Length; i++) { BasicInventory.UnityBones[i] = StringHelper.CleanString(BasicInventory.UnityBones[i]); } } // Object that will provide access to the keyboard, mouse, etc if (_InputSourceOwner != null) { _InputSource = InterfaceHelper.GetComponent <IInputSource>(_InputSourceOwner); } // If the input source is still null, see if we can grab a local input source if (_AutoFindInputSource && _InputSource == null) { _InputSource = InterfaceHelper.GetComponent <IInputSource>(gameObject); if (_InputSource != null) { _InputSourceOwner = gameObject; } } // If that's still null, see if we can grab one from the scene. This may happen // if the MC was instanciated from a prefab which doesn't hold a reference to the input source if (_AutoFindInputSource && _InputSource == null) { IInputSource[] lInputSources = InterfaceHelper.GetComponents <IInputSource>(); for (int i = 0; i < lInputSources.Length; i++) { GameObject lInputSourceOwner = ((MonoBehaviour)lInputSources[i]).gameObject; if (lInputSourceOwner.activeSelf && lInputSources[i].IsEnabled) { _InputSource = lInputSources[i]; _InputSourceOwner = lInputSourceOwner; } } } // Grab the motion controller mMotionController = gameObject.GetComponent <MotionController>(); #if USE_MOUNT_POINTS mMountPoints = gameObject.GetComponent <MountPoints>(); #endif }
/// <summary> /// Loads the mounts points that are part of object in the scene and /// NOT this one. /// </summary> private void LoadOtherMountPoints() { mScenePoints.Clear(); mScenePointPositions.Clear(); UnityEngine.Object[] lScenePointLists = Resources.FindObjectsOfTypeAll(typeof(MountPoints)); for (int i = 0; i < lScenePointLists.Length; i++) { MountPoints lScenePointList = lScenePointLists[i] as MountPoints; if (lScenePointList == mTarget) { continue; } if (lScenePointList.gameObject.activeInHierarchy == false) { continue; } for (int j = 0; j < lScenePointList.Points.Count; j++) { MountPoint lPoint = lScenePointList.Points[j] as MountPoint; if (lPoint.Owner != null && lPoint.Anchor != null) { mScenePoints.Add(lPoint); mScenePointPositions.Add(lPoint.Anchor.transform.position); } } } lScenePointLists = Resources.FindObjectsOfTypeAll(typeof(Mount)); for (int i = 0; i < lScenePointLists.Length; i++) { Mount lScenePoint = lScenePointLists[i] as Mount; if (lScenePoint == mTarget) { continue; } if (lScenePoint.gameObject.activeInHierarchy == false) { continue; } MountPoint lPoint = lScenePoint.Point; if (lPoint.Owner != null && lPoint.Anchor != null) { mScenePoints.Add(lPoint); mScenePointPositions.Add(lPoint.Anchor.transform.position); } } }
/// <summary> /// Called when the script object is loaded /// </summary> void OnEnable() { LoadBoneNames(); // Grab the serialized objects mTarget = (MountPoints)target; mTargetSO = new SerializedObject(target); InstanciatePointList(); InstanciateItemList(); // Runs through all other objects and loads the mount point LoadOtherMountPoints(); }
private void CreateMountPoints() { ProfilerShort.Begin("FractureComponent.CreateMountPoints"); Debug.Assert(m_tmpChildren.Count == 0); if (MyFakes.FRACTURED_BLOCK_AABB_MOUNT_POINTS) { if (MountPoints == null) { MountPoints = new List <MyCubeBlockDefinition.MountPoint>(); } else { MountPoints.Clear(); } var blockDef = Block.BlockDefinition; var size = new Vector3(blockDef.Size); var bb = new BoundingBox(-size / 2, size / 2); var he = bb.HalfExtents; bb.Min += he; bb.Max += he; Shape.GetChildren(m_tmpChildren); if (m_tmpChildren.Count > 0) { foreach (var child in m_tmpChildren) { var shape = child.Shape; shape = AddMountForShape(shape, Matrix.Identity, ref bb, Block.CubeGrid.GridSize, MountPoints); } } else { AddMountForShape(Shape, Matrix.Identity, ref bb, Block.CubeGrid.GridSize, MountPoints); } m_tmpChildren.Clear(); } else { MountPoints = MyCubeBuilder.AutogenerateMountpoints(new HkShape[] { Shape.GetShape() }, Block.CubeGrid.GridSize); } ProfilerShort.End(); }
public override bool RemoveChildShapes(string[] shapeNames) { base.RemoveChildShapes(shapeNames); if (!Shape.IsValid() || Shape.GetChildrenCount() == 0) { MountPoints.Clear(); // Remove block when no children if (Sync.IsServer) { return(true); } else { // Remove this component - if not done then clients add empty shapes to grid shape (MyGridShape.CreateBlockShape) Block.FatBlock.Components.Remove <MyFractureComponentBase>(); } } return(false); }
public void Start() { mCamera = Camera.main; mMountPoints = gameObject.GetComponent <MountPoints>(); }
public virtual void Init(Ob_Part v) { BlockSetInfo.BlockCountByType.Clear(); foreach (var kv in v.BlockCountByType) { BlockSetInfo.BlockCountByType[kv.Item1] = kv.Item2; } BlockSetInfo.ComponentCost.Clear(); foreach (var kv in v.ComponentCost) { BlockSetInfo.ComponentCost[MyDefinitionManager.Static.GetComponentDefinition(kv.Item1)] = kv.Item2; } m_blocks.Clear(); foreach (var kv in v.OccupiedLocations) { m_blocks[kv] = null; } BlockSetInfo.PowerConsumptionByGroup.Clear(); foreach (var kv in v.PowerConsumptionByGroup) { BlockSetInfo.PowerConsumptionByGroup[kv.Item1] = kv.Item2; } m_reservedSpaces.Clear(); m_reservedSpaces.AddRange(v.ReservedSpaces.Select(x => new ReservedSpace(x))); m_mountPoints.Clear(); m_mountPointBlocks.Clear(); foreach (var mp in v.MountPoints) { var block = new PartMount(this, mp.Type, mp.Name); block.Init(mp); Dictionary <string, PartMount> partsOfType; if (!m_mountPoints.TryGetValue(mp.Type, out partsOfType)) { partsOfType = m_mountPoints[mp.Type] = new Dictionary <string, PartMount>(); } partsOfType[mp.Name] = block; foreach (var kv in block.Blocks) { m_mountPointBlocks[kv.AnchorLocation] = kv; } } // Load AABBs BoundingBox = BoundingBox.CreateInvalid(); foreach (var p in v.OccupiedLocations) { BoundingBox = BoundingBox.Include((Vector3I)p); } ReservedSpace = BoundingBox.CreateInvalid(); foreach (var r in v.ReservedSpaces) { ReservedSpace = ReservedSpace.Include(r.Min); ReservedSpace = ReservedSpace.Include(r.Max); } BlockSetInfo.UpdateCache(); Logger.Info("Loaded {0} lazily with {1} mount points, {2} reserved spaces, and {3} occupied cubes.", Name, MountPoints.Count(), m_reservedSpaces.Count, m_blocks.Count); foreach (var type in MountPointTypes) { Logger.Info(" ...of type \"{0}\" there are {1}", type, MountPointsOfType(type).Count()); } }
public SettingsStore(JObject obj) : this() { JToken versionToken; if (obj.TryGetValue(nameof(Version), StringComparison.OrdinalIgnoreCase, out versionToken)) { Version = versionToken.ToString(); } JToken mountPointsToken; if (obj.TryGetValue("MountPoints", StringComparison.OrdinalIgnoreCase, out mountPointsToken)) { JArray mountPointsArray = mountPointsToken as JArray; if (mountPointsArray != null) { foreach (JToken entry in mountPointsArray) { if (entry != null && entry.Type == JTokenType.Object) { Guid parentMountPointId; Guid mountPointFactoryId; Guid mountPointId; JObject mp = (JObject)entry; JToken parentMountPointIdToken; if (!mp.TryGetValue("ParentMountPointId", StringComparison.OrdinalIgnoreCase, out parentMountPointIdToken) || parentMountPointIdToken == null || parentMountPointIdToken.Type != JTokenType.String || !Guid.TryParse(parentMountPointIdToken.ToString(), out parentMountPointId)) { continue; } JToken mountPointFactoryIdToken; if (!mp.TryGetValue("MountPointFactoryId", StringComparison.OrdinalIgnoreCase, out mountPointFactoryIdToken) || mountPointFactoryIdToken == null || mountPointFactoryIdToken.Type != JTokenType.String || !Guid.TryParse(mountPointFactoryIdToken.ToString(), out mountPointFactoryId)) { continue; } JToken mountPointIdToken; if (!mp.TryGetValue("MountPointId", StringComparison.OrdinalIgnoreCase, out mountPointIdToken) || mountPointIdToken == null || mountPointIdToken.Type != JTokenType.String || !Guid.TryParse(mountPointIdToken.ToString(), out mountPointId)) { continue; } JToken placeToken; if (!mp.TryGetValue("Place", StringComparison.OrdinalIgnoreCase, out placeToken) || placeToken == null || placeToken.Type != JTokenType.String) { continue; } string place = placeToken.ToString(); MountPointInfo mountPoint = new MountPointInfo(parentMountPointId, mountPointFactoryId, mountPointId, place); MountPoints.Add(mountPoint); } } } } JToken componentGuidToAssemblyQualifiedNameToken; if (obj.TryGetValue("ComponentGuidToAssemblyQualifiedName", StringComparison.OrdinalIgnoreCase, out componentGuidToAssemblyQualifiedNameToken)) { JObject componentGuidToAssemblyQualifiedNameObject = componentGuidToAssemblyQualifiedNameToken as JObject; if (componentGuidToAssemblyQualifiedNameObject != null) { foreach (JProperty entry in componentGuidToAssemblyQualifiedNameObject.Properties()) { if (entry.Value != null && entry.Value.Type == JTokenType.String) { ComponentGuidToAssemblyQualifiedName[entry.Name] = entry.Value.ToString(); } } } } JToken probingPathsToken; if (obj.TryGetValue("ProbingPaths", StringComparison.OrdinalIgnoreCase, out probingPathsToken)) { JArray probingPathsArray = probingPathsToken as JArray; if (probingPathsArray != null) { foreach (JToken path in probingPathsArray) { if (path != null && path.Type == JTokenType.String) { ProbingPaths.Add(path.ToString()); } } } } JToken componentTypeToGuidListToken; if (obj.TryGetValue("ComponentTypeToGuidList", StringComparison.OrdinalIgnoreCase, out componentTypeToGuidListToken)) { JObject componentTypeToGuidListObject = componentTypeToGuidListToken as JObject; if (componentTypeToGuidListObject != null) { foreach (JProperty entry in componentTypeToGuidListObject.Properties()) { JArray values = entry.Value as JArray; if (values != null) { HashSet <Guid> set = new HashSet <Guid>(); ComponentTypeToGuidList[entry.Name] = set; foreach (JToken value in values) { if (value != null && value.Type == JTokenType.String) { Guid id; if (Guid.TryParse(value.ToString(), out id)) { set.Add(id); } } } } } } } }
/// <summary> /// Raised when the object becomes active. Initialization can happen here. /// </summary> void Awake() { mMountPoints = GameObject.Find("DefaultMale").GetComponent <MountPoints>(); }
public void InitFromPrefab() { if (Initialized) { return; } var cob = GetObjectBuilder(); var chash = cob.ComputeHash(); Initialized = true; InitFromGrids(Prefab.CubeGrids[0], Prefab.CubeGrids); Logger.Info("Loaded {0} with {1} mount points, {2} reserved spaces, and {3} blocks. {4} aux grids", Name, MountPoints.Count(), ReservedSpaces.Count(), PrimaryGrid.CubeBlocks.Count, Prefab.CubeGrids.Length - 1); foreach (var type in MountPointTypes) { Logger.Info(" ...of type \"{0}\" there are {1}", type, MountPointsOfType(type).Count()); } var obs = GetObjectBuilder(); var nhash = obs.ComputeHash(); if (nhash == chash) { return; } MyAPIGateway.Parallel.StartBackground(ParallelUtilities.WrapAction(() => { try { Logger.Info("Invalid hash for cached definition of {0}; writing to local storage. {1} => {2}", Name, chash, nhash); using (var writer = MyAPIGateway.Utilities.WriteFileInLocalStorage(CacheName, typeof(PartFromPrefab))) { var xml = MyAPIGateway.Utilities.SerializeToXML(obs); writer.Write(xml); } } catch (Exception e) { Logger.Error("Write failed.\n{0}", e); } }, Manager)); }
/// <summary> /// Determine if we're dealing with an actual prefab or an instance /// </summary> /// <param name="rMountPoints"></param> /// <returns></returns> private bool IsAddMountPointEnabled(MountPoints rMountPoints) { PrefabType lType = PrefabUtility.GetPrefabType(rMountPoints); return(lType != PrefabType.Prefab); }