This repository has been archived by the owner on Nov 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmotionsController.cs
74 lines (64 loc) · 2.45 KB
/
EmotionsController.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EmotionsController
{
private Hashtable controllers;
private IEmotion angryEmotion;
private IEmotion happyEmotion;
private IEmotion surpriseEmotion;
public EmotionsController(Hashtable controllers)
{
if (controllers == null)
{
throw new System.Exception("You must provide a controllers");
}
this.controllers = controllers;
this.angryEmotion = new AngryEmotion(controllers);
this.happyEmotion = new HappyEmotion(controllers);
this.surpriseEmotion = new SurpriseEmotion(controllers);
}
public void Reset()
{
foreach (DictionaryEntry controller in this.controllers)
{
GameObject obj = (GameObject) controller.Value;
obj.transform.localPosition = new Vector3(0, 0, 0);
}
}
public EmotionsDistribution Randomize(IEmotion mainEmotion, float mainEmotionMinIntensity, float mainEmotionMaxIntensity)
{
EmotionsDistribution distribution = new EmotionsDistribution();
List<IEmotion> emotionsPool = this.GetPool();
IEmotion emotion;
float mainEmotionIntensity = Random.Range(mainEmotionMinIntensity, mainEmotionMaxIntensity);
int index = emotionsPool.FindIndex(e => e.GetType() == mainEmotion.GetType());
emotion = emotionsPool[index];
emotionsPool.RemoveAt(index);
emotion.Apply(mainEmotionIntensity);
distribution.SetDistribution(emotion, mainEmotionIntensity);
float remainingIntensity = 1 - mainEmotionIntensity;
while (emotionsPool.Count > 1)
{
index = Random.Range(0, emotionsPool.Count);
emotion = emotionsPool[index];
emotionsPool.RemoveAt(index);
float intensity = Random.Range(0.0f, remainingIntensity);
emotion.Apply(intensity);
distribution.SetDistribution(emotion, intensity);
remainingIntensity = remainingIntensity - intensity;
}
emotion = emotionsPool[0];
emotion.Apply(remainingIntensity);
distribution.SetDistribution(emotion, remainingIntensity);
return distribution;
}
public List<IEmotion> GetPool()
{
List<IEmotion> pool = new List<IEmotion>();
pool.Add(this.angryEmotion);
pool.Add(this.happyEmotion);
pool.Add(this.surpriseEmotion);
return pool;
}
}