/// <summary>
    /// Makes a shadow, which is a hierarchy of GameObjects
    /// that matches the hierarchy given by root. It only
    /// contains the transform hierarchy and an animation
    /// component, nothing else!
    /// </summary>
    /// <param name="originalRoot">Root of the hierarchy to be shadowed</param>
    /// <param name="controller">The controller being assigned this shadow</param>
    /// <returns></returns>
    public Shadow(
        Transform originalRoot,
        Transform originalHips,
        ShadowController controller)
    {
        if (originalRoot.animation == null)
        {
            throw new System.ArgumentException(
                      "Component to be shadowed must have animation component",
                      "originalRoot");
        }

        this.controller = controller;
        this.quickFind  = new Dictionary <string, Transform>();

        // Incorporate both ignored bones and ignored non-bone transforms
        HashSet <string> ignores = new HashSet <string>(controller.ignoreBones);

        ignores.UnionWith(controller.Coordinator.NonBoneTransformsSet);

        this._rootObject = CloneHierarchy(originalRoot, ignores, quickFind);
        this._rootHips   = quickFind[originalHips.name];

        // Add the ShadowGizmo
        ShadowGizmo sg = this._rootObject.AddComponent <ShadowGizmo>();

        sg.parentController = controller;

        // Add animations in original GameObject to the shadow.
        // TODO: Allow shadow controllers to be more choosy about what
        //       animations get copied over, and make the animation
        //       component itself optional. - AS
        this._rootObject.AddComponent <Animation>();
        foreach (AnimationState aState in originalRoot.animation)
        {
            this._rootObject.animation.AddClip(aState.clip, aState.name);
        }
        this._rootObject.animation.playAutomatically = false;

        // The shadow should always animate, despite not being rendered
        // TODO: Adjust this as per LOD. - AS
        this._rootObject.animation.cullingType =
            AnimationCullingType.AlwaysAnimate;

        // Set the name based on what's being cloned
        string name = controller.GetType().ToString();

        this._rootObject.name += " (Shadow: " + name + ")";
    }
    public void RegisterController(ShadowController controller)
    {
        if (this.shadowControllers == null)
            this.shadowControllers = new Dictionary<string, ShadowController>();

        if (this.boneKeys == null)
            this.InitBoneKeys();

        string name = controller.GetType().ToString();
        this.shadowControllers[name] = controller;
        controller.shadow = new Shadow(this.transform, controller);

        // The controller is now ready to wake up
        controller.ControlledAwake();
    }
Beispiel #3
0
    public void RegisterController(ShadowController controller)
    {
        if (this.shadowControllers == null)
        {
            this.shadowControllers = new Dictionary <string, ShadowController>();
        }

        if (this.boneKeys == null)
        {
            this.InitBoneKeys();
        }

        string name = controller.GetType().ToString();

        this.shadowControllers[name] = controller;
        controller.shadow            = new Shadow(this.transform, this.hips, controller);

        // The controller is now ready to wake up
        controller.ControlledAwake();
    }
Beispiel #4
0
    /// <summary>
    /// Makes a shadow, which is a hierarchy of GameObjects
    /// that matches the hierarchy given by root. It only
    /// contains the transform hierarchy and an animation 
    /// component, nothing else! 
    /// </summary>
    /// <param name="originalRoot">Root of the hierarchy to be shadowed</param>
    /// <param name="controller">The controller being assigned this shadow</param>
    /// <returns></returns>
    public Shadow(
        Transform originalRoot,
        ShadowController controller)
    {
        if (originalRoot.animation == null)
            throw new System.ArgumentException(
                "Component to be shadowed must have animation component",
                "originalRoot");

        this.controller = controller;
        this.quickFind = new Dictionary<string, Transform>();
        this._rootObject = CloneHierarchy(
            originalRoot,
            new HashSet<string>(controller.ignoreTransforms),
            quickFind);

        // Add the ShadowGizmo
        ShadowGizmo sg = this._rootObject.AddComponent<ShadowGizmo>();
        sg.parentController = controller;

        // Add animations in original GameObject to the shadow.
        // TODO: Allow shadow controllers to be more choosy about what
        //       animations get copied over, and make the animation
        //       component itself optional. - AS
        this._rootObject.AddComponent<Animation>();
        foreach (AnimationState aState in originalRoot.animation)
            this._rootObject.animation.AddClip(aState.clip, aState.name);
        this._rootObject.animation.playAutomatically = false;

        // The shadow should always animate, despite not being rendered
        // TODO: Adjust this as per LOD. - AS
        this._rootObject.animation.cullingType =
            AnimationCullingType.AlwaysAnimate;

        // Set the name based on what's being cloned
        string name = controller.GetType().ToString();
        this._rootObject.name += " (Shadow: " + name + ")";
    }