Forum rules - please read before posting.

Switching Expression Portraits

2»

Comments

  • I get this error however:

    Assets/Sleepytime Village/Scripts/CursorUtils.cs(10,62): error CS0103: The name 'Pointer' does not exist in the current context

    This is path to .png:
    Assets/Sleepytime Village/UI/Cursor/Village Cursors/Pointer.png

  • This is my code:

    AC.KickStarter.cursorManager.pointerIcon.ReplaceTexture (Pointer.png);

  • Also,how do i change the cursor manager to UI? Mine only lists software and hardware?

  • The name 'Pointer' does not exist in the current context

    You are attempting to texture's filename as a function parameter - this is not possible. You must create a public Texture2D variable outside of the function that can be assigned in the Inspector. See my earlier example.

    how do i change the cursor manager to UI?

    Update to the latest release.

  • So I’m ignoring the object:call action now and just dropping the texture into my prefab with script on? I don’t Really get it sorry. Especially as there are quite a few examples in this thread. Thanks
  • edited September 2021

    Also, will you have a Cursor UI tutorial soon, to show its advantages etc?

  • PS I have cursor swap sorted now! Thanks!

  • SO, I have a custom action script that changes Default Portrait Graphics, and expressions, however, it only changes the expression Index and not the Default Portrait Graphic - any ideas?

    /*
    *
    * Adventure Creator
    * by Chris Burton, 2013-2021
    *
    * "ActionTemplate.cs"
    *
    * This is a blank action template.
    *
    */

    using UnityEngine;
    using System.Collections.Generic;

    if UNITY_EDITOR

    using UnityEditor;

    endif

    namespace AC
    {
    [System.Serializable]
    public class ChangeExpressionsAction : Action
    {

        // Declare properties here
        public override ActionCategory Category { get { return ActionCategory.Custom; } }
        public override string Title { get { return "Switch Expression Textures"; } }
        public override string Description { get { return "This switches the expression textures"; } }
    
        // Declare variables here
        public AC.Char _myCharacter;
        public int _expressionIndex;
        public Texture2D _newExpressionTexture;
        public Texture2D _newPortraitIcon;
    
        public override float Run()
        {
            /* 
             * This function is called when the action is performed.
             * 
             * The float to return is the time that the game
             * should wait before moving on to the next action.
             * Return 0f to make the action instantenous.
             * 
             * For actions that take longer than one frame,
             * you can return "defaultPauseTime" to make the game
             * re-run this function a short time later. You can
             * use the isRunning boolean to check if the action is
             * being run for the first time, eg: 
             */
            int numExpressions = _myCharacter.expressions.Count;
            if( numExpressions == 0)
            {
                Debug.LogError("Trying to change expression on character without expressions");
            }
            if (_myCharacter != null && _newExpressionTexture != null && _expressionIndex>=0 && _expressionIndex < numExpressions )
            {
                _myCharacter.portraitIcon.ReplaceTexture(_newPortraitIcon);
                _myCharacter.expressions[_expressionIndex].portraitIcon.ReplaceTexture( _newExpressionTexture );
            }
    
            if (!isRunning)
            {
                isRunning = true;
                return defaultPauseTime;
            }
            else
            {
                isRunning = false;
                return 0f;
            }
        }
    
    
        public override void Skip()
        {
            /*
             * This function is called when the Action is skipped, as a
             * result of the player invoking the "EndCutscene" input.
             * 
             * It should perform the instructions of the Action instantly -
             * regardless of whether or not the Action itself has been run
             * normally yet.  If this method is left blank, then skipping
             * the Action will have no effect.  If this method is removed,
             * or if the Run() method call is left below, then skipping the
             * Action will cause it to run itself as normal.
             */
    
            Run();
        }
    

    if UNITY_EDITOR

        public override void ShowGUI()
        {
            // Action-specific Inspector GUI code here
            _newExpressionTexture = (Texture2D)EditorGUILayout.ObjectField("New Texture:", _newExpressionTexture, typeof(Texture2D), true);
            _expressionIndex = EditorGUILayout.IntField( _expressionIndex );
            _myCharacter = (AC.Char)EditorGUILayout.ObjectField("Character:", _myCharacter, typeof(AC.Char), true);
            _newPortraitIcon = (Texture2D)EditorGUILayout.ObjectField("New Portrait:", _newPortraitIcon, typeof(Texture2D), true);
        }
    
    
        public override string SetLabel()
        {
            // (Optional) Return a string used to describe the specific action's job.
    
            return string.Empty;
        }
    

    endif

    }
    

    }

  • Your code only updates the portrait icon if the expression index is valid. Move it outside to make it independent:

    using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ChangeExpressionsAction : Action
        {
    
            public override ActionCategory Category { get { return ActionCategory.Custom; } }
            public override string Title { get { return "Switch Expression Textures"; } }
            public override string Description { get { return "This switches the expression textures"; } }
    
    
            public AC.Char _myCharacter;
            public int _expressionIndex;
            public Texture2D _newExpressionTexture;
            public Texture2D _newPortraitIcon;
    
    
            public override float Run()
            {
                int numExpressions = _myCharacter.expressions.Count;
                if (numExpressions == 0)
                {
                    Debug.LogError("Trying to change expression on character without expressions");
                }
    
                if (_newPortraitIcon != null)
                {
                    _myCharacter.portraitIcon.ReplaceTexture (_newPortraitIcon);
                }
                if (_myCharacter != null && _newExpressionTexture != null && _expressionIndex >= 0 && _expressionIndex < numExpressions)
                {
                    _myCharacter.expressions[_expressionIndex].portraitIcon.ReplaceTexture (_newExpressionTexture );
                }
    
                return 0f;
            }
    
    
            public override void Skip ()
            {
                Run ();
            }
    
    
            #if UNITY_EDITOR
    
            public override void ShowGUI ()
            {
                _newExpressionTexture = (Texture2D) EditorGUILayout.ObjectField ("New Texture:", _newExpressionTexture, typeof (Texture2D), true);
                _expressionIndex = EditorGUILayout.IntField (_expressionIndex );
                _myCharacter = (AC.Char) EditorGUILayout.ObjectField ("Character:", _myCharacter, typeof (AC.Char), true);
                _newPortraitIcon = (Texture2D) EditorGUILayout.ObjectField ("New Portrait:", _newPortraitIcon, typeof (Texture2D), true);
            }
    
            #endif
    
        }
    
    }
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.