-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampleCharacter.cs
More file actions
73 lines (64 loc) · 1.81 KB
/
Copy pathSampleCharacter.cs
File metadata and controls
73 lines (64 loc) · 1.81 KB
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
using System;
using System.Collections.Generic;
using RePraxis;
using UnityEngine;
public class SampleCharacter : MonoBehaviour
{
public string characterName;
public List<Relationship> relationships;
private DatabaseManager databaseManager;
void Awake()
{
databaseManager = FindFirstObjectByType<DatabaseManager>();
}
void Start()
{
databaseManager.Database.Insert( $"{characterName}" );
UpdateRelationshipsInDB( databaseManager.Database );
// databaseManager.Database.AddBeforeAccessListener(
// $"{characterName}.to", UpdateRelationshipsInDB );
}
void OnEnable()
{
// Add the listener when the gameobject is active.
databaseManager.Database.AddBeforeAccessListener(
$"{characterName}.to", UpdateRelationshipsInDB );
}
void OnDisable()
{
// Remove the listener when the gameobject is not active.
databaseManager.Database.RemoveBeforeAccessListener(
$"{characterName}.to", UpdateRelationshipsInDB );
}
void UpdateRelationshipsInDB(RePraxisDatabase database)
{
// Remove all relationship entries under the given prefix
database.Delete( $"{characterName}.to" );
// Loop through all current relationships and add their info to the database
// Example: 'Alice.to.Player.type!Friend' and 'Alice.to.Player.opinion!10'
foreach ( var r in relationships )
{
string targetName = r.target.characterName;
string relationshipType = r.relationshipType.ToString();
database.Insert( $"{characterName}.to.{targetName}.type!{relationshipType}" );
database.Insert( $"{characterName}.to.{targetName}.opinion!{r.opinion}" );
}
}
[Serializable]
public class Relationship
{
public SampleCharacter target;
public RelationshipType relationshipType;
[Range( 0, 10 )]
public int opinion;
}
public enum RelationshipType
{
None,
Acquaintance,
Friend,
Enemy,
Crush,
Lover
}
}