forked from JPLRepo/ResearchBodies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RBInstructor.cs
123 lines (115 loc) · 5.42 KB
/
RBInstructor.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
/*
* (C) Copyright 2016, Jamie Leighton
* Original code by KSP forum User simon56modder.
* License : MIT
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Original code was developed by
* Kerbal Space Program is Copyright (C) 2013 Squad. See http://kerbalspaceprogram.com/. This
* project is in no way associated with nor endorsed by Squad.
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace ResearchBodies
{
/// <summary>
/// Instructor: Wernher Von Kerman, prefab: Instructor_Wernher
/// anim_idle
/// anim_idle_lookAround
/// anim_idle_sigh
/// anim_idle_wonder
/// anim_true_thumbUp
/// anim_true_thumbsUp
/// anim_true_nodA
/// anim_true_nodB
/// anim_true_smileA
/// anim_true_smileB
/// anim_false_disappointed
/// anim_false_disagreeA
/// anim_false_disagreeB
/// anim_false_disagreeC
/// anim_false_sadA
/// </summary>
public class ResearchBodiesInstructor
{
#region InstructorVariables
private KerbalInstructor _instructor;
public KerbalInstructor Instructor { get { return _instructor; } }
private RenderTexture _portrait;
public RenderTexture Portrait { get { return _portrait; } }
private Dictionary<GUIContent, CharacterAnimationState> _responses;
private const int PortraitWidth = 128;
private System.Random random = new System.Random();
public string InstructorName = "";
#endregion
#region Instructor Functions
public ResearchBodiesInstructor(string instructorName)
{
GameObject prefab = AssetBase.GetPrefab(instructorName);
if (prefab == null)
throw new ArgumentException("Could not find instructor named '" + instructorName + "'");
if (instructorName == "Instructor_Wernher")
{
InstructorName = KSP.Localization.Localizer.Format("#autoLOC_RBodies_00102");
}
else if(instructorName == "Strategy_ScienceGuy")
{
InstructorName = KSP.Localization.Localizer.Format("#autoLOC_501659");
}
GameObject prefabInstance = UnityEngine.Object.Instantiate(prefab);
_instructor = prefabInstance.GetComponent<KerbalInstructor>();
_portrait = new RenderTexture(PortraitWidth, PortraitWidth, 8);
_instructor.instructorCamera.targetTexture = _portrait;
_responses = _instructor.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)
.Where(fi => fi.FieldType == typeof(CharacterAnimationState))
.Where(fi => fi.GetValue(_instructor) != null)
.ToDictionary(fi => new GUIContent(fi.Name), fi => fi.GetValue(_instructor) as CharacterAnimationState);
}
public void Destroy()
{
if (_portrait != null)
_portrait.Release();
}
public void PlayEmote(int emote)
{
_instructor.PlayEmote(_responses[_responses.Keys.ToArray()[emote]]);
}
public void PlayOKEmote()
{
int rand = random.Next(4);
if (rand == 1)
_instructor.PlayEmote(_responses[_responses.Keys.ToArray()[2]]);
else if (rand == 2)
_instructor.PlayEmote(_responses[_responses.Keys.ToArray()[6]]);
else
_instructor.PlayEmote(_responses[_responses.Keys.ToArray()[7]]);
}
public void PlayNiceEmote()
{
int rand = random.Next(3);
if (rand == 1)
_instructor.PlayEmote(_responses[_responses.Keys.ToArray()[4]]);
else
_instructor.PlayEmote(_responses[_responses.Keys.ToArray()[5]]);
}
public void PlayBadEmote()
{
int rand = random.Next(5);
if (rand == 1)
_instructor.PlayEmote(_responses[_responses.Keys.ToArray()[11]]);
else if (rand == 2)
_instructor.PlayEmote(_responses[_responses.Keys.ToArray()[12]]);
else if (rand == 3)
_instructor.PlayEmote(_responses[_responses.Keys.ToArray()[13]]);
else
_instructor.PlayEmote(_responses[_responses.Keys.ToArray()[14]]);
}
#endregion
}
}