-
Notifications
You must be signed in to change notification settings - Fork 0
/
LabelManager2.cs
718 lines (605 loc) · 29 KB
/
LabelManager2.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public enum TLabelType { boardLabel, anchoredLabel}
public class CLabelTransform
{
public Vector3 boardPosition;
public Quaternion boardRotation;
public Vector3 anchorPosition;
}
public class CLabelData
{
public string id;
public string areaId;
public string text;
public string colour;
}
public class LabelManager2 : MonoBehaviour
{
List<GameObject> labelList; // List of all labels (visible and hiddens)
List<GameObject> hiddenLabelList; // List of hidden labels
CLabelData currentLabel; // Store the label ID during the anchor point position capture
GameObject selectedLabel; // Store the label selected
GameObject labelCanvasGO; // Label Editor Canvas
float defaultLabelDistance; // Distance to place the label by default
void Awake()
{
labelList = new List<GameObject>();
hiddenLabelList = new List<GameObject>();
currentLabel = new CLabelData();
}
/////////////////
// ADD LABEL //
/////////////////
/// <summary>
/// Add a new label of type board into the scene. The board will be draw in a default position/orientation.
/// </summary>
/// <param name="_labelId">Id assign to the board</param>
/// <param name="_text">Text to show into the board</param>
public void AddBoard(string _labelId, string _text)
{
// If the navigation edit is not available, the process to create a new label is not available
if (!hom3r.quickLinks.scriptsObject.GetComponent<ConfigurationManager>().GetActiveLabelEdition()) { return; }
// Check current state
if (hom3r.state.currentLabelMode == THom3rLabelMode.add) { return; }
if (hom3r.state.currentLabelMode == THom3rLabelMode.edit) { this.CloseEditMode(); }
// Change to Adding label mode
hom3r.state.currentLabelMode = THom3rLabelMode.add;
// Get a reference area
string _areadId = hom3r.quickLinks.scriptsObject.GetComponent<ModelManager>().GetFirstAreaId();
// Calculate initial position
CLabelTransform labelPosition = this.GetDefaultBoardTransform(_areadId);
// Start label creation
this.AddLabel(_labelId, null, TLabelType.boardLabel, _text, labelPosition);
}
/// <summary>
/// Add a new label of type board into the scene. The board will be draw in the position/orientation indicated.
/// </summary>
/// <param name="_labelId">Id assign to the board</param>
/// <param name="_text">Text to show into the board</param>
/// <param name="_boardPosition">Position in which the label will be draw</param>
/// <param name="_boardRotation">Orientation in which the label will be draw</param>
public void AddBoard(string _labelId, string _text, Vector3 _boardPosition, Quaternion _boardRotation, float _scaleFactor)
{
CLabelTransform labelPosition = new CLabelTransform();
labelPosition.boardPosition = _boardPosition;
labelPosition.boardRotation = _boardRotation;
// Get a reference area
string _areaId = hom3r.quickLinks.scriptsObject.GetComponent<ModelManager>().GetFirstAreaId();
if (_areaId == null) { return; }
// Start label show
this.AddLabel(_labelId, null, TLabelType.boardLabel, _text, labelPosition, _scaleFactor);
}
/// <summary>
/// Add a new label into the scene. The label will be draw in a default position/orientation based...
/// </summary>
/// <param name="_labelId"></param>
/// <param name="_areaId"></param>
/// <param name="_text"></param>
public void AddAnchoredLabel(string _labelId, string _areaId, string _text, string _colour)
{
// If the navigation edit is not availabled, the proccess to create a new label is not available
if (!hom3r.quickLinks.scriptsObject.GetComponent<ConfigurationManager>().GetActiveLabelEdition()) { return; }
// If the area doesn't exist, the process to create a new label is not available
if (!hom3r.quickLinks.scriptsObject.GetComponent<ModelManager>().IsArea(_areaId)) { return; };
// If the area is removed, the process to create a new label is not available
if (hom3r.quickLinks.scriptsObject.GetComponent<RemoveManager>().IsRemovedArea(_areaId)) { return; };
// Check current state
if (hom3r.state.currentLabelMode == THom3rLabelMode.add) { return; }
if (hom3r.state.currentLabelMode == THom3rLabelMode.edit) { this.CloseEditMode(); }
hom3r.state.currentLabelMode = THom3rLabelMode.add;
currentLabel.id = _labelId; // Save to use later
currentLabel.areaId = _areaId; // Save to use later
currentLabel.text = _text; // Save to use later
currentLabel.colour = _colour; // Save to use later // TODO Not implemented yet
hom3r.coreLink.Do(new CPointOnSurfaceCommand(TPointOnSurfaceCommands.StartPointCaptureSpecificArea, _areaId));
}
/// <summary>
/// Add an anchored label when we previosly known all the label data (position, orientation...)
/// </summary>
/// <param name="_labelId"></param>
/// <param name="_areaId"></param>
/// <param name="_text"></param>
/// <param name="_labelPosition"></param>
/// <param name="_anchorPosition"></param>
/// <param name="_scaleFactor"></param>
public void AddAnchoredLabel(string _labelId, string _areaId, string _text, Vector3 _labelPosition, Vector3 _anchorPosition, float _scaleFactor)
{
// If the area doesn't exist, the process to create a new label is not available
if (!hom3r.quickLinks.scriptsObject.GetComponent<ModelManager>().IsArea(_areaId)) { return; };
CLabelTransform labelTransform = new CLabelTransform();
labelTransform.boardPosition = _labelPosition;
labelTransform.anchorPosition = _anchorPosition;
this.AddLabel(_labelId, _areaId, TLabelType.anchoredLabel, _text, labelTransform, _scaleFactor);
}
public void UpdateLabelText(string _labelId, string _newText)
{
GameObject _labelToEdit = this.labelList.Find(r => r.GetComponent<Label2>().GetLabelId() == _labelId);
if (_labelToEdit != null && _newText != "")
{
_labelToEdit.GetComponent<Label2>().UpdateText(_newText);
}
}
public void AfterAnchorPointCapture(Vector3 _anchorPosition, string _areaId)
{
CLabelTransform labelPosition = this.GetDefaultPositionAnchoredLabel(_anchorPosition, _areaId);
this.AddLabel(currentLabel.id, _areaId, TLabelType.anchoredLabel, currentLabel.text, labelPosition);
}
public void AfterAnchorPointCaptureError()
{
if (this.labelList.Count == 0) {
hom3r.state.currentLabelMode = THom3rLabelMode.idle;
} else {
hom3r.state.currentLabelMode = THom3rLabelMode.show;
}
currentLabel = new CLabelData();
}
/// <summary>
/// Add label to scene
/// </summary>
/// <param name="_labelId"></param>
/// <param name="_areaId"></param>
/// <param name="_labelType"></param>
/// <param name="_text"></param>
/// <param name="_labelPosition"></param>
private void AddLabel(string _labelId, string _areaId, TLabelType _labelType, string _text, CLabelTransform _labelPosition, float _scaleFactor = 1.0f)
{
// Check if this labelID already exist
if (this.labelList.Find(r => r.GetComponent<Label2>().GetLabelId() == _labelId) != null) { return; }
// If not this label ID doesn't exit we'll create a new one
GameObject newLabelGO = null;
if (_labelType == TLabelType.boardLabel) {
newLabelGO = hom3r.coreLink.InstantiatePrefab("prefabs/Label/BoardPrefab", hom3r.quickLinks.labelsObject);
newLabelGO.transform.name = "Board_" + _labelId;
} else if (_labelType == TLabelType.anchoredLabel) {
newLabelGO = hom3r.coreLink.InstantiatePrefab("prefabs/Label/AnchoredLabelPrefab", hom3r.quickLinks.labelsObject);
newLabelGO.transform.name = "AnchoredLabel_" + _labelId;
} else
{
return;
}
// Initialize the new label
newLabelGO.GetComponent<Label2>().Create(_labelId, _areaId, _labelType, _text, _labelPosition, _scaleFactor);
labelList.Add(newLabelGO); //Add to label list
// If the area is removed, we hide the label
if ((_labelType == TLabelType.anchoredLabel) && (hom3r.quickLinks.scriptsObject.GetComponent<RemoveManager>().IsRemovedArea(_areaId))) {
this.HideLabel(newLabelGO);
}
//Update core and emit events
hom3r.state.currentLabelMode = THom3rLabelMode.show;
this.EmitLabelData(newLabelGO);
}
/// <summary>
/// Calculate a default position/rotation to emplace a board label on the scene
/// </summary>
/// <returns></returns>
private CLabelTransform GetDefaultBoardTransform(string _areaId)
{
CLabelTransform labelTransform = new CLabelTransform();
// Calculate Default Position
Bounds _3DObjectBounds = hom3r.quickLinks.scriptsObject.GetComponent<ModelManager>().Get3DModelBoundingBox();
Vector3 defaultPosition = Vector3.zero;
float pos = Mathf.Sqrt(MathHom3r.Pow2(_3DObjectBounds.extents.z) + MathHom3r.Pow2(_3DObjectBounds.extents.x));
defaultPosition.z = (-1.0f) * pos;
defaultPosition.x = (+1.0f) * pos;
// Transform to local position
GameObject areaGO = hom3r.quickLinks.scriptsObject.GetComponent<ModelManager>().GetAreaGameObject_ByAreaID(_areaId);
Vector3 boardLocalPosition = areaGO.transform.InverseTransformPoint(defaultPosition);
// Store board position
labelTransform.boardPosition = boardLocalPosition;
// Calculate Default Rotation
Vector3 direction = labelTransform.boardPosition - Camera.main.transform.position;
direction = direction.normalized; //Desired direction, looking to the camera
Quaternion globalBoardRotation = Quaternion.LookRotation(direction, Vector3.up);
// Save Rotation
labelTransform.boardRotation = globalBoardRotation;
// TODO maybe we should save the forward vector of the 3DProduct model
return labelTransform;
}
/// <summary>
///
/// </summary>
/// <param name="_areaId"></param>
/// <returns></returns>
private CLabelTransform GetDefaultPositionAnchoredLabel(Vector3 _anchorLocalPosition, string _areaId)
{
CLabelTransform labelTransform = new CLabelTransform();
// Save ANCHOR Local Position
labelTransform.anchorPosition = _anchorLocalPosition;
// Calculate ANCHOR Global position (world coordinates based on the areaID received)
GameObject areaGO = hom3r.quickLinks.scriptsObject.GetComponent<ModelManager>().GetAreaGameObject_ByAreaID(_areaId);
Vector3 anchorGlobalPosition = areaGO.transform.TransformPoint(_anchorLocalPosition);
// Calculate POLE origin
Vector3 poleOrigin = CalculatePoleOriginPosition(anchorGlobalPosition);
// Calculate POLE end
Vector3 poleEnd = CalculatePoleEndPosition(anchorGlobalPosition, poleOrigin);
// Transform to local position
Vector3 boardLocalPosition = areaGO.transform.InverseTransformPoint(poleEnd);
// Store board position
labelTransform.boardPosition = boardLocalPosition;
//Store default label distance to use it when restrinting the label movement
defaultLabelDistance = Vector3.Distance(_anchorLocalPosition, boardLocalPosition);
return labelTransform;
}
/// <summary>
/// Calculate the pole origin, based on the anchor position and object geometry
/// </summary>
/// <param name="anchorPosition"></param>
/// <returns></returns>
private Vector3 CalculatePoleOriginPosition(Vector3 anchorPosition)
{
Bounds modelBoundingBox = hom3r.quickLinks.scriptsObject.GetComponent<ModelManager>().Get3DModelBoundingBox();
Vector3 cuttingPointWithAxis;
float a;
if (modelBoundingBox.size.x > modelBoundingBox.size.y)
{
///////////////////////
// horizontal object //
///////////////////////
//Move to centre in order to do the calculations, because the bounding box could not be centred in origin (0,0)
anchorPosition = anchorPosition - modelBoundingBox.center;
//Projection to the XZ plane
float x0 = anchorPosition.x;
float z0 = Mathf.Sqrt(MathHom3r.Pow2(anchorPosition.y) + MathHom3r.Pow2(anchorPosition.z));
//Calculate the ellipse on the plane XZ
a = modelBoundingBox.size.x * 0.5f; // We fix a of the ellipse to object size in x axis
float aPow2 = MathHom3r.Pow2(a);
float bPow2 = (aPow2 * MathHom3r.Pow2(z0)) / (aPow2 - MathHom3r.Pow2(x0));
//To avoid very flat ellipse, this happens when x0 ~= a --> b ~= 0
if (bPow2 < 10.0f)
{
//Calculate the ellipse fixing b to object size in z axis
float b = modelBoundingBox.size.z * 0.5f;
bPow2 = MathHom3r.Pow2(b);
aPow2 = (bPow2 * MathHom3r.Pow2(x0)) / (bPow2 - MathHom3r.Pow2(z0));
}
//Cutting Point with the X axis
cuttingPointWithAxis.x = (x0 * (1 - (bPow2 / aPow2)));
cuttingPointWithAxis.y = 0.0f;
cuttingPointWithAxis.z = 0.0f;
//Move back to its original position, because the bounding box could not be centred in origin (0,0)
cuttingPointWithAxis = cuttingPointWithAxis + modelBoundingBox.center;
}
else
{
///////////////////////
// vertical object //
///////////////////////
//Move to centre in order to do the calculations, because the bounding box could not be centred in origin (0,0)
anchorPosition = anchorPosition - modelBoundingBox.center;
//Projection to the YZ plane
float y0 = anchorPosition.y;
float z0 = Mathf.Sqrt(MathHom3r.Pow2(anchorPosition.x) + MathHom3r.Pow2(anchorPosition.z));
//Calculate the ellipse on the plane YZ
a = modelBoundingBox.size.y * 0.5f; // We fix a of the ellipse to object size in y axis
float aPow2 = MathHom3r.Pow2(a);
float bPow2 = (aPow2 * MathHom3r.Pow2(z0)) / (aPow2 - MathHom3r.Pow2(y0));
//To avoid very flat ellipse, this happens when y0 ~= a --> b ~= 0
if (bPow2 < 10.0f)
{
//Calculate the ellipse fixing b to object size in z axis
float b = modelBoundingBox.size.z * 0.5f;
bPow2 = MathHom3r.Pow2(b);
aPow2 = (bPow2 * MathHom3r.Pow2(y0)) / (bPow2 - MathHom3r.Pow2(z0));
}
//Cutting Point with the Y axis
cuttingPointWithAxis.x = 0.0f;
cuttingPointWithAxis.y = (y0 * (1 - (bPow2 / aPow2)));
cuttingPointWithAxis.z = 0.0f;
//Move back to its original position, because the bounding box could not be centred in origin (0,0)
cuttingPointWithAxis = cuttingPointWithAxis + modelBoundingBox.center;
}
return cuttingPointWithAxis;
}
/// <summary>
/// Calculate the pole end position, based on anchor, pole origin and object dimensions
/// </summary>
/// <param name="_anchorPosition"></param>
/// <param name="_poleOrigin"></param>
/// <returns></returns>
private Vector3 CalculatePoleEndPosition(Vector3 _anchorPosition, Vector3 _poleOrigin)
{
// Set direction of pole
Vector3 poleDirection = _anchorPosition - _poleOrigin;
poleDirection.Normalize();
// Set pole lengh
float poleLength = hom3r.quickLinks.scriptsObject.GetComponent<ModelManager>().CalculateDiagonalBoundingBox();
poleLength = 0.2f * poleLength;
//Set pole end position acording to the lengh and the direction
Vector3 poleEnd = _anchorPosition + poleDirection * poleLength;
return poleEnd;
}
/////////////////
// EDIT LABEL //
/////////////////
/// <summary>
/// Start to edit a new label
/// </summary>
/// <param name="_newPanelToEdit">Pointer to the label object to edit</param>
public void StartEditLabel(GameObject _newPanelToEdit)
{
// Get pointer to selected label
GameObject _newSelectedLabel = _newPanelToEdit.transform.parent.parent.gameObject;
// Check that everything is OK
if (!hom3r.quickLinks.scriptsObject.GetComponent<ConfigurationManager>().GetActiveLabelEdition()) { return; }
if (_newSelectedLabel == null) { return; }
if (_newPanelToEdit.transform.parent.gameObject.name != "Board") { return; }
//Start selection process
if (hom3r.state.currentLabelMode == THom3rLabelMode.show)
{
// Currently we are no editing any label
hom3r.state.currentLabelMode = THom3rLabelMode.edit;
labelCanvasGO = InstantiateLabelEditorCanvas(); // Show canvas
this.selectedLabel = _newSelectedLabel; // Save selected label
}
else if ((hom3r.state.currentLabelMode == THom3rLabelMode.edit) && this.selectedLabel != _newSelectedLabel)
{
// We have change the selected label
this.selectedLabel.GetComponent<Label2>().SelectLabel(false); // Change label state to NO-selected state
this.selectedLabel = _newSelectedLabel; // Save NEW selected label
}
this.UpdateCanvasSliders(this.selectedLabel.GetComponent<Label2>().GetLabelType());
this.selectedLabel.GetComponent<Label2>().SelectLabel(true); // Change label state to selected state
this.selectedLabel.GetComponent<Label2>().StartMovingLabel(); // Change label state to moving
//Block selection
hom3r.coreLink.Do(new CSelectionCommand(TSelectionCommands.BlockSelection, true));
}
/// <summary>
/// Finish label drag gesture
/// </summary>
public void StopDragLabelLabel()
{
if (this.selectedLabel == null) { return; }
this.selectedLabel.GetComponent<Label2>().StopMovingLabel(); // Change label state
this.EmitLabelData();
//Unblock selection
hom3r.coreLink.Do(new CSelectionCommand(TSelectionCommands.BlockSelection, false));
}
/// <summary>
/// Execute label drag movements based. The real movement of the label will depend of
/// camera position and object size on the screen
/// </summary>
/// <param name="dragMovementX">Label movement in X axis </param>
/// <param name="dragMovementY">Label movement in Y axis</param>
public void DragLabel(float dragMovementX, float dragMovementY)
{
if (hom3r.state.currentLabelMode != THom3rLabelMode.edit) { return; }
this.selectedLabel.GetComponent<Label2>().UpdateBoardPosition(dragMovementX, dragMovementY);
}
public void UpdateAnchoredLabelsOrientation()
{
foreach (GameObject label in labelList)
{
if (label.GetComponent<Label2>().GetLabelType() == TLabelType.anchoredLabel)
{
label.GetComponent<Label2>().UpdateOrientation();
}
}
}
public void UpdateAnchoredLabelsOrientationAndPole()
{
foreach (GameObject label in labelList)
{
if (label.GetComponent<Label2>().GetLabelType() == TLabelType.anchoredLabel)
{
label.GetComponent<Label2>().UpdateOrientation();
label.GetComponent<Label2>().UpdatePolePosition();
}
}
}
private void CloseEditMode()
{
selectedLabel.GetComponent<Label2>().SelectLabel(false);
Destroy(labelCanvasGO);
selectedLabel = null;
hom3r.state.currentLabelMode = THom3rLabelMode.show;
hom3r.state.navigationBlocked = false;
StartCoroutine(UnBlockSelectionWitDelay(0.1f));
}
IEnumerator UnBlockSelectionWitDelay(float _delay)
{
yield return new WaitForSeconds(_delay);
hom3r.state.selectionBlocked = false;
}
///////////////////
// CANVAS ///
//////////////////
/// <summary>
///
/// </summary>
/// <returns></returns>
private GameObject InstantiateLabelEditorCanvas()
{
GameObject tempGO = hom3r.coreLink.InstantiatePrefab("prefabs/Label/LabelEditorCanvasPrefab", hom3r.quickLinks.uiObject);
tempGO.transform.Find("Panel_LabelEditor").gameObject.transform.Find("SliderRotation").gameObject.GetComponent<Slider>().onValueChanged.AddListener(OnChangeLabelEditorSliderRotation);
tempGO.transform.Find("Panel_LabelEditor").gameObject.transform.Find("SliderScale").gameObject.GetComponent<Slider>().onValueChanged.AddListener(OnChangeLabelEditorSliderScale);
tempGO.transform.Find("Panel_LabelEditor").gameObject.transform.Find("ImageClose").gameObject.GetComponent<Button>().onClick.AddListener(OnClickLabelCloseButton);
//tempGO.transform.Find("Panel_LabelEditor").gameObject.GetComponent<EventTrigger>().OnPointerEnter(OnPointerEnterEvent);
// Add event to POINTER ENTER
EventTrigger.Entry entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.PointerEnter;
entry.callback.AddListener((data) => { OnPointerEnterDelegate((PointerEventData)data); });
tempGO.transform.Find("Panel_LabelEditor").gameObject.GetComponent<EventTrigger>().triggers.Add(entry);
// Add event to POINTER Exit
EventTrigger.Entry entry2 = new EventTrigger.Entry();
entry2.eventID = EventTriggerType.PointerExit;
entry2.callback.AddListener((data) => { OnPointerExitDelegate((PointerEventData)data); });
tempGO.transform.Find("Panel_LabelEditor").gameObject.GetComponent<EventTrigger>().triggers.Add(entry2);
return tempGO;
}
private void OnChangeLabelEditorSliderRotation(float value)
{
selectedLabel.GetComponent<Label2>().UpdateBoardOrientation(value);
this.EmitLabelData();
}
private void OnChangeLabelEditorSliderScale(float value)
{
selectedLabel.GetComponent<Label2>().UpdateBoardScale(value);
this.EmitLabelData();
}
private void OnClickLabelCloseButton()
{
this.CloseEditMode();
}
public void OnPointerEnterDelegate(PointerEventData data)
{
hom3r.state.navigationBlocked = true;
hom3r.state.selectionBlocked = true;
}
public void OnPointerExitDelegate(PointerEventData data)
{
hom3r.state.navigationBlocked = false;
hom3r.state.selectionBlocked = false;
}
private void UpdateCanvasSliders(TLabelType _labelType)
{
this.UpdateCanvasRotationSlider(_labelType);
this.UpdateCanvasScaleSlider();
}
private void UpdateCanvasRotationSlider(TLabelType _labelType)
{
GameObject canvasRotationSlider = labelCanvasGO.transform.Find("Panel_LabelEditor").gameObject.transform.Find("SliderRotation").gameObject;
if (_labelType == TLabelType.boardLabel)
{
canvasRotationSlider.SetActive(true);
canvasRotationSlider.GetComponent<Slider>().value = this.selectedLabel.GetComponent<Label2>().GetLabelTransform().boardRotation.eulerAngles.y;
} else
{
canvasRotationSlider.SetActive(false);
}
}
private void UpdateCanvasScaleSlider()
{
GameObject canvasScaleSlider = labelCanvasGO.transform.Find("Panel_LabelEditor").gameObject.transform.Find("SliderScale").gameObject;
canvasScaleSlider.GetComponent<Slider>().value = this.selectedLabel.GetComponent<Label2>().GetScaleFactor();
}
///////////////////
// REMOVE LABEL //
///////////////////
/// <summary>
/// Remove one label from the scene
/// </summary>
/// <param name="_labelId"></param>
public void RemoveLabel(string _labelId)
{
GameObject labelToRemove = this.labelList.Find(r => r.GetComponent<Label2>().GetLabelId() == _labelId);
if (labelToRemove != null)
{
// Close label edition to avoid conflicts, just in case
if (this.selectedLabel) { this.CloseEditMode(); }
// Remove Label
Destroy(labelToRemove);
this.labelList.Remove(labelToRemove);
}
// Update hom3r mode
if (this.labelList.Count == 0) { hom3r.state.currentLabelMode = THom3rLabelMode.idle; }
}
/// <summary>
/// Remove all the labels from the scene
/// </summary>
public void RemoveAllBoardLabel()
{
//
List<GameObject> listLabelToRemove = this.labelList.FindAll(r => r.GetComponent<Label2>().GetLabelType() == TLabelType.boardLabel);
if (listLabelToRemove != null)
{
// Close label edition to avoid conflicts, just in case
if (this.selectedLabel) { this.CloseEditMode(); }
foreach (GameObject labelToRemove in listLabelToRemove)
{
// Remove Label
Destroy(labelToRemove);
this.labelList.Remove(labelToRemove);
}
}
// Update hom3r mode
if (this.labelList.Count == 0) { hom3r.state.currentLabelMode = THom3rLabelMode.idle; }
}
/// <summary>
/// Remove all the labels from the scene
/// </summary>
public void RemoveAllLabels()
{
// Close label edition to avoid conflicts, just in case
if (this.selectedLabel) { this.CloseEditMode(); }
// Remove labels
foreach (GameObject label in this.labelList)
{
Destroy(label);
}
this.labelList.Clear();
this.hiddenLabelList.Clear();
// Update hom3r mode
hom3r.state.currentLabelMode = THom3rLabelMode.idle;
}
////////////////////
// HIDE LABELS //
////////////////////
public void CheckIfAreThereAnyLabelToHide(string _areaID)
{
List<GameObject> listLabelToHide = this.labelList.FindAll(r => r.GetComponent<Label2>().GetAreaId() == _areaID);
if (listLabelToHide != null)
{
foreach (GameObject _label in listLabelToHide)
{
this.HideLabel(_label);
}
}
}
private void HideLabel(GameObject _label)
{
hiddenLabelList.Add(_label);
_label.SetActive(false);
}
public void CheckIfAreThereAnyHiddenLabelToShow(string _areaID)
{
List<GameObject> listOfHiddenLabelToShow = this.hiddenLabelList.FindAll(r => r.GetComponent<Label2>().GetAreaId() == _areaID);
if (listOfHiddenLabelToShow != null)
{
foreach (GameObject _label in listOfHiddenLabelToShow)
{
this.ShowHiddenLabel(_label);
}
}
}
private void ShowHiddenLabel(GameObject _label)
{
hiddenLabelList.Remove(_label);
_label.SetActive(true);
}
/////////////////
// OTHERS //
/////////////////
/// <summary>
/// Emit label transform after to rest of the hom3r
/// </summary>
private void EmitLabelData()
{
if (this.selectedLabel == null) { return; }
this.EmitLabelData(this.selectedLabel);
}
/// <summary>
/// Emit an event when a label is created or edited
/// </summary>
/// <param name="labelGO"></param>
private void EmitLabelData(GameObject labelGO)
{
string labelId = labelGO.GetComponent<Label2>().GetLabelId();
TLabelType labelType = labelGO.GetComponent<Label2>().GetLabelType();
CLabelTransform labelTransform = labelGO.GetComponent<Label2>().GetLabelLocalTransform();
float scaleFactor = labelGO.GetComponent<Label2>().GetScaleFactor();
string areaId = labelGO.GetComponent<Label2>().GetAreaId();
if (labelType == TLabelType.boardLabel)
{
// labelID, boardPosition, boardRotation, scaleFactor
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.LabelManager_LabelDataUpdated, labelId, labelType, labelTransform.boardPosition, labelTransform.boardRotation, scaleFactor));
} else if (labelType == TLabelType.anchoredLabel)
{
// labelID, boardPosition, anchorPosition, scaleFactor
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.LabelManager_LabelDataUpdated, labelId, areaId, labelType, labelTransform.boardPosition, labelTransform.anchorPosition, scaleFactor));
}
}
}