Example #1
0
        // This code dynamically discovers eligible classes and builds the menu
        // data for the various component pipeline stages.
        void UpdateStaticData()
        {
            if (sStageData != null)
            {
                return;
            }
            sStageData = new StageData[Enum.GetValues(typeof(CinemachineCore.Stage)).Length];

            var stageTypes = new List <Type> [Enum.GetValues(typeof(CinemachineCore.Stage)).Length];

            for (int i = 0; i < stageTypes.Length; ++i)
            {
                sStageData[i].Name = ((CinemachineCore.Stage)i).ToString();
                stageTypes[i]      = new List <Type>();
            }

            // Get all ICinemachineComponents
            var allTypes
                = CReflectionHelpers.GetTypesInAllLoadedAssemblies(
                      (Type t) => t.IsSubclassOf(typeof(CinemachineComponentBase)));

            // Create a temp game object so we can instance behaviours
            GameObject go = new GameObject("Cinemachine Temp Object");

            go.hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor;
            foreach (Type t in allTypes)
            {
                MonoBehaviour            b = go.AddComponent(t) as MonoBehaviour;
                CinemachineComponentBase c = b != null ? (CinemachineComponentBase)b : null;
                if (c != null)
                {
                    CinemachineCore.Stage stage = c.Stage;
                    stageTypes[(int)stage].Add(t);
                }
            }
            GameObject.DestroyImmediate(go);

            // Create the static lists
            for (int i = 0; i < stageTypes.Length; ++i)
            {
                stageTypes[i].Insert(0, null);  // first item is "none"
                sStageData[i].types = stageTypes[i].ToArray();
                GUIContent[] names = new GUIContent[sStageData[i].types.Length];
                for (int n = 0; n < names.Length; ++n)
                {
                    if (n == 0)
                    {
                        bool useSimple
                            = (i == (int)CinemachineCore.Stage.Aim) ||
                              (i == (int)CinemachineCore.Stage.Body);
                        names[n] = new GUIContent((useSimple) ? "Do nothing" : "none");
                    }
                    else
                    {
                        names[n] = new GUIContent(NicifyName(sStageData[i].types[n].Name));
                    }
                }
                sStageData[i].PopupOptions = names;
            }
        }
Example #2
0
 protected virtual void OnEnable()
 {
     if (sExtensionTypes == null)
     {
         // Populate the extension list
         List <Type>   exts  = new List <Type>();
         List <string> names = new List <string>();
         exts.Add(null);
         names.Add("(select)");
         var allExtensions
             = CReflectionHelpers.GetTypesInAllLoadedAssemblies(
                   (Type t) => t.IsSubclassOf(typeof(CinemachineExtension)));
         foreach (Type t in allExtensions)
         {
             exts.Add(t);
             names.Add(t.Name);
         }
         sExtensionTypes = exts.ToArray();
         sExtensionNames = names.ToArray();
     }
 }