/** * Draw Inspector GUI for this PrefabBuilder. */ public void OnInspectorGUI(Action onValueChanged) { if (m_replacingObject == null) { m_replacingObject = new GameObjectReference(); } EditorGUILayout.HelpBox("Replace With Incoming GameObject creates prefab by replacing child of assigned Prefab with incoming GameObjects using name.", MessageType.Info); using (new EditorGUILayout.VerticalScope(GUI.skin.box)) { var newObj = (UnityEngine.GameObject)EditorGUILayout.ObjectField( m_replacingObject.Object, typeof(UnityEngine.GameObject), false); if (newObj != m_replacingObject.Object) { m_replacingObject.Object = newObj; onValueChanged(); } } }
protected override Func <string,GameObjectResource> GenerateResource(GameObjectReference reference) { return((fname) => { /** Better set this up! **/ IffFile iff = null; if (reference.Source == GameObjectSource.Far) { iff = GameObjects.Get(reference.FileName.ToLower()); iff.InitHash(); if (iff != null) { iff.RuntimeInfo.Path = reference.FileName; } } else { //unused iff = new IffFile(reference.FileName,reference.Source == GameObjectSource.User); iff.InitHash(); iff.RuntimeInfo.Path = reference.FileName; iff.RuntimeInfo.State = IffRuntimeState.Standalone; } if (iff != null) { if (iff != null && iff.RuntimeInfo.State == IffRuntimeState.PIFFPatch) { //OBJDs may have changed due to patch. Remove all file references ResetFile(iff); } iff.RuntimeInfo.UseCase = IffUseCase.Object; } return new GameObjectResource(iff,null,null,reference.FileName,ContentManager); }); }
public void ServerBeginUnCuffAttempt() { if (uncuffCoroutine != null) { StopCoroutine(uncuffCoroutine); } float resistTime = GameObjectReference.GetComponent <Restraint>().ResistTime; healthCache = thisPlayerScript.playerHealth.OverallHealth; positionCache = thisPlayerScript.registerTile.LocalPositionServer; if (!CanUncuff()) { return; } uncuffCoroutine = UncuffCountDown(resistTime); StartCoroutine(uncuffCoroutine); Chat.AddActionMsgToChat( thisPlayerScript.gameObject, $"You are attempting to remove the cuffs. This takes up to {resistTime:0} seconds", thisPlayerScript.playerName + " is attempting to remove their cuffs"); }
public void ServerBeginUnCuffAttempt() { if (uncuffCoroutine != null) { StopCoroutine(uncuffCoroutine); } float resistTime = GameObjectReference.GetComponent <Restraint>().ResistTime; positionCache = thisPlayerScript.registerTile.LocalPositionServer; if (!CanUncuff()) { return; } var bar = StandardProgressAction.Create(new StandardProgressActionConfig(StandardProgressActionType.Unbuckle, false, false, true), TryUncuff); bar.ServerStartProgress(thisPlayerScript.registerTile, resistTime, thisPlayerScript.gameObject); Chat.AddActionMsgToChat( thisPlayerScript.gameObject, $"You are attempting to remove the cuffs. This takes up to {resistTime:0} seconds", thisPlayerScript.playerName + " is attempting to remove their cuffs"); }
public static void SelectionRay(MouseButtonEventArgs e, Point p) { //if (wasDragging) return; Viewport[] vps = Game.Device.Rasterizer.GetViewports(); if (vps == null || vps.Length == 0) { return; } moveX = 0; moveY = 0; moveZ = 0; if (e.ChangedButton == MouseButton.Left && e.ButtonState == MouseButtonState.Pressed) { Viewport vp = Game.Device.Rasterizer.GetViewports()[0]; Vector2 mousePosition = new Vector2((float)p.X, (float)p.Y); int mouseX = (int)p.X; int mouseY = (int)p.Y; if (mouseX < 0) { mouseX = 0; } if (mouseY < 0) { mouseY = 0; } if (mouseX > vp.Width) { mouseX = vp.Width; } if (mouseY > vp.Height) { mouseY = vp.Height; } Vector3 near = new Vector3(mouseX, mouseY, 0f); Vector3 far = new Vector3(mouseX, mouseY, 1f); Vector3 position; Vector3 direction; Ray transformedRay; bool found = false; Dictionary <String, GameObjectReference> objDic = MainPlayer.CurrentWorldSpace.GetAllModelObjRefs(Global.GlobalSettings.CurrentCell); List <GameObjectReference> gm = new List <GameObjectReference>(); foreach (GameObjectReference objRef in objDic.Values) { gm.Add(objRef); } for (int i = gm.Count - 1; i >= 0 && !found; i--) { Model model = gm[i].BaseGameObject as Model; Vector3 v; v.X = (((2.0f * mouseX) / vp.Width) - 1) / Camera.ProjectionMatrix[0, 0]; v.Y = -(((2.0f * mouseY) / vp.Height) - 1) / Camera.ProjectionMatrix[1, 1]; v.Z = 1.0f; // Get the inverse view matrix Matrix m = Matrix.Invert(Matrix.Scaling(gm[i].Scale.X, gm[i].Scale.Y, gm[i].Scale.Z) * gm[i].Rotation * WorldSpace.GetRealWorldMatrix(gm[i].Position, Global.GlobalSettings.CurrentCell) * Camera.ViewMatrix); // Transform the screen space pick ray into 3D space direction.X = v.X * m[0, 0] + v.Y * m[1, 0] + v.Z * m[2, 0]; direction.Y = v.X * m[0, 1] + v.Y * m[1, 1] + v.Z * m[2, 1]; direction.Z = v.X * m[0, 2] + v.Y * m[1, 2] + v.Z * m[2, 2]; position.X = m[3, 0]; position.Y = m[3, 1]; position.Z = m[3, 2]; transformedRay = new Ray(position, direction); float distance; if (Ray.Intersects(transformedRay, model.Mesh3d.bb, out distance)) { if (DoesRayInterestMesh(gm[i].BaseGameObject, position, direction)) { SelectedObject = gm[i]; found = true; if (SelectedObjectChanged != null) { SelectedObjectChanged(null, EventArgs.Empty); } } else { SelectedObject = null; } } else { SelectedObject = null; } } } }
protected override void OnUpdate() { for (var i = 0; i < addedEntitiesData.Length; i++) { var prefabMapping = PrefabConfig.PrefabMappings[addedEntitiesData.PrefabNames[i].Prefab]; var transform = addedEntitiesData.Transforms[i]; var entity = addedEntitiesData.Entities[i]; var spatialEntityId = addedEntitiesData.SpatialEntityIds[i].EntityId; if (!SystemConfig.UnityClient.Equals(worker.WorkerType) && !SystemConfig.UnityGameLogic.Equals(worker.WorkerType)) { worker.LogDispatcher.HandleLog(LogType.Error, new LogEvent( "Worker type isn't supported by the GameObjectInitializationSystem.") .WithField("WorldName", World.Name) .WithField("WorkerType", worker)); continue; } var prefabName = SystemConfig.UnityGameLogic.Equals(worker.WorkerType) ? prefabMapping.UnityGameLogic : prefabMapping.UnityClient; var position = new Vector3(transform.Location.X, transform.Location.Y, transform.Location.Z) + worker.Origin; var rotation = new UnityEngine.Quaternion(transform.Rotation.X, transform.Rotation.Y, transform.Rotation.Z, transform.Rotation.W); var gameObject = entityGameObjectCreator.CreateEntityGameObject(entity, prefabName, position, rotation, spatialEntityId); var gameObjectReference = new GameObjectReference { GameObject = gameObject }; entityGameObjectCache[entity.Index] = gameObject; var gameObjectReferenceHandleComponent = new GameObjectReferenceHandle(); PostUpdateCommands.AddComponent(addedEntitiesData.Entities[i], gameObjectReferenceHandleComponent); viewCommandBuffer.AddComponent(entity, gameObjectReference); entityGameObjectLinker.LinkGameObjectToEntity(gameObject, entity, spatialEntityId, viewCommandBuffer); } for (var i = 0; i < removedEntitiesData.Length; i++) { var entity = removedEntitiesData.Entities[i]; var entityIndex = entity.Index; if (!entityGameObjectCache.TryGetValue(entityIndex, out var gameObject)) { worker.LogDispatcher.HandleLog(LogType.Error, new LogEvent( "GameObject corresponding to removed entity not found.") .WithField("EntityIndex", entityIndex)); continue; } entityGameObjectCache.Remove(entityIndex); UnityObjectDestroyer.Destroy(gameObject); PostUpdateCommands.RemoveComponent <GameObjectReferenceHandle>(entity); } viewCommandBuffer.FlushBuffer(); }
public void CreateGameObjectReference() { gameObjectReference = ScriptableObject.CreateInstance <GameObjectReference> (); gameObjectReference.reference = new GameObject(); }
public static void Start(GameObjectReference prefab, string text, float duration, Vector3 start, Vector3 end, Color?color) { var txtHolder = _pool.New(); txtHolder.Setup(prefab, text, duration, start, end, color); }
protected override void Perform(GameObject obj, object referenceParent, FieldInfo field) { if (obj is Ocean) { if (LotManager.sOceanObject == obj) { return; } } else if (obj is Terrain) { if (Terrain.sTerrain == obj) { return; } } if (DereferenceManager.HasBeenDestroyed(obj)) { if (obj is Sim) { LotManager.sActorList.Remove(obj as Sim); DereferenceManager.Perform(obj, ObjectLookup.GetReference(new ReferenceWrapper(obj)), true, false); } else { GameObjectReference refObj = ObjectLookup.GetReference(new ReferenceWrapper(obj)); if (DereferenceManager.Perform(obj, refObj, false, false)) { DereferenceManager.Perform(obj, refObj, true, false); ErrorTrap.LogCorrection("Destroyed Object Found: " + obj.GetType()); } } return; } if (kShowFullReferencing) { DereferenceManager.Perform(obj, ObjectLookup.GetReference(new ReferenceWrapper(obj)), false, true); } if (obj.InWorld) { return; } if (obj.InInventory) { if (Inventories.ParentInventory(obj) == null) { if ((obj.Parent != null) || (Consignment.ContainsKey(obj))) { obj.SetFlags(GameObject.FlagField.InInventory, false); ErrorTrap.LogCorrection("Invalid Inventory Object Unflagged: " + obj.GetType()); } else { ErrorTrap.LogCorrection("Invalid Inventory Object Found: " + obj.GetType()); ErrorTrap.AddToBeDeleted(obj, true); } } return; } else { if (SharedInventories.ContainsKey(obj.ObjectId)) { obj.SetFlags(GameObject.FlagField.InInventory, true); ErrorTrap.LogCorrection("Inventory Object Flagged: " + obj.GetType()); return; } } if (EventItems.ContainsKey(obj.ObjectId)) { return; } bool hasParent = false; IGameObject parent = obj.Parent; while (parent != null) { hasParent = true; if (DereferenceManager.HasBeenDestroyed(parent)) { ErrorTrap.LogCorrection("Destroyed Parent Object Found: " + parent.GetType()); ErrorTrap.AddToBeDeleted(obj, true); hasParent = false; break; } parent = parent.Parent; } if (!hasParent) { ReferenceWrapper refObj = new ReferenceWrapper(obj); GameObjectReference reference = ObjectLookup.GetReference(refObj); if ((reference != null) && (reference.HasReferences)) { if (DereferenceManager.Perform(obj, ObjectLookup.GetReference(refObj), false, false)) { IScriptProxy proxy = Simulator.GetProxy(obj.ObjectId); if (proxy != null) { IScriptLogic logic = proxy.Target; if (object.ReferenceEquals(logic, obj)) { bool log = !sSilentDestroy.ContainsKey(obj.GetType()); if (log) { ErrorTrap.LogCorrection("Out of World Object Found 2: " + obj.GetType()); } else { ErrorTrap.DebugLogCorrection("Out of World Object Found 3: " + obj.GetType()); } ErrorTrap.AddToBeDeleted(obj, log); } else { ErrorTrap.DebugLogCorrection("Out of World Object Found 4: " + obj.GetType()); ErrorTrap.DebugLogCorrection("Out of World Object Found 5: " + logic.GetType()); } } else { DereferenceManager.Perform(obj, ObjectLookup.GetReference(refObj), true, false); } } } else { ErrorTrap.LogCorrection("Out of World Object Found 1: " + obj.GetType()); ErrorTrap.AddToBeDeleted(obj, true); } } }
public static bool Perform(object obj, GameObjectReference references, bool perform, bool reportFound) { bool immediate = false; bool report = true; if ((obj is RabbitHoleDoorJig) || (obj is PhoneCell)) { report = ErrorTrap.kDebugging; } else if (obj is Lot) { immediate = true; } else if (obj is Sim) { Sim sim = obj as Sim; if (sim.LotHome != null) { if ((RecoverMissingSimTask.FindPlaceholderForSim(sim.SimDescription) == null) && ((sim.SimDescription.CreatedSim == null) || (sim.SimDescription.CreatedSim == sim))) { immediate = true; } } } ReferenceLog log = null; if (!perform) { log = new ReferenceLog("Potential Object Found: " + ErrorTrap.GetQualifiedName(obj), report, immediate); } if (references == null) { return(false); } if ((!ErrorTrap.kDebugging) && (references.Count == 0)) { return(false); } if (perform) { log = new ReferenceLog("Destroyed Object Found: " + ErrorTrap.GetQualifiedName(obj), report, immediate); } log.Perform = perform; log.ReportFound = reportFound; if ((!ErrorTrap.kDebugging) && (obj is Lot)) { return(false); } List <DereferenceStack> stack = new List <DereferenceStack>(); foreach (KeyValuePair <object, FieldInfo> pair in references) { stack.Add(new DereferenceStack(pair, new Dictionary <ReferenceWrapper, bool>(), new List <ReferenceWrapper>(), new ReferenceWrapper(obj), false, false)); } bool firstFailure = true; int index = 0; while (index < stack.Count) { DereferenceStack stackObject = stack[index]; index++; ReferenceWrapper key = new ReferenceWrapper(stackObject.mReference.Key); bool recursion = false; if (stackObject.ContainsKey(key)) { recursion = true; } if ((perform) && (stackObject.Count == 1)) { log.DumpLog(false); } object reference = stackObject.mReference.Key; string depth = ""; for (int i = 0; i < stackObject.Count - 1; i++) { depth += " "; } bool reset = false, success = false; foreach (IDereference dereference in DereferenceManager.Dereferences) { DereferenceResult result = dereference.IPerform(stackObject.mReference, stackObject.mList, perform); if (result == DereferenceResult.Found) { log.SetFoundSuccess(); } if (result != DereferenceResult.Failure) { stackObject.mResult = depth + " Reference " + result + ": " + reference.GetType() + " " + stackObject.mReference.Value + " (Using " + dereference.GetType().Name + ")"; if (report) { log.Add(stackObject.mResult); } success = true; bool checkSuccess = false; if (reference is GameObject) { stackObject.mEndFound = true; checkSuccess = true; GameObject gameObject = reference as GameObject; if ((perform) && (!HasBeenDestroyed(gameObject)) && (!reset) && (!(reference is Sim))) { try { reset = true; gameObject.SetObjectToReset(); log.Add(depth + " Object Reset: " + ErrorTrap.GetQualifiedName(gameObject)); } catch //(Exception e) { //Common.DebugException(gameObject, e); } } } else { switch (result) { case DereferenceResult.End: case DereferenceResult.Found: stackObject.mEndFound = true; break; case DereferenceResult.Continue: case DereferenceResult.ContinueIfReferenced: case DereferenceResult.Ignore: bool unimportant = stackObject.mUnimportant; switch (result) { case DereferenceResult.ContinueIfReferenced: unimportant = true; break; case DereferenceResult.Ignore: unimportant = true; stackObject.mEndFound = true; break; } if (!recursion) { if (ShouldRecurse(reference)) { bool referenced = false; GameObjectReference gameReference = ObjectLookup.GetReference(key); if (gameReference != null) { foreach (KeyValuePair <object, FieldInfo> pair in gameReference) { stack.Insert(index, new DereferenceStack(pair, stackObject, key, unimportant, stackObject.mEndFound)); referenced = true; } } if (!referenced) { checkSuccess = true; if (result == DereferenceResult.ContinueIfReferenced) { stackObject.mEndFound = true; } } else { stackObject.mBridge = true; } } else { stackObject.mEndFound = true; } } else if (result == DereferenceResult.ContinueIfReferenced) { stackObject.mEndFound = true; } else { checkSuccess = true; } break; default: if (recursion) { checkSuccess = true; } break; } } if (checkSuccess) { switch (result) { case DereferenceResult.End: case DereferenceResult.Ignore: break; default: if (recursion) { if (!object.ReferenceEquals(key.mObject, obj)) { log.SetFailure("A"); } else { stackObject.mEndFound = true; } } else { log.SetFailure("B"); } break; } } } } if (!success) { bool mustRecurse = false; string priority = "UNHANDLED"; if (recursion) { priority = "Recursion"; if (object.ReferenceEquals(key.mObject, obj)) { stackObject.mEndFound = true; } else { stackObject.mBridge = true; } } else if ((reference.GetType().IsArray) || (reference is IList) || (reference is IDictionary) || (reference is ICollection) || (reference.GetType().Name.Contains("ForgetfulList")) || (reference.GetType().Name.Contains("PairedListDictionary"))) { priority = "Bridge"; mustRecurse = true; stackObject.mBridge = true; } else if (stackObject.mUnimportant) { priority = "Ancillary"; if ((reference is GameObject) || (reference is SimDescription)) { recursion = true; } else { mustRecurse = true; } stackObject.mBridge = true; } else { log.ImportantFound(); log.SetFailure("C"); } stackObject.mResult = depth + " " + priority + " Reference: " + ErrorTrap.GetQualifiedName(reference) + " " + stackObject.mReference.Value; if (report) { log.Add(stackObject.mResult); } bool referenced = false; if (!recursion) { if (ShouldRecurse(reference)) { GameObjectReference gameReference = ObjectLookup.GetReference(key); if (gameReference != null) { foreach (KeyValuePair <object, FieldInfo> pair in gameReference) { stack.Insert(index, new DereferenceStack(pair, stackObject, key, stackObject.mUnimportant, stackObject.mEndFound)); referenced = true; } } } else { stackObject.mEndFound = true; mustRecurse = false; } } if (!referenced) { if (mustRecurse) { log.SetFailure("D"); } } else { stackObject.mBridge = true; } } if ((!perform) && (!log.IsTotalSuccess) && (firstFailure)) { firstFailure = false; log.Add(depth + " RETAINED " + log.FailureReason); } } bool first = true; foreach (DereferenceStack stackObject in stack) { if (stackObject.mEndFound) { continue; } if (stackObject.mBridge) { continue; } log.EndMissing(); if (first) { first = false; log.Add(" OPEN ENDED"); } log.Add(stackObject.mResult); } log.DumpLog(false); Logger.ForceRecord(); return(log.IsTotalSuccess); }
protected abstract Func <string, GameObjectResource> GenerateResource(GameObjectReference reference);
public EventLoadModel(GameObjectReference data) { Data = data; }
/// <summary> /// Indicates whether this instance and a specified object are equal. /// </summary> /// <param name="other"> /// The other. /// </param> /// <returns> /// The equals. /// </returns> public bool Equals(GameObjectReference other) { return(other.index == this.index && other.uid == this.uid); }
/// <summary> /// Indicates whether this instance and a specified object are equal. /// </summary> /// <param name="other"> /// The other. /// </param> /// <returns> /// The equals. /// </returns> public bool Equals(GameObjectReference other) { return other.index == this.index && other.uid == this.uid; }
public SpawnPrefabOnDeath(GameObjectReference prefab, IntRange count, float radius) { Prefab = prefab; CountRange = count; Radius = radius; }