public void AddGizmoArea(Gizmo gizmo) { if (!(gizmo is GizmoArea)) { return; } GizmoArea gizmoArea = (GizmoArea)gizmo; GameObject gizmoObject = new GameObject("area"); gizmoObject.transform.SetParent(gizmoWrapper.transform); AreaBehaviour areaBehaviour = gizmoObject.AddComponent <AreaBehaviour>(); areaBehaviour.Init(geoCamera); FaceRefer face = gizmoArea.face; Vector3 center = geometry.Center(); Vector3[] vectors = new Vector3[face.ids.Length]; for (int i = 0; i < face.ids.Length; i++) { vectors[i] = geometry.UnitVector(face.ids[i]); } float area = geometry.FaceArea(face.ids); areaBehaviour.SetData(center, vectors, area); gizmoMap.Add(gizmoArea, areaBehaviour); }
/// <summary> /// This method allows to remove a area from the manager cache. /// </summary> public void RemoveArea(AreaBehaviour area) { if (area == null) { return; } Areas.Remove(area); }
/// <summary> /// This method allows to add a area from the manager cache. /// </summary> public void AddArea(AreaBehaviour area) { if (area == null) { return; } Areas.Add(area); }
/// <summary> /// This method allows to update the destruction preview. /// </summary> public void UpdateRemovePreview() { foreach (SocketBehaviour Socket in BuildManager.Instance.Sockets) { if (Socket != null) { Socket.DisableCollider(); } } float Distance = OutOfRangeDistance == 0 ? ActionDistance : OutOfRangeDistance; if (CurrentRemovePreview != null) { AreaBehaviour NearestArea = BuildManager.Instance.GetNearestArea(CurrentRemovePreview.transform.position); if (NearestArea != null) { AllowDestruction = NearestArea.AllowDestruction; } else { AllowDestruction = true; } CurrentRemovePreview.ChangeState(StateType.Remove); AllowPlacement = false; } if (Physics.Raycast(GetRay(), out RaycastHit Hit, Distance, BuildManager.Instance.FreeLayers)) { PartBehaviour Part = Hit.collider.GetComponentInParent <PartBehaviour>(); if (Part != null) { if (CurrentRemovePreview != null) { if (CurrentRemovePreview.GetInstanceID() != Part.GetInstanceID()) { ClearRemovePreview(); CurrentRemovePreview = Part; } } else { CurrentRemovePreview = Part; } } else { ClearRemovePreview(); } }
/// <summary> /// Creates an ObjectBlock representing a given area. /// </summary> /// <param name="area">An object representing the behaviour of /// and information about the ObjectBlock which is to be created.</param> /// <returns>An ObjectBlock representing the given area.</returns> public ObjectBlock CreateAreaBlock(AreaBehaviour area) { if (area == null) { throw new ArgumentNullException("area"); } ObjectBlock block = new ObjectBlock(null, area); block.AssignImage(images); return(block); }
/// <summary> /// Creates an ObjectBlock representing a given area. /// </summary> /// <param name="area">The area to represent.</param> /// <returns>An ObjectBlock representing the given area.</returns> public ObjectBlock CreateAreaBlock(NWN2GameArea area) { if (area == null) { throw new ArgumentNullException("area"); } AreaBehaviour behaviour = CreateAreaBehaviour(area); ObjectBlock block = CreateAreaBlock(behaviour); return(block); }
public void RemoveGizmoArea(Gizmo gizmo) { if (!(gizmo is GizmoArea)) { return; } GizmoArea gizmoArea = (GizmoArea)gizmo; AreaBehaviour areaBehaviour = (AreaBehaviour)gizmoMap[gizmoArea]; Destroy(areaBehaviour.gameObject); gizmoMap.Remove(gizmoArea); }
public Image GetImage(AreaBehaviour behaviour) { Image image; if (behaviour.IsExterior) { image = GetImage("Other", "Area_Exterior"); } else { image = GetImage("Other", "Area_Interior"); } if (image == null) { image = GetImage("Placeholder", "Default"); } return(image); }
/// <summary> /// This method allows to check the condition of close area(s). /// </summary> public bool CheckAreas() { AreaBehaviour NearestArea = BuildManager.Instance.GetNearestArea(transform.position); if (NearestArea != null) { if (!NearestArea.AllowPlacement) { return(true); } else { if (NearestArea.AllowPartPlacement.Count != 0 && !NearestArea.CheckAllowedPart(this)) { return(true); } } } return(false); }
public void UpdateGizmoArea(Gizmo gizmo) { if (!(gizmo is GizmoArea)) { return; } GizmoArea gizmoArea = (GizmoArea)gizmo; AreaBehaviour areaBehaviour = (AreaBehaviour)gizmoMap[gizmoArea]; FaceRefer face = gizmoArea.face; Vector3 center = geometry.Center(); Vector3[] vectors = new Vector3[face.ids.Length]; for (int i = 0; i < face.ids.Length; i++) { vectors[i] = geometry.UnitVector(face.ids[i]); } float area = geometry.FaceArea(face.ids); areaBehaviour.SetData(center, vectors, area); }
private void OnEnable() { Target = (AreaBehaviour)target; MainEditor.LoadAddons(Target, AddOnTarget.AreaBehaviour); }
protected void TrackToolsetChanges(ToolsetEventReporter reporter) { if (!reporter.IsRunning) { reporter.Start(); } reporter.ModuleChanged += delegate(object oSender, ModuleChangedEventArgs eArgs) { /* Fires when a module closes, but that doesn't mean that the new module has * been fully opened yet... usually takes a while! */ Action action = new Action ( delegate() { if (manager != null) { manager.EmptyBag(AreasBagName); foreach (NWN2ObjectType type in Enum.GetValues(typeof(NWN2ObjectType))) { string bag = String.Format(InstanceBagNamingFormat, type); if (manager.HasBag(bag)) { manager.EmptyBag(bag); } } manager.AddMoveable("Creatures", blocks.CreatePlayerBlock()); } } ); uiThreadAccess.Dispatcher.Invoke(DispatcherPriority.Normal, action); }; reporter.InstanceAdded += delegate(object sender, InstanceEventArgs e) { if (manager == null) { return; } string bag = String.Format(InstanceBagNamingFormat, e.Instance.ObjectType.ToString()); if (!manager.HasBag(bag)) { return; } ObjectBlock block = blocks.CreateInstanceBlock(e.Instance, e.Area); manager.AddMoveable(bag, block); }; reporter.InstanceRemoved += delegate(object sender, InstanceEventArgs e) { if (manager == null || e.Instance == null) { return; } string bag = String.Format(InstanceBagNamingFormat, Nwn2ScriptSlot.GetNwn2Type(e.Instance.ObjectType)); if (!manager.HasBag(bag)) { return; } try { UIElementCollection collection = manager.GetMoveables(bag); ObjectBlock lost = blocks.CreateInstanceBlock(e.Instance, e.Area); foreach (ObjectBlock block in collection) { if (block.Equals(lost)) { manager.RemoveMoveable(bag, block); return; } } } catch (Exception) {} }; reporter.BlueprintAdded += delegate(object sender, BlueprintEventArgs e) { if (manager == null || e.Blueprint == null) { return; } if (nt.CreatedByNarrativeThreads(e.Blueprint)) { Thread thread = new Thread(new ParameterizedThreadStart(CreateNarrativeThreadsBlock)); thread.IsBackground = true; thread.Start(e.Blueprint); } if (loadBlueprints) { Action action = new Action ( delegate() { string bag = String.Format(BlueprintBagNamingFormat, e.Blueprint.ObjectType.ToString()); if (manager.HasBag(bag)) { ObjectBlock block = blocks.CreateBlueprintBlock(e.Blueprint); manager.AddMoveable(bag, block); } } ); uiThreadAccess.Dispatcher.Invoke(DispatcherPriority.Normal, action); } }; reporter.BlueprintRemoved += delegate(object sender, BlueprintEventArgs e) { if (manager == null || e.Blueprint == null) { return; } if (nt.CreatedByNarrativeThreads(e.Blueprint)) { Action action = new Action ( delegate() { string bag = String.Format(InstanceBagNamingFormat, e.Blueprint.ObjectType.ToString()); if (manager.HasBag(bag)) { ObjectBlock lost = blocks.CreateInstanceBlockFromBlueprint(e.Blueprint); ObjectBlock removing = null; foreach (ObjectBlock block in manager.GetMoveables(bag)) { if (block.Equals(lost)) { removing = block; break; } } if (removing != null) { manager.RemoveMoveable(bag, removing); } } } ); uiThreadAccess.Dispatcher.Invoke(DispatcherPriority.Normal, action); } if (loadBlueprints) { Action action = new Action ( delegate() { string bag = String.Format(BlueprintBagNamingFormat, e.Blueprint.ObjectType.ToString()); if (manager.HasBag(bag)) { ObjectBlock lost = blocks.CreateBlueprintBlock(e.Blueprint); ObjectBlock removing = null; foreach (ObjectBlock block in manager.GetMoveables(bag)) { if (block.Equals(lost)) { removing = block; break; } } if (removing != null) { manager.RemoveMoveable(bag, removing); } } } ); uiThreadAccess.Dispatcher.Invoke(DispatcherPriority.Normal, action); } }; reporter.AreaOpened += delegate(object sender, AreaEventArgs e) { if (manager == null) { return; } Thread thread = new Thread(new ParameterizedThreadStart(CreateBlocksWhenAreaIsReady)); thread.IsBackground = true; thread.Start(e.Area); }; reporter.ResourceViewerClosed += delegate(object sender, ResourceViewerClosedEventArgs e) { if (manager == null) { return; } foreach (Moveable moveable in manager.GetMoveables(AreasBagName)) { ObjectBlock block = moveable as ObjectBlock; if (block == null) { continue; } AreaBehaviour area = block.Behaviour as AreaBehaviour; if (area == null) { continue; } // Assumes that there are no conversations or scripts with the same name as an // area, but there's no immediately apparent way around this: // (TODO: Could check that module doesn't have a script or conversation of the same name.) if (area.Identifier == e.ResourceName) { manager.RemoveMoveable(AreasBagName, moveable); break; } } if (NWN2ToolsetMainForm.App.Module != null && NWN2ToolsetMainForm.App.Module.Areas.ContainsCaseInsensitive(e.ResourceName)) { // At this point we think it's an area that's been closed, so remove // any instances associated with that area: foreach (NWN2ObjectType type in Enum.GetValues(typeof(NWN2ObjectType))) { string bag = String.Format(InstanceBagNamingFormat, type); if (manager.HasBag(bag)) { List <Moveable> removing = new List <Moveable>(); foreach (Moveable moveable in manager.GetMoveables(bag)) { ObjectBlock block = moveable as ObjectBlock; if (block == null) { continue; } InstanceBehaviour instance = block.Behaviour as InstanceBehaviour; if (instance == null) { continue; } if (instance.AreaTag.ToLower() == e.ResourceName.ToLower()) { removing.Add(moveable); } } foreach (Moveable moveable in removing) { manager.RemoveMoveable(bag, moveable); } } } } }; // Ensure that an area always has the same resource name and tag: reporter.AreaNameChanged += delegate(object oObject, NameChangedEventArgs eArgs) { NWN2GameArea area = eArgs.Item as NWN2GameArea; if (area == null) { return; } string blockHasTag = area.Tag; if (area.Tag != area.Name) { area.Tag = area.Name; } OEIShared.Utils.OEIExoLocString oeiStr = Nwn2Strings.GetOEIStringFromString(area.Name); if (area.DisplayName != oeiStr) { area.DisplayName = oeiStr; } // Note that this will only work for areas that are currently open... // we'll deal with changing the name of closed areas when they open. // Update the area block, if the area is open: bool open = false; foreach (NWN2AreaViewer av in NWN2ToolsetMainForm.App.GetAllAreaViewers()) { if (av.Area == area) { open = true; break; } } if (!open) { return; } AreaBehaviour behaviour = blocks.CreateAreaBehaviour(area); if (manager.HasBag(AreasBagName)) { UIElementCollection existingBlocks = manager.GetMoveables(AreasBagName); bool updated = false; foreach (UIElement u in existingBlocks) { ObjectBlock existing = u as ObjectBlock; if (existing == null) { continue; } AreaBehaviour existingBehaviour = existing.Behaviour as AreaBehaviour; if (existingBehaviour == null) { continue; } // If you find an area with the same tag, replace its behaviour to update it: if (existingBehaviour.Tag == blockHasTag) { existing.Behaviour = behaviour; updated = true; break; } } if (!updated) { ObjectBlock block = blocks.CreateAreaBlock(behaviour); manager.AddMoveable(AreasBagName, block, false); } } }; // If a script has its name changed, change it back: reporter.ScriptNameChanged += delegate(object oObject, NameChangedEventArgs eArgs) { Thread thread = new Thread(new ParameterizedThreadStart(ReverseScriptNameChange)); thread.IsBackground = false; thread.Start(eArgs); }; }
public void UpdateBlockWithNewTag(NWN2PropertyValueChangedEventArgs e) { try { if (tracking.Contains(e.PropertyName) && e.NewValue != e.OldValue) { foreach (object o in e.ChangedObjects) { if (o is INWN2Instance) { INWN2Instance instance = (INWN2Instance)o; InstanceBehaviour behaviour = blocks.CreateInstanceBehaviour(instance); string bag = String.Format(Nwn2MoveableProvider.InstanceBagNamingFormat, instance.ObjectType); if (window.BlockBox.HasBag(bag)) { UIElementCollection existingBlocks = window.BlockBox.GetMoveables(bag); // If it's the tag that's changed, use the old tag to search, otherwise use the current one: string tag; if (e.PropertyName == "Tag") { tag = e.OldValue as string; } else { tag = ((INWN2Object)instance).Tag; } bool updated = false; foreach (UIElement u in existingBlocks) { ObjectBlock existing = u as ObjectBlock; if (existing == null) { continue; } InstanceBehaviour existingBehaviour = existing.Behaviour as InstanceBehaviour; if (existingBehaviour == null) { continue; } // If you find an instance of the same type, resref and tag, replace its behaviour to update it: if (existingBehaviour.ResRef == behaviour.ResRef && existingBehaviour.Nwn2Type == behaviour.Nwn2Type && existingBehaviour.Tag == tag) { existing.Behaviour = behaviour; updated = true; break; } } if (!updated) { ObjectBlock block = blocks.CreateInstanceBlock(behaviour); window.BlockBox.AddMoveable(bag, block, false); } } if (e.PropertyName == "Tag") { UpdateScriptsFollowingTagChange(instance, (string)e.OldValue, (string)e.NewValue, true); } } else if (o is NWN2GameArea) { NWN2GameArea area = (NWN2GameArea)o; // Refuse changes to tags or areas unless they are to match the resource name: if (e.PropertyName == "Tag" && ((string)e.NewValue) != area.Name) { area.Tag = area.Name; return; } else if (e.PropertyName == "Display Name" && (Nwn2Strings.GetStringFromOEIString((OEIShared.Utils.OEIExoLocString)e.NewValue) != area.Name)) { area.DisplayName = Nwn2Strings.GetOEIStringFromString(area.Name); return; } AreaBehaviour behaviour = blocks.CreateAreaBehaviour(area); if (window.BlockBox.HasBag(Nwn2MoveableProvider.AreasBagName)) { UIElementCollection existingBlocks = window.BlockBox.GetMoveables(Nwn2MoveableProvider.AreasBagName); string tag; if (e.PropertyName == "Tag") { tag = e.OldValue as string; } else { tag = area.Tag; } bool updated = false; foreach (UIElement u in existingBlocks) { ObjectBlock existing = u as ObjectBlock; if (existing == null) { continue; } AreaBehaviour existingBehaviour = existing.Behaviour as AreaBehaviour; if (existingBehaviour == null) { continue; } // If you find an area with the same tag, replace its behaviour to update it: if (existingBehaviour.Tag == tag) { existing.Behaviour = behaviour; updated = true; break; } } if (!updated) { ObjectBlock block = blocks.CreateAreaBlock(behaviour); window.BlockBox.AddMoveable(Nwn2MoveableProvider.AreasBagName, block, false); } } } } } } catch (Exception x) { MessageBox.Show("Something went wrong when updating a block.\n\n" + x); } }
void DoMyWindow(int windowID) { // farm /* H A R D C O D E * A * R * D * C * O * D * E */ // maak switch met 3 cases voor level description //maak switch met 3 cases voor mission description. switch (levelType) { case "Farm": //farm //farmDescription = GUI.TextArea (new Rect (50, 50, 400, 75), farmDescription, 200); GUI.Label(new Rect(50, 50, 400, 75), farmDescription); GUI.DrawTexture(new Rect(50, 210, 200, 200), farmTexture, ScaleMode.StretchToFill); break; case "Suburbs": //suburbDescription = GUI.TextArea (new Rect (50, 50, 400, 75), suburbDescription, 200); GUI.Label(new Rect(50, 50, 400, 75), suburbDescription); GUI.DrawTexture(new Rect(50, 210, 200, 200), suburbTexture, ScaleMode.StretchToFill); //Debug.Log (suburbTexture); break; case "City": //cityDescription = GUI.TextArea (new Rect (50, 50, 400, 75), cityDescription, 200); GUI.Label(new Rect(50, 50, 400, 75), cityDescription); GUI.DrawTexture(new Rect(50, 210, 200, 200), cityTexture, ScaleMode.StretchToFill); break; default: GUI.Label(new Rect(50, 50, 400, 150), defaultDescription); //draw 3 textures for each color here. GUI.DrawTexture(new Rect(50, 210, 50, 50), greenTexture, ScaleMode.StretchToFill); GUI.DrawTexture(new Rect(50, 260, 50, 50), brownTexture, ScaleMode.StretchToFill); GUI.DrawTexture(new Rect(50, 310, 50, 50), greyTexture, ScaleMode.StretchToFill); GUI.DrawTexture(new Rect(50, 360, 50, 50), redTexture, ScaleMode.StretchToFill); GUI.Label(new Rect(100, 210, 100, 50), "Green is farmlands"); GUI.Label(new Rect(100, 260, 100, 50), "Brown is suburbs"); GUI.Label(new Rect(100, 310, 100, 50), "Grey is for City"); GUI.Label(new Rect(100, 360, 100, 50), "Red means a mission has spawned"); break; } switch (missionType) { case "Defend": //defendMissionDescription = GUI.TextArea (new Rect (50, 125, 400, 75), defendMissionDescription, 200); GUI.Label(new Rect(50, 125, 400, 75), defendMissionDescription); break; case "Kill Count": //killcountMissionDescription = GUI.TextArea (new Rect (50, 125, 400, 75), killcountMissionDescription, 200); GUI.Label(new Rect(50, 125, 400, 75), killcountMissionDescription); break; case "Rescue": //rescueMissionDescription = GUI.TextArea (new Rect (50, 125, 400, 75), rescueMissionDescription, 200); GUI.Label(new Rect(50, 125, 400, 75), rescueMissionDescription); break; default: //GUI.Label (new Rect (50, 125, 400, 75), defaultDescription); break; } //teken de plattegrond //pistol GUI.DrawTexture(new Rect(275, 210, 50, 50), pistolTexture, ScaleMode.ScaleToFit); //GUI.TextField (new Rect (325, 210, 50, 50), PlayerAmmoManager.currentPistolAmmo.ToString () + " / " + PlayerAmmoManager.pistolClip.ToString ()); GUI.Label(new Rect(330, 210, 50, 50), PlayerAmmoManager.currentPistolAmmo.ToString() + " / " + PlayerAmmoManager.pistolClip.ToString()); // shotgun GUI.DrawTexture(new Rect(275, 260, 50, 50), shotgunTexture, ScaleMode.ScaleToFit); //GUI.TextField (new Rect (325, 260, 50, 50), PlayerAmmoManager.currentShotgunAmmo.ToString () + " / " + PlayerAmmoManager.shotgunClip.ToString ()); GUI.Label(new Rect(330, 260, 50, 50), PlayerAmmoManager.currentShotgunAmmo.ToString() + " / " + PlayerAmmoManager.shotgunClip.ToString()); //Machinegun GUI.DrawTexture(new Rect(275, 310, 50, 50), machinegunTexture, ScaleMode.ScaleToFit); //GUI.TextField (new Rect (325, 310, 50, 50), PlayerAmmoManager.currentMachinegunAmmo.ToString () + " / " + PlayerAmmoManager.machinegunClip.ToString ()); GUI.Label(new Rect(330, 310, 50, 50), PlayerAmmoManager.currentMachinegunAmmo.ToString() + " / " + PlayerAmmoManager.machinegunClip.ToString()); //difficulty //GUI.TextField (new Rect (325, 360, 150, 25), "Difficulty Level " + difficultyLevel.ToString()); //GUI.Button (new Rect (330, 420, 150, 25), "Start Mission"); //doet alleen iets als er op een area geklikt is oftewel niet voor de default box. if (boolPopup == true) { if (GUI.Button(new Rect(330, 420, 150, 25), "Start Mission")) { print("thankyou"); AreaBehaviour.IncreaseDifficulty(); startMission = true; } //laat de difficulty level zien van het level GUI.Label(new Rect(330, 360, 150, 25), "Difficulty Level " + difficultyLevel.ToString()); } // deze moet blijven anders verdwijnt de hele GUI op magische wijze if (GUILayout.Button(" ")) { } }